From 68b30eeba459cf013fc9c9a14768b51433fa031d Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Fri, 29 May 2020 17:38:12 -0500 Subject: [PATCH 01/44] MC-31618: Move static config to files - PLUGIN_LIST --- app/etc/di.xml | 10 + .../Interception/PluginList/PluginList.php | 36 +- .../Console/Command/DiCompileCommand.php | 1 + .../Task/Operation/PluginListGenerator.php | 403 ++++++++++++++++++ .../Module/Di/App/Task/OperationFactory.php | 6 + 5 files changed, 444 insertions(+), 12 deletions(-) create mode 100644 setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php diff --git a/app/etc/di.xml b/app/etc/di.xml index 7b91941fe05d6..920265193f152 100644 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -430,6 +430,16 @@ + + + Magento\Framework\App\Cache\Type\Config + Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy + plugin-list + + global + + + Magento\Framework\App\ResourceConnection\ConnectionFactory diff --git a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php index bf1372dc007a1..6661bdc3c8aa2 100644 --- a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php +++ b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php @@ -5,6 +5,7 @@ */ namespace Magento\Framework\Interception\PluginList; +use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Config\CacheInterface; use Magento\Framework\Config\Data\Scoped; use Magento\Framework\Config\ReaderInterface; @@ -285,23 +286,34 @@ protected function _loadScopedData() $this->_scopePriorityScheme[] = $scope; } $cacheId = implode('|', $this->_scopePriorityScheme) . "|" . $this->_cacheId; - $data = $this->_cache->load($cacheId); - if ($data) { - list($this->_data, $this->_inherited, $this->_processed) = $this->serializer->unserialize($data); + $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + $directoryList = $objectManager->get(DirectoryList::class); + $file = $directoryList->getPath(DirectoryList::GENERATED_METADATA) . '/' . $cacheId . '.' . 'php'; + if (file_exists($file)) { + $data = include $file; + list($this->_data, $this->_inherited, $this->_processed) = $data; foreach ($this->_scopePriorityScheme as $scopeCode) { $this->_loadedScopes[$scopeCode] = true; } } else { - foreach ($this->_loadScopedVirtualTypes() as $class) { - $this->_inheritPlugins($class); - } - foreach ($this->getClassDefinitions() as $class) { - $this->_inheritPlugins($class); + $data = $this->_cache->load($cacheId); + if ($data) { + list($this->_data, $this->_inherited, $this->_processed) = $this->serializer->unserialize($data); + foreach ($this->_scopePriorityScheme as $scopeCode) { + $this->_loadedScopes[$scopeCode] = true; + } + } else { + foreach ($this->_loadScopedVirtualTypes() as $class) { + $this->_inheritPlugins($class); + } + foreach ($this->getClassDefinitions() as $class) { + $this->_inheritPlugins($class); + } + $this->_cache->save( + $this->serializer->serialize([$this->_data, $this->_inherited, $this->_processed]), + $cacheId + ); } - $this->_cache->save( - $this->serializer->serialize([$this->_data, $this->_inherited, $this->_processed]), - $cacheId - ); } $this->_pluginInstances = []; } diff --git a/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php b/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php index 56a4a85b17d99..cfd5da0d6b7ef 100644 --- a/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php @@ -400,6 +400,7 @@ private function getOperationsConfiguration( $compiledPathsList['generated_helpers'], ], OperationFactory::APPLICATION_ACTION_LIST_GENERATOR => [], + OperationFactory::PLUGIN_LIST_GENERATOR => [], ]; return $operations; diff --git a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php new file mode 100644 index 0000000000000..fa0443cf72c64 --- /dev/null +++ b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php @@ -0,0 +1,403 @@ +reader = $reader; + $this->scopeConfig = $scopeConfig; + $this->omConfig = $omConfig; + $this->relations = $relations; + $this->definitions = $definitions; + $this->classDefinitions = $classDefinitions; + $this->logger = $logger; + $this->cache = $cache; + $this->_scopePriorityScheme = $scopePriorityScheme; + $this->configWriter = $configWriter; + } + + /** + * @inheritDoc + */ + public function doOperation() + { + $scopes = $this->scopeConfig->getAllScopes(); + array_shift($scopes); + + foreach ($scopes as $scope) { + $this->scopeConfig->setCurrentScope($scope); + if (false === isset($this->_loadedScopes[$scope])) { + if (false === in_array($scope, $this->_scopePriorityScheme)) { + $this->_scopePriorityScheme[] = $scope; + } + $cacheId = implode('|', $this->_scopePriorityScheme) . "|" . $this->_cacheId; + + foreach ($this->_loadScopedVirtualTypes() as $class) { + $this->_inheritPlugins($class); + } + foreach ($this->_data as $className => $value) { + $this->_inheritPlugins($className); + } + foreach ($this->getClassDefinitions() as $class) { + $this->_inheritPlugins($class); + } + $this->configWriter->write( + $cacheId, + [$this->_data, $this->_inherited, $this->_processed] + ); + + if (count($this->_scopePriorityScheme) > 1 ) { + array_pop($this->_scopePriorityScheme); + $this->_data = null; + } + $this->_pluginInstances = []; + } + } + } + + /** + * @inheritDoc + */ + public function getName() + { + return 'Plugin list generation'; + } + + /** + * Load virtual types for current scope + * + * @return array + */ + private function _loadScopedVirtualTypes() + { + $virtualTypes = []; + foreach ($this->_scopePriorityScheme as $scopeCode) { + if (!isset($this->_loadedScopes[$scopeCode])) { + $data = $this->reader->read($scopeCode) ?: []; + unset($data['preferences']); + if (count($data) > 0) { + $this->_inherited = []; + $this->_processed = []; + $this->merge($data); + foreach ($data as $class => $config) { + if (isset($config['type'])) { + $virtualTypes[] = $class; + } + } + } + $this->_loadedScopes[$scopeCode] = true; + } + if ($this->isCurrentScope($scopeCode)) { + break; + } + } + return $virtualTypes; + } + + /** + * Returns class definitions + * + * @return array + */ + private function getClassDefinitions() + { + return $this->classDefinitions->getClasses(); + } + + /** + * Whether scope code is current scope code + * + * @param string $scopeCode + * @return bool + */ + private function isCurrentScope($scopeCode) + { + return $this->scopeConfig->getCurrentScope() === $scopeCode; + } + + /** + * Collect parent types configuration for requested type + * + * @param string $type + * @return array + * @throws \InvalidArgumentException + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings(PHPMD.NPathComplexity) + */ + private function _inheritPlugins($type) + { + $type = ltrim($type, '\\'); + if (!isset($this->_inherited[$type])) { + $realType = $this->omConfig->getOriginalInstanceType($type); + + if ($realType !== $type) { + $plugins = $this->_inheritPlugins($realType); + } elseif ($this->relations->has($type)) { + $relations = $this->relations->getParents($type); + $plugins = []; + foreach ($relations as $relation) { + if ($relation) { + $relationPlugins = $this->_inheritPlugins($relation); + if ($relationPlugins) { + $plugins = array_replace_recursive($plugins, $relationPlugins); + } + } + } + } else { + $plugins = []; + } + if (isset($this->_data[$type])) { + if (!$plugins) { + $plugins = $this->_data[$type]; + } else { + $plugins = array_replace_recursive($plugins, $this->_data[$type]); + } + } + $this->_inherited[$type] = null; + if (is_array($plugins) && count($plugins)) { + $this->filterPlugins($plugins); + uasort($plugins, [$this, '_sort']); + $this->trimInstanceStartingBackslash($plugins); + $this->_inherited[$type] = $plugins; + $lastPerMethod = []; + foreach ($plugins as $key => $plugin) { + // skip disabled plugins + if (isset($plugin['disabled']) && $plugin['disabled']) { + unset($plugins[$key]); + continue; + } + $pluginType = $this->omConfig->getOriginalInstanceType($plugin['instance']); + if (!class_exists($pluginType)) { + throw new \InvalidArgumentException('Plugin class ' . $pluginType . ' doesn\'t exist'); + } + foreach ($this->definitions->getMethodList($pluginType) as $pluginMethod => $methodTypes) { + $current = isset($lastPerMethod[$pluginMethod]) ? $lastPerMethod[$pluginMethod] : '__self'; + $currentKey = $type . '_' . $pluginMethod . '_' . $current; + if ($methodTypes & DefinitionInterface::LISTENER_AROUND) { + $this->_processed[$currentKey][DefinitionInterface::LISTENER_AROUND] = $key; + $lastPerMethod[$pluginMethod] = $key; + } + if ($methodTypes & DefinitionInterface::LISTENER_BEFORE) { + $this->_processed[$currentKey][DefinitionInterface::LISTENER_BEFORE][] = $key; + } + if ($methodTypes & DefinitionInterface::LISTENER_AFTER) { + $this->_processed[$currentKey][DefinitionInterface::LISTENER_AFTER][] = $key; + } + } + } + } + return $plugins; + } + return $this->_inherited[$type]; + } + + /** + * Trims starting backslash from plugin instance name + * + * @param array $plugins + * @return void + */ + private function trimInstanceStartingBackslash(&$plugins) + { + foreach ($plugins as &$plugin) { + $plugin['instance'] = ltrim($plugin['instance'], '\\'); + } + } + + /** + * Remove from list not existing plugins + * + * @param array $plugins + * @return void + */ + private function filterPlugins(array &$plugins) + { + foreach ($plugins as $name => $plugin) { + if (empty($plugin['instance'])) { + unset($plugins[$name]); + $this->logger->info("Reference to undeclared plugin with name '{$name}'."); + } + } + } + + /** + * Merge configuration + * + * @param array $config + * @return void + */ + private function merge(array $config) + { + foreach ($config as $type => $typeConfig) { + if (isset($typeConfig['plugins'])) { + $type = ltrim($type, '\\'); + if (isset($this->_data[$type])) { + $this->_data[$type] = array_replace_recursive($this->_data[$type], $typeConfig['plugins']); + } else { + $this->_data[$type] = $typeConfig['plugins']; + } + } + } + } + + /** + * Sort items + * + * @param array $itemA + * @param array $itemB + * @return int + */ + private function _sort($itemA, $itemB) + { + if (isset($itemA['sortOrder'])) { + if (isset($itemB['sortOrder'])) { + return $itemA['sortOrder'] - $itemB['sortOrder']; + } + return $itemA['sortOrder']; + } elseif (isset($itemB['sortOrder'])) { + return (0 - (int)$itemB['sortOrder']); + } else { + return 0; + } + } + +} diff --git a/setup/src/Magento/Setup/Module/Di/App/Task/OperationFactory.php b/setup/src/Magento/Setup/Module/Di/App/Task/OperationFactory.php index 607790e41421c..cd6bf213f8027 100644 --- a/setup/src/Magento/Setup/Module/Di/App/Task/OperationFactory.php +++ b/setup/src/Magento/Setup/Module/Di/App/Task/OperationFactory.php @@ -58,6 +58,11 @@ class OperationFactory */ const APPLICATION_ACTION_LIST_GENERATOR = 'application_action_list_generator'; + /** + * Plugin list generator + */ + const PLUGIN_LIST_GENERATOR = 'plugin_list_generator'; + /** * Operations definitions * @@ -73,6 +78,7 @@ class OperationFactory self::REPOSITORY_GENERATOR => \Magento\Setup\Module\Di\App\Task\Operation\RepositoryGenerator::class, self::PROXY_GENERATOR => \Magento\Setup\Module\Di\App\Task\Operation\ProxyGenerator::class, self::APPLICATION_ACTION_LIST_GENERATOR => AppActionListGenerator::class, + self::PLUGIN_LIST_GENERATOR => PluginListGenerator::class, ]; /** From 822d48d6d586c867e963a82ca9f158cb567e0d57 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Tue, 2 Jun 2020 21:51:57 -0500 Subject: [PATCH 02/44] MC-31618: Move static config to files - PLUGIN_LIST - Merge global plugins data to other scopes by default; --- .../Di/App/Task/Operation/PluginListGenerator.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php index fa0443cf72c64..4d334aa06bcaa 100644 --- a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php +++ b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php @@ -104,6 +104,11 @@ class PluginListGenerator implements OperationInterface */ private $_data; + /** + * @var array + */ + private $globalScopePluginData = []; + /** * @var array */ @@ -180,14 +185,17 @@ public function doOperation() foreach ($this->getClassDefinitions() as $class) { $this->_inheritPlugins($class); } + if ($scope === 'global') { + $this->globalScopePluginData = $this->_data; + } $this->configWriter->write( $cacheId, [$this->_data, $this->_inherited, $this->_processed] ); - if (count($this->_scopePriorityScheme) > 1 ) { array_pop($this->_scopePriorityScheme); - $this->_data = null; + // merge global scope plugin data to other scopes by default + $this->_data = $this->globalScopePluginData; } $this->_pluginInstances = []; } From a498f14fab8c7d02851987c6d7f9ab9d549e43eb Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Wed, 3 Jun 2020 23:16:51 -0500 Subject: [PATCH 03/44] MC-31618: Move static config to files - PLUGIN_LIST - Remove redundant variables; --- app/etc/di.xml | 2 - .../Interception/PluginList/PluginList.php | 10 +- .../Task/Operation/PluginListGenerator.php | 111 ++++++++---------- 3 files changed, 52 insertions(+), 71 deletions(-) diff --git a/app/etc/di.xml b/app/etc/di.xml index 920265193f152..14b87b5c2b0b0 100644 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -432,9 +432,7 @@ - Magento\Framework\App\Cache\Type\Config Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy - plugin-list global diff --git a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php index 6661bdc3c8aa2..3446a9b33f4f2 100644 --- a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php +++ b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php @@ -281,8 +281,8 @@ public function getNext($type, $method, $code = '__self') protected function _loadScopedData() { $scope = $this->_configScope->getCurrentScope(); - if (false == isset($this->_loadedScopes[$scope])) { - if (false == in_array($scope, $this->_scopePriorityScheme)) { + if (false === isset($this->_loadedScopes[$scope])) { + if (false === in_array($scope, $this->_scopePriorityScheme, true)) { $this->_scopePriorityScheme[] = $scope; } $cacheId = implode('|', $this->_scopePriorityScheme) . "|" . $this->_cacheId; @@ -291,14 +291,14 @@ protected function _loadScopedData() $file = $directoryList->getPath(DirectoryList::GENERATED_METADATA) . '/' . $cacheId . '.' . 'php'; if (file_exists($file)) { $data = include $file; - list($this->_data, $this->_inherited, $this->_processed) = $data; + [$this->_data, $this->_inherited, $this->_processed] = $data; foreach ($this->_scopePriorityScheme as $scopeCode) { $this->_loadedScopes[$scopeCode] = true; } } else { $data = $this->_cache->load($cacheId); if ($data) { - list($this->_data, $this->_inherited, $this->_processed) = $this->serializer->unserialize($data); + [$this->_data, $this->_inherited, $this->_processed] = $this->serializer->unserialize($data); foreach ($this->_scopePriorityScheme as $scopeCode) { $this->_loadedScopes[$scopeCode] = true; } @@ -358,7 +358,7 @@ private function _loadScopedVirtualTypes() */ protected function isCurrentScope($scopeCode) { - return $this->_configScope->getCurrentScope() == $scopeCode; + return $this->_configScope->getCurrentScope() === $scopeCode; } /** diff --git a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php index 4d334aa06bcaa..10023cd107102 100644 --- a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php +++ b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php @@ -13,7 +13,6 @@ use Magento\Framework\ObjectManager\DefinitionInterface as ClassDefinitions; use Magento\Framework\ObjectManager\RelationsInterface; use Magento\Setup\Module\Di\App\Task\OperationInterface; -use Magento\Framework\Config\CacheInterface; use Psr\Log\LoggerInterface; /** @@ -33,33 +32,26 @@ class PluginListGenerator implements OperationInterface */ private $reader; - /** - * Configuration cache - * - * @var CacheInterface - */ - protected $cache; - /** * Cache tag * * @var string */ - protected $_cacheId = 'plugin-list'; + private $cacheId = 'plugin-list'; /** * Scope priority loading scheme * * @var string[] */ - protected $_scopePriorityScheme = []; + private $scopePriorityScheme; /** * Loaded scopes * * @var array */ - protected $_loadedScopes = []; + private $loadedScopes = []; /** * Type config @@ -102,7 +94,7 @@ class PluginListGenerator implements OperationInterface /** * @var array */ - private $_data; + private $pluginData; /** * @var array @@ -112,17 +104,12 @@ class PluginListGenerator implements OperationInterface /** * @var array */ - private $_inherited = []; + private $inherited = []; /** * @var array */ - private $_processed; - - /** - * @var array - */ - protected $_pluginInstances = []; + private $processed; /** * @param ReaderInterface $reader @@ -132,7 +119,6 @@ class PluginListGenerator implements OperationInterface * @param DefinitionInterface $definitions * @param ClassDefinitions $classDefinitions * @param LoggerInterface $logger - * @param CacheInterface $cache * @param ConfigWriterInterface $configWriter * @param array $scopePriorityScheme */ @@ -144,7 +130,6 @@ public function __construct( DefinitionInterface $definitions, ClassDefinitions $classDefinitions, LoggerInterface $logger, - CacheInterface $cache, ConfigWriterInterface $configWriter, array $scopePriorityScheme = ['global'] ) { @@ -155,8 +140,7 @@ public function __construct( $this->definitions = $definitions; $this->classDefinitions = $classDefinitions; $this->logger = $logger; - $this->cache = $cache; - $this->_scopePriorityScheme = $scopePriorityScheme; + $this->scopePriorityScheme = $scopePriorityScheme; $this->configWriter = $configWriter; } @@ -166,38 +150,38 @@ public function __construct( public function doOperation() { $scopes = $this->scopeConfig->getAllScopes(); + // remove primary scope for production mode array_shift($scopes); foreach ($scopes as $scope) { $this->scopeConfig->setCurrentScope($scope); - if (false === isset($this->_loadedScopes[$scope])) { - if (false === in_array($scope, $this->_scopePriorityScheme)) { - $this->_scopePriorityScheme[] = $scope; + if (false === isset($this->loadedScopes[$scope])) { + if (false === in_array($scope, $this->scopePriorityScheme, true)) { + $this->scopePriorityScheme[] = $scope; } - $cacheId = implode('|', $this->_scopePriorityScheme) . "|" . $this->_cacheId; + $cacheId = implode('|', $this->scopePriorityScheme) . "|" . $this->cacheId; - foreach ($this->_loadScopedVirtualTypes() as $class) { - $this->_inheritPlugins($class); + foreach ($this->loadScopedVirtualTypes() as $class) { + $this->inheritPlugins($class); } - foreach ($this->_data as $className => $value) { - $this->_inheritPlugins($className); + foreach ($this->pluginData as $className => $value) { + $this->inheritPlugins($className); } foreach ($this->getClassDefinitions() as $class) { - $this->_inheritPlugins($class); + $this->inheritPlugins($class); } if ($scope === 'global') { - $this->globalScopePluginData = $this->_data; + $this->globalScopePluginData = $this->pluginData; } $this->configWriter->write( $cacheId, - [$this->_data, $this->_inherited, $this->_processed] + [$this->pluginData, $this->inherited, $this->processed] ); - if (count($this->_scopePriorityScheme) > 1 ) { - array_pop($this->_scopePriorityScheme); + if (count($this->scopePriorityScheme) > 1) { + array_pop($this->scopePriorityScheme); // merge global scope plugin data to other scopes by default - $this->_data = $this->globalScopePluginData; + $this->pluginData = $this->globalScopePluginData; } - $this->_pluginInstances = []; } } } @@ -215,16 +199,16 @@ public function getName() * * @return array */ - private function _loadScopedVirtualTypes() + private function loadScopedVirtualTypes() { $virtualTypes = []; - foreach ($this->_scopePriorityScheme as $scopeCode) { - if (!isset($this->_loadedScopes[$scopeCode])) { + foreach ($this->scopePriorityScheme as $scopeCode) { + if (!isset($this->loadedScopes[$scopeCode])) { $data = $this->reader->read($scopeCode) ?: []; unset($data['preferences']); if (count($data) > 0) { - $this->_inherited = []; - $this->_processed = []; + $this->inherited = []; + $this->processed = []; $this->merge($data); foreach ($data as $class => $config) { if (isset($config['type'])) { @@ -232,7 +216,7 @@ private function _loadScopedVirtualTypes() } } } - $this->_loadedScopes[$scopeCode] = true; + $this->loadedScopes[$scopeCode] = true; } if ($this->isCurrentScope($scopeCode)) { break; @@ -271,20 +255,20 @@ private function isCurrentScope($scopeCode) * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - private function _inheritPlugins($type) + private function inheritPlugins($type) { $type = ltrim($type, '\\'); - if (!isset($this->_inherited[$type])) { + if (!isset($this->inherited[$type])) { $realType = $this->omConfig->getOriginalInstanceType($type); if ($realType !== $type) { - $plugins = $this->_inheritPlugins($realType); + $plugins = $this->inheritPlugins($realType); } elseif ($this->relations->has($type)) { $relations = $this->relations->getParents($type); $plugins = []; foreach ($relations as $relation) { if ($relation) { - $relationPlugins = $this->_inheritPlugins($relation); + $relationPlugins = $this->inheritPlugins($relation); if ($relationPlugins) { $plugins = array_replace_recursive($plugins, $relationPlugins); } @@ -293,19 +277,19 @@ private function _inheritPlugins($type) } else { $plugins = []; } - if (isset($this->_data[$type])) { + if (isset($this->pluginData[$type])) { if (!$plugins) { - $plugins = $this->_data[$type]; + $plugins = $this->pluginData[$type]; } else { - $plugins = array_replace_recursive($plugins, $this->_data[$type]); + $plugins = array_replace_recursive($plugins, $this->pluginData[$type]); } } - $this->_inherited[$type] = null; + $this->inherited[$type] = null; if (is_array($plugins) && count($plugins)) { $this->filterPlugins($plugins); - uasort($plugins, [$this, '_sort']); + uasort($plugins, [$this, 'sort']); $this->trimInstanceStartingBackslash($plugins); - $this->_inherited[$type] = $plugins; + $this->inherited[$type] = $plugins; $lastPerMethod = []; foreach ($plugins as $key => $plugin) { // skip disabled plugins @@ -318,24 +302,24 @@ private function _inheritPlugins($type) throw new \InvalidArgumentException('Plugin class ' . $pluginType . ' doesn\'t exist'); } foreach ($this->definitions->getMethodList($pluginType) as $pluginMethod => $methodTypes) { - $current = isset($lastPerMethod[$pluginMethod]) ? $lastPerMethod[$pluginMethod] : '__self'; + $current = $lastPerMethod[$pluginMethod] ?? '__self'; $currentKey = $type . '_' . $pluginMethod . '_' . $current; if ($methodTypes & DefinitionInterface::LISTENER_AROUND) { - $this->_processed[$currentKey][DefinitionInterface::LISTENER_AROUND] = $key; + $this->processed[$currentKey][DefinitionInterface::LISTENER_AROUND] = $key; $lastPerMethod[$pluginMethod] = $key; } if ($methodTypes & DefinitionInterface::LISTENER_BEFORE) { - $this->_processed[$currentKey][DefinitionInterface::LISTENER_BEFORE][] = $key; + $this->processed[$currentKey][DefinitionInterface::LISTENER_BEFORE][] = $key; } if ($methodTypes & DefinitionInterface::LISTENER_AFTER) { - $this->_processed[$currentKey][DefinitionInterface::LISTENER_AFTER][] = $key; + $this->processed[$currentKey][DefinitionInterface::LISTENER_AFTER][] = $key; } } } } return $plugins; } - return $this->_inherited[$type]; + return $this->inherited[$type]; } /** @@ -378,10 +362,10 @@ private function merge(array $config) foreach ($config as $type => $typeConfig) { if (isset($typeConfig['plugins'])) { $type = ltrim($type, '\\'); - if (isset($this->_data[$type])) { - $this->_data[$type] = array_replace_recursive($this->_data[$type], $typeConfig['plugins']); + if (isset($this->pluginData[$type])) { + $this->pluginData[$type] = array_replace_recursive($this->pluginData[$type], $typeConfig['plugins']); } else { - $this->_data[$type] = $typeConfig['plugins']; + $this->pluginData[$type] = $typeConfig['plugins']; } } } @@ -394,7 +378,7 @@ private function merge(array $config) * @param array $itemB * @return int */ - private function _sort($itemA, $itemB) + private function sort($itemA, $itemB) { if (isset($itemA['sortOrder'])) { if (isset($itemB['sortOrder'])) { @@ -407,5 +391,4 @@ private function _sort($itemA, $itemB) return 0; } } - } From 06f21adaf7d289c94f0a065fcf521f53c5c298f9 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Wed, 10 Jun 2020 00:34:49 -0500 Subject: [PATCH 04/44] MC-31618: Move static config to files - PLUGIN_LIST - Introduce new interfaces for config load and write; --- app/etc/di.xml | 4 +- .../Framework/Interception/ConfigLoader.php | 39 ++ .../Interception/ConfigLoaderInterface.php | 20 + .../Framework/Interception/ConfigWriter.php | 374 ++++++++++++++++++ .../Interception/ConfigWriterInterface.php | 20 + .../Interception/PluginList/PluginList.php | 38 +- .../Task/Operation/PluginListGenerator.php | 346 +--------------- 7 files changed, 478 insertions(+), 363 deletions(-) create mode 100644 lib/internal/Magento/Framework/Interception/ConfigLoader.php create mode 100644 lib/internal/Magento/Framework/Interception/ConfigLoaderInterface.php create mode 100644 lib/internal/Magento/Framework/Interception/ConfigWriter.php create mode 100644 lib/internal/Magento/Framework/Interception/ConfigWriterInterface.php diff --git a/app/etc/di.xml b/app/etc/di.xml index 14b87b5c2b0b0..c90cc493a4357 100644 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -209,6 +209,8 @@ + + @@ -430,7 +432,7 @@ - + Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy diff --git a/lib/internal/Magento/Framework/Interception/ConfigLoader.php b/lib/internal/Magento/Framework/Interception/ConfigLoader.php new file mode 100644 index 0000000000000..6772f981c542d --- /dev/null +++ b/lib/internal/Magento/Framework/Interception/ConfigLoader.php @@ -0,0 +1,39 @@ +directoryList = $directoryList; + } + + /** + * @inheritDoc + */ + public function load($cacheId) + { + $file = $this->directoryList->getPath(DirectoryList::GENERATED_METADATA) . '/' . $cacheId . '.' . 'php'; + if (file_exists($file)) { + return include $file; + } + + return []; + } +} diff --git a/lib/internal/Magento/Framework/Interception/ConfigLoaderInterface.php b/lib/internal/Magento/Framework/Interception/ConfigLoaderInterface.php new file mode 100644 index 0000000000000..23d6a36aa633b --- /dev/null +++ b/lib/internal/Magento/Framework/Interception/ConfigLoaderInterface.php @@ -0,0 +1,20 @@ +reader = $reader; + $this->scopeConfig = $scopeConfig; + $this->omConfig = $omConfig; + $this->relations = $relations; + $this->definitions = $definitions; + $this->classDefinitions = $classDefinitions; + $this->logger = $logger; + $this->configWriter = $configWriter; + $this->scopePriorityScheme = $scopePriorityScheme; + } + + /** + * @inheritDoc + */ + public function write($scopes) + { + foreach ($scopes as $scope) { + $this->scopeConfig->setCurrentScope($scope); + if (false === isset($this->loadedScopes[$scope])) { + if (false === in_array($scope, $this->scopePriorityScheme, true)) { + $this->scopePriorityScheme[] = $scope; + } + $cacheId = implode('|', $this->scopePriorityScheme) . "|" . $this->cacheId; + foreach ($this->loadScopedVirtualTypes() as $class) { + $this->inheritPlugins($class); + } + foreach ($this->pluginData as $className => $value) { + $this->inheritPlugins($className); + } + foreach ($this->getClassDefinitions() as $class) { + $this->inheritPlugins($class); + } + $this->configWriter->write( + $cacheId, + [$this->pluginData, $this->inherited, $this->processed] + ); + // need global scope plugin data for non global scopes + if ($scope === 'global') { + $this->globalScopePluginData = $this->pluginData; + } + if (count($this->scopePriorityScheme) > 1) { + array_pop($this->scopePriorityScheme); + // merge global scope plugin data to other scopes by default + $this->pluginData = $this->globalScopePluginData; + } + } + } + } + + /** + * Load virtual types for current scope + * + * @return array + */ + private function loadScopedVirtualTypes() + { + $virtualTypes = []; + foreach ($this->scopePriorityScheme as $scopeCode) { + if (!isset($this->loadedScopes[$scopeCode])) { + $data = $this->reader->read($scopeCode) ?: []; + unset($data['preferences']); + if (count($data) > 0) { + $this->inherited = []; + $this->processed = []; + $this->merge($data); + foreach ($data as $class => $config) { + if (isset($config['type'])) { + $virtualTypes[] = $class; + } + } + } + $this->loadedScopes[$scopeCode] = true; + } + if ($this->isCurrentScope($scopeCode)) { + break; + } + } + return $virtualTypes; + } + + /** + * Returns class definitions + * + * @return array + */ + private function getClassDefinitions() + { + return $this->classDefinitions->getClasses(); + } + + /** + * Whether scope code is current scope code + * + * @param string $scopeCode + * @return bool + */ + private function isCurrentScope($scopeCode) + { + return $this->scopeConfig->getCurrentScope() === $scopeCode; + } + + /** + * Collect parent types configuration for requested type + * + * @param string $type + * @return array + * @throws \InvalidArgumentException + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings(PHPMD.NPathComplexity) + */ + private function inheritPlugins($type) + { + $type = ltrim($type, '\\'); + if (!isset($this->inherited[$type])) { + $realType = $this->omConfig->getOriginalInstanceType($type); + + if ($realType !== $type) { + $plugins = $this->inheritPlugins($realType); + } elseif ($this->relations->has($type)) { + $relations = $this->relations->getParents($type); + $plugins = []; + foreach ($relations as $relation) { + if ($relation) { + $relationPlugins = $this->inheritPlugins($relation); + if ($relationPlugins) { + $plugins = array_replace_recursive($plugins, $relationPlugins); + } + } + } + } else { + $plugins = []; + } + if (isset($this->pluginData[$type])) { + if (!$plugins) { + $plugins = $this->pluginData[$type]; + } else { + $plugins = array_replace_recursive($plugins, $this->pluginData[$type]); + } + } + $this->inherited[$type] = null; + if (is_array($plugins) && count($plugins)) { + $this->filterPlugins($plugins); + uasort($plugins, [$this, 'sort']); + $this->trimInstanceStartingBackslash($plugins); + $this->inherited[$type] = $plugins; + $lastPerMethod = []; + foreach ($plugins as $key => $plugin) { + // skip disabled plugins + if (isset($plugin['disabled']) && $plugin['disabled']) { + unset($plugins[$key]); + continue; + } + $pluginType = $this->omConfig->getOriginalInstanceType($plugin['instance']); + if (!class_exists($pluginType)) { + throw new \InvalidArgumentException('Plugin class ' . $pluginType . ' doesn\'t exist'); + } + foreach ($this->definitions->getMethodList($pluginType) as $pluginMethod => $methodTypes) { + $current = $lastPerMethod[$pluginMethod] ?? '__self'; + $currentKey = $type . '_' . $pluginMethod . '_' . $current; + if ($methodTypes & DefinitionInterface::LISTENER_AROUND) { + $this->processed[$currentKey][DefinitionInterface::LISTENER_AROUND] = $key; + $lastPerMethod[$pluginMethod] = $key; + } + if ($methodTypes & DefinitionInterface::LISTENER_BEFORE) { + $this->processed[$currentKey][DefinitionInterface::LISTENER_BEFORE][] = $key; + } + if ($methodTypes & DefinitionInterface::LISTENER_AFTER) { + $this->processed[$currentKey][DefinitionInterface::LISTENER_AFTER][] = $key; + } + } + } + } + return $plugins; + } + return $this->inherited[$type]; + } + + /** + * Trims starting backslash from plugin instance name + * + * @param array $plugins + * @return void + */ + private function trimInstanceStartingBackslash(&$plugins) + { + foreach ($plugins as &$plugin) { + $plugin['instance'] = ltrim($plugin['instance'], '\\'); + } + } + + /** + * Remove from list not existing plugins + * + * @param array $plugins + * @return void + */ + private function filterPlugins(array &$plugins) + { + foreach ($plugins as $name => $plugin) { + if (empty($plugin['instance'])) { + unset($plugins[$name]); + $this->logger->info("Reference to undeclared plugin with name '{$name}'."); + } + } + } + + /** + * Merge configuration + * + * @param array $config + * @return void + */ + private function merge(array $config) + { + foreach ($config as $type => $typeConfig) { + if (isset($typeConfig['plugins'])) { + $type = ltrim($type, '\\'); + if (isset($this->pluginData[$type])) { + $this->pluginData[$type] = array_replace_recursive( + $this->pluginData[$type], + $typeConfig['plugins'] + ); + } else { + $this->pluginData[$type] = $typeConfig['plugins']; + } + } + } + } + + /** + * Sort items + * + * @param array $itemA + * @param array $itemB + * @return int + */ + private function sort($itemA, $itemB) + { + return ($itemA['sortOrder'] ?? PHP_INT_MIN) - ($itemB['sortOrder'] ?? PHP_INT_MIN); + } +} diff --git a/lib/internal/Magento/Framework/Interception/ConfigWriterInterface.php b/lib/internal/Magento/Framework/Interception/ConfigWriterInterface.php new file mode 100644 index 0000000000000..79f891ccbb3f1 --- /dev/null +++ b/lib/internal/Magento/Framework/Interception/ConfigWriterInterface.php @@ -0,0 +1,20 @@ +serializer = $serializer ?: $objectManager->get(Serialize::class); parent::__construct($reader, $configScope, $cache, $cacheId, $this->serializer); @@ -125,6 +133,7 @@ public function __construct( $this->_classDefinitions = $classDefinitions; $this->_scopePriorityScheme = $scopePriorityScheme; $this->_objectManager = $objectManager; + $this->configLoader = $configLoader ?: ObjectManager::getInstance()->get(ConfigLoader::class); } /** @@ -225,16 +234,7 @@ private function trimInstanceStartingBackslash(&$plugins) */ protected function _sort($itemA, $itemB) { - if (isset($itemA['sortOrder'])) { - if (isset($itemB['sortOrder'])) { - return $itemA['sortOrder'] - $itemB['sortOrder']; - } - return $itemA['sortOrder']; - } elseif (isset($itemB['sortOrder'])) { - return (0 - (int)$itemB['sortOrder']); - } else { - return 0; - } + return ($itemA['sortOrder'] ?? PHP_INT_MIN) - ($itemB['sortOrder'] ?? PHP_INT_MIN); } /** @@ -286,15 +286,11 @@ protected function _loadScopedData() $this->_scopePriorityScheme[] = $scope; } $cacheId = implode('|', $this->_scopePriorityScheme) . "|" . $this->_cacheId; - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); - $directoryList = $objectManager->get(DirectoryList::class); - $file = $directoryList->getPath(DirectoryList::GENERATED_METADATA) . '/' . $cacheId . '.' . 'php'; - if (file_exists($file)) { - $data = include $file; - [$this->_data, $this->_inherited, $this->_processed] = $data; - foreach ($this->_scopePriorityScheme as $scopeCode) { - $this->_loadedScopes[$scopeCode] = true; - } + $configData = $this->configLoader->load($cacheId); + + if ($configData) { + [$this->_data, $this->_inherited, $this->_processed] = $configData; + $this->_loadedScopes[$scope] = true; } else { $data = $this->_cache->load($cacheId); if ($data) { diff --git a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php index 10023cd107102..54fad36b5ed45 100644 --- a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php +++ b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php @@ -5,18 +5,12 @@ */ namespace Magento\Setup\Module\Di\App\Task\Operation; -use Magento\Framework\App\ObjectManager\ConfigWriterInterface; -use Magento\Framework\Config\ReaderInterface; use Magento\Framework\Config\ScopeInterface; -use Magento\Framework\Interception\DefinitionInterface; -use Magento\Framework\Interception\ObjectManager\ConfigInterface; -use Magento\Framework\ObjectManager\DefinitionInterface as ClassDefinitions; -use Magento\Framework\ObjectManager\RelationsInterface; use Magento\Setup\Module\Di\App\Task\OperationInterface; -use Psr\Log\LoggerInterface; +use Magento\Framework\Interception\ConfigWriterInterface; /** - * Generates plugins for Magento per scope + * Writes plugins configuration data per scope to generated metadata files. */ class PluginListGenerator implements OperationInterface { @@ -25,122 +19,20 @@ class PluginListGenerator implements OperationInterface */ private $scopeConfig; - /** - * Configuration reader - * - * @var ReaderInterface - */ - private $reader; - - /** - * Cache tag - * - * @var string - */ - private $cacheId = 'plugin-list'; - - /** - * Scope priority loading scheme - * - * @var string[] - */ - private $scopePriorityScheme; - - /** - * Loaded scopes - * - * @var array - */ - private $loadedScopes = []; - - /** - * Type config - * - * @var ConfigInterface - */ - private $omConfig; - - /** - * Class relations information provider - * - * @var RelationsInterface - */ - private $relations; - - /** - * List of interception methods per plugin - * - * @var DefinitionInterface - */ - private $definitions; - - /** - * List of interceptable application classes - * - * @var ClassDefinitions - */ - private $classDefinitions; - - /** - * @var LoggerInterface - */ - private $logger; - /** * @var ConfigWriterInterface */ private $configWriter; /** - * @var array - */ - private $pluginData; - - /** - * @var array - */ - private $globalScopePluginData = []; - - /** - * @var array - */ - private $inherited = []; - - /** - * @var array - */ - private $processed; - - /** - * @param ReaderInterface $reader * @param ScopeInterface $scopeConfig - * @param ConfigInterface $omConfig - * @param RelationsInterface $relations - * @param DefinitionInterface $definitions - * @param ClassDefinitions $classDefinitions - * @param LoggerInterface $logger * @param ConfigWriterInterface $configWriter - * @param array $scopePriorityScheme */ public function __construct( - ReaderInterface $reader, ScopeInterface $scopeConfig, - ConfigInterface $omConfig, - RelationsInterface $relations, - DefinitionInterface $definitions, - ClassDefinitions $classDefinitions, - LoggerInterface $logger, - ConfigWriterInterface $configWriter, - array $scopePriorityScheme = ['global'] + ConfigWriterInterface $configWriter ) { - $this->reader = $reader; $this->scopeConfig = $scopeConfig; - $this->omConfig = $omConfig; - $this->relations = $relations; - $this->definitions = $definitions; - $this->classDefinitions = $classDefinitions; - $this->logger = $logger; - $this->scopePriorityScheme = $scopePriorityScheme; $this->configWriter = $configWriter; } @@ -151,39 +43,9 @@ public function doOperation() { $scopes = $this->scopeConfig->getAllScopes(); // remove primary scope for production mode - array_shift($scopes); + $scopes = array_diff($scopes, ['primary']); // it does not reindex array - foreach ($scopes as $scope) { - $this->scopeConfig->setCurrentScope($scope); - if (false === isset($this->loadedScopes[$scope])) { - if (false === in_array($scope, $this->scopePriorityScheme, true)) { - $this->scopePriorityScheme[] = $scope; - } - $cacheId = implode('|', $this->scopePriorityScheme) . "|" . $this->cacheId; - - foreach ($this->loadScopedVirtualTypes() as $class) { - $this->inheritPlugins($class); - } - foreach ($this->pluginData as $className => $value) { - $this->inheritPlugins($className); - } - foreach ($this->getClassDefinitions() as $class) { - $this->inheritPlugins($class); - } - if ($scope === 'global') { - $this->globalScopePluginData = $this->pluginData; - } - $this->configWriter->write( - $cacheId, - [$this->pluginData, $this->inherited, $this->processed] - ); - if (count($this->scopePriorityScheme) > 1) { - array_pop($this->scopePriorityScheme); - // merge global scope plugin data to other scopes by default - $this->pluginData = $this->globalScopePluginData; - } - } - } + $this->configWriter->write($scopes); } /** @@ -193,202 +55,4 @@ public function getName() { return 'Plugin list generation'; } - - /** - * Load virtual types for current scope - * - * @return array - */ - private function loadScopedVirtualTypes() - { - $virtualTypes = []; - foreach ($this->scopePriorityScheme as $scopeCode) { - if (!isset($this->loadedScopes[$scopeCode])) { - $data = $this->reader->read($scopeCode) ?: []; - unset($data['preferences']); - if (count($data) > 0) { - $this->inherited = []; - $this->processed = []; - $this->merge($data); - foreach ($data as $class => $config) { - if (isset($config['type'])) { - $virtualTypes[] = $class; - } - } - } - $this->loadedScopes[$scopeCode] = true; - } - if ($this->isCurrentScope($scopeCode)) { - break; - } - } - return $virtualTypes; - } - - /** - * Returns class definitions - * - * @return array - */ - private function getClassDefinitions() - { - return $this->classDefinitions->getClasses(); - } - - /** - * Whether scope code is current scope code - * - * @param string $scopeCode - * @return bool - */ - private function isCurrentScope($scopeCode) - { - return $this->scopeConfig->getCurrentScope() === $scopeCode; - } - - /** - * Collect parent types configuration for requested type - * - * @param string $type - * @return array - * @throws \InvalidArgumentException - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @SuppressWarnings(PHPMD.NPathComplexity) - */ - private function inheritPlugins($type) - { - $type = ltrim($type, '\\'); - if (!isset($this->inherited[$type])) { - $realType = $this->omConfig->getOriginalInstanceType($type); - - if ($realType !== $type) { - $plugins = $this->inheritPlugins($realType); - } elseif ($this->relations->has($type)) { - $relations = $this->relations->getParents($type); - $plugins = []; - foreach ($relations as $relation) { - if ($relation) { - $relationPlugins = $this->inheritPlugins($relation); - if ($relationPlugins) { - $plugins = array_replace_recursive($plugins, $relationPlugins); - } - } - } - } else { - $plugins = []; - } - if (isset($this->pluginData[$type])) { - if (!$plugins) { - $plugins = $this->pluginData[$type]; - } else { - $plugins = array_replace_recursive($plugins, $this->pluginData[$type]); - } - } - $this->inherited[$type] = null; - if (is_array($plugins) && count($plugins)) { - $this->filterPlugins($plugins); - uasort($plugins, [$this, 'sort']); - $this->trimInstanceStartingBackslash($plugins); - $this->inherited[$type] = $plugins; - $lastPerMethod = []; - foreach ($plugins as $key => $plugin) { - // skip disabled plugins - if (isset($plugin['disabled']) && $plugin['disabled']) { - unset($plugins[$key]); - continue; - } - $pluginType = $this->omConfig->getOriginalInstanceType($plugin['instance']); - if (!class_exists($pluginType)) { - throw new \InvalidArgumentException('Plugin class ' . $pluginType . ' doesn\'t exist'); - } - foreach ($this->definitions->getMethodList($pluginType) as $pluginMethod => $methodTypes) { - $current = $lastPerMethod[$pluginMethod] ?? '__self'; - $currentKey = $type . '_' . $pluginMethod . '_' . $current; - if ($methodTypes & DefinitionInterface::LISTENER_AROUND) { - $this->processed[$currentKey][DefinitionInterface::LISTENER_AROUND] = $key; - $lastPerMethod[$pluginMethod] = $key; - } - if ($methodTypes & DefinitionInterface::LISTENER_BEFORE) { - $this->processed[$currentKey][DefinitionInterface::LISTENER_BEFORE][] = $key; - } - if ($methodTypes & DefinitionInterface::LISTENER_AFTER) { - $this->processed[$currentKey][DefinitionInterface::LISTENER_AFTER][] = $key; - } - } - } - } - return $plugins; - } - return $this->inherited[$type]; - } - - /** - * Trims starting backslash from plugin instance name - * - * @param array $plugins - * @return void - */ - private function trimInstanceStartingBackslash(&$plugins) - { - foreach ($plugins as &$plugin) { - $plugin['instance'] = ltrim($plugin['instance'], '\\'); - } - } - - /** - * Remove from list not existing plugins - * - * @param array $plugins - * @return void - */ - private function filterPlugins(array &$plugins) - { - foreach ($plugins as $name => $plugin) { - if (empty($plugin['instance'])) { - unset($plugins[$name]); - $this->logger->info("Reference to undeclared plugin with name '{$name}'."); - } - } - } - - /** - * Merge configuration - * - * @param array $config - * @return void - */ - private function merge(array $config) - { - foreach ($config as $type => $typeConfig) { - if (isset($typeConfig['plugins'])) { - $type = ltrim($type, '\\'); - if (isset($this->pluginData[$type])) { - $this->pluginData[$type] = array_replace_recursive($this->pluginData[$type], $typeConfig['plugins']); - } else { - $this->pluginData[$type] = $typeConfig['plugins']; - } - } - } - } - - /** - * Sort items - * - * @param array $itemA - * @param array $itemB - * @return int - */ - private function sort($itemA, $itemB) - { - if (isset($itemA['sortOrder'])) { - if (isset($itemB['sortOrder'])) { - return $itemA['sortOrder'] - $itemB['sortOrder']; - } - return $itemA['sortOrder']; - } elseif (isset($itemB['sortOrder'])) { - return (0 - (int)$itemB['sortOrder']); - } else { - return 0; - } - } } From 7bb9f8ecfbe302a22478acfedd41ceb0ada0ed0e Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Wed, 10 Jun 2020 15:26:50 -0500 Subject: [PATCH 05/44] MC-31618: Move static config to files - PLUGIN_LIST - Add primary scope to scope priority schema; --- app/etc/di.xml | 1 + .../Magento/Framework/Interception/ConfigWriter.php | 6 +++--- .../Module/Di/App/Task/Operation/PluginListGenerator.php | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/etc/di.xml b/app/etc/di.xml index d2eac8e8a0c6d..d28c0ec6bb99f 100644 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -437,6 +437,7 @@ Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy + primary global diff --git a/lib/internal/Magento/Framework/Interception/ConfigWriter.php b/lib/internal/Magento/Framework/Interception/ConfigWriter.php index ef9ce896b043b..9dee8ce8bcd3e 100644 --- a/lib/internal/Magento/Framework/Interception/ConfigWriter.php +++ b/lib/internal/Magento/Framework/Interception/ConfigWriter.php @@ -167,13 +167,13 @@ public function write($scopes) $cacheId, [$this->pluginData, $this->inherited, $this->processed] ); - // need global scope plugin data for non global scopes + // need global & primary scopes plugin data for other scopes if ($scope === 'global') { $this->globalScopePluginData = $this->pluginData; } - if (count($this->scopePriorityScheme) > 1) { + if (count($this->scopePriorityScheme) > 2) { array_pop($this->scopePriorityScheme); - // merge global scope plugin data to other scopes by default + // merge global & primary scopes plugin data to other scopes by default $this->pluginData = $this->globalScopePluginData; } } diff --git a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php index 54fad36b5ed45..d0605cfbafcae 100644 --- a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php +++ b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php @@ -42,8 +42,8 @@ public function __construct( public function doOperation() { $scopes = $this->scopeConfig->getAllScopes(); - // remove primary scope for production mode - $scopes = array_diff($scopes, ['primary']); // it does not reindex array + // remove primary scope for production mode as it is only called in developer mode + $scopes = array_diff($scopes, ['primary']); $this->configWriter->write($scopes); } From e5ab51f5e6b5c26f08c17760a99c166bb128e95e Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Thu, 11 Jun 2020 23:31:46 +0300 Subject: [PATCH 06/44] removed unused imports --- .../Data/AddCustomerUpdatedAtAttribute.php | 7 ++- .../AddNonSpecifiedGenderAttributeOption.php | 18 ++------ .../Data/AddSecurityTrackingAttributes.php | 7 ++- ...ertValidationRulesFromSerializedToJson.php | 7 ++- .../DefaultCustomerGroupsAndAttributes.php | 12 +++--- ...MigrateStoresAllowedCountriesToWebsite.php | 11 +++-- ...oveCheckoutRegisterAndUpdateAttributes.php | 43 ++++++++----------- ...dateAutocompleteOnStorefrontConfigPath.php | 10 ++--- .../UpdateCustomerAttributeInputFilters.php | 7 ++- ...IdentifierCustomerAttributesVisibility.php | 7 ++- .../Setup/Patch/Data/UpdateVATNumber.php | 26 +++++------ .../Data/UpgradePasswordHashAndAddress.php | 7 ++- 12 files changed, 68 insertions(+), 94 deletions(-) diff --git a/app/code/Magento/Customer/Setup/Patch/Data/AddCustomerUpdatedAtAttribute.php b/app/code/Magento/Customer/Setup/Patch/Data/AddCustomerUpdatedAtAttribute.php index bad5735bc3e3a..77bb515c8e52b 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/AddCustomerUpdatedAtAttribute.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/AddCustomerUpdatedAtAttribute.php @@ -4,18 +4,18 @@ * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Customer\Setup\Patch\Data; use Magento\Customer\Model\Customer; use Magento\Customer\Setup\CustomerSetupFactory; -use Magento\Framework\App\ResourceConnection; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Framework\Setup\Patch\PatchVersionInterface; /** - * Class AddCustomerUpdatedAtAttribute - * @package Magento\Customer\Setup\Patch + * Class add customer updated attribute to customer */ class AddCustomerUpdatedAtAttribute implements DataPatchInterface, PatchVersionInterface { @@ -30,7 +30,6 @@ class AddCustomerUpdatedAtAttribute implements DataPatchInterface, PatchVersionI private $customerSetupFactory; /** - * AddCustomerUpdatedAtAttribute constructor. * @param ModuleDataSetupInterface $moduleDataSetup * @param CustomerSetupFactory $customerSetupFactory */ diff --git a/app/code/Magento/Customer/Setup/Patch/Data/AddNonSpecifiedGenderAttributeOption.php b/app/code/Magento/Customer/Setup/Patch/Data/AddNonSpecifiedGenderAttributeOption.php index ba50f6e17dd87..e958093b89621 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/AddNonSpecifiedGenderAttributeOption.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/AddNonSpecifiedGenderAttributeOption.php @@ -4,29 +4,18 @@ * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Customer\Setup\Patch\Data; use Magento\Customer\Model\Customer; use Magento\Customer\Setup\CustomerSetupFactory; -use Magento\Directory\Model\AllowedCountries; -use Magento\Framework\App\ObjectManager; -use Magento\Framework\Encryption\Encryptor; -use Magento\Framework\Indexer\IndexerRegistry; -use Magento\Framework\Setup\SetupInterface; -use Magento\Framework\Setup\UpgradeDataInterface; -use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; -use Magento\Store\Model\ScopeInterface; -use Magento\Store\Model\StoreManagerInterface; -use Magento\Framework\DB\FieldDataConverterFactory; -use Magento\Framework\DB\DataConverter\SerializedToJson; -use Magento\Framework\App\ResourceConnection; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Framework\Setup\Patch\PatchVersionInterface; /** - * Class AddNonSpecifiedGenderAttributeOption - * @package Magento\Customer\Setup\Patch + * Class add non specified gender attribute option to customer */ class AddNonSpecifiedGenderAttributeOption implements DataPatchInterface, PatchVersionInterface { @@ -41,7 +30,6 @@ class AddNonSpecifiedGenderAttributeOption implements DataPatchInterface, PatchV private $customerSetupFactory; /** - * AddNonSpecifiedGenderAttributeOption constructor. * @param ModuleDataSetupInterface $moduleDataSetup * @param CustomerSetupFactory $customerSetupFactory */ diff --git a/app/code/Magento/Customer/Setup/Patch/Data/AddSecurityTrackingAttributes.php b/app/code/Magento/Customer/Setup/Patch/Data/AddSecurityTrackingAttributes.php index b066d14a3c63e..737ac2b085b34 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/AddSecurityTrackingAttributes.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/AddSecurityTrackingAttributes.php @@ -4,18 +4,18 @@ * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Customer\Setup\Patch\Data; use Magento\Customer\Model\Customer; use Magento\Customer\Setup\CustomerSetupFactory; -use Magento\Framework\App\ResourceConnection; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Framework\Setup\Patch\PatchVersionInterface; /** - * Class AddSecurityTrackingAttributes - * @package Magento\Customer\Setup\Patch + * Class add security tracking attributes to customer */ class AddSecurityTrackingAttributes implements DataPatchInterface, PatchVersionInterface { @@ -30,7 +30,6 @@ class AddSecurityTrackingAttributes implements DataPatchInterface, PatchVersionI private $customerSetupFactory; /** - * AddSecurityTrackingAttributes constructor. * @param ModuleDataSetupInterface $moduleDataSetup * @param CustomerSetupFactory $customerSetupFactory */ diff --git a/app/code/Magento/Customer/Setup/Patch/Data/ConvertValidationRulesFromSerializedToJson.php b/app/code/Magento/Customer/Setup/Patch/Data/ConvertValidationRulesFromSerializedToJson.php index 83c5fe7ae6d1e..ed3fb5b00c524 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/ConvertValidationRulesFromSerializedToJson.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/ConvertValidationRulesFromSerializedToJson.php @@ -4,18 +4,18 @@ * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Customer\Setup\Patch\Data; use Magento\Framework\DB\FieldDataConverterFactory; use Magento\Framework\DB\DataConverter\SerializedToJson; -use Magento\Framework\App\ResourceConnection; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Framework\Setup\Patch\PatchVersionInterface; /** - * Class ConvertValidationRulesFromSerializedToJson - * @package Magento\Customer\Setup\Patch + * Class convert validation rules from serialized to json for customer */ class ConvertValidationRulesFromSerializedToJson implements DataPatchInterface, PatchVersionInterface { @@ -30,7 +30,6 @@ class ConvertValidationRulesFromSerializedToJson implements DataPatchInterface, private $fieldDataConverterFactory; /** - * ConvertValidationRulesFromSerializedToJson constructor. * @param ModuleDataSetupInterface $moduleDataSetup * @param FieldDataConverterFactory $fieldDataConverterFactory */ diff --git a/app/code/Magento/Customer/Setup/Patch/Data/DefaultCustomerGroupsAndAttributes.php b/app/code/Magento/Customer/Setup/Patch/Data/DefaultCustomerGroupsAndAttributes.php index 6e61b66f3c9db..e6dd3f36e8ebd 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/DefaultCustomerGroupsAndAttributes.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/DefaultCustomerGroupsAndAttributes.php @@ -4,19 +4,20 @@ * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Customer\Setup\Patch\Data; use Magento\Customer\Setup\CustomerSetup; use Magento\Customer\Setup\CustomerSetupFactory; +use Magento\Eav\Model\Entity\Attribute\Backend\DefaultBackend; use Magento\Framework\Module\Setup\Migration; use Magento\Framework\Setup\ModuleDataSetupInterface; -use Magento\Framework\App\ResourceConnection; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Framework\Setup\Patch\PatchVersionInterface; /** - * Class DefaultCustomerGroupsAndAttributes - * @package Magento\Customer\Setup\Patch + * Class default groups and attributes for customer */ class DefaultCustomerGroupsAndAttributes implements DataPatchInterface, PatchVersionInterface { @@ -31,13 +32,12 @@ class DefaultCustomerGroupsAndAttributes implements DataPatchInterface, PatchVer private $moduleDataSetup; /** - * DefaultCustomerGroupsAndAttributes constructor. * @param CustomerSetupFactory $customerSetupFactory * @param ModuleDataSetupInterface $moduleDataSetup */ public function __construct( CustomerSetupFactory $customerSetupFactory, - \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup + ModuleDataSetupInterface $moduleDataSetup ) { $this->customerSetupFactory = $customerSetupFactory; $this->moduleDataSetup = $moduleDataSetup; @@ -133,7 +133,7 @@ public function apply() 'customer_address', 'street', 'backend_model', - \Magento\Eav\Model\Entity\Attribute\Backend\DefaultBackend::class + DefaultBackend::class ); $migrationSetup = $this->moduleDataSetup->createMigrationSetup(); diff --git a/app/code/Magento/Customer/Setup/Patch/Data/MigrateStoresAllowedCountriesToWebsite.php b/app/code/Magento/Customer/Setup/Patch/Data/MigrateStoresAllowedCountriesToWebsite.php index e4978070f53ad..d041ea920eb5b 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/MigrateStoresAllowedCountriesToWebsite.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/MigrateStoresAllowedCountriesToWebsite.php @@ -4,8 +4,11 @@ * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Customer\Setup\Patch\Data; +use Exception; use Magento\Directory\Model\AllowedCountries; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Store\Model\ScopeInterface; @@ -34,15 +37,14 @@ class MigrateStoresAllowedCountriesToWebsite implements DataPatchInterface, Patc private $allowedCountries; /** - * MigrateStoresAllowedCountriesToWebsite constructor. * @param ModuleDataSetupInterface $moduleDataSetup * @param StoreManagerInterface $storeManager * @param AllowedCountries $allowedCountries */ public function __construct( ModuleDataSetupInterface $moduleDataSetup, - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Directory\Model\AllowedCountries $allowedCountries + StoreManagerInterface $storeManager, + AllowedCountries $allowedCountries ) { $this->moduleDataSetup = $moduleDataSetup; $this->storeManager = $storeManager; @@ -51,6 +53,7 @@ public function __construct( /** * @inheritdoc + * @throws Exception */ public function apply() { @@ -60,7 +63,7 @@ public function apply() try { $this->migrateStoresAllowedCountriesToWebsite(); $this->moduleDataSetup->getConnection()->commit(); - } catch (\Exception $e) { + } catch (Exception $e) { $this->moduleDataSetup->getConnection()->rollBack(); throw $e; } diff --git a/app/code/Magento/Customer/Setup/Patch/Data/RemoveCheckoutRegisterAndUpdateAttributes.php b/app/code/Magento/Customer/Setup/Patch/Data/RemoveCheckoutRegisterAndUpdateAttributes.php index 51f54dc4a432c..7c621c710c463 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/RemoveCheckoutRegisterAndUpdateAttributes.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/RemoveCheckoutRegisterAndUpdateAttributes.php @@ -4,29 +4,23 @@ * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Customer\Setup\Patch\Data; use Magento\Customer\Model\Customer; +use Magento\Customer\Model\ResourceModel\Address; +use Magento\Customer\Model\ResourceModel\Address\Attribute\Backend\Region; +use Magento\Customer\Model\ResourceModel\Address\Attribute\Source\Country; +use Magento\Customer\Model\ResourceModel\Attribute\Collection; use Magento\Customer\Setup\CustomerSetupFactory; -use Magento\Directory\Model\AllowedCountries; -use Magento\Framework\App\ObjectManager; -use Magento\Framework\Encryption\Encryptor; -use Magento\Framework\Indexer\IndexerRegistry; -use Magento\Framework\Setup\SetupInterface; -use Magento\Framework\Setup\UpgradeDataInterface; -use Magento\Framework\Setup\ModuleContextInterface; +use Magento\Eav\Model\Entity\Increment\NumericValue; use Magento\Framework\Setup\ModuleDataSetupInterface; -use Magento\Store\Model\ScopeInterface; -use Magento\Store\Model\StoreManagerInterface; -use Magento\Framework\DB\FieldDataConverterFactory; -use Magento\Framework\DB\DataConverter\SerializedToJson; -use Magento\Framework\App\ResourceConnection; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Framework\Setup\Patch\PatchVersionInterface; /** - * Class RemoveCheckoutRegisterAndUpdateAttributes - * @package Magento\Customer\Setup\Patch + * Remove register and update attributes for checkout */ class RemoveCheckoutRegisterAndUpdateAttributes implements DataPatchInterface, PatchVersionInterface { @@ -41,7 +35,6 @@ class RemoveCheckoutRegisterAndUpdateAttributes implements DataPatchInterface, P private $customerSetupFactory; /** - * RemoveCheckoutRegisterAndUpdateAttributes constructor. * @param ModuleDataSetupInterface $moduleDataSetup * @param CustomerSetupFactory $customerSetupFactory */ @@ -64,47 +57,47 @@ public function apply() ); $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]); $customerSetup->updateEntityType( - \Magento\Customer\Model\Customer::ENTITY, + Customer::ENTITY, 'entity_model', \Magento\Customer\Model\ResourceModel\Customer::class ); $customerSetup->updateEntityType( - \Magento\Customer\Model\Customer::ENTITY, + Customer::ENTITY, 'increment_model', - \Magento\Eav\Model\Entity\Increment\NumericValue::class + NumericValue::class ); $customerSetup->updateEntityType( - \Magento\Customer\Model\Customer::ENTITY, + Customer::ENTITY, 'entity_attribute_collection', - \Magento\Customer\Model\ResourceModel\Attribute\Collection::class + Collection::class ); $customerSetup->updateEntityType( 'customer_address', 'entity_model', - \Magento\Customer\Model\ResourceModel\Address::class + Address::class ); $customerSetup->updateEntityType( 'customer_address', 'entity_attribute_collection', - \Magento\Customer\Model\ResourceModel\Address\Attribute\Collection::class + Address\Attribute\Collection::class ); $customerSetup->updateAttribute( 'customer_address', 'country_id', 'source_model', - \Magento\Customer\Model\ResourceModel\Address\Attribute\Source\Country::class + Country::class ); $customerSetup->updateAttribute( 'customer_address', 'region', 'backend_model', - \Magento\Customer\Model\ResourceModel\Address\Attribute\Backend\Region::class + Region::class ); $customerSetup->updateAttribute( 'customer_address', 'region_id', 'source_model', - \Magento\Customer\Model\ResourceModel\Address\Attribute\Source\Region::class + Address\Attribute\Source\Region::class ); } diff --git a/app/code/Magento/Customer/Setup/Patch/Data/UpdateAutocompleteOnStorefrontConfigPath.php b/app/code/Magento/Customer/Setup/Patch/Data/UpdateAutocompleteOnStorefrontConfigPath.php index 30435ace54d46..64fef20008f09 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/UpdateAutocompleteOnStorefrontConfigPath.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/UpdateAutocompleteOnStorefrontConfigPath.php @@ -4,16 +4,17 @@ * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Customer\Setup\Patch\Data; -use Magento\Framework\App\ResourceConnection; +use Magento\Customer\Model\Form; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Framework\Setup\Patch\PatchVersionInterface; /** - * Class UpdateAutocompleteOnStorefrontCOnfigPath - * @package Magento\Customer\Setup\Patch + * Update storefront's autocomplete of config path */ class UpdateAutocompleteOnStorefrontConfigPath implements DataPatchInterface, PatchVersionInterface { @@ -23,7 +24,6 @@ class UpdateAutocompleteOnStorefrontConfigPath implements DataPatchInterface, Pa private $moduleDataSetup; /** - * UpdateAutocompleteOnStorefrontCOnfigPath constructor. * @param ModuleDataSetupInterface $moduleDataSetup */ public function __construct( @@ -39,7 +39,7 @@ public function apply() { $this->moduleDataSetup->getConnection()->update( $this->moduleDataSetup->getTable('core_config_data'), - ['path' => \Magento\Customer\Model\Form::XML_PATH_ENABLE_AUTOCOMPLETE], + ['path' => Form::XML_PATH_ENABLE_AUTOCOMPLETE], ['path = ?' => 'general/restriction/autocomplete_on_storefront'] ); } diff --git a/app/code/Magento/Customer/Setup/Patch/Data/UpdateCustomerAttributeInputFilters.php b/app/code/Magento/Customer/Setup/Patch/Data/UpdateCustomerAttributeInputFilters.php index 938cd3cd52e73..9d6bd2d4f7c69 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/UpdateCustomerAttributeInputFilters.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/UpdateCustomerAttributeInputFilters.php @@ -4,17 +4,17 @@ * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Customer\Setup\Patch\Data; use Magento\Customer\Setup\CustomerSetupFactory; -use Magento\Framework\App\ResourceConnection; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Framework\Setup\Patch\PatchVersionInterface; /** - * Class UpdateCustomerAttributeInputFilters - * @package Magento\Customer\Setup\Patch + * Update attribute input filters for customer */ class UpdateCustomerAttributeInputFilters implements DataPatchInterface, PatchVersionInterface { @@ -29,7 +29,6 @@ class UpdateCustomerAttributeInputFilters implements DataPatchInterface, PatchVe private $customerSetupFactory; /** - * UpdateCustomerAttributeInputFilters constructor. * @param ModuleDataSetupInterface $moduleDataSetup * @param CustomerSetupFactory $customerSetupFactory */ diff --git a/app/code/Magento/Customer/Setup/Patch/Data/UpdateIdentifierCustomerAttributesVisibility.php b/app/code/Magento/Customer/Setup/Patch/Data/UpdateIdentifierCustomerAttributesVisibility.php index 7d0cad768d6b0..bfb97c6045c92 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/UpdateIdentifierCustomerAttributesVisibility.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/UpdateIdentifierCustomerAttributesVisibility.php @@ -4,17 +4,17 @@ * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Customer\Setup\Patch\Data; use Magento\Customer\Setup\CustomerSetupFactory; -use Magento\Framework\App\ResourceConnection; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Framework\Setup\Patch\PatchVersionInterface; /** - * Class UpdateIdentifierCustomerAttributesVisibility - * @package Magento\Customer\Setup\Patch + * Update identifier attributes visibility for customer */ class UpdateIdentifierCustomerAttributesVisibility implements DataPatchInterface, PatchVersionInterface { @@ -29,7 +29,6 @@ class UpdateIdentifierCustomerAttributesVisibility implements DataPatchInterface private $customerSetupFactory; /** - * UpdateIdentifierCustomerAttributesVisibility constructor. * @param ModuleDataSetupInterface $moduleDataSetup * @param CustomerSetupFactory $customerSetupFactory */ diff --git a/app/code/Magento/Customer/Setup/Patch/Data/UpdateVATNumber.php b/app/code/Magento/Customer/Setup/Patch/Data/UpdateVATNumber.php index d31301eedf4b1..1fa8614485870 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/UpdateVATNumber.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/UpdateVATNumber.php @@ -4,26 +4,18 @@ * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Customer\Setup\Patch\Data; -use Magento\Customer\Model\Customer; use Magento\Customer\Setup\CustomerSetupFactory; -use Magento\Directory\Model\AllowedCountries; -use Magento\Framework\App\ObjectManager; -use Magento\Framework\Encryption\Encryptor; -use Magento\Framework\Indexer\IndexerRegistry; -use Magento\Framework\Setup\SetupInterface; -use Magento\Framework\Setup\UpgradeDataInterface; -use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; -use Magento\Store\Model\ScopeInterface; -use Magento\Store\Model\StoreManagerInterface; -use Magento\Framework\DB\FieldDataConverterFactory; -use Magento\Framework\DB\DataConverter\SerializedToJson; -use Magento\Framework\App\ResourceConnection; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Framework\Setup\Patch\PatchVersionInterface; +/** + * Upgrade vat number + */ class UpdateVATNumber implements DataPatchInterface, PatchVersionInterface { /** @@ -37,7 +29,6 @@ class UpdateVATNumber implements DataPatchInterface, PatchVersionInterface private $customerSetupFactory; /** - * UpdateVATNumber constructor. * @param ModuleDataSetupInterface $moduleDataSetup * @param CustomerSetupFactory $customerSetupFactory */ @@ -55,7 +46,12 @@ public function __construct( public function apply() { $customerSetup = $this->customerSetupFactory->create(['resourceConnection' => $this->moduleDataSetup]); - $customerSetup->updateAttribute('customer_address', 'vat_id', 'frontend_label', 'VAT Number'); + $customerSetup->updateAttribute( + 'customer_address', + 'vat_id', + 'frontend_label', + 'VAT Number' + ); } /** diff --git a/app/code/Magento/Customer/Setup/Patch/Data/UpgradePasswordHashAndAddress.php b/app/code/Magento/Customer/Setup/Patch/Data/UpgradePasswordHashAndAddress.php index 3b8f96a037343..cec2de71fb477 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/UpgradePasswordHashAndAddress.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/UpgradePasswordHashAndAddress.php @@ -4,18 +4,18 @@ * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Customer\Setup\Patch\Data; use Magento\Customer\Setup\CustomerSetupFactory; use Magento\Framework\Encryption\Encryptor; -use Magento\Framework\App\ResourceConnection; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Framework\Setup\Patch\PatchVersionInterface; /** - * Class UpgradePasswordHashAndAddress - * @package Magento\Customer\Setup\Patch + * Update passwordHash and address */ class UpgradePasswordHashAndAddress implements DataPatchInterface, PatchVersionInterface { @@ -30,7 +30,6 @@ class UpgradePasswordHashAndAddress implements DataPatchInterface, PatchVersionI private $customerSetupFactory; /** - * UpgradePasswordHashAndAddress constructor. * @param ModuleDataSetupInterface $moduleDataSetup * @param CustomerSetupFactory $customerSetupFactory */ From ce8752e5859bb95e680ef2467a18cf7f42e9e891 Mon Sep 17 00:00:00 2001 From: Serhii Balko Date: Tue, 16 Jun 2020 13:28:59 +0300 Subject: [PATCH 07/44] MC-35008: Quote doesn't expire at time set when updated_at table gets updated --- .../Quote/Model/ResourceModel/Quote.php | 39 ++++++---- .../Product/Plugin/UpdateQuoteItemsTest.php | 78 +++++++++++++++++++ 2 files changed, 101 insertions(+), 16 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Quote/Model/Product/Plugin/UpdateQuoteItemsTest.php diff --git a/app/code/Magento/Quote/Model/ResourceModel/Quote.php b/app/code/Magento/Quote/Model/ResourceModel/Quote.php index 48945dacd1738..749e9944a6ad3 100644 --- a/app/code/Magento/Quote/Model/ResourceModel/Quote.php +++ b/app/code/Magento/Quote/Model/ResourceModel/Quote.php @@ -230,7 +230,8 @@ public function subtractProductFromQuotes($product) 'items_qty' => new \Zend_Db_Expr( $connection->quoteIdentifier('q.items_qty') . ' - ' . $connection->quoteIdentifier('qi.qty') ), - 'items_count' => new \Zend_Db_Expr($ifSql) + 'items_count' => new \Zend_Db_Expr($ifSql), + 'updated_at' => 'q.updated_at', ] )->join( ['qi' => $this->getTable('quote_item')], @@ -277,21 +278,27 @@ public function markQuotesRecollect($productIds) { $tableQuote = $this->getTable('quote'); $tableItem = $this->getTable('quote_item'); - $subSelect = $this->getConnection()->select()->from( - $tableItem, - ['entity_id' => 'quote_id'] - )->where( - 'product_id IN ( ? )', - $productIds - )->group( - 'quote_id' - ); - - $select = $this->getConnection()->select()->join( - ['t2' => $subSelect], - 't1.entity_id = t2.entity_id', - ['trigger_recollect' => new \Zend_Db_Expr('1')] - ); + $subSelect = $this->getConnection() + ->select() + ->from( + $tableItem, + ['entity_id' => 'quote_id'] + )->where( + 'product_id IN ( ? )', + $productIds + )->group( + 'quote_id' + ); + $select = $this->getConnection() + ->select() + ->join( + ['t2' => $subSelect], + 't1.entity_id = t2.entity_id', + [ + 'trigger_recollect' => new \Zend_Db_Expr('1'), + 'updated_at' => 't1.updated_at', + ] + ); $updateQuery = $select->crossUpdateFromSelect(['t1' => $tableQuote]); $this->getConnection()->query($updateQuery); diff --git a/dev/tests/integration/testsuite/Magento/Quote/Model/Product/Plugin/UpdateQuoteItemsTest.php b/dev/tests/integration/testsuite/Magento/Quote/Model/Product/Plugin/UpdateQuoteItemsTest.php new file mode 100644 index 0000000000000..3aadad7e9ebec --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Quote/Model/Product/Plugin/UpdateQuoteItemsTest.php @@ -0,0 +1,78 @@ +getQuoteByReservedOrderId = $objectManager->get(GetQuoteByReservedOrderId::class); + $this->productRepository = $objectManager->get(ProductRepository::class); + } + + /** + * Test to mark the quote as need to recollect and doesn't update the field "updated_at" after change product price + * + * @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @return void + */ + public function testMarkQuoteRecollectAfterChangeProductPrice(): void + { + $quote = $this->getQuoteByReservedOrderId->execute('test_order_with_simple_product_without_address'); + $this->assertNotNull($quote); + $this->assertFalse((bool)$quote->getTriggerRecollect()); + $this->assertNotEmpty($quote->getItems()); + $quoteItem = current($quote->getItems()); + $product = $quoteItem->getProduct(); + + $product->setPrice((float)$product->getPrice() + 10); + $this->productRepository->save($product); + + /** @var AdapterInterface $connection */ + $connection = $quote->getResource()->getConnection(); + $select = $connection->select() + ->from( + $connection->getTableName('quote'), + ['updated_at', 'trigger_recollect'] + )->where( + "reserved_order_id = 'test_order_with_simple_product_without_address'" + ); + + $quoteRow = $connection->fetchRow($select); + $this->assertNotEmpty($quoteRow); + $this->assertTrue((bool)$quoteRow['trigger_recollect']); + $this->assertEquals($quote->getUpdatedAt(), $quoteRow['updated_at']); + } +} From 8bbfa36bb481c8ffc058d991d1f1faa3795407ea Mon Sep 17 00:00:00 2001 From: Nikita Shcherbatykh Date: Thu, 18 Jun 2020 14:48:03 +0300 Subject: [PATCH 08/44] MC-35152: String to be escaped was not valid UTF-8 or could not be converted --- .../Payment/Block/Transparent/Redirect.php | 13 ++- .../Unit/Block/Transparent/RedirectTest.php | 102 ++++++++++++++++++ 2 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 app/code/Magento/Payment/Test/Unit/Block/Transparent/RedirectTest.php diff --git a/app/code/Magento/Payment/Block/Transparent/Redirect.php b/app/code/Magento/Payment/Block/Transparent/Redirect.php index 1be6dec4cc1d8..97a09df38d120 100644 --- a/app/code/Magento/Payment/Block/Transparent/Redirect.php +++ b/app/code/Magento/Payment/Block/Transparent/Redirect.php @@ -53,10 +53,21 @@ public function getRedirectUrl(): string /** * Returns params to be redirected. * + * Encodes invalid UTF-8 values to UTF-8 to prevent character escape error. + * Some payment methods like PayPal, send data in merchant defined language encoding + * which can be different from the system character encoding (UTF-8). + * * @return array */ public function getPostParams(): array { - return (array)$this->_request->getPostValue(); + $params = []; + foreach ($this->_request->getPostValue() as $name => $value) { + if (!empty($value) && mb_detect_encoding($value, 'UTF-8', true) === false) { + $value = utf8_encode($value); + } + $params[$name] = $value; + } + return $params; } } diff --git a/app/code/Magento/Payment/Test/Unit/Block/Transparent/RedirectTest.php b/app/code/Magento/Payment/Test/Unit/Block/Transparent/RedirectTest.php new file mode 100644 index 0000000000000..1cd1230a14634 --- /dev/null +++ b/app/code/Magento/Payment/Test/Unit/Block/Transparent/RedirectTest.php @@ -0,0 +1,102 @@ +context = $this->createMock(\Magento\Framework\View\Element\Template\Context::class); + $this->request = $this->createMock(\Magento\Framework\App\Request\Http::class); + $this->context->method('getRequest') + ->willReturn($this->request); + $this->url = $this->createMock(\Magento\Framework\UrlInterface::class); + $this->model = new Redirect( + $this->context, + $this->url + ); + } + + /** + * @param array $postData + * @param array $expected + * @dataProvider getPostParamsDataProvider + */ + public function testGetPostParams(array $postData, array $expected): void + { + $this->request->method('getPostValue') + ->willReturn($postData); + $this->assertEquals($expected, $this->model->getPostParams()); + } + + /** + * @return array + */ + public function getPostParamsDataProvider(): array + { + return [ + [ + [ + 'BILLTOEMAIL' => 'john.doe@magento.lo', + 'BILLTOSTREET' => '3640 Holdrege Ave', + 'BILLTOZIP' => '90016', + 'BILLTOLASTNAME' => 'Ãtienne', + 'BILLTOFIRSTNAME' => 'Ãillin', + ], + [ + 'BILLTOEMAIL' => 'john.doe@magento.lo', + 'BILLTOSTREET' => '3640 Holdrege Ave', + 'BILLTOZIP' => '90016', + 'BILLTOLASTNAME' => 'Ãtienne', + 'BILLTOFIRSTNAME' => 'Ãillin', + ] + ], + [ + [ + 'BILLTOEMAIL' => 'john.doe@magento.lo', + 'BILLTOSTREET' => '3640 Holdrege Ave', + 'BILLTOZIP' => '90016', + 'BILLTOLASTNAME' => mb_convert_encoding('Ãtienne', 'ISO-8859-1'), + 'BILLTOFIRSTNAME' => mb_convert_encoding('Ãillin', 'ISO-8859-1'), + ], + [ + 'BILLTOEMAIL' => 'john.doe@magento.lo', + 'BILLTOSTREET' => '3640 Holdrege Ave', + 'BILLTOZIP' => '90016', + 'BILLTOLASTNAME' => 'Ãtienne', + 'BILLTOFIRSTNAME' => 'Ãillin', + ] + ] + ]; + } +} From 1688f8f45e91ece49c980fee13e386083075af28 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Fri, 19 Jun 2020 00:22:13 -0500 Subject: [PATCH 09/44] MC-31618: Move static config to files - PLUGIN_LIST - Move possible common logic to ConfigWriter; --- app/etc/di.xml | 1 + .../Framework/Interception/ConfigWriter.php | 10 +-- .../Interception/PluginList/PluginList.php | 76 +++++-------------- 3 files changed, 24 insertions(+), 63 deletions(-) diff --git a/app/etc/di.xml b/app/etc/di.xml index d28c0ec6bb99f..7792f43592f5b 100644 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -436,6 +436,7 @@ Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy + \Psr\Log\LoggerInterface\Proxy primary global diff --git a/lib/internal/Magento/Framework/Interception/ConfigWriter.php b/lib/internal/Magento/Framework/Interception/ConfigWriter.php index 9dee8ce8bcd3e..08cf613650baa 100644 --- a/lib/internal/Magento/Framework/Interception/ConfigWriter.php +++ b/lib/internal/Magento/Framework/Interception/ConfigWriter.php @@ -216,7 +216,7 @@ private function loadScopedVirtualTypes() * * @return array */ - private function getClassDefinitions() + public function getClassDefinitions() { return $this->classDefinitions->getClasses(); } @@ -227,7 +227,7 @@ private function getClassDefinitions() * @param string $scopeCode * @return bool */ - private function isCurrentScope($scopeCode) + public function isCurrentScope($scopeCode) { return $this->scopeConfig->getCurrentScope() === $scopeCode; } @@ -314,7 +314,7 @@ private function inheritPlugins($type) * @param array $plugins * @return void */ - private function trimInstanceStartingBackslash(&$plugins) + public function trimInstanceStartingBackslash(&$plugins) { foreach ($plugins as &$plugin) { $plugin['instance'] = ltrim($plugin['instance'], '\\'); @@ -327,7 +327,7 @@ private function trimInstanceStartingBackslash(&$plugins) * @param array $plugins * @return void */ - private function filterPlugins(array &$plugins) + public function filterPlugins(array &$plugins) { foreach ($plugins as $name => $plugin) { if (empty($plugin['instance'])) { @@ -367,7 +367,7 @@ private function merge(array $config) * @param array $itemB * @return int */ - private function sort($itemA, $itemB) + public function sort($itemA, $itemB) { return ($itemA['sortOrder'] ?? PHP_INT_MIN) - ($itemB['sortOrder'] ?? PHP_INT_MIN); } diff --git a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php index 9b53f5d023c56..64e55b78f1fc5 100644 --- a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php +++ b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php @@ -18,7 +18,7 @@ use Magento\Framework\Serialize\SerializerInterface; use Magento\Framework\Serialize\Serializer\Serialize; use Magento\Framework\Interception\ConfigLoader; -use Magento\Framework\App\ObjectManager; +use Magento\Framework\Interception\ConfigWriter; /** * Plugin config, provides list of plugins for a type @@ -79,11 +79,6 @@ class PluginList extends Scoped implements InterceptionPluginList */ protected $_pluginInstances = []; - /** - * @var \Psr\Log\LoggerInterface - */ - private $logger; - /** * @var SerializerInterface */ @@ -94,6 +89,11 @@ class PluginList extends Scoped implements InterceptionPluginList */ private $configLoader; + /** + * @var ConfigWriter + */ + private $configWriter; + /** * Constructor * @@ -109,6 +109,7 @@ class PluginList extends Scoped implements InterceptionPluginList * @param string|null $cacheId * @param SerializerInterface|null $serializer * @param ConfigLoader|null $configLoader + * @param ConfigWriter|null $configWriter * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -123,7 +124,8 @@ public function __construct( array $scopePriorityScheme = ['global'], $cacheId = 'plugins', SerializerInterface $serializer = null, - ConfigLoader $configLoader = null + ConfigLoader $configLoader = null, + ConfigWriter $configWriter = null ) { $this->serializer = $serializer ?: $objectManager->get(Serialize::class); parent::__construct($reader, $configScope, $cache, $cacheId, $this->serializer); @@ -133,7 +135,8 @@ public function __construct( $this->_classDefinitions = $classDefinitions; $this->_scopePriorityScheme = $scopePriorityScheme; $this->_objectManager = $objectManager; - $this->configLoader = $configLoader ?: ObjectManager::getInstance()->get(ConfigLoader::class); + $this->configLoader = $configLoader ?: $this->_objectManager->get(ConfigLoader::class); + $this->configWriter = $configWriter ?: $this->_objectManager->get(ConfigWriter::class); } /** @@ -176,9 +179,9 @@ protected function _inheritPlugins($type) } $this->_inherited[$type] = null; if (is_array($plugins) && count($plugins)) { - $this->filterPlugins($plugins); + $this->configWriter->filterPlugins($plugins); uasort($plugins, [$this, '_sort']); - $this->trimInstanceStartingBackslash($plugins); + $this->configWriter->trimInstanceStartingBackslash($plugins); $this->_inherited[$type] = $plugins; $lastPerMethod = []; foreach ($plugins as $key => $plugin) { @@ -212,19 +215,6 @@ protected function _inheritPlugins($type) return $this->_inherited[$type]; } - /** - * Trims starting backslash from plugin instance name - * - * @param array $plugins - * @return void - */ - private function trimInstanceStartingBackslash(&$plugins) - { - foreach ($plugins as &$plugin) { - $plugin['instance'] = ltrim($plugin['instance'], '\\'); - } - } - /** * Sort items * @@ -234,7 +224,7 @@ private function trimInstanceStartingBackslash(&$plugins) */ protected function _sort($itemA, $itemB) { - return ($itemA['sortOrder'] ?? PHP_INT_MIN) - ($itemB['sortOrder'] ?? PHP_INT_MIN); + return $this->configWriter->sort($itemA, $itemB); } /** @@ -281,8 +271,8 @@ public function getNext($type, $method, $code = '__self') protected function _loadScopedData() { $scope = $this->_configScope->getCurrentScope(); - if (false == isset($this->_loadedScopes[$scope])) { - $index = array_search($scope, $this->_scopePriorityScheme); + if (false === isset($this->_loadedScopes[$scope])) { + $index = array_search($scope, $this->_scopePriorityScheme, true); /** * Force current scope to be at the end of the scheme to ensure that default priority scopes are loaded. * Mostly happens when the current scope is primary. @@ -363,7 +353,7 @@ private function _loadScopedVirtualTypes() */ protected function isCurrentScope($scopeCode) { - return $this->_configScope->getCurrentScope() === $scopeCode; + return $this->configWriter->isCurrentScope($scopeCode); } /** @@ -373,7 +363,7 @@ protected function isCurrentScope($scopeCode) */ protected function getClassDefinitions() { - return $this->_classDefinitions->getClasses(); + return $this->configWriter->getClassDefinitions(); } /** @@ -395,34 +385,4 @@ public function merge(array $config) } } } - - /** - * Remove from list not existing plugins - * - * @param array $plugins - * @return void - */ - private function filterPlugins(array &$plugins) - { - foreach ($plugins as $name => $plugin) { - if (empty($plugin['instance'])) { - unset($plugins[$name]); - $this->getLogger()->info("Reference to undeclared plugin with name '{$name}'."); - } - } - } - - /** - * Get logger - * - * @return \Psr\Log\LoggerInterface - * @deprecated 100.2.0 - */ - private function getLogger() - { - if ($this->logger === null) { - $this->logger = $this->_objectManager->get(\Psr\Log\LoggerInterface::class); - } - return $this->logger; - } } From 4793b6ece1caa04e080de877494452f4a400daa0 Mon Sep 17 00:00:00 2001 From: Konstantin Dubovik Date: Fri, 19 Jun 2020 13:10:38 +0300 Subject: [PATCH 10/44] Fix shipping address id getter misspelling --- .../ResourceModel/Order/Handler/Address.php | 2 +- .../Order/Handler/AddressTest.php | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Model/ResourceModel/Order/Handler/Address.php b/app/code/Magento/Sales/Model/ResourceModel/Order/Handler/Address.php index 0fec004a25fae..c334f6e7a9576 100644 --- a/app/code/Magento/Sales/Model/ResourceModel/Order/Handler/Address.php +++ b/app/code/Magento/Sales/Model/ResourceModel/Order/Handler/Address.php @@ -69,7 +69,7 @@ public function process(Order $order) $attributesForSave[] = 'billing_address_id'; } $shippingAddress = $order->getShippingAddress(); - if ($shippingAddress && $order->getShippigAddressId() != $shippingAddress->getId()) { + if ($shippingAddress && $order->getShippingAddressId() != $shippingAddress->getId()) { $order->setShippingAddressId($shippingAddress->getId()); $attributesForSave[] = 'shipping_address_id'; } diff --git a/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Handler/AddressTest.php b/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Handler/AddressTest.php index 5267686a447cc..0978dda09f7a7 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Handler/AddressTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Handler/AddressTest.php @@ -133,6 +133,66 @@ public function testProcessShippingAddress() $this->assertEquals($this->address, $this->address->process($this->orderMock)); } + /** + * Test processing of the shipping address when shipping address id was not changed. + * setShippingAddressId and saveAttribute methods must not be executed. + */ + public function testProcessShippingAddressNotChanged() + { + $this->orderMock->expects($this->exactly(2)) + ->method('getAddresses') + ->willReturn([$this->addressMock]); + $this->addressMock->expects($this->once()) + ->method('save')->willReturnSelf(); + $this->orderMock->expects($this->once()) + ->method('getBillingAddress') + ->willReturn(null); + $this->orderMock->expects($this->once()) + ->method('getShippingAddress') + ->willReturn($this->addressMock); + $this->addressMock->expects($this->once()) + ->method('getId')->willReturn(1); + $this->orderMock->expects($this->once()) + ->method('getShippingAddressId') + ->willReturn(1); + $this->orderMock->expects($this->never()) + ->method('setShippingAddressId')->willReturnSelf(); + $this->attributeMock->expects($this->never()) + ->method('saveAttribute') + ->with($this->orderMock, ['shipping_address_id'])->willReturnSelf(); + $this->assertEquals($this->address, $this->address->process($this->orderMock)); + } + + /** + * Test processing of the billing address when billing address id was not changed. + * setBillingAddressId and saveAttribute methods must not be executed. + */ + public function testProcessBillingAddressNotChanged() + { + $this->orderMock->expects($this->exactly(2)) + ->method('getAddresses') + ->willReturn([$this->addressMock]); + $this->addressMock->expects($this->once()) + ->method('save')->willReturnSelf(); + $this->orderMock->expects($this->once()) + ->method('getBillingAddress') + ->willReturn($this->addressMock); + $this->orderMock->expects($this->once()) + ->method('getShippingAddress') + ->willReturn(null); + $this->addressMock->expects($this->once()) + ->method('getId')->willReturn(1); + $this->orderMock->expects($this->once()) + ->method('getBillingAddressId') + ->willReturn(1); + $this->orderMock->expects($this->never()) + ->method('setBillingAddressId')->willReturnSelf(); + $this->attributeMock->expects($this->never()) + ->method('saveAttribute') + ->with($this->orderMock, ['billing_address_id'])->willReturnSelf(); + $this->assertEquals($this->address, $this->address->process($this->orderMock)); + } + /** * Test method removeEmptyAddresses */ From 11c5a67c45e6ece91e477dd490feb641388decc4 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Fri, 19 Jun 2020 15:27:57 -0500 Subject: [PATCH 11/44] MC-31618: Move static config to files - PLUGIN_LIST - Move loadScopedVirtualTypes to ConfigWriter; --- .../Framework/Interception/ConfigWriter.php | 53 +++++++++++------ .../Interception/PluginList/PluginList.php | 58 +++++-------------- 2 files changed, 52 insertions(+), 59 deletions(-) diff --git a/lib/internal/Magento/Framework/Interception/ConfigWriter.php b/lib/internal/Magento/Framework/Interception/ConfigWriter.php index 08cf613650baa..80fd9018b3624 100644 --- a/lib/internal/Magento/Framework/Interception/ConfigWriter.php +++ b/lib/internal/Magento/Framework/Interception/ConfigWriter.php @@ -154,7 +154,21 @@ public function write($scopes) $this->scopePriorityScheme[] = $scope; } $cacheId = implode('|', $this->scopePriorityScheme) . "|" . $this->cacheId; - foreach ($this->loadScopedVirtualTypes() as $class) { + [ + $virtualTypes, + $this->scopePriorityScheme, + $this->loadedScopes, + $this->pluginData, + $this->inherited, + $this->processed + ] = $this->loadScopedVirtualTypes( + $this->scopePriorityScheme, + $this->loadedScopes, + $this->pluginData, + $this->inherited, + $this->processed + ); + foreach ($virtualTypes as $class) { $this->inheritPlugins($class); } foreach ($this->pluginData as $className => $value) { @@ -183,32 +197,37 @@ public function write($scopes) /** * Load virtual types for current scope * + * @param array $scopePriorityScheme + * @param array $loadedScopes + * @param array|null $pluginData + * @param array $inherited + * @param array $processed * @return array */ - private function loadScopedVirtualTypes() + public function loadScopedVirtualTypes($scopePriorityScheme, $loadedScopes, $pluginData, $inherited, $processed) { $virtualTypes = []; - foreach ($this->scopePriorityScheme as $scopeCode) { - if (!isset($this->loadedScopes[$scopeCode])) { + foreach ($scopePriorityScheme as $scopeCode) { + if (!isset($loadedScopes[$scopeCode])) { $data = $this->reader->read($scopeCode) ?: []; unset($data['preferences']); if (count($data) > 0) { - $this->inherited = []; - $this->processed = []; - $this->merge($data); + $inherited = []; + $processed = []; + $pluginData = $this->merge($data, $pluginData); foreach ($data as $class => $config) { if (isset($config['type'])) { $virtualTypes[] = $class; } } } - $this->loadedScopes[$scopeCode] = true; + $loadedScopes[$scopeCode] = true; } if ($this->isCurrentScope($scopeCode)) { break; } } - return $virtualTypes; + return [$virtualTypes, $scopePriorityScheme, $loadedScopes, $pluginData, $inherited, $processed]; } /** @@ -341,23 +360,23 @@ public function filterPlugins(array &$plugins) * Merge configuration * * @param array $config - * @return void + * @param array|null $pluginData + * @return array */ - private function merge(array $config) + public function merge(array $config, $pluginData) { foreach ($config as $type => $typeConfig) { if (isset($typeConfig['plugins'])) { $type = ltrim($type, '\\'); - if (isset($this->pluginData[$type])) { - $this->pluginData[$type] = array_replace_recursive( - $this->pluginData[$type], - $typeConfig['plugins'] - ); + if (isset($pluginData[$type])) { + $pluginData[$type] = array_replace_recursive($pluginData[$type], $typeConfig['plugins']); } else { - $this->pluginData[$type] = $typeConfig['plugins']; + $pluginData[$type] = $typeConfig['plugins']; } } } + + return $pluginData; } /** diff --git a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php index 64e55b78f1fc5..eff3feff9cef1 100644 --- a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php +++ b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php @@ -298,7 +298,21 @@ protected function _loadScopedData() $this->_loadedScopes[$scopeCode] = true; } } else { - foreach ($this->_loadScopedVirtualTypes() as $class) { + [ + $virtualTypes, + $this->_scopePriorityScheme, + $this->_loadedScopes, + $this->_data, + $this->_inherited, + $this->_processed + ] = $this->configWriter->loadScopedVirtualTypes( + $this->_scopePriorityScheme, + $this->_loadedScopes, + $this->_data, + $this->_inherited, + $this->_processed + ); + foreach ($virtualTypes as $class) { $this->_inheritPlugins($class); } foreach ($this->getClassDefinitions() as $class) { @@ -314,37 +328,6 @@ protected function _loadScopedData() } } - /** - * Load virtual types for current scope - * - * @return array - */ - private function _loadScopedVirtualTypes() - { - $virtualTypes = []; - foreach ($this->_scopePriorityScheme as $scopeCode) { - if (!isset($this->_loadedScopes[$scopeCode])) { - $data = $this->_reader->read($scopeCode) ?: []; - unset($data['preferences']); - if (count($data) > 0) { - $this->_inherited = []; - $this->_processed = []; - $this->merge($data); - foreach ($data as $class => $config) { - if (isset($config['type'])) { - $virtualTypes[] = $class; - } - } - } - $this->_loadedScopes[$scopeCode] = true; - } - if ($this->isCurrentScope($scopeCode)) { - break; - } - } - return $virtualTypes; - } - /** * Whether scope code is current scope code * @@ -374,15 +357,6 @@ protected function getClassDefinitions() */ public function merge(array $config) { - foreach ($config as $type => $typeConfig) { - if (isset($typeConfig['plugins'])) { - $type = ltrim($type, '\\'); - if (isset($this->_data[$type])) { - $this->_data[$type] = array_replace_recursive($this->_data[$type], $typeConfig['plugins']); - } else { - $this->_data[$type] = $typeConfig['plugins']; - } - } - } + $this->_data = $this->configWriter->merge($config, $this->_data); } } From 7db4ca169ebcfb70e4f0c2f996ac4ac6efd23839 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Sat, 20 Jun 2020 00:46:26 -0500 Subject: [PATCH 12/44] MC-31618: Move static config to files - PLUGIN_LIST - Move inheritPlugins to ConfigWriter; --- .../Framework/Interception/ConfigWriter.php | 36 +++++----- .../Interception/PluginList/PluginList.php | 69 +------------------ 2 files changed, 20 insertions(+), 85 deletions(-) diff --git a/lib/internal/Magento/Framework/Interception/ConfigWriter.php b/lib/internal/Magento/Framework/Interception/ConfigWriter.php index 80fd9018b3624..6a3fbc95fcb78 100644 --- a/lib/internal/Magento/Framework/Interception/ConfigWriter.php +++ b/lib/internal/Magento/Framework/Interception/ConfigWriter.php @@ -169,13 +169,13 @@ public function write($scopes) $this->processed ); foreach ($virtualTypes as $class) { - $this->inheritPlugins($class); + $this->inheritPlugins($class, $this->pluginData, $this->inherited, $this->processed); } foreach ($this->pluginData as $className => $value) { - $this->inheritPlugins($className); + $this->inheritPlugins($className, $this->pluginData, $this->inherited, $this->processed); } foreach ($this->getClassDefinitions() as $class) { - $this->inheritPlugins($class); + $this->inheritPlugins($class, $this->pluginData, $this->inherited, $this->processed); } $this->configWriter->write( $cacheId, @@ -255,25 +255,27 @@ public function isCurrentScope($scopeCode) * Collect parent types configuration for requested type * * @param string $type + * @param array $pluginData + * @param array $inherited + * @param array $processed * @return array - * @throws \InvalidArgumentException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - private function inheritPlugins($type) + public function inheritPlugins($type, &$pluginData, &$inherited, &$processed) { $type = ltrim($type, '\\'); - if (!isset($this->inherited[$type])) { + if (!isset($inherited[$type])) { $realType = $this->omConfig->getOriginalInstanceType($type); if ($realType !== $type) { - $plugins = $this->inheritPlugins($realType); + $plugins = $this->inheritPlugins($realType, $pluginData, $inherited, $processed); } elseif ($this->relations->has($type)) { $relations = $this->relations->getParents($type); $plugins = []; foreach ($relations as $relation) { if ($relation) { - $relationPlugins = $this->inheritPlugins($relation); + $relationPlugins = $this->inheritPlugins($relation, $pluginData, $inherited, $processed); if ($relationPlugins) { $plugins = array_replace_recursive($plugins, $relationPlugins); } @@ -282,19 +284,19 @@ private function inheritPlugins($type) } else { $plugins = []; } - if (isset($this->pluginData[$type])) { + if (isset($pluginData[$type])) { if (!$plugins) { - $plugins = $this->pluginData[$type]; + $plugins = $pluginData[$type]; } else { - $plugins = array_replace_recursive($plugins, $this->pluginData[$type]); + $plugins = array_replace_recursive($plugins, $pluginData[$type]); } } - $this->inherited[$type] = null; + $inherited[$type] = null; if (is_array($plugins) && count($plugins)) { $this->filterPlugins($plugins); uasort($plugins, [$this, 'sort']); $this->trimInstanceStartingBackslash($plugins); - $this->inherited[$type] = $plugins; + $inherited[$type] = $plugins; $lastPerMethod = []; foreach ($plugins as $key => $plugin) { // skip disabled plugins @@ -310,21 +312,21 @@ private function inheritPlugins($type) $current = $lastPerMethod[$pluginMethod] ?? '__self'; $currentKey = $type . '_' . $pluginMethod . '_' . $current; if ($methodTypes & DefinitionInterface::LISTENER_AROUND) { - $this->processed[$currentKey][DefinitionInterface::LISTENER_AROUND] = $key; + $processed[$currentKey][DefinitionInterface::LISTENER_AROUND] = $key; $lastPerMethod[$pluginMethod] = $key; } if ($methodTypes & DefinitionInterface::LISTENER_BEFORE) { - $this->processed[$currentKey][DefinitionInterface::LISTENER_BEFORE][] = $key; + $processed[$currentKey][DefinitionInterface::LISTENER_BEFORE][] = $key; } if ($methodTypes & DefinitionInterface::LISTENER_AFTER) { - $this->processed[$currentKey][DefinitionInterface::LISTENER_AFTER][] = $key; + $processed[$currentKey][DefinitionInterface::LISTENER_AFTER][] = $key; } } } } return $plugins; } - return $this->inherited[$type]; + return $inherited[$type]; } /** diff --git a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php index eff3feff9cef1..096e58ab3a273 100644 --- a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php +++ b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php @@ -22,8 +22,6 @@ /** * Plugin config, provides list of plugins for a type - * - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class PluginList extends Scoped implements InterceptionPluginList { @@ -144,75 +142,10 @@ public function __construct( * * @param string $type * @return array - * @throws \InvalidArgumentException - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function _inheritPlugins($type) { - $type = ltrim($type, '\\'); - if (!isset($this->_inherited[$type])) { - $realType = $this->_omConfig->getOriginalInstanceType($type); - - if ($realType !== $type) { - $plugins = $this->_inheritPlugins($realType); - } elseif ($this->_relations->has($type)) { - $relations = $this->_relations->getParents($type); - $plugins = []; - foreach ($relations as $relation) { - if ($relation) { - $relationPlugins = $this->_inheritPlugins($relation); - if ($relationPlugins) { - $plugins = array_replace_recursive($plugins, $relationPlugins); - } - } - } - } else { - $plugins = []; - } - if (isset($this->_data[$type])) { - if (!$plugins) { - $plugins = $this->_data[$type]; - } else { - $plugins = array_replace_recursive($plugins, $this->_data[$type]); - } - } - $this->_inherited[$type] = null; - if (is_array($plugins) && count($plugins)) { - $this->configWriter->filterPlugins($plugins); - uasort($plugins, [$this, '_sort']); - $this->configWriter->trimInstanceStartingBackslash($plugins); - $this->_inherited[$type] = $plugins; - $lastPerMethod = []; - foreach ($plugins as $key => $plugin) { - // skip disabled plugins - if (isset($plugin['disabled']) && $plugin['disabled']) { - unset($plugins[$key]); - continue; - } - $pluginType = $this->_omConfig->getOriginalInstanceType($plugin['instance']); - if (!class_exists($pluginType)) { - throw new \InvalidArgumentException('Plugin class ' . $pluginType . ' doesn\'t exist'); - } - foreach ($this->_definitions->getMethodList($pluginType) as $pluginMethod => $methodTypes) { - $current = isset($lastPerMethod[$pluginMethod]) ? $lastPerMethod[$pluginMethod] : '__self'; - $currentKey = $type . '_' . $pluginMethod . '_' . $current; - if ($methodTypes & DefinitionInterface::LISTENER_AROUND) { - $this->_processed[$currentKey][DefinitionInterface::LISTENER_AROUND] = $key; - $lastPerMethod[$pluginMethod] = $key; - } - if ($methodTypes & DefinitionInterface::LISTENER_BEFORE) { - $this->_processed[$currentKey][DefinitionInterface::LISTENER_BEFORE][] = $key; - } - if ($methodTypes & DefinitionInterface::LISTENER_AFTER) { - $this->_processed[$currentKey][DefinitionInterface::LISTENER_AFTER][] = $key; - } - } - } - } - return $plugins; - } - return $this->_inherited[$type]; + return $this->configWriter->inheritPlugins($type, $this->_data, $this->_inherited, $this->_processed); } /** From e2933a9b78d8c5c8b21e8d4b46cef413fed5f7c2 Mon Sep 17 00:00:00 2001 From: Konstantin Dubovik Date: Mon, 22 Jun 2020 12:10:17 +0300 Subject: [PATCH 13/44] Remove sales order address handler class phpdoc (static test compliance) --- .../Sales/Model/ResourceModel/Order/Handler/Address.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/code/Magento/Sales/Model/ResourceModel/Order/Handler/Address.php b/app/code/Magento/Sales/Model/ResourceModel/Order/Handler/Address.php index c334f6e7a9576..274132a7fea50 100644 --- a/app/code/Magento/Sales/Model/ResourceModel/Order/Handler/Address.php +++ b/app/code/Magento/Sales/Model/ResourceModel/Order/Handler/Address.php @@ -9,9 +9,6 @@ use Magento\Sales\Model\Order; use Magento\Sales\Model\ResourceModel\Attribute; -/** - * Class Address - */ class Address { /** From 76e011a981d2ab38e6d23763e55dd53c2859fbcf Mon Sep 17 00:00:00 2001 From: Oleksandr Dubovyk Date: Mon, 22 Jun 2020 20:55:57 -0500 Subject: [PATCH 14/44] MC-31085: Add/Edit Product | Duplicating ".00" zeros on saves - fixed - modified test --- .../Magento/Framework/Locale/Format.php | 34 +++++++++++++++++++ .../Framework/Locale/Test/Unit/FormatTest.php | 2 ++ 2 files changed, 36 insertions(+) diff --git a/lib/internal/Magento/Framework/Locale/Format.php b/lib/internal/Magento/Framework/Locale/Format.php index 934c9638c7392..e332840327bf7 100644 --- a/lib/internal/Magento/Framework/Locale/Format.php +++ b/lib/internal/Magento/Framework/Locale/Format.php @@ -15,6 +15,17 @@ class Format implements \Magento\Framework\Locale\FormatInterface */ private const JAPAN_LOCALE_CODE = 'ja_JP'; + /** + * Arab locale code + */ + private const ARABIC_LOCALE_CODES = [ + 'ar_DZ', + 'ar_EG', + 'ar_KW', + 'ar_MA', + 'ar_SA', + ]; + /** * @var \Magento\Framework\App\ScopeResolverInterface */ @@ -73,6 +84,11 @@ public function getNumber($value) return (float)$value; } + /** Normalize for Arabic locale */ + if (in_array($this->_localeResolver->getLocale(), self::ARABIC_LOCALE_CODES)) { + $value = $this->normalizeArabicLocale($value); + } + //trim spaces and apostrophes $value = preg_replace('/[^0-9^\^.,-]/m', '', $value); @@ -163,4 +179,22 @@ public function getPriceFormat($localeCode = null, $currencyCode = null) return $result; } + + /** + * Normalizes the number of Arabic locale. + * + * Substitutes Arabic thousands grouping and Arabic decimal separator symbols (U+066C, U+066B) + * with common grouping and decimal separator + * + * @param string $value + * @return string + */ + private function normalizeArabicLocale($value): string + { + $arabicGroupSymbol = '٬'; + $arabicDecimalSymbol = '٫'; + $value = str_replace([$arabicGroupSymbol, $arabicDecimalSymbol], [',', '.'], $value); + + return $value; + } } diff --git a/lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php b/lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php index a204a733dc848..9c992ecff245c 100644 --- a/lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php +++ b/lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php @@ -146,6 +146,8 @@ public function provideNumbers(): array ['2,054.00', 2054], ['4,000', 4000.0, 'ja_JP'], ['4,000', 4.0, 'en_US'], + ['2٬599٫50', 2599.50, 'ar_EG'], + ['2٬000٬000٫99', 2000000.99, 'ar_SA'], ]; } } From 6085e89e65bce88b4878ac2d6b5efdba4edf660a Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Mon, 22 Jun 2020 23:42:42 -0500 Subject: [PATCH 15/44] MC-31618: Move static config to files - PLUGIN_LIST - Fix integration tests; --- .../TestFramework/Interception/PluginList.php | 12 +++++++++-- .../Framework/Interception/AbstractPlugin.php | 11 ++++++++++ .../Framework/Interception/ConfigLoader.php | 6 +++++- .../Framework/Interception/ConfigWriter.php | 5 ++++- .../Interception/ConfigWriterInterface.php | 2 +- .../Interception/PluginList/PluginList.php | 20 +++++++++---------- .../Console/Command/DiCompileCommandTest.php | 5 +++-- 7 files changed, 44 insertions(+), 17 deletions(-) diff --git a/dev/tests/integration/framework/Magento/TestFramework/Interception/PluginList.php b/dev/tests/integration/framework/Magento/TestFramework/Interception/PluginList.php index 88c9086f8270b..5bad5acf51b37 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Interception/PluginList.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Interception/PluginList.php @@ -5,6 +5,8 @@ */ namespace Magento\TestFramework\Interception; +use Magento\Framework\Interception\ConfigLoaderInterface; +use Magento\Framework\Interception\ConfigWriterInterface; use Magento\Framework\Serialize\SerializerInterface; /** @@ -31,6 +33,8 @@ class PluginList extends \Magento\Framework\Interception\PluginList\PluginList * @param array $scopePriorityScheme * @param string|null $cacheId * @param SerializerInterface|null $serializer + * @param ConfigLoaderInterface|null $configLoader + * @param ConfigWriterInterface|null $configWriter * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -44,7 +48,9 @@ public function __construct( \Magento\Framework\ObjectManager\DefinitionInterface $classDefinitions, array $scopePriorityScheme, $cacheId = 'plugins', - SerializerInterface $serializer = null + SerializerInterface $serializer = null, + ConfigLoaderInterface $configLoader = null, + ConfigWriterInterface $configWriter = null ) { parent::__construct( $reader, @@ -57,7 +63,9 @@ public function __construct( $classDefinitions, $scopePriorityScheme, $cacheId, - $serializer + $serializer, + $configLoader, + $configWriter ); $this->_originScopeScheme = $this->_scopePriorityScheme; } diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/AbstractPlugin.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/AbstractPlugin.php index 1f65bca8f5f1d..e05ed274d097a 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Interception/AbstractPlugin.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/AbstractPlugin.php @@ -5,6 +5,8 @@ */ namespace Magento\Framework\Interception; +use Magento\Framework\App\Filesystem\DirectoryList; + /** * Class GeneralTest * @@ -81,6 +83,10 @@ public function setUpInterceptionConfig($pluginConfig) $cacheManager->method('load')->willReturn(null); $definitions = new \Magento\Framework\ObjectManager\Definition\Runtime(); $relations = new \Magento\Framework\ObjectManager\Relations\Runtime(); + $dirList = new DirectoryList(DirectoryList::GENERATED_METADATA); + $configLoader = new \Magento\Framework\Interception\ConfigLoader($dirList); + $logger = $this->createMock(\Psr\Log\LoggerInterface::class); + $configWriter = $this->createMock(\Magento\Framework\App\ObjectManager\ConfigWriterInterface::class); $interceptionConfig = new Config\Config( $this->_configReader, $configScope, @@ -104,6 +110,9 @@ public function setUpInterceptionConfig($pluginConfig) \Magento\Framework\ObjectManager\DefinitionInterface::class => $definitions, \Magento\Framework\Interception\DefinitionInterface::class => $interceptionDefinitions, \Magento\Framework\Serialize\SerializerInterface::class => $json, + \Magento\Framework\Interception\ConfigLoaderInterface::class => $configLoader, + \Psr\Log\LoggerInterface::class => $logger, + \Magento\Framework\App\ObjectManager\ConfigWriterInterface::class => $configWriter ]; $this->_objectManager = new \Magento\Framework\ObjectManager\ObjectManager( $factory, @@ -120,6 +129,8 @@ public function setUpInterceptionConfig($pluginConfig) \Magento\Framework\Interception\PluginList\PluginList::class, \Magento\Framework\Interception\ChainInterface::class => \Magento\Framework\Interception\Chain\Chain::class, + \Magento\Framework\Interception\ConfigWriterInterface::class => + \Magento\Framework\Interception\ConfigWriter::class ], ] ); diff --git a/lib/internal/Magento/Framework/Interception/ConfigLoader.php b/lib/internal/Magento/Framework/Interception/ConfigLoader.php index 6772f981c542d..c83c5d8c2bcbd 100644 --- a/lib/internal/Magento/Framework/Interception/ConfigLoader.php +++ b/lib/internal/Magento/Framework/Interception/ConfigLoader.php @@ -25,7 +25,11 @@ public function __construct( } /** - * @inheritDoc + * Load interception configuration data per scope. + * + * @param string $cacheId + * @return array + * @throws \Magento\Framework\Exception\FileSystemException */ public function load($cacheId) { diff --git a/lib/internal/Magento/Framework/Interception/ConfigWriter.php b/lib/internal/Magento/Framework/Interception/ConfigWriter.php index 6a3fbc95fcb78..050513a55f07d 100644 --- a/lib/internal/Magento/Framework/Interception/ConfigWriter.php +++ b/lib/internal/Magento/Framework/Interception/ConfigWriter.php @@ -143,7 +143,10 @@ public function __construct( } /** - * @inheritDoc + * Write interception configuration for scopes. + * + * @param array $scopes + * @return void */ public function write($scopes) { diff --git a/lib/internal/Magento/Framework/Interception/ConfigWriterInterface.php b/lib/internal/Magento/Framework/Interception/ConfigWriterInterface.php index 79f891ccbb3f1..635833cf4f8d3 100644 --- a/lib/internal/Magento/Framework/Interception/ConfigWriterInterface.php +++ b/lib/internal/Magento/Framework/Interception/ConfigWriterInterface.php @@ -14,7 +14,7 @@ interface ConfigWriterInterface * Write interception configuration for scopes. * * @param array $scopes - * @return array + * @return void */ public function write($scopes); } diff --git a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php index 096e58ab3a273..9acc8c547ae7f 100644 --- a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php +++ b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php @@ -9,6 +9,8 @@ use Magento\Framework\Config\Data\Scoped; use Magento\Framework\Config\ReaderInterface; use Magento\Framework\Config\ScopeInterface; +use Magento\Framework\Interception\ConfigLoaderInterface; +use Magento\Framework\Interception\ConfigWriterInterface; use Magento\Framework\Interception\DefinitionInterface; use Magento\Framework\Interception\PluginListInterface as InterceptionPluginList; use Magento\Framework\Interception\ObjectManager\ConfigInterface; @@ -17,8 +19,6 @@ use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Serialize\SerializerInterface; use Magento\Framework\Serialize\Serializer\Serialize; -use Magento\Framework\Interception\ConfigLoader; -use Magento\Framework\Interception\ConfigWriter; /** * Plugin config, provides list of plugins for a type @@ -83,12 +83,12 @@ class PluginList extends Scoped implements InterceptionPluginList private $serializer; /** - * @var ConfigLoader + * @var ConfigLoaderInterface */ private $configLoader; /** - * @var ConfigWriter + * @var ConfigWriterInterface */ private $configWriter; @@ -106,8 +106,8 @@ class PluginList extends Scoped implements InterceptionPluginList * @param array $scopePriorityScheme * @param string|null $cacheId * @param SerializerInterface|null $serializer - * @param ConfigLoader|null $configLoader - * @param ConfigWriter|null $configWriter + * @param ConfigLoaderInterface|null $configLoader + * @param ConfigWriterInterface|null $configWriter * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -122,8 +122,8 @@ public function __construct( array $scopePriorityScheme = ['global'], $cacheId = 'plugins', SerializerInterface $serializer = null, - ConfigLoader $configLoader = null, - ConfigWriter $configWriter = null + ConfigLoaderInterface $configLoader = null, + ConfigWriterInterface $configWriter = null ) { $this->serializer = $serializer ?: $objectManager->get(Serialize::class); parent::__construct($reader, $configScope, $cache, $cacheId, $this->serializer); @@ -133,8 +133,8 @@ public function __construct( $this->_classDefinitions = $classDefinitions; $this->_scopePriorityScheme = $scopePriorityScheme; $this->_objectManager = $objectManager; - $this->configLoader = $configLoader ?: $this->_objectManager->get(ConfigLoader::class); - $this->configWriter = $configWriter ?: $this->_objectManager->get(ConfigWriter::class); + $this->configLoader = $configLoader ?: $this->_objectManager->get(ConfigLoaderInterface::class); + $this->configWriter = $configWriter ?: $this->_objectManager->get(ConfigWriterInterface::class); } /** diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php index e269f89073dd7..a085eb0b20611 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php @@ -160,7 +160,7 @@ public function testExecute() ->with(ProgressBar::class) ->willReturn($progressBar); - $this->managerMock->expects($this->exactly(8))->method('addOperation') + $this->managerMock->expects($this->exactly(9))->method('addOperation') ->withConsecutive( [OperationFactory::PROXY_GENERATOR, []], [OperationFactory::REPOSITORY_GENERATOR, $this->anything()], @@ -178,7 +178,8 @@ public function testExecute() [OperationFactory::INTERCEPTION, $this->anything()], [OperationFactory::AREA_CONFIG_GENERATOR, $this->anything()], [OperationFactory::INTERCEPTION_CACHE, $this->anything()], - [OperationFactory::APPLICATION_ACTION_LIST_GENERATOR, $this->anything()] + [OperationFactory::APPLICATION_ACTION_LIST_GENERATOR, $this->anything()], + [OperationFactory::PLUGIN_LIST_GENERATOR, $this->anything()] ); $this->managerMock->expects($this->once())->method('process'); From 5a4c5bedab4eddbbb5ec006d3119c8b564acf2e7 Mon Sep 17 00:00:00 2001 From: "rostyslav.hymon" Date: Tue, 23 Jun 2020 16:56:01 +0300 Subject: [PATCH 16/44] MC-35295: Unable to hide product images via import --- .../Model/Import/Product.php | 12 +++++---- .../Import/Product/MediaGalleryProcessor.php | 4 ++- .../Model/Import/ProductTest.php | 25 +++++++++++++++++++ .../import_image_name_without_slash.csv | 3 +++ 4 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/_files/import_image_name_without_slash.csv diff --git a/app/code/Magento/CatalogImportExport/Model/Import/Product.php b/app/code/Magento/CatalogImportExport/Model/Import/Product.php index c5fcac99767bd..189bfa61f2c42 100644 --- a/app/code/Magento/CatalogImportExport/Model/Import/Product.php +++ b/app/code/Magento/CatalogImportExport/Model/Import/Product.php @@ -1595,6 +1595,7 @@ protected function _saveProducts() } $rowSku = $rowData[self::COL_SKU]; + $rowSkuNormalized = mb_strtolower($rowSku); if (null === $rowSku) { $this->getErrorAggregator()->addRowToSkip($rowNum); @@ -1604,9 +1605,9 @@ protected function _saveProducts() $storeId = !empty($rowData[self::COL_STORE]) ? $this->getStoreIdByCode($rowData[self::COL_STORE]) : Store::DEFAULT_STORE_ID; - $rowExistingImages = $existingImages[$storeId][$rowSku] ?? []; + $rowExistingImages = $existingImages[$storeId][$rowSkuNormalized] ?? []; $rowStoreMediaGalleryValues = $rowExistingImages; - $rowExistingImages += $existingImages[Store::DEFAULT_STORE_ID][$rowSku] ?? []; + $rowExistingImages += $existingImages[Store::DEFAULT_STORE_ID][$rowSkuNormalized] ?? []; if (self::SCOPE_STORE == $rowScope) { // set necessary data from SCOPE_DEFAULT row @@ -1762,10 +1763,11 @@ protected function _saveProducts() continue; } - if (isset($rowExistingImages[$uploadedFile])) { - $currentFileData = $rowExistingImages[$uploadedFile]; + $uploadedFileNormalized = ltrim($uploadedFile, '/\\'); + if (isset($rowExistingImages[$uploadedFileNormalized])) { + $currentFileData = $rowExistingImages[$uploadedFileNormalized]; $currentFileData['store_id'] = $storeId; - $storeMediaGalleryValueExists = isset($rowStoreMediaGalleryValues[$uploadedFile]); + $storeMediaGalleryValueExists = isset($rowStoreMediaGalleryValues[$uploadedFileNormalized]); if (array_key_exists($uploadedFile, $imageHiddenStates) && $currentFileData['disabled'] != $imageHiddenStates[$uploadedFile] ) { diff --git a/app/code/Magento/CatalogImportExport/Model/Import/Product/MediaGalleryProcessor.php b/app/code/Magento/CatalogImportExport/Model/Import/Product/MediaGalleryProcessor.php index a94a87a44b32a..d4694b72ba64f 100644 --- a/app/code/Magento/CatalogImportExport/Model/Import/Product/MediaGalleryProcessor.php +++ b/app/code/Magento/CatalogImportExport/Model/Import/Product/MediaGalleryProcessor.php @@ -384,7 +384,9 @@ public function getExistingImages(array $bunch) foreach ($this->connection->fetchAll($select) as $image) { $storeId = $image['store_id']; unset($image['store_id']); - $result[$storeId][$image['sku']][$image['value']] = $image; + $sku = mb_strtolower($image['sku']); + $value = ltrim($image['value'], '/\\'); + $result[$storeId][$sku][$value] = $image; } return $result; diff --git a/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php index 9dee418f010a8..d3f012bb0852f 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php @@ -3196,4 +3196,29 @@ public function testImportProductsWithLinksInDifferentBunches() } $this->assertEquals($linksData, $importedProductLinks); } + + /** + * Tests that image name does not have to be prefixed by slash + * + * @magentoDataFixture mediaImportImageFixture + * @magentoDataFixture Magento/Store/_files/core_fixturestore.php + * @magentoDataFixture Magento/Catalog/_files/product_with_image.php + */ + public function testUpdateImageByNameNotPrefixedWithSlash() + { + $expectedLabelForDefaultStoreView = 'image label updated'; + $expectedImageFile = '/m/a/magento_image.jpg'; + $secondStoreCode = 'fixturestore'; + $productSku = 'simple'; + $this->importDataForMediaTest('import_image_name_without_slash.csv'); + $product = $this->getProductBySku($productSku); + $imageItems = $product->getMediaGalleryImages()->getItems(); + $this->assertCount(1, $imageItems); + $imageItem = array_shift($imageItems); + $this->assertEquals($expectedImageFile, $imageItem->getFile()); + $this->assertEquals($expectedLabelForDefaultStoreView, $imageItem->getLabel()); + $product = $this->getProductBySku($productSku, $secondStoreCode); + $imageItems = $product->getMediaGalleryImages()->getItems(); + $this->assertCount(0, $imageItems); + } } diff --git a/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/_files/import_image_name_without_slash.csv b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/_files/import_image_name_without_slash.csv new file mode 100644 index 0000000000000..415501daf89d8 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/_files/import_image_name_without_slash.csv @@ -0,0 +1,3 @@ +"sku","store_view_code","base_image","base_image_label","hide_from_product_page" +"simple",,"m/a/magento_image.jpg","image label updated", +"simple","fixturestore",,,"m/a/magento_image.jpg" From c9ed41b28779b748f4cb46d706ce30133995de6c Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Wed, 24 Jun 2020 00:00:15 -0500 Subject: [PATCH 17/44] MC-31618: Move static config to files - PLUGIN_LIST - Fix unit tests; - Some assertions from PluginList unit test were removed because its logic was moved to ConfigWriter; --- .../Framework/Interception/AbstractPlugin.php | 2 - .../Test/Unit/PluginList/PluginListTest.php | 399 +++++++++--------- .../Test/Unit/_files/load_scoped_mock_map.php | 85 ++++ 3 files changed, 279 insertions(+), 207 deletions(-) create mode 100644 lib/internal/Magento/Framework/Interception/Test/Unit/_files/load_scoped_mock_map.php diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/AbstractPlugin.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/AbstractPlugin.php index e05ed274d097a..d9c0e0e17da3a 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Interception/AbstractPlugin.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/AbstractPlugin.php @@ -127,8 +127,6 @@ public function setUpInterceptionConfig($pluginConfig) 'preferences' => [ \Magento\Framework\Interception\PluginListInterface::class => \Magento\Framework\Interception\PluginList\PluginList::class, - \Magento\Framework\Interception\ChainInterface::class => - \Magento\Framework\Interception\Chain\Chain::class, \Magento\Framework\Interception\ConfigWriterInterface::class => \Magento\Framework\Interception\ConfigWriter::class ], diff --git a/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php b/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php index 56740268026c2..ef24c2d9329da 100644 --- a/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php +++ b/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php @@ -9,23 +9,23 @@ use Magento\Framework\Config\CacheInterface; use Magento\Framework\Config\ScopeInterface; +use Magento\Framework\Interception\ConfigLoaderInterface; +use Magento\Framework\Interception\ConfigWriterInterface; use Magento\Framework\Interception\ObjectManager\ConfigInterface; use Magento\Framework\Interception\PluginList\PluginList; use Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item; -use Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item\Enhanced; use Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer; +use Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainerPlugin\Simple as ItemContainerPlugin; use Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemPlugin\Advanced; use Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemPlugin\Simple; use Magento\Framework\Interception\Test\Unit\Custom\Module\Model\StartingBackslash; -use Magento\Framework\Interception\Test\Unit\Custom\Module\Model\StartingBackslash\Plugin; +use Magento\Framework\Interception\Test\Unit\Custom\Module\Model\StartingBackslash\Plugin as StartingBackslashPlugin; use Magento\Framework\ObjectManager\Config\Reader\Dom; use Magento\Framework\ObjectManager\Definition\Runtime; use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Serialize\SerializerInterface; -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Psr\Log\LoggerInterface; require_once __DIR__ . '/../Custom/Module/Model/Item.php'; require_once __DIR__ . '/../Custom/Module/Model/Item/Enhanced.php'; @@ -57,81 +57,151 @@ class PluginListTest extends TestCase */ private $cacheMock; - /** - * @var LoggerInterface|MockObject - */ - private $loggerMock; - /** * @var SerializerInterface|MockObject */ private $serializerMock; /** - * @var ObjectManagerInterface|MockObject + * @var ConfigLoaderInterface|MockObject */ - private $objectManagerMock; + private $configLoaderMock; protected function setUp(): void { - $readerMap = include __DIR__ . '/../_files/reader_mock_map.php'; + $loadScoped = include __DIR__ . '/../_files/load_scoped_mock_map.php'; $readerMock = $this->createMock(Dom::class); - $readerMock->expects($this->any())->method('read')->willReturnMap($readerMap); $this->configScopeMock = $this->getMockForAbstractClass(ScopeInterface::class); $this->cacheMock = $this->getMockBuilder(CacheInterface::class) ->setMethods(['get']) ->getMockForAbstractClass(); // turn cache off - $this->cacheMock->expects($this->any()) - ->method('get') - ->willReturn(false); + $this->cacheMock->method('get')->willReturn(false); $omConfigMock = $this->getMockForAbstractClass( ConfigInterface::class ); - $omConfigMock->expects($this->any())->method('getOriginalInstanceType')->willReturnArgument(0); + $omConfigMock->method('getOriginalInstanceType')->willReturnArgument(0); - $this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class) + $objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class) ->setMethods(['get']) ->getMockForAbstractClass(); - $this->objectManagerMock->expects($this->any()) - ->method('get') - ->willReturnArgument(0); + $objectManagerMock->method('get')->willReturnArgument(0); $this->serializerMock = $this->getMockForAbstractClass(SerializerInterface::class); - $definitions = new Runtime(); + $this->configLoaderMock = $this->getMockBuilder(ConfigLoaderInterface::class) + ->onlyMethods(['load']) + ->getMockForAbstractClass(); + $configWriterMock = $this->getMockBuilder(ConfigWriterInterface::class) + ->addMethods(['loadScopedVirtualTypes', 'getClassDefinitions', 'inheritPlugins']) + ->getMockForAbstractClass(); + $configWriterMock->method('loadScopedVirtualTypes') + ->willReturnMap($loadScoped); + $configWriterMock->method('getClassDefinitions') + ->willReturn([]); - $objectManagerHelper = new ObjectManager($this); - $this->object = $objectManagerHelper->getObject( - PluginList::class, - [ - 'reader' => $readerMock, - 'configScope' => $this->configScopeMock, - 'cache' => $this->cacheMock, - 'relations' => new \Magento\Framework\ObjectManager\Relations\Runtime(), - 'omConfig' => $omConfigMock, - 'definitions' => new \Magento\Framework\Interception\Definition\Runtime(), - 'objectManager' => $this->objectManagerMock, - 'classDefinitions' => $definitions, - 'scopePriorityScheme' => ['global'], - 'cacheId' => 'interception', - 'serializer' => $this->serializerMock - ] - ); + $definitions = new Runtime(); - $this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class); - $objectManagerHelper->setBackwardCompatibleProperty( - $this->object, - 'logger', - $this->loggerMock - ); + // tested class is a mock to be able to set its protected properties values in closure + $this->object = $this->getMockBuilder(PluginList::class) + ->disableProxyingToOriginalMethods() + ->onlyMethods(['_inheritPlugins']) + ->setConstructorArgs( + [ + 'reader' => $readerMock, + 'configScope' => $this->configScopeMock, + 'cache' => $this->cacheMock, + 'relations' => new \Magento\Framework\ObjectManager\Relations\Runtime(), + 'omConfig' => $omConfigMock, + 'definitions' => new \Magento\Framework\Interception\Definition\Runtime(), + 'objectManager' => $objectManagerMock, + 'classDefinitions' => $definitions, + 'scopePriorityScheme' => ['global'], + 'cacheId' => 'interception', + 'serializer' => $this->serializerMock, + 'configLoader' => $this->configLoaderMock, + 'configWriter' => $configWriterMock + ] + ) + ->getMock(); } public function testGetPlugin() { - $this->configScopeMock->expects($this->any())->method('getCurrentScope')->willReturn('backend'); + $inheritPlugins = function ($type) + { + $inheritedItem = [ + Item::class => [ + 'advanced_plugin' => [ + 'sortOrder' => 5, + 'instance' => Advanced::class, + ], + 'simple_plugin' => [ + 'sortOrder' => 10, + 'instance' => Simple::class + ] + ] + ]; + $processedItem = [ + 'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item_getName___self' => [ + 2 => 'advanced_plugin', + 4 => [ + 'advanced_plugin' + ] + ], + 'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item_getName_advanced_plugin' => [ + 4 => [ + 'simple_plugin' + ] + ] + ]; + + $inheritedItemContainer = [ + ItemContainer::class => [ + 'simple_plugin' => [ + 'sortOrder' => 15, + 'instance' => ItemContainerPlugin::class + ] + ] + ]; + $processedItemContainer = [ + 'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer_getName___self' => [ + 4 => [ + 'simple_plugin' + ] + ] + ]; + + $inheritedStartingBackslash = [ + StartingBackslash::class => [ + 'simple_plugin' => [ + 'sortOrder' => 20, + 'instance' => StartingBackslashPlugin::class + ] + ] + ]; + + if ($type === 'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item') { + $this->_inherited = $inheritedItem; + $this->_processed = $processedItem; + } + + if ($type === 'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer') { + $this->_inherited = array_merge($inheritedItem, $inheritedItemContainer); + $this->_processed = array_merge($processedItem, $processedItemContainer); + } + + if ($type === 'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\StartingBackslash') { + $this->_inherited = array_merge($inheritedItem, $inheritedItemContainer, $inheritedStartingBackslash); + $this->_processed = array_merge($processedItem, $processedItemContainer); + } + }; + $inheritPlugins = $inheritPlugins->bindTo($this->object, PluginList::class); + $this->object->method('_inheritPlugins')->willReturnCallback($inheritPlugins); + + $this->configScopeMock->method('getCurrentScope')->willReturn('backend'); $this->object->getNext(Item::class, 'getName'); $this->object->getNext( ItemContainer::class, @@ -156,14 +226,14 @@ public function testGetPlugin() ) ); $this->assertEquals( - \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainerPlugin\Simple::class, + ItemContainerPlugin::class, $this->object->getPlugin( ItemContainer::class, 'simple_plugin' ) ); $this->assertEquals( - Plugin::class, + StartingBackslashPlugin::class, $this->object->getPlugin( StartingBackslash::class, 'simple_plugin' @@ -189,13 +259,34 @@ public function testGetPlugins( array $scopePriorityScheme = ['global'] ): void { $this->setScopePriorityScheme($scopePriorityScheme); - $this->configScopeMock->expects( - $this->any() - )->method( - 'getCurrentScope' - )->willReturn( - $scopeCode - ); + $this->configScopeMock->method('getCurrentScope')->willReturn($scopeCode); + + $inheritPlugins = function ($type) + { + $inheritedItem = [ + Item::class => [ + 'simple_plugin' => [ + 'sortOrder' => 10, + 'instance' => Simple::class + ] + ] + ]; + $processedItem = [ + 'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item_getName___self' => [ + 4 => [ + 'simple_plugin' + ] + ], + ]; + + if ($type === 'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item') { + $this->_inherited = $inheritedItem; + $this->_processed = $processedItem; + } + }; + $inheritPlugins = $inheritPlugins->bindTo($this->object, PluginList::class); + $this->object->method('_inheritPlugins')->willReturnCallback($inheritPlugins); + $this->assertEquals($expectedResult, $this->object->getNext($type, $method, $code)); } @@ -209,139 +300,10 @@ public function getPluginsDataProvider() [4 => ['simple_plugin']], Item::class, 'getName', 'global', - ], - [ - // advanced plugin has lower sort order - [2 => 'advanced_plugin', 4 => ['advanced_plugin']], - Item::class, - 'getName', - 'backend' - ], - [ - // advanced plugin has lower sort order - [4 => ['simple_plugin']], - Item::class, - 'getName', - 'backend', - 'advanced_plugin' - ], - // simple plugin is disabled in configuration for - // \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item in frontend - [null, Item::class, 'getName', 'frontend'], - // test plugin inheritance - [ - [4 => ['simple_plugin']], - Enhanced::class, - 'getName', - 'global' - ], - [ - // simple plugin is disabled in configuration for parent - [2 => 'advanced_plugin', 4 => ['advanced_plugin']], - Enhanced::class, - 'getName', - 'frontend' - ], - [ - null, - ItemContainer::class, - 'getName', - 'global' - ], - [ - [4 => ['simple_plugin']], - ItemContainer::class, - 'getName', - 'backend' - ], - [ - // even though the scope is primary, both primary and global scopes are loaded - // because global is in default priority scheme - [ - 4 => [ - 'primary_plugin', - 'simple_plugin', - ] - ], - \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item::class, - 'getName', - 'primary', - '__self', - ['primary', 'global'] - ], - [ - [ - 4 => [ - 'primary_plugin', - 'simple_plugin', - ] - ], - \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item::class, - 'getName', - 'global', - '__self', - ['primary', 'global'] - ], - [ - [ - 4 => [ - 'primary_plugin', - ] - ], - \Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item::class, - 'getName', - 'frontend', - '__self', - ['primary', 'global'] - ], + ] ]; } - /** - * @covers \Magento\Framework\Interception\PluginList\PluginList::getNext - * @covers \Magento\Framework\Interception\PluginList\PluginList::_inheritPlugins - */ - public function testInheritPluginsWithNonExistingClass() - { - $this->expectException('InvalidArgumentException'); - $this->configScopeMock->expects($this->any()) - ->method('getCurrentScope') - ->willReturn('frontend'); - - $this->object->getNext('SomeType', 'someMethod'); - } - - public function testLoadScopedDataNotCached() - { - $this->configScopeMock->expects($this->exactly(3)) - ->method('getCurrentScope') - ->willReturn('scope'); - $this->serializerMock->expects($this->once()) - ->method('serialize'); - $this->serializerMock->expects($this->never()) - ->method('unserialize'); - $this->cacheMock->expects($this->once()) - ->method('save'); - - $this->assertNull($this->object->getNext('Type', 'method')); - } - - /** - * @covers \Magento\Framework\Interception\PluginList\PluginList::getNext - * @covers \Magento\Framework\Interception\PluginList\PluginList::_inheritPlugins - */ - public function testInheritPluginsWithNotExistingPlugin() - { - $this->loggerMock->expects($this->once()) - ->method('info') - ->with("Reference to undeclared plugin with name 'simple_plugin'."); - $this->configScopeMock->expects($this->any()) - ->method('getCurrentScope') - ->willReturn('frontend'); - - $this->assertNull($this->object->getNext('typeWithoutInstance', 'someMethod')); - } - /** * @covers \Magento\Framework\Interception\PluginList\PluginList::getNext * @covers \Magento\Framework\Interception\PluginList\PluginList::_loadScopedData @@ -365,6 +327,24 @@ public function testLoadScopedDataCached() ->with('global|scope|interception') ->willReturn($serializedData); + $inheritPlugins = function ($type) + { + $inherited = [ + 0 => 'key', + 'Type' => null + ]; + $processed = [ + 0 => 'key' + ]; + + if ($type === 'Type') { + $this->_inherited = $inherited; + $this->_processed = $processed; + } + }; + $inheritPlugins = $inheritPlugins->bindTo($this->object, PluginList::class); + $this->object->method('_inheritPlugins')->willReturnCallback($inheritPlugins); + $this->assertNull($this->object->getNext('Type', 'method')); } @@ -372,29 +352,38 @@ public function testLoadScopedDataCached() * @covers \Magento\Framework\Interception\PluginList\PluginList::getNext * @covers \Magento\Framework\Interception\PluginList\PluginList::_loadScopedData */ - public function testLoadScopeDataWithEmptyData() + public function testLoadScopedDataGenerated() { - $this->objectManagerMock->expects($this->any()) - ->method('get') - ->willReturnArgument(0); - $this->configScopeMock->expects($this->any()) + $this->configScopeMock->expects($this->once()) ->method('getCurrentScope') - ->willReturn('emptyscope'); + ->willReturn('scope'); - $this->assertEquals( - [4 => ['simple_plugin']], - $this->object->getNext( - Item::class, - 'getName' - ) - ); - $this->assertEquals( - Simple::class, - $this->object->getPlugin( - Item::class, - 'simple_plugin' - ) - ); + $data = [['key'], ['key'], ['key']]; + + $this->configLoaderMock->expects($this->once()) + ->method('load') + ->with('global|scope|interception') + ->willReturn($data); + + $inheritPlugins = function ($type) + { + $inherited = [ + 0 => 'key', + 'Type' => null + ]; + $processed = [ + 0 => 'key' + ]; + + if ($type === 'Type') { + $this->_inherited = $inherited; + $this->_processed = $processed; + } + }; + $inheritPlugins = $inheritPlugins->bindTo($this->object, PluginList::class); + $this->object->method('_inheritPlugins')->willReturnCallback($inheritPlugins); + + $this->assertNull($this->object->getNext('Type', 'method')); } /** diff --git a/lib/internal/Magento/Framework/Interception/Test/Unit/_files/load_scoped_mock_map.php b/lib/internal/Magento/Framework/Interception/Test/Unit/_files/load_scoped_mock_map.php new file mode 100644 index 0000000000000..3773ea0007590 --- /dev/null +++ b/lib/internal/Magento/Framework/Interception/Test/Unit/_files/load_scoped_mock_map.php @@ -0,0 +1,85 @@ + 'global'], + [], + [], + [], + null, + [ + [], + [1 => 'global'], + ['global' => true], + [ + Item::class => [ + 'simple_plugin' => [ + 'sortOrder' => 10, + 'instance' => ItemPluginSimple::class, + ], + ] + ], + [], + [] + ], + ], + [ + [ + 'global', + 'backend' + ], + [], + [], + [], + null, + [ + [], + [ + 'global', + 'backend' + ], + [ + 'global' => true, + 'backend' => true + ], + [ + Item::class => [ + 'simple_plugin' => [ + 'sortOrder' => 10, + 'instance' => Simple::class, + ], + 'advanced_plugin' => [ + 'sortOrder' => 5, + 'instance' => Advanced::class, + ], + ], + ItemContainer::class => [ + 'simple_plugin' => [ + 'sortOrder' => 15, + 'instance' => Simple::class, + ], + ], + StartingBackslash::class => [ + 'simple_plugin' => [ + 'sortOrder' => 20, + 'instance' => Plugin::class, + ], + ] + ], + [], + [] + ] + ] +]; From 1de0335fdaad95ff8ec3faf74d47c9ed2e540964 Mon Sep 17 00:00:00 2001 From: Serhii Balko Date: Wed, 24 Jun 2020 12:56:05 +0300 Subject: [PATCH 18/44] MC-35361: [GraphQL] - Grouped Products - No data returns for arrays like "product_links" --- .../Model/ProductLinksTypeResolver.php | 6 +- .../Resolver/Product/BatchProductLinks.php | 12 +- app/code/Magento/CatalogGraphQl/etc/di.xml | 10 ++ .../Model/GroupedProductLinksTypeResolver.php | 8 +- .../Magento/GroupedProductGraphQl/etc/di.xml | 7 ++ .../GroupedProduct/GroupedProductViewTest.php | 107 +++++++++++++----- 6 files changed, 113 insertions(+), 37 deletions(-) diff --git a/app/code/Magento/CatalogGraphQl/Model/ProductLinksTypeResolver.php b/app/code/Magento/CatalogGraphQl/Model/ProductLinksTypeResolver.php index 5a230ceed0ca4..c6de07bdedd19 100644 --- a/app/code/Magento/CatalogGraphQl/Model/ProductLinksTypeResolver.php +++ b/app/code/Magento/CatalogGraphQl/Model/ProductLinksTypeResolver.php @@ -10,7 +10,7 @@ use Magento\Framework\GraphQl\Query\Resolver\TypeResolverInterface; /** - * {@inheritdoc} + * @inheritdoc */ class ProductLinksTypeResolver implements TypeResolverInterface { @@ -20,9 +20,9 @@ class ProductLinksTypeResolver implements TypeResolverInterface private $linkTypes = ['related', 'upsell', 'crosssell']; /** - * {@inheritdoc} + * @inheritdoc */ - public function resolveType(array $data) : string + public function resolveType(array $data): string { if (isset($data['link_type'])) { $linkType = $data['link_type']; diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/BatchProductLinks.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/BatchProductLinks.php index 14732ecf37c63..187fd05c1001e 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/BatchProductLinks.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/BatchProductLinks.php @@ -22,7 +22,15 @@ class BatchProductLinks implements BatchServiceContractResolverInterface /** * @var string[] */ - private static $linkTypes = ['related', 'upsell', 'crosssell']; + private $linkTypes; + + /** + * @param array $linkTypes + */ + public function __construct(array $linkTypes) + { + $this->linkTypes = $linkTypes; + } /** * @inheritDoc @@ -44,7 +52,7 @@ public function convertToServiceArgument(ResolveRequestInterface $request) /** @var \Magento\Catalog\Model\Product $product */ $product = $value['model']; - return new ListCriteria((string)$product->getId(), self::$linkTypes, $product); + return new ListCriteria((string)$product->getId(), $this->linkTypes, $product); } /** diff --git a/app/code/Magento/CatalogGraphQl/etc/di.xml b/app/code/Magento/CatalogGraphQl/etc/di.xml index 5fec7bfd4fda7..03f9d7ad03f04 100644 --- a/app/code/Magento/CatalogGraphQl/etc/di.xml +++ b/app/code/Magento/CatalogGraphQl/etc/di.xml @@ -74,4 +74,14 @@ + + + + + related + upsell + crosssell + + + diff --git a/app/code/Magento/GroupedProductGraphQl/Model/GroupedProductLinksTypeResolver.php b/app/code/Magento/GroupedProductGraphQl/Model/GroupedProductLinksTypeResolver.php index 92cfb375fea41..29fa2bffabb3b 100644 --- a/app/code/Magento/GroupedProductGraphQl/Model/GroupedProductLinksTypeResolver.php +++ b/app/code/Magento/GroupedProductGraphQl/Model/GroupedProductLinksTypeResolver.php @@ -10,7 +10,7 @@ use Magento\Framework\GraphQl\Query\Resolver\TypeResolverInterface; /** - * {@inheritdoc} + * @inheritdoc */ class GroupedProductLinksTypeResolver implements TypeResolverInterface { @@ -20,14 +20,14 @@ class GroupedProductLinksTypeResolver implements TypeResolverInterface private $linkTypes = ['associated']; /** - * {@inheritdoc} + * @inheritdoc */ - public function resolveType(array $data) : string + public function resolveType(array $data): string { if (isset($data['link_type'])) { $linkType = $data['link_type']; if (in_array($linkType, $this->linkTypes)) { - return 'GroupedProductLinks'; + return 'ProductLinks'; } } return ''; diff --git a/app/code/Magento/GroupedProductGraphQl/etc/di.xml b/app/code/Magento/GroupedProductGraphQl/etc/di.xml index 35b63370baf2f..717bc14826f70 100644 --- a/app/code/Magento/GroupedProductGraphQl/etc/di.xml +++ b/app/code/Magento/GroupedProductGraphQl/etc/di.xml @@ -13,4 +13,11 @@ + + + + associated + + + diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/GroupedProduct/GroupedProductViewTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/GroupedProduct/GroupedProductViewTest.php index e6db0b9e808ef..8cb0a6db972b4 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/GroupedProduct/GroupedProductViewTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/GroupedProduct/GroupedProductViewTest.php @@ -7,12 +7,29 @@ namespace Magento\GraphQl\GroupedProduct; +use Magento\Catalog\Api\Data\ProductInterface; use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\TestFramework\ObjectManager; use Magento\TestFramework\TestCase\GraphQlAbstract; +/** + * Class to test GraphQl response with grouped products + */ class GroupedProductViewTest extends GraphQlAbstract { + /** + * @var ProductRepositoryInterface + */ + private $productRepository; + + /** + * @inheritdoc + */ + protected function setUp(): void + { + parent::setUp(); + $this->productRepository = ObjectManager::getInstance()->get(ProductRepositoryInterface::class); + } /** * @magentoApiDataFixture Magento/GroupedProduct/_files/product_grouped.php @@ -20,17 +37,16 @@ class GroupedProductViewTest extends GraphQlAbstract public function testAllFieldsGroupedProduct() { $productSku = 'grouped-product'; - $query - = <<graphQlQuery($query); - /** @var ProductRepositoryInterface $productRepository */ - $productRepository = ObjectManager::getInstance()->get(ProductRepositoryInterface::class); - $groupedProduct = $productRepository->get($productSku, false, null, true); + $groupedProduct = $this->productRepository->get($productSku, false, null, true); - $this->assertGroupedProductItems($groupedProduct, $response['products']['items'][0]); + $this->assertNotEmpty( + $response['products']['items'][0]['items'], + "Precondition failed: 'Grouped product items' must not be empty" + ); + $this->assertGroupedProductItems($groupedProduct, $response['products']['items'][0]['items']); + $this->assertNotEmpty( + $response['products']['items'][0]['product_links'], + "Precondition failed: 'Linked product items' must not be empty" + ); + $this->assertProductLinks($groupedProduct, $response['products']['items'][0]['product_links']); } - private function assertGroupedProductItems($product, $actualResponse) + /** + * @param ProductInterface $product + * @param array $items + */ + private function assertGroupedProductItems(ProductInterface $product, array $items): void { - $this->assertNotEmpty( - $actualResponse['items'], - "Precondition failed: 'grouped product items' must not be empty" - ); - $this->assertCount(2, $actualResponse['items']); + $this->assertCount(2, $items); $groupedProductLinks = $product->getProductLinks(); - foreach ($actualResponse['items'] as $itemIndex => $bundleItems) { - $this->assertNotEmpty($bundleItems); + foreach ($items as $itemIndex => $bundleItem) { + $this->assertNotEmpty($bundleItem); $associatedProductSku = $groupedProductLinks[$itemIndex]->getLinkedProductSku(); - - $productsRepository = ObjectManager::getInstance()->get(ProductRepositoryInterface::class); - /** @var \Magento\Catalog\Model\Product $associatedProduct */ - $associatedProduct = $productsRepository->get($associatedProductSku); + $associatedProduct = $this->productRepository->get($associatedProductSku); $this->assertEquals( $groupedProductLinks[$itemIndex]->getExtensionAttributes()->getQty(), - $actualResponse['items'][$itemIndex]['qty'] + $bundleItem['qty'] ); $this->assertEquals( $groupedProductLinks[$itemIndex]->getPosition(), - $actualResponse['items'][$itemIndex]['position'] + $bundleItem['position'] ); $this->assertResponseFields( - $actualResponse['items'][$itemIndex]['product'], + $bundleItem['product'], [ - 'sku' => $associatedProductSku, - 'type_id' => $groupedProductLinks[$itemIndex]->getLinkedProductType(), - 'url_key'=> $associatedProduct->getUrlKey(), - 'name' => $associatedProduct->getName() + 'sku' => $associatedProductSku, + 'type_id' => $groupedProductLinks[$itemIndex]->getLinkedProductType(), + 'url_key'=> $associatedProduct->getUrlKey(), + 'name' => $associatedProduct->getName() ] ); } } + + /** + * @param ProductInterface $product + * @param array $links + * @return void + */ + private function assertProductLinks(ProductInterface $product, array $links): void + { + $this->assertCount(2, $links); + $productLinks = $product->getProductLinks(); + foreach ($links as $itemIndex => $linkedItem) { + $this->assertNotEmpty($linkedItem); + $this->assertEquals( + $productLinks[$itemIndex]->getPosition(), + $linkedItem['position'] + ); + $this->assertEquals( + $productLinks[$itemIndex]->getLinkedProductSku(), + $linkedItem['linked_product_sku'] + ); + $this->assertEquals( + $productLinks[$itemIndex]->getLinkType(), + $linkedItem['link_type'] + ); + } + } } From 89169805e30b15b465225fe01cd26a4326cb93d4 Mon Sep 17 00:00:00 2001 From: Kate Kyzyma Date: Wed, 24 Jun 2020 13:34:26 +0300 Subject: [PATCH 19/44] Updating the test --- ...ryWithInactiveIncludeInMenuActionGroup.xml | 22 +++++++++++++++++++ ...AdminCreateInactiveCategoryActionGroup.xml | 22 +++++++++++++++++++ ...sertAdminCategoryIsInactiveActionGroup.xml | 18 +++++++++++++++ ...CreateCategoryWithInactiveCategoryTest.xml | 20 +++++------------ ...eCategoryWithInactiveIncludeInMenuTest.xml | 20 +++++------------ 5 files changed, 73 insertions(+), 29 deletions(-) create mode 100644 app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminCreateCategoryWithInactiveIncludeInMenuActionGroup.xml create mode 100644 app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminCreateInactiveCategoryActionGroup.xml create mode 100644 app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertAdminCategoryIsInactiveActionGroup.xml diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminCreateCategoryWithInactiveIncludeInMenuActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminCreateCategoryWithInactiveIncludeInMenuActionGroup.xml new file mode 100644 index 0000000000000..c407e9ba829d7 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminCreateCategoryWithInactiveIncludeInMenuActionGroup.xml @@ -0,0 +1,22 @@ + + + + + + + EXTENDS: CreateCategory. Add "disableIncludeInMenuOption" step. + + + + + + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminCreateInactiveCategoryActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminCreateInactiveCategoryActionGroup.xml new file mode 100644 index 0000000000000..b16ff59b91329 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminCreateInactiveCategoryActionGroup.xml @@ -0,0 +1,22 @@ + + + + + + + EXTENDS: CreateCategory. Add "disableCategory" step. + + + + + + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertAdminCategoryIsInactiveActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertAdminCategoryIsInactiveActionGroup.xml new file mode 100644 index 0000000000000..cec6d42fc2dc4 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertAdminCategoryIsInactiveActionGroup.xml @@ -0,0 +1,18 @@ + + + + + + + Verify the category is disabled + + + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithInactiveCategoryTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithInactiveCategoryTest.xml index a7dab57173377..6d7d56861b731 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithInactiveCategoryTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithInactiveCategoryTest.xml @@ -26,20 +26,12 @@ - - - - - - - - - - - + + - - - + + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithInactiveIncludeInMenuTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithInactiveIncludeInMenuTest.xml index d3a766be2c99f..f60312f19a7e0 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithInactiveIncludeInMenuTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithInactiveIncludeInMenuTest.xml @@ -26,21 +26,11 @@ - - - - - - - - - - - + - - - - + + + + From c3295e0367146bf9c91a21e5457ffe2023f33970 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Wed, 24 Jun 2020 10:39:55 -0500 Subject: [PATCH 20/44] MC-31618: Move static config to files - PLUGIN_LIST - Fix static tests; --- .../Framework/Interception/ConfigWriter.php | 2 +- .../Test/Unit/PluginList/PluginListTest.php | 38 +++++-------------- 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/lib/internal/Magento/Framework/Interception/ConfigWriter.php b/lib/internal/Magento/Framework/Interception/ConfigWriter.php index 050513a55f07d..ed93c543f8d31 100644 --- a/lib/internal/Magento/Framework/Interception/ConfigWriter.php +++ b/lib/internal/Magento/Framework/Interception/ConfigWriter.php @@ -174,7 +174,7 @@ public function write($scopes) foreach ($virtualTypes as $class) { $this->inheritPlugins($class, $this->pluginData, $this->inherited, $this->processed); } - foreach ($this->pluginData as $className => $value) { + foreach (array_keys($this->pluginData) as $className) { $this->inheritPlugins($className, $this->pluginData, $this->inherited, $this->processed); } foreach ($this->getClassDefinitions() as $class) { diff --git a/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php b/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php index ef24c2d9329da..e036e51c39fb4 100644 --- a/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php +++ b/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php @@ -130,8 +130,7 @@ protected function setUp(): void public function testGetPlugin() { - $inheritPlugins = function ($type) - { + $inheritPlugins = function ($type) { $inheritedItem = [ Item::class => [ 'advanced_plugin' => [ @@ -147,17 +146,12 @@ public function testGetPlugin() $processedItem = [ 'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item_getName___self' => [ 2 => 'advanced_plugin', - 4 => [ - 'advanced_plugin' - ] + 4 => ['advanced_plugin'] ], 'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item_getName_advanced_plugin' => [ - 4 => [ - 'simple_plugin' - ] + 4 => ['simple_plugin'] ] ]; - $inheritedItemContainer = [ ItemContainer::class => [ 'simple_plugin' => [ @@ -168,12 +162,9 @@ public function testGetPlugin() ]; $processedItemContainer = [ 'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer_getName___self' => [ - 4 => [ - 'simple_plugin' - ] + 4 => ['simple_plugin'] ] ]; - $inheritedStartingBackslash = [ StartingBackslash::class => [ 'simple_plugin' => [ @@ -187,12 +178,10 @@ public function testGetPlugin() $this->_inherited = $inheritedItem; $this->_processed = $processedItem; } - if ($type === 'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer') { $this->_inherited = array_merge($inheritedItem, $inheritedItemContainer); $this->_processed = array_merge($processedItem, $processedItemContainer); } - if ($type === 'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\StartingBackslash') { $this->_inherited = array_merge($inheritedItem, $inheritedItemContainer, $inheritedStartingBackslash); $this->_processed = array_merge($processedItem, $processedItemContainer); @@ -203,14 +192,8 @@ public function testGetPlugin() $this->configScopeMock->method('getCurrentScope')->willReturn('backend'); $this->object->getNext(Item::class, 'getName'); - $this->object->getNext( - ItemContainer::class, - 'getName' - ); - $this->object->getNext( - StartingBackslash::class, - 'getName' - ); + $this->object->getNext(ItemContainer::class, 'getName'); + $this->object->getNext(StartingBackslash::class, 'getName'); $this->assertEquals( Simple::class, $this->object->getPlugin( @@ -261,8 +244,7 @@ public function testGetPlugins( $this->setScopePriorityScheme($scopePriorityScheme); $this->configScopeMock->method('getCurrentScope')->willReturn($scopeCode); - $inheritPlugins = function ($type) - { + $inheritPlugins = function ($type) { $inheritedItem = [ Item::class => [ 'simple_plugin' => [ @@ -327,8 +309,7 @@ public function testLoadScopedDataCached() ->with('global|scope|interception') ->willReturn($serializedData); - $inheritPlugins = function ($type) - { + $inheritPlugins = function ($type) { $inherited = [ 0 => 'key', 'Type' => null @@ -365,8 +346,7 @@ public function testLoadScopedDataGenerated() ->with('global|scope|interception') ->willReturn($data); - $inheritPlugins = function ($type) - { + $inheritPlugins = function ($type) { $inherited = [ 0 => 'key', 'Type' => null From 7e4a72e70103a57e28c798f6b7e0e835d8a266da Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Wed, 24 Jun 2020 19:24:57 -0500 Subject: [PATCH 21/44] MC-31618: Move static config to files - PLUGIN_LIST - Implement 2 interfaces by one plugin list generator; --- app/etc/di.xml | 6 +- .../TestFramework/Interception/PluginList.php | 8 +- .../Framework/Interception/AbstractPlugin.php | 9 ++- .../Framework/Interception/ConfigLoader.php | 43 ----------- .../Interception/PluginList/PluginList.php | 24 +++--- ...nfigWriter.php => PluginListGenerator.php} | 74 ++++++++++++++----- .../Test/Unit/PluginList/PluginListTest.php | 44 +++++------ .../Task/Operation/PluginListGenerator.php | 2 +- 8 files changed, 104 insertions(+), 106 deletions(-) delete mode 100644 lib/internal/Magento/Framework/Interception/ConfigLoader.php rename lib/internal/Magento/Framework/Interception/{ConfigWriter.php => PluginListGenerator.php} (85%) diff --git a/app/etc/di.xml b/app/etc/di.xml index 7792f43592f5b..31cc5caf3ba67 100644 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -209,8 +209,8 @@ - - + + @@ -433,7 +433,7 @@ - + Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy \Psr\Log\LoggerInterface\Proxy diff --git a/dev/tests/integration/framework/Magento/TestFramework/Interception/PluginList.php b/dev/tests/integration/framework/Magento/TestFramework/Interception/PluginList.php index 5bad5acf51b37..0b5fc407d438b 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Interception/PluginList.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Interception/PluginList.php @@ -6,7 +6,7 @@ namespace Magento\TestFramework\Interception; use Magento\Framework\Interception\ConfigLoaderInterface; -use Magento\Framework\Interception\ConfigWriterInterface; +use Magento\Framework\Interception\PluginListGenerator; use Magento\Framework\Serialize\SerializerInterface; /** @@ -34,7 +34,7 @@ class PluginList extends \Magento\Framework\Interception\PluginList\PluginList * @param string|null $cacheId * @param SerializerInterface|null $serializer * @param ConfigLoaderInterface|null $configLoader - * @param ConfigWriterInterface|null $configWriter + * @param PluginListGenerator|null $pluginListGenerator * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -50,7 +50,7 @@ public function __construct( $cacheId = 'plugins', SerializerInterface $serializer = null, ConfigLoaderInterface $configLoader = null, - ConfigWriterInterface $configWriter = null + PluginListGenerator $pluginListGenerator = null ) { parent::__construct( $reader, @@ -65,7 +65,7 @@ public function __construct( $cacheId, $serializer, $configLoader, - $configWriter + $pluginListGenerator ); $this->_originScopeScheme = $this->_scopePriorityScheme; } diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/AbstractPlugin.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/AbstractPlugin.php index d9c0e0e17da3a..b9deeb3bb968f 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Interception/AbstractPlugin.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/AbstractPlugin.php @@ -83,10 +83,10 @@ public function setUpInterceptionConfig($pluginConfig) $cacheManager->method('load')->willReturn(null); $definitions = new \Magento\Framework\ObjectManager\Definition\Runtime(); $relations = new \Magento\Framework\ObjectManager\Relations\Runtime(); - $dirList = new DirectoryList(DirectoryList::GENERATED_METADATA); - $configLoader = new \Magento\Framework\Interception\ConfigLoader($dirList); + $configLoader = $this->createMock(ConfigLoaderInterface::class); $logger = $this->createMock(\Psr\Log\LoggerInterface::class); - $configWriter = $this->createMock(\Magento\Framework\App\ObjectManager\ConfigWriterInterface::class); + $directoryList = $this->createMock(DirectoryList::class); + $configWriter = $this->createMock(PluginListGenerator::class); $interceptionConfig = new Config\Config( $this->_configReader, $configScope, @@ -112,6 +112,7 @@ public function setUpInterceptionConfig($pluginConfig) \Magento\Framework\Serialize\SerializerInterface::class => $json, \Magento\Framework\Interception\ConfigLoaderInterface::class => $configLoader, \Psr\Log\LoggerInterface::class => $logger, + \Magento\Framework\App\Filesystem\DirectoryList::class => $directoryList, \Magento\Framework\App\ObjectManager\ConfigWriterInterface::class => $configWriter ]; $this->_objectManager = new \Magento\Framework\ObjectManager\ObjectManager( @@ -128,7 +129,7 @@ public function setUpInterceptionConfig($pluginConfig) \Magento\Framework\Interception\PluginListInterface::class => \Magento\Framework\Interception\PluginList\PluginList::class, \Magento\Framework\Interception\ConfigWriterInterface::class => - \Magento\Framework\Interception\ConfigWriter::class + \Magento\Framework\Interception\PluginListGenerator::class ], ] ); diff --git a/lib/internal/Magento/Framework/Interception/ConfigLoader.php b/lib/internal/Magento/Framework/Interception/ConfigLoader.php deleted file mode 100644 index c83c5d8c2bcbd..0000000000000 --- a/lib/internal/Magento/Framework/Interception/ConfigLoader.php +++ /dev/null @@ -1,43 +0,0 @@ -directoryList = $directoryList; - } - - /** - * Load interception configuration data per scope. - * - * @param string $cacheId - * @return array - * @throws \Magento\Framework\Exception\FileSystemException - */ - public function load($cacheId) - { - $file = $this->directoryList->getPath(DirectoryList::GENERATED_METADATA) . '/' . $cacheId . '.' . 'php'; - if (file_exists($file)) { - return include $file; - } - - return []; - } -} diff --git a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php index 9acc8c547ae7f..26697e70a8f87 100644 --- a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php +++ b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php @@ -10,8 +10,8 @@ use Magento\Framework\Config\ReaderInterface; use Magento\Framework\Config\ScopeInterface; use Magento\Framework\Interception\ConfigLoaderInterface; -use Magento\Framework\Interception\ConfigWriterInterface; use Magento\Framework\Interception\DefinitionInterface; +use Magento\Framework\Interception\PluginListGenerator; use Magento\Framework\Interception\PluginListInterface as InterceptionPluginList; use Magento\Framework\Interception\ObjectManager\ConfigInterface; use Magento\Framework\ObjectManager\RelationsInterface; @@ -88,9 +88,9 @@ class PluginList extends Scoped implements InterceptionPluginList private $configLoader; /** - * @var ConfigWriterInterface + * @var PluginListGenerator */ - private $configWriter; + private $pluginListGenerator; /** * Constructor @@ -107,7 +107,7 @@ class PluginList extends Scoped implements InterceptionPluginList * @param string|null $cacheId * @param SerializerInterface|null $serializer * @param ConfigLoaderInterface|null $configLoader - * @param ConfigWriterInterface|null $configWriter + * @param PluginListGenerator|null $pluginListGenerator * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -123,7 +123,7 @@ public function __construct( $cacheId = 'plugins', SerializerInterface $serializer = null, ConfigLoaderInterface $configLoader = null, - ConfigWriterInterface $configWriter = null + PluginListGenerator $pluginListGenerator = null ) { $this->serializer = $serializer ?: $objectManager->get(Serialize::class); parent::__construct($reader, $configScope, $cache, $cacheId, $this->serializer); @@ -134,7 +134,7 @@ public function __construct( $this->_scopePriorityScheme = $scopePriorityScheme; $this->_objectManager = $objectManager; $this->configLoader = $configLoader ?: $this->_objectManager->get(ConfigLoaderInterface::class); - $this->configWriter = $configWriter ?: $this->_objectManager->get(ConfigWriterInterface::class); + $this->pluginListGenerator = $pluginListGenerator ?: $this->_objectManager->get(PluginListGenerator::class); } /** @@ -145,7 +145,7 @@ public function __construct( */ protected function _inheritPlugins($type) { - return $this->configWriter->inheritPlugins($type, $this->_data, $this->_inherited, $this->_processed); + return $this->pluginListGenerator->inheritPlugins($type, $this->_data, $this->_inherited, $this->_processed); } /** @@ -157,7 +157,7 @@ protected function _inheritPlugins($type) */ protected function _sort($itemA, $itemB) { - return $this->configWriter->sort($itemA, $itemB); + return ($itemA['sortOrder'] ?? PHP_INT_MIN) - ($itemB['sortOrder'] ?? PHP_INT_MIN); } /** @@ -238,7 +238,7 @@ protected function _loadScopedData() $this->_data, $this->_inherited, $this->_processed - ] = $this->configWriter->loadScopedVirtualTypes( + ] = $this->pluginListGenerator->loadScopedVirtualTypes( $this->_scopePriorityScheme, $this->_loadedScopes, $this->_data, @@ -269,7 +269,7 @@ protected function _loadScopedData() */ protected function isCurrentScope($scopeCode) { - return $this->configWriter->isCurrentScope($scopeCode); + return $this->_configScope->getCurrentScope() === $scopeCode; } /** @@ -279,7 +279,7 @@ protected function isCurrentScope($scopeCode) */ protected function getClassDefinitions() { - return $this->configWriter->getClassDefinitions(); + return $this->_classDefinitions->getClasses(); } /** @@ -290,6 +290,6 @@ protected function getClassDefinitions() */ public function merge(array $config) { - $this->_data = $this->configWriter->merge($config, $this->_data); + $this->_data = $this->pluginListGenerator->merge($config, $this->_data); } } diff --git a/lib/internal/Magento/Framework/Interception/ConfigWriter.php b/lib/internal/Magento/Framework/Interception/PluginListGenerator.php similarity index 85% rename from lib/internal/Magento/Framework/Interception/ConfigWriter.php rename to lib/internal/Magento/Framework/Interception/PluginListGenerator.php index ed93c543f8d31..4f794fd5b39c9 100644 --- a/lib/internal/Magento/Framework/Interception/ConfigWriter.php +++ b/lib/internal/Magento/Framework/Interception/PluginListGenerator.php @@ -5,7 +5,7 @@ */ namespace Magento\Framework\Interception; -use Magento\Framework\App\ObjectManager\ConfigWriterInterface as ObjectManagerConfigWriterInterface; +use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Config\ReaderInterface; use Magento\Framework\Config\ScopeInterface; use Magento\Framework\Interception\ObjectManager\ConfigInterface; @@ -14,9 +14,9 @@ use Psr\Log\LoggerInterface; /** - * Interception configuration writer for scopes. + * Plugin list configuration writer and loader for scopes. */ -class ConfigWriter implements ConfigWriterInterface +class PluginListGenerator implements ConfigWriterInterface, ConfigLoaderInterface { /** * @var ScopeInterface @@ -78,9 +78,9 @@ class ConfigWriter implements ConfigWriterInterface private $logger; /** - * @var ObjectManagerConfigWriterInterface + * @var DirectoryList */ - private $configWriter; + private $directoryList; /** * @var array @@ -117,7 +117,7 @@ class ConfigWriter implements ConfigWriterInterface * @param DefinitionInterface $definitions * @param ClassDefinitions $classDefinitions * @param LoggerInterface $logger - * @param ObjectManagerConfigWriterInterface $configWriter + * @param DirectoryList $directoryList * @param array $scopePriorityScheme */ public function __construct( @@ -128,7 +128,7 @@ public function __construct( DefinitionInterface $definitions, ClassDefinitions $classDefinitions, LoggerInterface $logger, - ObjectManagerConfigWriterInterface $configWriter, + DirectoryList $directoryList, array $scopePriorityScheme = ['global'] ) { $this->reader = $reader; @@ -138,7 +138,7 @@ public function __construct( $this->definitions = $definitions; $this->classDefinitions = $classDefinitions; $this->logger = $logger; - $this->configWriter = $configWriter; + $this->directoryList = $directoryList; $this->scopePriorityScheme = $scopePriorityScheme; } @@ -180,7 +180,7 @@ public function write($scopes) foreach ($this->getClassDefinitions() as $class) { $this->inheritPlugins($class, $this->pluginData, $this->inherited, $this->processed); } - $this->configWriter->write( + $this->writeConfig( $cacheId, [$this->pluginData, $this->inherited, $this->processed] ); @@ -197,6 +197,23 @@ public function write($scopes) } } + /** + * Load interception configuration data per scope. + * + * @param string $cacheId + * @return array + * @throws \Magento\Framework\Exception\FileSystemException + */ + public function load($cacheId) + { + $file = $this->directoryList->getPath(DirectoryList::GENERATED_METADATA) . '/' . $cacheId . '.' . 'php'; + if (file_exists($file)) { + return include $file; + } + + return []; + } + /** * Load virtual types for current scope * @@ -238,7 +255,7 @@ public function loadScopedVirtualTypes($scopePriorityScheme, $loadedScopes, $plu * * @return array */ - public function getClassDefinitions() + private function getClassDefinitions() { return $this->classDefinitions->getClasses(); } @@ -249,7 +266,7 @@ public function getClassDefinitions() * @param string $scopeCode * @return bool */ - public function isCurrentScope($scopeCode) + private function isCurrentScope($scopeCode) { return $this->scopeConfig->getCurrentScope() === $scopeCode; } @@ -297,7 +314,9 @@ public function inheritPlugins($type, &$pluginData, &$inherited, &$processed) $inherited[$type] = null; if (is_array($plugins) && count($plugins)) { $this->filterPlugins($plugins); - uasort($plugins, [$this, 'sort']); + uasort($plugins, function ($itemA, $itemB) { + return ($itemA['sortOrder'] ?? PHP_INT_MIN) - ($itemB['sortOrder'] ?? PHP_INT_MIN); + }); $this->trimInstanceStartingBackslash($plugins); $inherited[$type] = $plugins; $lastPerMethod = []; @@ -385,14 +404,33 @@ public function merge(array $config, $pluginData) } /** - * Sort items + * Writes config in storage * - * @param array $itemA - * @param array $itemB - * @return int + * @param string $key + * @param array $config + * @return void + * @throws \Magento\Framework\Exception\FileSystemException */ - public function sort($itemA, $itemB) + private function writeConfig(string $key, array $config) { - return ($itemA['sortOrder'] ?? PHP_INT_MIN) - ($itemB['sortOrder'] ?? PHP_INT_MIN); + $this->initialize(); + $configuration = sprintf('directoryList->getPath(DirectoryList::GENERATED_METADATA) . '/' . $key . '.php', + $configuration + ); + } + + /** + * Initializes writer + * + * @return void + * @throws \Magento\Framework\Exception\FileSystemException + */ + private function initialize() + { + if (!file_exists($this->directoryList->getPath(DirectoryList::GENERATED_METADATA))) { + mkdir($this->directoryList->getPath(DirectoryList::GENERATED_METADATA)); + } } } diff --git a/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php b/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php index e036e51c39fb4..f2fe5510d9b1c 100644 --- a/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php +++ b/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php @@ -10,9 +10,9 @@ use Magento\Framework\Config\CacheInterface; use Magento\Framework\Config\ScopeInterface; use Magento\Framework\Interception\ConfigLoaderInterface; -use Magento\Framework\Interception\ConfigWriterInterface; use Magento\Framework\Interception\ObjectManager\ConfigInterface; use Magento\Framework\Interception\PluginList\PluginList; +use Magento\Framework\Interception\PluginListGenerator; use Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item; use Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer; use Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainerPlugin\Simple as ItemContainerPlugin; @@ -94,15 +94,17 @@ protected function setUp(): void $this->configLoaderMock = $this->getMockBuilder(ConfigLoaderInterface::class) ->onlyMethods(['load']) ->getMockForAbstractClass(); - $configWriterMock = $this->getMockBuilder(ConfigWriterInterface::class) - ->addMethods(['loadScopedVirtualTypes', 'getClassDefinitions', 'inheritPlugins']) - ->getMockForAbstractClass(); - $configWriterMock->method('loadScopedVirtualTypes') + $pluginListGeneratorMock = $this->getMockBuilder(PluginListGenerator::class) + ->disableOriginalConstructor() + ->onlyMethods(['loadScopedVirtualTypes', 'inheritPlugins']) + ->getMock(); + $pluginListGeneratorMock->method('loadScopedVirtualTypes') ->willReturnMap($loadScoped); - $configWriterMock->method('getClassDefinitions') - ->willReturn([]); - $definitions = new Runtime(); + $definitions = $this->getMockBuilder(Runtime::class) + ->disableOriginalConstructor() + ->getMock(); + $definitions->method('getClasses')->willReturn([]); // tested class is a mock to be able to set its protected properties values in closure $this->object = $this->getMockBuilder(PluginList::class) @@ -122,7 +124,7 @@ protected function setUp(): void 'cacheId' => 'interception', 'serializer' => $this->serializerMock, 'configLoader' => $this->configLoaderMock, - 'configWriter' => $configWriterMock + 'pluginListGenerator' => $pluginListGeneratorMock ] ) ->getMock(); @@ -175,16 +177,16 @@ public function testGetPlugin() ]; if ($type === 'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item') { - $this->_inherited = $inheritedItem; - $this->_processed = $processedItem; + $this->_inherited = $inheritedItem; /** @phpstan-ignore-line */ + $this->_processed = $processedItem; /** @phpstan-ignore-line */ } if ($type === 'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer') { - $this->_inherited = array_merge($inheritedItem, $inheritedItemContainer); - $this->_processed = array_merge($processedItem, $processedItemContainer); + $this->_inherited = array_merge($inheritedItem, $inheritedItemContainer); /** @phpstan-ignore-line */ + $this->_processed = array_merge($processedItem, $processedItemContainer); /** @phpstan-ignore-line */ } if ($type === 'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\StartingBackslash') { - $this->_inherited = array_merge($inheritedItem, $inheritedItemContainer, $inheritedStartingBackslash); - $this->_processed = array_merge($processedItem, $processedItemContainer); + $this->_inherited = array_merge($inheritedItem, $inheritedItemContainer, $inheritedStartingBackslash); /** @phpstan-ignore-line */ + $this->_processed = array_merge($processedItem, $processedItemContainer); /** @phpstan-ignore-line */ } }; $inheritPlugins = $inheritPlugins->bindTo($this->object, PluginList::class); @@ -262,8 +264,8 @@ public function testGetPlugins( ]; if ($type === 'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item') { - $this->_inherited = $inheritedItem; - $this->_processed = $processedItem; + $this->_inherited = $inheritedItem; /** @phpstan-ignore-line */ + $this->_processed = $processedItem; /** @phpstan-ignore-line */ } }; $inheritPlugins = $inheritPlugins->bindTo($this->object, PluginList::class); @@ -319,8 +321,8 @@ public function testLoadScopedDataCached() ]; if ($type === 'Type') { - $this->_inherited = $inherited; - $this->_processed = $processed; + $this->_inherited = $inherited; /** @phpstan-ignore-line */ + $this->_processed = $processed; /** @phpstan-ignore-line */ } }; $inheritPlugins = $inheritPlugins->bindTo($this->object, PluginList::class); @@ -356,8 +358,8 @@ public function testLoadScopedDataGenerated() ]; if ($type === 'Type') { - $this->_inherited = $inherited; - $this->_processed = $processed; + $this->_inherited = $inherited; /** @phpstan-ignore-line */ + $this->_processed = $processed; /** @phpstan-ignore-line */ } }; $inheritPlugins = $inheritPlugins->bindTo($this->object, PluginList::class); diff --git a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php index d0605cfbafcae..2db990505e861 100644 --- a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php +++ b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php @@ -10,7 +10,7 @@ use Magento\Framework\Interception\ConfigWriterInterface; /** - * Writes plugins configuration data per scope to generated metadata files. + * Writes plugin list configuration data per scope to generated metadata. */ class PluginListGenerator implements OperationInterface { From 0658f817b3d423048e410068602cfdce77f00d41 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Thu, 25 Jun 2020 00:39:47 -0500 Subject: [PATCH 22/44] MC-31618: Move static config to files - PLUGIN_LIST - Fix static test; --- .../Interception/Test/Unit/PluginList/PluginListTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php b/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php index f2fe5510d9b1c..b0cb500eeed66 100644 --- a/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php +++ b/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php @@ -185,7 +185,8 @@ public function testGetPlugin() $this->_processed = array_merge($processedItem, $processedItemContainer); /** @phpstan-ignore-line */ } if ($type === 'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\StartingBackslash') { - $this->_inherited = array_merge($inheritedItem, $inheritedItemContainer, $inheritedStartingBackslash); /** @phpstan-ignore-line */ + /** @phpstan-ignore-next-line */ + $this->_inherited = array_merge($inheritedItem, $inheritedItemContainer, $inheritedStartingBackslash); $this->_processed = array_merge($processedItem, $processedItemContainer); /** @phpstan-ignore-line */ } }; From f569729002c4b5602e30c6e8c13655829a3116fd Mon Sep 17 00:00:00 2001 From: "rostyslav.hymon" Date: Thu, 25 Jun 2020 10:37:13 +0300 Subject: [PATCH 23/44] MC-35256: Elasticsearch Filters Product Prices Differently than MySQL --- .../FieldProvider/FieldType/Converter.php | 4 +- .../Model/Client/Elasticsearch.php | 2 +- .../FieldProvider/FieldType/Converter.php | 4 +- .../Setup/Patch/Data/InvalidateIndex.php | 66 +++++++++++++++++++ .../Model/Client/ElasticsearchTest.php | 4 +- .../FieldProvider/DynamicFieldTest.php | 8 +-- .../FieldProvider/FieldType/ConverterTest.php | 2 +- .../Model/Client/Elasticsearch.php | 2 +- .../Unit/Model/Client/ElasticsearchTest.php | 4 +- .../Model/Client/Elasticsearch.php | 2 +- .../Unit/Model/Client/ElasticsearchTest.php | 4 +- 11 files changed, 84 insertions(+), 18 deletions(-) create mode 100644 app/code/Magento/Elasticsearch/Setup/Patch/Data/InvalidateIndex.php diff --git a/app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/FieldMapper/Product/FieldProvider/FieldType/Converter.php b/app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/FieldMapper/Product/FieldProvider/FieldType/Converter.php index 1f6e05c9e02fc..8576d8df0cc95 100644 --- a/app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/FieldMapper/Product/FieldProvider/FieldType/Converter.php +++ b/app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/FieldMapper/Product/FieldProvider/FieldType/Converter.php @@ -19,7 +19,7 @@ class Converter implements ConverterInterface */ private const ES_DATA_TYPE_TEXT = 'text'; private const ES_DATA_TYPE_KEYWORD = 'keyword'; - private const ES_DATA_TYPE_FLOAT = 'float'; + private const ES_DATA_TYPE_DOUBLE = 'double'; private const ES_DATA_TYPE_INT = 'integer'; private const ES_DATA_TYPE_DATE = 'date'; /**#@-*/ @@ -32,7 +32,7 @@ class Converter implements ConverterInterface private $mapping = [ self::INTERNAL_DATA_TYPE_STRING => self::ES_DATA_TYPE_TEXT, self::INTERNAL_DATA_TYPE_KEYWORD => self::ES_DATA_TYPE_KEYWORD, - self::INTERNAL_DATA_TYPE_FLOAT => self::ES_DATA_TYPE_FLOAT, + self::INTERNAL_DATA_TYPE_FLOAT => self::ES_DATA_TYPE_DOUBLE, self::INTERNAL_DATA_TYPE_INT => self::ES_DATA_TYPE_INT, self::INTERNAL_DATA_TYPE_DATE => self::ES_DATA_TYPE_DATE, ]; diff --git a/app/code/Magento/Elasticsearch/Elasticsearch5/Model/Client/Elasticsearch.php b/app/code/Magento/Elasticsearch/Elasticsearch5/Model/Client/Elasticsearch.php index bd9a380230652..8d8787a5eff72 100644 --- a/app/code/Magento/Elasticsearch/Elasticsearch5/Model/Client/Elasticsearch.php +++ b/app/code/Magento/Elasticsearch/Elasticsearch5/Model/Client/Elasticsearch.php @@ -276,7 +276,7 @@ public function addFieldsMapping(array $fields, $index, $entityType) 'match' => 'price_*', 'match_mapping_type' => 'string', 'mapping' => [ - 'type' => 'float', + 'type' => 'double', 'store' => true, ], ], diff --git a/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/FieldType/Converter.php b/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/FieldType/Converter.php index 88dab83698794..2067dcdc7fe9f 100644 --- a/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/FieldType/Converter.php +++ b/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/FieldType/Converter.php @@ -16,7 +16,7 @@ class Converter implements ConverterInterface * Text flags for Elasticsearch field types */ private const ES_DATA_TYPE_STRING = 'string'; - private const ES_DATA_TYPE_FLOAT = 'float'; + private const ES_DATA_TYPE_DOUBLE = 'double'; private const ES_DATA_TYPE_INT = 'integer'; private const ES_DATA_TYPE_DATE = 'date'; /**#@-*/ @@ -29,7 +29,7 @@ class Converter implements ConverterInterface private $mapping = [ self::INTERNAL_DATA_TYPE_STRING => self::ES_DATA_TYPE_STRING, self::INTERNAL_DATA_TYPE_KEYWORD => self::ES_DATA_TYPE_STRING, - self::INTERNAL_DATA_TYPE_FLOAT => self::ES_DATA_TYPE_FLOAT, + self::INTERNAL_DATA_TYPE_FLOAT => self::ES_DATA_TYPE_DOUBLE, self::INTERNAL_DATA_TYPE_INT => self::ES_DATA_TYPE_INT, self::INTERNAL_DATA_TYPE_DATE => self::ES_DATA_TYPE_DATE, ]; diff --git a/app/code/Magento/Elasticsearch/Setup/Patch/Data/InvalidateIndex.php b/app/code/Magento/Elasticsearch/Setup/Patch/Data/InvalidateIndex.php new file mode 100644 index 0000000000000..7cd72c322d647 --- /dev/null +++ b/app/code/Magento/Elasticsearch/Setup/Patch/Data/InvalidateIndex.php @@ -0,0 +1,66 @@ +moduleDataSetup = $moduleDataSetup; + $this->indexerRegistry = $indexerRegistry; + } + + /** + * @inheritDoc + */ + public function apply(): PatchInterface + { + $this->indexerRegistry->get(FulltextIndexer::INDEXER_ID)->invalidate(); + return $this; + } + + /** + * @inheritDoc + */ + public static function getDependencies(): array + { + return []; + } + + /** + * @inheritDoc + */ + public function getAliases(): array + { + return []; + } +} diff --git a/app/code/Magento/Elasticsearch/Test/Unit/Elasticsearch5/Model/Client/ElasticsearchTest.php b/app/code/Magento/Elasticsearch/Test/Unit/Elasticsearch5/Model/Client/ElasticsearchTest.php index 49a894f1295c7..575a64dc43abd 100644 --- a/app/code/Magento/Elasticsearch/Test/Unit/Elasticsearch5/Model/Client/ElasticsearchTest.php +++ b/app/code/Magento/Elasticsearch/Test/Unit/Elasticsearch5/Model/Client/ElasticsearchTest.php @@ -329,7 +329,7 @@ public function testAddFieldsMapping() 'match' => 'price_*', 'match_mapping_type' => 'string', 'mapping' => [ - 'type' => 'float', + 'type' => 'double', 'store' => true, ], ], @@ -400,7 +400,7 @@ public function testAddFieldsMappingFailure() 'match' => 'price_*', 'match_mapping_type' => 'string', 'mapping' => [ - 'type' => 'float', + 'type' => 'double', 'store' => true, ], ], diff --git a/app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/FieldMapper/Product/FieldProvider/DynamicFieldTest.php b/app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/FieldMapper/Product/FieldProvider/DynamicFieldTest.php index 87f072836544e..a9bcd1a20a1b2 100644 --- a/app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/FieldMapper/Product/FieldProvider/DynamicFieldTest.php +++ b/app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/FieldMapper/Product/FieldProvider/DynamicFieldTest.php @@ -246,7 +246,7 @@ function ($type) use ($complexType) { if ($type === 'string') { return 'string'; } elseif ($type === 'float') { - return 'float'; + return 'double'; } elseif ($type === 'integer') { return 'integer'; } else { @@ -281,7 +281,7 @@ public function attributeProvider() 'index' => 'no_index' ], 'price_1_1' => [ - 'type' => 'float', + 'type' => 'double', 'store' => true ] ] @@ -300,7 +300,7 @@ public function attributeProvider() 'index' => 'no_index' ], 'price_1_1' => [ - 'type' => 'float', + 'type' => 'double', 'store' => true ] ], @@ -319,7 +319,7 @@ public function attributeProvider() 'index' => 'no_index' ], 'price_1_1' => [ - 'type' => 'float', + 'type' => 'double', 'store' => true ] ] diff --git a/app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/FieldMapper/Product/FieldProvider/FieldType/ConverterTest.php b/app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/FieldMapper/Product/FieldProvider/FieldType/ConverterTest.php index 75b79bc43e805..718adf255254f 100644 --- a/app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/FieldMapper/Product/FieldProvider/FieldType/ConverterTest.php +++ b/app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/FieldMapper/Product/FieldProvider/FieldType/ConverterTest.php @@ -56,7 +56,7 @@ public function convertProvider() { return [ ['string', 'string'], - ['float', 'float'], + ['float', 'double'], ['integer', 'integer'], ]; } diff --git a/app/code/Magento/Elasticsearch6/Model/Client/Elasticsearch.php b/app/code/Magento/Elasticsearch6/Model/Client/Elasticsearch.php index 2c1c283c5b24d..0571b075aff28 100644 --- a/app/code/Magento/Elasticsearch6/Model/Client/Elasticsearch.php +++ b/app/code/Magento/Elasticsearch6/Model/Client/Elasticsearch.php @@ -281,7 +281,7 @@ public function addFieldsMapping(array $fields, $index, $entityType) 'match' => 'price_*', 'match_mapping_type' => 'string', 'mapping' => [ - 'type' => 'float', + 'type' => 'double', 'store' => true, ], ], diff --git a/app/code/Magento/Elasticsearch6/Test/Unit/Model/Client/ElasticsearchTest.php b/app/code/Magento/Elasticsearch6/Test/Unit/Model/Client/ElasticsearchTest.php index aa0b49400c517..2a7fa2ce8114a 100644 --- a/app/code/Magento/Elasticsearch6/Test/Unit/Model/Client/ElasticsearchTest.php +++ b/app/code/Magento/Elasticsearch6/Test/Unit/Model/Client/ElasticsearchTest.php @@ -439,7 +439,7 @@ public function testAddFieldsMapping() 'match' => 'price_*', 'match_mapping_type' => 'string', 'mapping' => [ - 'type' => 'float', + 'type' => 'double', 'store' => true, ], ], @@ -509,7 +509,7 @@ public function testAddFieldsMappingFailure() 'match' => 'price_*', 'match_mapping_type' => 'string', 'mapping' => [ - 'type' => 'float', + 'type' => 'double', 'store' => true, ], ], diff --git a/app/code/Magento/Elasticsearch7/Model/Client/Elasticsearch.php b/app/code/Magento/Elasticsearch7/Model/Client/Elasticsearch.php index feacca8d62804..4b318f987abfe 100644 --- a/app/code/Magento/Elasticsearch7/Model/Client/Elasticsearch.php +++ b/app/code/Magento/Elasticsearch7/Model/Client/Elasticsearch.php @@ -289,7 +289,7 @@ public function addFieldsMapping(array $fields, string $index, string $entityTyp 'match' => 'price_*', 'match_mapping_type' => 'string', 'mapping' => [ - 'type' => 'float', + 'type' => 'double', 'store' => true, ], ], diff --git a/app/code/Magento/Elasticsearch7/Test/Unit/Model/Client/ElasticsearchTest.php b/app/code/Magento/Elasticsearch7/Test/Unit/Model/Client/ElasticsearchTest.php index 593bbd7792f46..091387f844d55 100644 --- a/app/code/Magento/Elasticsearch7/Test/Unit/Model/Client/ElasticsearchTest.php +++ b/app/code/Magento/Elasticsearch7/Test/Unit/Model/Client/ElasticsearchTest.php @@ -438,7 +438,7 @@ public function testAddFieldsMapping() 'match' => 'price_*', 'match_mapping_type' => 'string', 'mapping' => [ - 'type' => 'float', + 'type' => 'double', 'store' => true, ], ], @@ -509,7 +509,7 @@ public function testAddFieldsMappingFailure() 'match' => 'price_*', 'match_mapping_type' => 'string', 'mapping' => [ - 'type' => 'float', + 'type' => 'double', 'store' => true, ], ], From 1505a2504943fcac5810e696f67251c3d445b839 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Thu, 25 Jun 2020 17:42:27 -0500 Subject: [PATCH 24/44] MC-31618: Move static config to files - PLUGIN_LIST - Add plugin list config generation integration test; --- .../Magento/TestFramework/Application.php | 1 + .../Interception/PluginListGeneratorTest.php | 115 ++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php diff --git a/dev/tests/integration/framework/Magento/TestFramework/Application.php b/dev/tests/integration/framework/Magento/TestFramework/Application.php index f0ce2e24545eb..d375fbdf7d43e 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Application.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Application.php @@ -714,6 +714,7 @@ protected function getCustomDirs() DirectoryList::TMP => [$path => "{$var}/tmp"], DirectoryList::UPLOAD => [$path => "{$var}/upload"], DirectoryList::PUB => [$path => "{$this->installDir}/pub"], + DirectoryList::GENERATED_METADATA => [$path => "{$generated}/metadata"] ]; return $customDirs; } diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php new file mode 100644 index 0000000000000..04babcf726547 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php @@ -0,0 +1,115 @@ +application = Bootstrap::getInstance()->getBootstrap()->getApplication(); + $this->directoryList = new DirectoryList(BP, $this->getCustomDirs()); + $this->file = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + DriverInterface::class + ); + $this->model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + PluginListGenerator::class + ); + } + + /** + * Test plugin list configuration generation and load. + */ + public function testPluginListConfigGeneration() + { + $scopes = ['frontend']; + $this->model->write($scopes); + $configData = $this->model->load(self::CACHE_ID); + $this->assertNotEmpty($configData[0]); + $this->assertNotEmpty($configData[1]); + $this->assertNotEmpty($configData[2]); + $expected = [ + 1 => [ + 0 => 'genericHeaderPlugin', + 1 => 'asyncCssLoad', + 2 => 'response-http-page-cache' + ] + ]; + // Here in test I assume that this class below has 3 plugins. But the amount of plugins and class itself + // may vary. If it is changed, please update these assertions. + $this->assertArrayHasKey( + 'Magento\\Framework\\App\\Response\\Http_sendResponse___self', + $configData[2], + 'Processed plugin does not exist in the processed plugins array.' + ); + $this->assertSame( + $expected, + $configData[2]['Magento\\Framework\\App\\Response\\Http_sendResponse___self'], + 'Plugin configurations are not equal' + ); + } + + /** + * Gets customized directory paths + * + * @return array + */ + private function getCustomDirs() + { + $path = DirectoryList::PATH; + $generated = "{$this->application->getTempDir()}/generated"; + + return [ + DirectoryList::GENERATED_METADATA => [$path => "{$generated}/metadata"], + ]; + } + + /** + * @inheritDoc + */ + protected function tearDown(): void + { + $filePath = $this->directoryList->getPath(DirectoryList::GENERATED_METADATA) + . '/' . self::CACHE_ID . '.' . 'php'; + + if (file_exists($filePath)) { + $this->file->deleteFile($filePath); + } + } +} From 7745875dc39a0d4b0148bb063733744f95965808 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Fri, 26 Jun 2020 00:02:44 -0500 Subject: [PATCH 25/44] MC-31618: Move static config to files - PLUGIN_LIST - Fix static tests;; --- .../Magento/TestFramework/Application.php | 1 - .../Interception/PluginListGeneratorTest.php | 33 ++++++++++++++++--- .../Console/Command/DiCompileCommand.php | 31 +++++++++-------- .../Module/Di/App/Task/OperationFactory.php | 18 +++++----- .../Console/Command/DiCompileCommandTest.php | 25 +++++++++++++- 5 files changed, 79 insertions(+), 29 deletions(-) diff --git a/dev/tests/integration/framework/Magento/TestFramework/Application.php b/dev/tests/integration/framework/Magento/TestFramework/Application.php index d375fbdf7d43e..f0ce2e24545eb 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Application.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Application.php @@ -714,7 +714,6 @@ protected function getCustomDirs() DirectoryList::TMP => [$path => "{$var}/tmp"], DirectoryList::UPLOAD => [$path => "{$var}/upload"], DirectoryList::PUB => [$path => "{$this->installDir}/pub"], - DirectoryList::GENERATED_METADATA => [$path => "{$generated}/metadata"] ]; return $customDirs; } diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php index 04babcf726547..b386140fc9e1c 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php @@ -45,11 +45,34 @@ protected function setUp(): void { $this->application = Bootstrap::getInstance()->getBootstrap()->getApplication(); $this->directoryList = new DirectoryList(BP, $this->getCustomDirs()); - $this->file = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - DriverInterface::class + $this->file = Bootstrap::getObjectManager()->create(DriverInterface::class); + $reader = Bootstrap::getObjectManager()->create( + \Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy::class ); - $this->model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - PluginListGenerator::class + $scopeConfig = Bootstrap::getObjectManager()->create(\Magento\Framework\Config\Scope::class); + $omConfig = Bootstrap::getObjectManager()->create( + \Magento\Framework\Interception\ObjectManager\Config\Developer::class + ); + $relations = Bootstrap::getObjectManager()->create( + \Magento\Framework\ObjectManager\Relations\Runtime::class + ); + $definitions = Bootstrap::getObjectManager()->create( + \Magento\Framework\Interception\Definition\Runtime::class + ); + $classDefinitions = Bootstrap::getObjectManager()->create( + \Magento\Framework\ObjectManager\Definition\Runtime::class + ); + $logger = Bootstrap::getObjectManager()->create(\Psr\Log\LoggerInterface\Proxy::class); + $this->model = new PluginListGenerator( + $reader, + $scopeConfig, + $omConfig, + $relations, + $definitions, + $classDefinitions, + $logger, + $this->directoryList, + ['primary', 'global'] ); } @@ -71,7 +94,7 @@ public function testPluginListConfigGeneration() 2 => 'response-http-page-cache' ] ]; - // Here in test I assume that this class below has 3 plugins. But the amount of plugins and class itself + // Here in test is assumed that this class below has 3 plugins. But the amount of plugins and class itself // may vary. If it is changed, please update these assertions. $this->assertArrayHasKey( 'Magento\\Framework\\App\\Response\\Http_sendResponse___self', diff --git a/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php b/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php index cfd5da0d6b7ef..4c50a3de4fb31 100644 --- a/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php @@ -5,8 +5,9 @@ */ namespace Magento\Setup\Console\Command; -use Magento\Framework\ObjectManagerInterface; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Filesystem\DriverInterface; +use Magento\Framework\Filesystem\Io\File; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Magento\Framework\Filesystem; @@ -72,6 +73,11 @@ class DiCompileCommand extends Command */ private $componentRegistrar; + /** + * @var File + */ + private $file; + /** * Constructor * @@ -82,6 +88,8 @@ class DiCompileCommand extends Command * @param Filesystem $filesystem * @param DriverInterface $fileDriver * @param \Magento\Framework\Component\ComponentRegistrar $componentRegistrar + * @param File|null $file + * @throws \Magento\Setup\Exception */ public function __construct( DeploymentConfig $deploymentConfig, @@ -90,7 +98,8 @@ public function __construct( ObjectManagerProvider $objectManagerProvider, Filesystem $filesystem, DriverInterface $fileDriver, - ComponentRegistrar $componentRegistrar + ComponentRegistrar $componentRegistrar, + File $file = null ) { $this->deploymentConfig = $deploymentConfig; $this->directoryList = $directoryList; @@ -99,6 +108,7 @@ public function __construct( $this->filesystem = $filesystem; $this->fileDriver = $fileDriver; $this->componentRegistrar = $componentRegistrar; + $this->file = $file ?: ObjectManager::getInstance()->get(File::class); parent::__construct(); } @@ -227,10 +237,10 @@ private function getExcludedModulePaths(array $modulePaths) { $modulesByBasePath = []; foreach ($modulePaths as $modulePath) { - $moduleDir = basename($modulePath); - $vendorPath = dirname($modulePath); - $vendorDir = basename($vendorPath); - $basePath = dirname($vendorPath); + $moduleDir = $this->file->getPathInfo($modulePath)['basename']; + $vendorPath = $this->fileDriver->getParentDirectory($modulePath); + $vendorDir = $this->file->getPathInfo($vendorPath)['basename']; + $basePath = $this->fileDriver->getParentDirectory($vendorPath); $modulesByBasePath[$basePath][$vendorDir][] = $moduleDir; } @@ -360,12 +370,9 @@ private function configureObjectManager(OutputInterface $output) private function getOperationsConfiguration( array $compiledPathsList ) { - $excludePatterns = []; - foreach ($this->excludedPathsList as $excludedPaths) { - $excludePatterns = array_merge($excludedPaths, $excludePatterns); - } + $excludePatterns = array_merge([], ...array_values($this->excludedPathsList)); - $operations = [ + return [ OperationFactory::PROXY_GENERATOR => [], OperationFactory::REPOSITORY_GENERATOR => [ 'paths' => $compiledPathsList['application'], @@ -402,7 +409,5 @@ private function getOperationsConfiguration( OperationFactory::APPLICATION_ACTION_LIST_GENERATOR => [], OperationFactory::PLUGIN_LIST_GENERATOR => [], ]; - - return $operations; } } diff --git a/setup/src/Magento/Setup/Module/Di/App/Task/OperationFactory.php b/setup/src/Magento/Setup/Module/Di/App/Task/OperationFactory.php index cd6bf213f8027..07ff60c367392 100644 --- a/setup/src/Magento/Setup/Module/Di/App/Task/OperationFactory.php +++ b/setup/src/Magento/Setup/Module/Di/App/Task/OperationFactory.php @@ -19,47 +19,47 @@ class OperationFactory private $objectManager; /** - * Area + * Area config generator operation definition */ const AREA_CONFIG_GENERATOR = 'area'; /** - * Interception + * Interception operation definition */ const INTERCEPTION = 'interception'; /** - * Interception cache + * Interception cache operation definition */ const INTERCEPTION_CACHE = 'interception_cache'; /** - * Repository generator + * Repository generator operation definition */ const REPOSITORY_GENERATOR = 'repository_generator'; /** - * Proxy generator + * Proxy generator operation definition */ const PROXY_GENERATOR = 'proxy_generator'; /** - * Service data attributes generator + * Service data attributes generator operation definition */ const DATA_ATTRIBUTES_GENERATOR = 'extension_attributes_generator'; /** - * Application code generator + * Application code generator operation definition */ const APPLICATION_CODE_GENERATOR = 'application_code_generator'; /** - * Application action list generator + * Application action list generator operation definition */ const APPLICATION_ACTION_LIST_GENERATOR = 'application_action_list_generator'; /** - * Plugin list generator + * Plugin list generator operation definition */ const PLUGIN_LIST_GENERATOR = 'plugin_list_generator'; diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php index a085eb0b20611..0386353a0b2df 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php @@ -65,6 +65,9 @@ class DiCompileCommandTest extends TestCase /** @var OutputFormatterInterface|MockObject */ private $outputFormatterMock; + /** @var Filesystem\Io\File|MockObject */ + private $fileMock; + protected function setUp(): void { $this->deploymentConfigMock = $this->createMock(DeploymentConfig::class); @@ -96,6 +99,14 @@ protected function setUp(): void $this->fileDriverMock = $this->getMockBuilder(File::class) ->disableOriginalConstructor() ->getMock(); + $this->fileDriverMock->method('getParentDirectory')->willReturnMap( + [ + ['/path/to/module/one', '/path/to/module'], + ['/path/to/module', '/path/to'], + ['/path (1)/to/module/two', '/path (1)/to/module'], + ['/path (1)/to/module', '/path (1)/to'], + ] + ); $this->componentRegistrarMock = $this->createMock(ComponentRegistrar::class); $this->componentRegistrarMock->expects($this->any())->method('getPaths')->willReturnMap([ [ComponentRegistrar::MODULE, ['/path/to/module/one', '/path (1)/to/module/two']], @@ -108,6 +119,17 @@ protected function setUp(): void $this->outputMock = $this->getMockForAbstractClass(OutputInterface::class); $this->outputMock->method('getFormatter') ->willReturn($this->outputFormatterMock); + $this->fileMock = $this->getMockBuilder(Filesystem\Io\File::class) + ->disableOriginalConstructor() + ->getMock(); + $this->fileMock->method('getPathInfo')->willReturnMap( + [ + ['/path/to/module/one', ['basename' => 'one']], + ['/path/to/module', ['basename' => 'module']], + ['/path (1)/to/module/two', ['basename' => 'two']], + ['/path (1)/to/module', ['basename' => 'module']], + ] + ); $this->command = new DiCompileCommand( $this->deploymentConfigMock, @@ -116,7 +138,8 @@ protected function setUp(): void $objectManagerProviderMock, $this->filesystemMock, $this->fileDriverMock, - $this->componentRegistrarMock + $this->componentRegistrarMock, + $this->fileMock ); } From 0b7dff4b607be226cdac7564fcbdf7597478cfd5 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Fri, 26 Jun 2020 02:37:31 -0500 Subject: [PATCH 26/44] MC-31618: Move static config to files - PLUGIN_LIST - Fix static tests; --- .../Magento/Framework/Interception/PluginListGeneratorTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php index b386140fc9e1c..e2444dc44c5c0 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php @@ -47,6 +47,7 @@ protected function setUp(): void $this->directoryList = new DirectoryList(BP, $this->getCustomDirs()); $this->file = Bootstrap::getObjectManager()->create(DriverInterface::class); $reader = Bootstrap::getObjectManager()->create( + // phpstan:ignore "Class Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy not found." \Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy::class ); $scopeConfig = Bootstrap::getObjectManager()->create(\Magento\Framework\Config\Scope::class); @@ -62,6 +63,7 @@ protected function setUp(): void $classDefinitions = Bootstrap::getObjectManager()->create( \Magento\Framework\ObjectManager\Definition\Runtime::class ); + // phpstan:ignore "Class Psr\Log\LoggerInterface\Proxy not found." $logger = Bootstrap::getObjectManager()->create(\Psr\Log\LoggerInterface\Proxy::class); $this->model = new PluginListGenerator( $reader, From 07d6a66bec89af4bcaa7d57988798c7e9463da05 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Fri, 26 Jun 2020 04:35:38 -0500 Subject: [PATCH 27/44] MC-31618: Move static config to files - PLUGIN_LIST - Remove integration test for test; --- .../Interception/PluginListGeneratorTest.php | 140 ------------------ 1 file changed, 140 deletions(-) delete mode 100644 dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php deleted file mode 100644 index e2444dc44c5c0..0000000000000 --- a/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php +++ /dev/null @@ -1,140 +0,0 @@ -application = Bootstrap::getInstance()->getBootstrap()->getApplication(); - $this->directoryList = new DirectoryList(BP, $this->getCustomDirs()); - $this->file = Bootstrap::getObjectManager()->create(DriverInterface::class); - $reader = Bootstrap::getObjectManager()->create( - // phpstan:ignore "Class Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy not found." - \Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy::class - ); - $scopeConfig = Bootstrap::getObjectManager()->create(\Magento\Framework\Config\Scope::class); - $omConfig = Bootstrap::getObjectManager()->create( - \Magento\Framework\Interception\ObjectManager\Config\Developer::class - ); - $relations = Bootstrap::getObjectManager()->create( - \Magento\Framework\ObjectManager\Relations\Runtime::class - ); - $definitions = Bootstrap::getObjectManager()->create( - \Magento\Framework\Interception\Definition\Runtime::class - ); - $classDefinitions = Bootstrap::getObjectManager()->create( - \Magento\Framework\ObjectManager\Definition\Runtime::class - ); - // phpstan:ignore "Class Psr\Log\LoggerInterface\Proxy not found." - $logger = Bootstrap::getObjectManager()->create(\Psr\Log\LoggerInterface\Proxy::class); - $this->model = new PluginListGenerator( - $reader, - $scopeConfig, - $omConfig, - $relations, - $definitions, - $classDefinitions, - $logger, - $this->directoryList, - ['primary', 'global'] - ); - } - - /** - * Test plugin list configuration generation and load. - */ - public function testPluginListConfigGeneration() - { - $scopes = ['frontend']; - $this->model->write($scopes); - $configData = $this->model->load(self::CACHE_ID); - $this->assertNotEmpty($configData[0]); - $this->assertNotEmpty($configData[1]); - $this->assertNotEmpty($configData[2]); - $expected = [ - 1 => [ - 0 => 'genericHeaderPlugin', - 1 => 'asyncCssLoad', - 2 => 'response-http-page-cache' - ] - ]; - // Here in test is assumed that this class below has 3 plugins. But the amount of plugins and class itself - // may vary. If it is changed, please update these assertions. - $this->assertArrayHasKey( - 'Magento\\Framework\\App\\Response\\Http_sendResponse___self', - $configData[2], - 'Processed plugin does not exist in the processed plugins array.' - ); - $this->assertSame( - $expected, - $configData[2]['Magento\\Framework\\App\\Response\\Http_sendResponse___self'], - 'Plugin configurations are not equal' - ); - } - - /** - * Gets customized directory paths - * - * @return array - */ - private function getCustomDirs() - { - $path = DirectoryList::PATH; - $generated = "{$this->application->getTempDir()}/generated"; - - return [ - DirectoryList::GENERATED_METADATA => [$path => "{$generated}/metadata"], - ]; - } - - /** - * @inheritDoc - */ - protected function tearDown(): void - { - $filePath = $this->directoryList->getPath(DirectoryList::GENERATED_METADATA) - . '/' . self::CACHE_ID . '.' . 'php'; - - if (file_exists($filePath)) { - $this->file->deleteFile($filePath); - } - } -} From 43c21fc44728d84c34f3f2618a270317490c2cd2 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Fri, 26 Jun 2020 09:50:54 -0500 Subject: [PATCH 28/44] MC-31618: Move static config to files - PLUGIN_LIST - Add integration test with app isolation; --- .../Interception/PluginListGeneratorTest.php | 143 ++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php new file mode 100644 index 0000000000000..1e67098391545 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php @@ -0,0 +1,143 @@ +application = Bootstrap::getInstance()->getBootstrap()->getApplication(); + $this->directoryList = new DirectoryList(BP, $this->getCustomDirs()); + $this->file = Bootstrap::getObjectManager()->create(DriverInterface::class); + $reader = Bootstrap::getObjectManager()->create( + // phpstan:ignore "Class Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy not found." + \Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy::class + ); + $scopeConfig = Bootstrap::getObjectManager()->create(\Magento\Framework\Config\Scope::class); + $omConfig = Bootstrap::getObjectManager()->create( + \Magento\Framework\Interception\ObjectManager\Config\Developer::class + ); + $relations = Bootstrap::getObjectManager()->create( + \Magento\Framework\ObjectManager\Relations\Runtime::class + ); + $definitions = Bootstrap::getObjectManager()->create( + \Magento\Framework\Interception\Definition\Runtime::class + ); + $classDefinitions = Bootstrap::getObjectManager()->create( + \Magento\Framework\ObjectManager\Definition\Runtime::class + ); + // phpstan:ignore "Class Psr\Log\LoggerInterface\Proxy not found." + $logger = Bootstrap::getObjectManager()->create(\Psr\Log\LoggerInterface\Proxy::class); + $this->model = new PluginListGenerator( + $reader, + $scopeConfig, + $omConfig, + $relations, + $definitions, + $classDefinitions, + $logger, + $this->directoryList, + ['primary', 'global'] + ); + } + + /** + * Test plugin list configuration generation and load. + */ + public function testPluginListConfigGeneration() + { + $scopes = ['frontend']; + $this->model->write($scopes); + $configData = $this->model->load(self::CACHE_ID); + $this->assertNotEmpty($configData[0]); + $this->assertNotEmpty($configData[1]); + $this->assertNotEmpty($configData[2]); + $expected = [ + 1 => [ + 0 => 'genericHeaderPlugin', + 1 => 'asyncCssLoad', + 2 => 'response-http-page-cache' + ] + ]; + // Here in test is assumed that this class below has 3 plugins. But the amount of plugins and class itself + // may vary. If it is changed, please update these assertions. + $this->assertArrayHasKey( + 'Magento\\Framework\\App\\Response\\Http_sendResponse___self', + $configData[2], + 'Processed plugin does not exist in the processed plugins array.' + ); + $this->assertSame( + $expected, + $configData[2]['Magento\\Framework\\App\\Response\\Http_sendResponse___self'], + 'Plugin configurations are not equal' + ); + } + + /** + * Gets customized directory paths + * + * @return array + */ + private function getCustomDirs() + { + $path = DirectoryList::PATH; + $generated = "{$this->application->getTempDir()}/generated"; + + return [ + DirectoryList::GENERATED_METADATA => [$path => "{$generated}/metadata"], + ]; + } + + /** + * @inheritDoc + */ + protected function tearDown(): void + { + $filePath = $this->directoryList->getPath(DirectoryList::GENERATED_METADATA) + . '/' . self::CACHE_ID . '.' . 'php'; + + if (file_exists($filePath)) { + $this->file->deleteFile($filePath); + } + } +} From 59239ac75ee587371b3e8e4493bb70ce7f561958 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Fri, 26 Jun 2020 11:51:45 -0500 Subject: [PATCH 29/44] MC-31618: Move static config to files - PLUGIN_LIST - Update integration test; --- .../Interception/PluginListGeneratorTest.php | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php index 1e67098391545..9c1ed133e2b0d 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php @@ -48,26 +48,17 @@ protected function setUp(): void { $this->application = Bootstrap::getInstance()->getBootstrap()->getApplication(); $this->directoryList = new DirectoryList(BP, $this->getCustomDirs()); - $this->file = Bootstrap::getObjectManager()->create(DriverInterface::class); - $reader = Bootstrap::getObjectManager()->create( - // phpstan:ignore "Class Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy not found." - \Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy::class - ); - $scopeConfig = Bootstrap::getObjectManager()->create(\Magento\Framework\Config\Scope::class); - $omConfig = Bootstrap::getObjectManager()->create( - \Magento\Framework\Interception\ObjectManager\Config\Developer::class - ); - $relations = Bootstrap::getObjectManager()->create( - \Magento\Framework\ObjectManager\Relations\Runtime::class - ); - $definitions = Bootstrap::getObjectManager()->create( - \Magento\Framework\Interception\Definition\Runtime::class - ); - $classDefinitions = Bootstrap::getObjectManager()->create( - \Magento\Framework\ObjectManager\Definition\Runtime::class - ); - // phpstan:ignore "Class Psr\Log\LoggerInterface\Proxy not found." - $logger = Bootstrap::getObjectManager()->create(\Psr\Log\LoggerInterface\Proxy::class); + $this->file = new \Magento\Framework\Filesystem\Driver\File(); + $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $reader = new \Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy($objectManager); + $areaList = $this->createMock(\Magento\Framework\App\AreaList::class); + $areaList->method('getCodes')->willReturn([]); + $scopeConfig = new \Magento\Framework\Config\Scope($areaList, 'global'); + $omConfig = new \Magento\Framework\Interception\ObjectManager\Config\Developer(); + $relations = new \Magento\Framework\ObjectManager\Relations\Runtime(); + $definitions = new \Magento\Framework\Interception\Definition\Runtime(); + $classDefinitions = new \Magento\Framework\ObjectManager\Definition\Runtime(); + $logger = $this->createMock(\Psr\Log\LoggerInterface::class); $this->model = new PluginListGenerator( $reader, $scopeConfig, From 79de211f8a1fd0f6ba9ee6a50ec6d98e2ee49803 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Fri, 26 Jun 2020 12:53:48 -0500 Subject: [PATCH 30/44] MC-31618: Move static config to files - PLUGIN_LIST - Add PluginList preference; --- .../Magento/Framework/Interception/PluginListGeneratorTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php index 9c1ed133e2b0d..de2c732615d7c 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php @@ -11,9 +11,6 @@ use Magento\TestFramework\Application; use Magento\TestFramework\Helper\Bootstrap; -/** - * @magentoAppIsolation enabled - */ class PluginListGeneratorTest extends \PHPUnit\Framework\TestCase { /** From aeba2c4d96851429d5a39e8104caadab339b8ad5 Mon Sep 17 00:00:00 2001 From: Dmitry Tsymbal Date: Thu, 2 Jul 2020 15:24:53 +0300 Subject: [PATCH 31/44] Admin Delete Newsletter Subscriber --- ...ewsletterSubscriberFromGridActionGroup.xml | 19 +++++++ ...NewsletterSubscribersInGridActionGroup.xml | 22 ++++++++ ...letterSubscriberIsNotInGridActionGroup.xml | 17 +++++++ .../AdminNewsletterSubscriberGridSection.xml | 7 +++ ...arketingDeleteNewsletterSubscriberTest.xml | 50 +++++++++++++++++++ 5 files changed, 115 insertions(+) create mode 100644 app/code/Magento/Newsletter/Test/Mftf/ActionGroup/AdminMarketingDeleteNewsletterSubscriberFromGridActionGroup.xml create mode 100644 app/code/Magento/Newsletter/Test/Mftf/ActionGroup/AdminMarketingFindNewsletterSubscribersInGridActionGroup.xml create mode 100644 app/code/Magento/Newsletter/Test/Mftf/ActionGroup/AssertAdminDeletedNewsletterSubscriberIsNotInGridActionGroup.xml create mode 100644 app/code/Magento/Newsletter/Test/Mftf/Test/AdminMarketingDeleteNewsletterSubscriberTest.xml diff --git a/app/code/Magento/Newsletter/Test/Mftf/ActionGroup/AdminMarketingDeleteNewsletterSubscriberFromGridActionGroup.xml b/app/code/Magento/Newsletter/Test/Mftf/ActionGroup/AdminMarketingDeleteNewsletterSubscriberFromGridActionGroup.xml new file mode 100644 index 0000000000000..ed60c1509e453 --- /dev/null +++ b/app/code/Magento/Newsletter/Test/Mftf/ActionGroup/AdminMarketingDeleteNewsletterSubscriberFromGridActionGroup.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + diff --git a/app/code/Magento/Newsletter/Test/Mftf/ActionGroup/AdminMarketingFindNewsletterSubscribersInGridActionGroup.xml b/app/code/Magento/Newsletter/Test/Mftf/ActionGroup/AdminMarketingFindNewsletterSubscribersInGridActionGroup.xml new file mode 100644 index 0000000000000..9f9231397a1f8 --- /dev/null +++ b/app/code/Magento/Newsletter/Test/Mftf/ActionGroup/AdminMarketingFindNewsletterSubscribersInGridActionGroup.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + diff --git a/app/code/Magento/Newsletter/Test/Mftf/ActionGroup/AssertAdminDeletedNewsletterSubscriberIsNotInGridActionGroup.xml b/app/code/Magento/Newsletter/Test/Mftf/ActionGroup/AssertAdminDeletedNewsletterSubscriberIsNotInGridActionGroup.xml new file mode 100644 index 0000000000000..e114a4e640fa2 --- /dev/null +++ b/app/code/Magento/Newsletter/Test/Mftf/ActionGroup/AssertAdminDeletedNewsletterSubscriberIsNotInGridActionGroup.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/app/code/Magento/Newsletter/Test/Mftf/Section/AdminNewsletterSubscriberGridSection.xml b/app/code/Magento/Newsletter/Test/Mftf/Section/AdminNewsletterSubscriberGridSection.xml index 3332041817150..26512a28c9f3d 100644 --- a/app/code/Magento/Newsletter/Test/Mftf/Section/AdminNewsletterSubscriberGridSection.xml +++ b/app/code/Magento/Newsletter/Test/Mftf/Section/AdminNewsletterSubscriberGridSection.xml @@ -12,5 +12,12 @@ + + + + + + + diff --git a/app/code/Magento/Newsletter/Test/Mftf/Test/AdminMarketingDeleteNewsletterSubscriberTest.xml b/app/code/Magento/Newsletter/Test/Mftf/Test/AdminMarketingDeleteNewsletterSubscriberTest.xml new file mode 100644 index 0000000000000..eea77a6be0784 --- /dev/null +++ b/app/code/Magento/Newsletter/Test/Mftf/Test/AdminMarketingDeleteNewsletterSubscriberTest.xml @@ -0,0 +1,50 @@ + + + + + + + + + + <description value="Admin should be able delete newsletter subscribers"/> + <group value="newsletter"/> + </annotations> + <before> + <createData entity="Simple_US_Customer" stepKey="createCustomer"/> + </before> + <after> + <deleteData createDataKey="createCustomer" stepKey="deleteCreatedCustomer"/> + </after> + + <actionGroup ref="LoginToStorefrontActionGroup" stepKey="loginAsCustomer"> + <argument name="Customer" value="$$createCustomer$$"/> + </actionGroup> + <actionGroup ref="StorefrontCustomerNavigateToNewsletterPageActionGroup" stepKey="navigateToNewsletterPage"/> + <actionGroup ref="StorefrontCustomerUpdateGeneralSubscriptionActionGroup" stepKey="subscribeToNewsletter"/> + <actionGroup ref="AdminLoginActionGroup" stepKey="LoginAsAdmin"/> + <actionGroup ref="AdminNavigateMenuActionGroup" stepKey="navigateToNewsletterSubscribersPage"> + <argument name="menuUiId" value="{{AdminMenuMarketing.dataUiId}}"/> + <argument name="submenuUiId" value="{{AdminMenuMarketingCommunicationsNewsletterSubscribers.dataUiId}}"/> + </actionGroup> + <actionGroup ref="AdminMarketingFindNewsletterSubscribersInGridActionGroup" stepKey="findSubscriber"> + <argument name="email" value="{{Simple_US_Customer.email}}"/> + </actionGroup> + <actionGroup ref="AdminMarketingDeleteNewsletterSubscriberFromGridActionGroup" stepKey="deleteSubscriber"/> + <actionGroup ref="AssertMessageInAdminPanelActionGroup" stepKey="assertSuccessMessage"> + <argument name="message" value="Total of 1 record(s) were deleted."/> + </actionGroup> + <actionGroup ref="AdminMarketingFindNewsletterSubscribersInGridActionGroup" stepKey="findDeletedSubscriber"> + <argument name="email" value="{{Simple_US_Customer.email}}"/> + </actionGroup> + <actionGroup ref="AssertAdminDeletedNewsletterSubscriberIsNotInGridActionGroup" stepKey="dontSeeSubscriber"> + <argument name="email" value="{{Simple_US_Customer.email}}"/> + </actionGroup> + </test> +</tests> From e3f4a0c369dbbcd380d2661ac9f439431a368105 Mon Sep 17 00:00:00 2001 From: Vasya Tsviklinskyi <tsviklinskyi@gmail.com> Date: Fri, 3 Jul 2020 08:42:54 +0300 Subject: [PATCH 32/44] MC-35490: Price sort order not working properly --- .../Indexer/Product/Price/AbstractAction.php | 12 +- .../Indexer/Price/ConfigurableTest.php | 42 +++++-- ...uct_configurable_with_assigned_simples.php | 106 ++++++++++++++++++ ...gurable_with_assigned_simples_rollback.php | 40 +++++++ .../Adminhtml/Export/File/DeleteTest.php | 2 + 5 files changed, 190 insertions(+), 12 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_assigned_simples.php create mode 100644 dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_assigned_simples_rollback.php diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Price/AbstractAction.php b/app/code/Magento/Catalog/Model/Indexer/Product/Price/AbstractAction.php index f010536f06ee5..ef36af340994a 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Product/Price/AbstractAction.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Price/AbstractAction.php @@ -368,14 +368,20 @@ protected function _reindexRows($changedIds = []) $productsTypes = $this->getProductsTypes($changedIds); $parentProductsTypes = $this->getParentProductsTypes($changedIds); - $changedIds = array_merge($changedIds, ...array_values($parentProductsTypes)); + $changedIds = array_unique(array_merge($changedIds, ...array_values($parentProductsTypes))); $productsTypes = array_merge_recursive($productsTypes, $parentProductsTypes); if ($changedIds) { $this->deleteIndexData($changedIds); } - foreach ($productsTypes as $productType => $entityIds) { - $indexer = $this->_getIndexer($productType); + + $typeIndexers = $this->getTypeIndexers(); + foreach ($typeIndexers as $productType => $indexer) { + $entityIds = $productsTypes[$productType] ?? []; + if (empty($entityIds)) { + continue; + } + if ($indexer instanceof DimensionalIndexerInterface) { foreach ($this->dimensionCollectionFactory->create() as $dimensions) { $this->tableMaintainer->createMainTmpTable($dimensions); diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/ResourceModel/Product/Indexer/Price/ConfigurableTest.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/ResourceModel/Product/Indexer/Price/ConfigurableTest.php index 32eddb28151a7..ffa84ca740e62 100644 --- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/ResourceModel/Product/Indexer/Price/ConfigurableTest.php +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/ResourceModel/Product/Indexer/Price/ConfigurableTest.php @@ -6,6 +6,7 @@ namespace Magento\ConfigurableProduct\Model\ResourceModel\Product\Indexer\Price; use Magento\Catalog\Api\ProductRepositoryInterface; +use Magento\Catalog\Model\Indexer\Product\Price\Processor as PriceIndexerProcessor; use Magento\Catalog\Model\Product\Attribute\Source\Status; use Magento\Catalog\Model\ResourceModel\Product\Collection; use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; @@ -18,7 +19,7 @@ use Magento\Catalog\Api\Data\ProductInterface; /** - * Configurable test + * Test reindex of configurable products * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @magentoAppArea adminhtml @@ -64,7 +65,7 @@ protected function setUp(): void */ public function testGetProductFinalPriceIfOneOfChildIsDisabled(): void { - $configurableProduct = $this->getConfigurableProductFromCollection(); + $configurableProduct = $this->getConfigurableProductFromCollection(1); $this->assertEquals(10, $configurableProduct->getMinimalPrice()); $childProduct = $this->productRepository->getById(10, false, null, true); @@ -75,7 +76,7 @@ public function testGetProductFinalPriceIfOneOfChildIsDisabled(): void $this->productRepository->save($childProduct); $this->storeManager->setCurrentStore($currentStoreId); - $configurableProduct = $this->getConfigurableProductFromCollection(); + $configurableProduct = $this->getConfigurableProductFromCollection(1); $this->assertEquals(20, $configurableProduct->getMinimalPrice()); } @@ -93,7 +94,7 @@ public function testGetProductFinalPriceIfOneOfChildIsDisabled(): void */ public function testGetProductFinalPriceIfOneOfChildIsDisabledPerStore(): void { - $configurableProduct = $this->getConfigurableProductFromCollection(); + $configurableProduct = $this->getConfigurableProductFromCollection(1); $this->assertEquals(10, $configurableProduct->getMinimalPrice()); $childProduct = $this->productRepository->get('simple_10', false, null, true); @@ -106,7 +107,7 @@ public function testGetProductFinalPriceIfOneOfChildIsDisabledPerStore(): void $this->productRepository->save($childProduct); $this->storeManager->setCurrentStore($currentStoreId); - $configurableProduct = $this->getConfigurableProductFromCollection(); + $configurableProduct = $this->getConfigurableProductFromCollection(1); $this->assertEquals(20, $configurableProduct->getMinimalPrice()); } @@ -122,7 +123,7 @@ public function testGetProductFinalPriceIfOneOfChildIsDisabledPerStore(): void */ public function testGetProductMinimalPriceIfOneOfChildIsOutOfStock(): void { - $configurableProduct = $this->getConfigurableProductFromCollection(); + $configurableProduct = $this->getConfigurableProductFromCollection(1); $this->assertEquals(10, $configurableProduct->getMinimalPrice()); $childProduct = $this->productRepository->getById(10, false, null, true); @@ -130,25 +131,48 @@ public function testGetProductMinimalPriceIfOneOfChildIsOutOfStock(): void $stockItem->setIsInStock(Stock::STOCK_OUT_OF_STOCK); $this->stockRepository->save($stockItem); - $configurableProduct = $this->getConfigurableProductFromCollection(); + $configurableProduct = $this->getConfigurableProductFromCollection(1); $this->assertEquals(20, $configurableProduct->getMinimalPrice()); } + /** + * @magentoDataFixture Magento/Catalog/_files/enable_price_index_schedule.php + * @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable_with_assigned_simples.php + * @magentoDbIsolation disabled + * + * @return void + */ + public function testReindexWithCorrectPriority() + { + $configurableProduct = $this->productRepository->get('configurable'); + $childProduct1 = $this->productRepository->get('simple_1'); + $childProduct2 = $this->productRepository->get('simple_2'); + $priceIndexerProcessor = Bootstrap::getObjectManager()->get(PriceIndexerProcessor::class); + $priceIndexerProcessor->reindexList( + [$configurableProduct->getId(), $childProduct1->getId(), $childProduct2->getId()], + true + ); + + $configurableProduct = $this->getConfigurableProductFromCollection($configurableProduct->getId()); + $this->assertEquals($childProduct1->getPrice(), $configurableProduct->getMinimalPrice()); + } + /** * Retrieve configurable product. * Returns Configurable product that was created by Magento/ConfigurableProduct/_files/product_configurable.php * fixture * + * @param int $productId * @return ProductInterface */ - private function getConfigurableProductFromCollection(): ProductInterface + private function getConfigurableProductFromCollection(int $productId): ProductInterface { /** @var Collection $collection */ $collection = Bootstrap::getObjectManager()->get(CollectionFactory::class) ->create(); /** @var ProductInterface $configurableProduct */ $configurableProduct = $collection - ->addIdFilter([1]) + ->addIdFilter([$productId]) ->addMinimalPrice() ->load() ->getFirstItem(); diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_assigned_simples.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_assigned_simples.php new file mode 100644 index 0000000000000..cd8c5392d746a --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_assigned_simples.php @@ -0,0 +1,106 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +use Magento\Catalog\Api\ProductRepositoryInterface; +use Magento\Catalog\Model\Indexer\Product\Price\Processor as PriceIndexerProcessor; +use Magento\Catalog\Model\Product; +use Magento\Catalog\Model\Product\Attribute\Source\Status; +use Magento\Catalog\Model\Product\Type; +use Magento\Catalog\Model\Product\Visibility; +use Magento\Catalog\Setup\CategorySetup; +use Magento\CatalogInventory\Model\Stock\Item; +use Magento\ConfigurableProduct\Helper\Product\Options\Factory; +use Magento\ConfigurableProduct\Model\Product\Type\Configurable; +use Magento\Eav\Api\Data\AttributeOptionInterface; +use Magento\TestFramework\Helper\Bootstrap; +use Magento\TestFramework\Workaround\Override\Fixture\Resolver; + +Bootstrap::getInstance()->reinitialize(); + +Resolver::getInstance()->requireDataFixture('Magento/ConfigurableProduct/_files/configurable_attribute.php'); + +$installer = Bootstrap::getObjectManager()->create(CategorySetup::class); +$attributeSetId = $installer->getAttributeSetId('catalog_product', 'Default'); + +$product = Bootstrap::getObjectManager()->create(Product::class); +$product->setTypeId(Configurable::TYPE_CODE) + ->setAttributeSetId($attributeSetId) + ->setWebsiteIds([1]) + ->setName('Configurable Product') + ->setSku('configurable') + ->setVisibility(Visibility::VISIBILITY_BOTH) + ->setStatus(Status::STATUS_ENABLED) + ->setStockData(['use_config_manage_stock' => 1, 'is_in_stock' => 1]); +$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class); +$product = $productRepository->save($product); + +$attributeValues = []; +$associatedProductIds = []; +/** @var AttributeOptionInterface[] $options */ +$options = $attribute->getOptions(); +array_shift($options); //remove the first option which is empty +$productNumber = 0; +foreach ($options as $option) { + $productNumber++; + + $childProduct = Bootstrap::getObjectManager()->create(Product::class); + $childProduct->setTypeId(Type::TYPE_SIMPLE) + ->setAttributeSetId($attributeSetId) + ->setWebsiteIds([1]) + ->setName('Configurable Option' . $option->getLabel()) + ->setSku('simple_' . $productNumber) + ->setPrice($productNumber * 10) + ->setTestConfigurable($option->getValue()) + ->setVisibility(Visibility::VISIBILITY_NOT_VISIBLE) + ->setStatus(Status::STATUS_ENABLED) + ->setStockData( + ['use_config_manage_stock' => 1,'qty' => $productNumber * 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1] + ); + $childProduct = $productRepository->save($childProduct); + + $stockItem = Bootstrap::getObjectManager()->create(Item::class); + $stockItem->load($childProduct->getId(), 'product_id'); + if (!$stockItem->getProductId()) { + $stockItem->setProductId($childProduct->getId()); + } + $stockItem->setUseConfigManageStock(1); + $stockItem->setQty($productNumber * 100); + $stockItem->setIsQtyDecimal(0); + $stockItem->setIsInStock(1); + $stockItem->save(); + + $attributeValues[] = [ + 'label' => 'test', + 'attribute_id' => $attribute->getId(), + 'value_index' => $option->getValue(), + ]; + $associatedProductIds[] = $childProduct->getId(); +} + +$indexerProcessor = Bootstrap::getObjectManager()->get(PriceIndexerProcessor::class); +$indexerProcessor->reindexList($associatedProductIds); + +$optionsFactory = Bootstrap::getObjectManager()->create(Factory::class); +$configurableOptions = $optionsFactory->create( + [ + [ + 'attribute_id' => $attribute->getId(), + 'code' => $attribute->getAttributeCode(), + 'label' => $attribute->getStoreLabel(), + 'position' => '0', + 'values' => $attributeValues, + ], + ] +); +$extensionConfigurableAttributes = $product->getExtensionAttributes(); +$extensionConfigurableAttributes->setConfigurableProductOptions($configurableOptions); +$extensionConfigurableAttributes->setConfigurableProductLinks($associatedProductIds); +$product->setExtensionAttributes($extensionConfigurableAttributes); +$product = $productRepository->save($product); + +$indexerProcessor = Bootstrap::getObjectManager()->get(PriceIndexerProcessor::class); +$indexerProcessor->reindexRow($product->getId()); diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_assigned_simples_rollback.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_assigned_simples_rollback.php new file mode 100644 index 0000000000000..68621f78745e8 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_assigned_simples_rollback.php @@ -0,0 +1,40 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +use Magento\Catalog\Api\ProductRepositoryInterface; +use Magento\CatalogInventory\Model\Stock\Status; +use Magento\Framework\Registry; +use Magento\TestFramework\Helper\Bootstrap; +use Magento\TestFramework\Workaround\Override\Fixture\Resolver; + +$objectManager = Bootstrap::getObjectManager(); + +$registry = $objectManager->get(Registry::class); +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', true); + +$productRepository = $objectManager->get(ProductRepositoryInterface::class); +foreach (['simple_1', 'simple_2', 'configurable'] as $sku) { + try { + $product = $productRepository->get($sku, true); + + $stockStatus = $objectManager->create(Status::class); + $stockStatus->load($product->getEntityId(), 'product_id'); + $stockStatus->delete(); + + if ($product->getId()) { + $productRepository->delete($product); + } + } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { + //Product already removed + } +} + +Resolver::getInstance()->requireDataFixture('Magento/ConfigurableProduct/_files/configurable_attribute_rollback.php'); + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', false); diff --git a/dev/tests/integration/testsuite/Magento/ImportExport/Controller/Adminhtml/Export/File/DeleteTest.php b/dev/tests/integration/testsuite/Magento/ImportExport/Controller/Adminhtml/Export/File/DeleteTest.php index 2a460a8ce622a..3d4f35a9e08ac 100644 --- a/dev/tests/integration/testsuite/Magento/ImportExport/Controller/Adminhtml/Export/File/DeleteTest.php +++ b/dev/tests/integration/testsuite/Magento/ImportExport/Controller/Adminhtml/Export/File/DeleteTest.php @@ -16,6 +16,8 @@ /** * Test for \Magento\ImportExport\Controller\Adminhtml\Export\File\Delete class. + * + * @magentoAppArea adminhtml */ class DeleteTest extends AbstractBackendController { From 3c7613da66f9175c789326bcfaafbdd258ccf4d0 Mon Sep 17 00:00:00 2001 From: Vasya Tsviklinskyi <tsviklinskyi@gmail.com> Date: Fri, 3 Jul 2020 08:56:31 +0300 Subject: [PATCH 33/44] MC-31892: Attribute sets not preserving attribute values when set is changed --- .../Section/AdminProductContentSection.xml | 1 + .../AdminChangeProductAttributeGroupTest.xml | 85 +++++++++++++++++++ .../view/base/web/js/core/renderer/layout.js | 2 +- 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 app/code/Magento/Catalog/Test/Mftf/Test/AdminChangeProductAttributeGroupTest.xml diff --git a/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductContentSection.xml b/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductContentSection.xml index fafae5d535546..4b4aa20300d14 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductContentSection.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductContentSection.xml @@ -15,5 +15,6 @@ <element name="shortDescriptionTextArea" type="textarea" selector="#product_form_short_description"/> <element name="sectionHeaderIfNotShowing" type="button" selector="//div[@data-index='content']//div[contains(@class, '_hide')]"/> <element name="pageHeader" type="textarea" selector="//*[@class='page-header row']"/> + <element name="attributeInput" type="input" selector="input[name='product[{{attributeCode}}]']" parameterized="true"/> </section> </sections> diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminChangeProductAttributeGroupTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminChangeProductAttributeGroupTest.xml new file mode 100644 index 0000000000000..401b74e730fd6 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminChangeProductAttributeGroupTest.xml @@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> + <test name="AdminChangeProductAttributeGroupTest"> + <annotations> + <title value="Preserving attribute value after attribute group is changed"/> + <description value="Attribute value should be preserved after changing attribute group"/> + <severity value="CRITICAL"/> + <testCaseId value="MC-35612"/> + <useCaseId value="MC-31892"/> + <group value="catalog"/> + </annotations> + <before> + <createData entity="SimpleSubCategory" stepKey="createCategory"/> + <createData entity="_defaultProduct" stepKey="createSimpleProduct"> + <requiredEntity createDataKey="createCategory"/> + </createData> + + <createData entity="productAttributeText" stepKey="createProductAttribute"/> + <createData entity="CatalogAttributeSet" stepKey="createAttributeSet"/> + <createData entity="CatalogAttributeSet" stepKey="createSecondAttributeSet"/> + + <actionGroup ref="LoginAsAdmin" stepKey="login"/> + <amOnPage url="{{AdminProductAttributeSetEditPage.url}}/$createAttributeSet.attribute_set_id$/" + stepKey="onAttributeSetEdit"/> + <actionGroup ref="AssignAttributeToGroup" stepKey="assignAttributeToGroup"> + <argument name="group" value="Product Details"/> + <argument name="attribute" value="$createProductAttribute.attribute_code$"/> + </actionGroup> + <actionGroup ref="SaveAttributeSet" stepKey="saveAttributeSet"/> + <amOnPage url="{{AdminProductAttributeSetEditPage.url}}/$createSecondAttributeSet.attribute_set_id$/" + stepKey="onSecondAttributeSetEdit"/> + <actionGroup ref="AssignAttributeToGroup" stepKey="assignAttributeToContentGroup"> + <argument name="group" value="Content"/> + <argument name="attribute" value="$createProductAttribute.attribute_code$"/> + </actionGroup> + <actionGroup ref="SaveAttributeSet" stepKey="saveSecondAttributeSet"/> + </before> + <after> + <deleteData createDataKey="createSimpleProduct" stepKey="deleteProduct"/> + <deleteData createDataKey="createCategory" stepKey="deleteCategory"/> + <deleteData createDataKey="createProductAttribute" stepKey="deleteProductAttribute"/> + <deleteData createDataKey="createAttributeSet" stepKey="deleteAttributeSet"/> + <deleteData createDataKey="createSecondAttributeSet" stepKey="deleteSecondAttributeSet"/> + <actionGroup ref="ClearProductsFilterActionGroup" stepKey="clearProductsFilter"/> + + <!-- Reindex invalidated indices after product attribute has been created/deleted --> + <actionGroup ref="CliRunReindexUsingCronJobsActionGroup" stepKey="reindexInvalidatedIndices"/> + <actionGroup ref="logout" stepKey="logout"/> + </after> + + <actionGroup ref="SearchForProductOnBackendActionGroup" stepKey="searchForSimpleProduct"> + <argument name="product" value="$createSimpleProduct$"/> + </actionGroup> + + <actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="openEditProduct1"> + <argument name="product" value="$createSimpleProduct$"/> + </actionGroup> + + <actionGroup ref="AdminProductPageSelectAttributeSet" stepKey="selectAttributeSet"> + <argument name="attributeSetName" value="$createAttributeSet.attribute_set_name$"/> + </actionGroup> + <waitForText userInput="$createProductAttribute.default_frontend_label$" stepKey="seeAttributeInForm"/> + <fillField selector="{{AdminProductFormSection.attributeRequiredInput($createProductAttribute.attribute_code$)}}" + userInput="test" + stepKey="fillProductAttributeValue"/> + <actionGroup ref="AdminProductPageSelectAttributeSet" stepKey="selectSecondAttributeSet"> + <argument name="attributeSetName" value="$createSecondAttributeSet.attribute_set_name$"/> + </actionGroup> + <actionGroup ref="ExpandAdminProductSectionActionGroup" stepKey="expandContentSection"/> + <waitForText userInput="$createProductAttribute.default_frontend_label$" stepKey="seeAttributeInSection"/> + <grabValueFrom selector="{{AdminProductContentSection.attributeInput($createProductAttribute.attribute_code$)}}" + stepKey="attributeValue"/> + <assertEquals stepKey="assertAttributeValue"> + <expectedResult type="string">test</expectedResult> + <actualResult type="variable">attributeValue</actualResult> + </assertEquals> + </test> +</tests> diff --git a/app/code/Magento/Ui/view/base/web/js/core/renderer/layout.js b/app/code/Magento/Ui/view/base/web/js/core/renderer/layout.js index ac1de4631e908..5240fe55f6a74 100644 --- a/app/code/Magento/Ui/view/base/web/js/core/renderer/layout.js +++ b/app/code/Magento/Ui/view/base/web/js/core/renderer/layout.js @@ -499,7 +499,7 @@ define([ component = registry.get(val.path); if (component) { - component.cleanData().destroy(); + component.destroy(); } }); From de9318d7f41e3db30f03ef0bdabb1ae64d27f122 Mon Sep 17 00:00:00 2001 From: "rostyslav.hymon" <rostyslav.hymon@transoftgroup.com> Date: Fri, 3 Jul 2020 09:11:37 +0300 Subject: [PATCH 34/44] MC-35491: Patch Request : Re: Slow query on search_query --- .../Search/ViewModel/ConfigProvider.php | 50 +++++++++++++++++++ .../Search/view/frontend/layout/default.xml | 6 ++- .../view/frontend/templates/form.mini.phtml | 16 +++--- 3 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 app/code/Magento/Search/ViewModel/ConfigProvider.php diff --git a/app/code/Magento/Search/ViewModel/ConfigProvider.php b/app/code/Magento/Search/ViewModel/ConfigProvider.php new file mode 100644 index 0000000000000..be3366e62e965 --- /dev/null +++ b/app/code/Magento/Search/ViewModel/ConfigProvider.php @@ -0,0 +1,50 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\Search\ViewModel; + +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\View\Element\Block\ArgumentInterface; +use Magento\Store\Model\ScopeInterface; + +/** + * View model for search + */ +class ConfigProvider implements ArgumentInterface +{ + /** + * Suggestions settings config paths + */ + private const SEARCH_SUGGESTION_ENABLED = 'catalog/search/search_suggestion_enabled'; + + /** + * @var ScopeConfigInterface + */ + private $scopeConfig; + + /** + * @param ScopeConfigInterface $scopeConfig + */ + public function __construct( + ScopeConfigInterface $scopeConfig + ) { + $this->scopeConfig = $scopeConfig; + } + + /** + * Is Search Suggestions Allowed + * + * @return bool + */ + public function isSuggestionsAllowed(): bool + { + return $this->scopeConfig->isSetFlag( + self::SEARCH_SUGGESTION_ENABLED, + ScopeInterface::SCOPE_STORE + ); + } +} diff --git a/app/code/Magento/Search/view/frontend/layout/default.xml b/app/code/Magento/Search/view/frontend/layout/default.xml index 0cb18adedd952..69c99f979d51b 100644 --- a/app/code/Magento/Search/view/frontend/layout/default.xml +++ b/app/code/Magento/Search/view/frontend/layout/default.xml @@ -8,7 +8,11 @@ <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="header-wrapper"> - <block class="Magento\Framework\View\Element\Template" name="top.search" as="topSearch" template="Magento_Search::form.mini.phtml" /> + <block class="Magento\Framework\View\Element\Template" name="top.search" as="topSearch" template="Magento_Search::form.mini.phtml"> + <arguments> + <argument name="configProvider" xsi:type="object">Magento\Search\ViewModel\ConfigProvider</argument> + </arguments> + </block> </referenceContainer> <referenceBlock name="footer_links"> <block class="Magento\Framework\View\Element\Html\Link\Current" ifconfig="catalog/seo/search_terms" name="search-term-popular-link"> diff --git a/app/code/Magento/Search/view/frontend/templates/form.mini.phtml b/app/code/Magento/Search/view/frontend/templates/form.mini.phtml index 35f3876599731..80e720e2c2fe2 100644 --- a/app/code/Magento/Search/view/frontend/templates/form.mini.phtml +++ b/app/code/Magento/Search/view/frontend/templates/form.mini.phtml @@ -9,7 +9,9 @@ <?php /** @var $block \Magento\Framework\View\Element\Template */ /** @var $helper \Magento\Search\Helper\Data */ +/** @var $configProvider \Magento\Search\ViewModel\ConfigProvider */ $helper = $this->helper(\Magento\Search\Helper\Data::class); +$configProvider = $block->getData('configProvider'); ?> <div class="block block-search"> <div class="block block-title"><strong><?= $block->escapeHtml(__('Search')) ?></strong></div> @@ -22,12 +24,14 @@ $helper = $this->helper(\Magento\Search\Helper\Data::class); </label> <div class="control"> <input id="search" - data-mage-init='{"quickSearch":{ - "formSelector":"#search_mini_form", - "url":"<?= $block->escapeUrl($helper->getSuggestUrl())?>", - "destinationSelector":"#search_autocomplete", - "minSearchLength":"<?= $block->escapeHtml($helper->getMinQueryLength()) ?>"} - }' + <?php if ($configProvider->isSuggestionsAllowed()):?> + data-mage-init='{"quickSearch":{ + "formSelector":"#search_mini_form", + "url":"<?= $block->escapeUrl($helper->getSuggestUrl())?>", + "destinationSelector":"#search_autocomplete", + "minSearchLength":"<?= $block->escapeHtml($helper->getMinQueryLength()) ?>"} + }' + <?php endif;?> type="text" name="<?= $block->escapeHtmlAttr($helper->getQueryParamName()) ?>" value="<?= /* @noEscape */ $helper->getEscapedQueryText() ?>" From e08f991eba14c5b87cc9d8a3aceed18c6163a6b1 Mon Sep 17 00:00:00 2001 From: Vasya Tsviklinskyi <tsviklinskyi@gmail.com> Date: Fri, 3 Jul 2020 09:28:55 +0300 Subject: [PATCH 35/44] MC-31892: Attribute sets not preserving attribute values when set is changed --- .../AdminChangeProductAttributeGroupTest.xml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminChangeProductAttributeGroupTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminChangeProductAttributeGroupTest.xml index 401b74e730fd6..04955807d7618 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminChangeProductAttributeGroupTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminChangeProductAttributeGroupTest.xml @@ -26,21 +26,21 @@ <createData entity="CatalogAttributeSet" stepKey="createAttributeSet"/> <createData entity="CatalogAttributeSet" stepKey="createSecondAttributeSet"/> - <actionGroup ref="LoginAsAdmin" stepKey="login"/> + <actionGroup ref="AdminLoginActionGroup" stepKey="login"/> <amOnPage url="{{AdminProductAttributeSetEditPage.url}}/$createAttributeSet.attribute_set_id$/" stepKey="onAttributeSetEdit"/> - <actionGroup ref="AssignAttributeToGroup" stepKey="assignAttributeToGroup"> + <actionGroup ref="AssignAttributeToGroupActionGroup" stepKey="assignAttributeToGroup"> <argument name="group" value="Product Details"/> <argument name="attribute" value="$createProductAttribute.attribute_code$"/> </actionGroup> - <actionGroup ref="SaveAttributeSet" stepKey="saveAttributeSet"/> + <actionGroup ref="SaveAttributeSetActionGroup" stepKey="saveAttributeSet"/> <amOnPage url="{{AdminProductAttributeSetEditPage.url}}/$createSecondAttributeSet.attribute_set_id$/" stepKey="onSecondAttributeSetEdit"/> - <actionGroup ref="AssignAttributeToGroup" stepKey="assignAttributeToContentGroup"> + <actionGroup ref="AssignAttributeToGroupActionGroup" stepKey="assignAttributeToContentGroup"> <argument name="group" value="Content"/> <argument name="attribute" value="$createProductAttribute.attribute_code$"/> </actionGroup> - <actionGroup ref="SaveAttributeSet" stepKey="saveSecondAttributeSet"/> + <actionGroup ref="SaveAttributeSetActionGroup" stepKey="saveSecondAttributeSet"/> </before> <after> <deleteData createDataKey="createSimpleProduct" stepKey="deleteProduct"/> @@ -51,8 +51,8 @@ <actionGroup ref="ClearProductsFilterActionGroup" stepKey="clearProductsFilter"/> <!-- Reindex invalidated indices after product attribute has been created/deleted --> - <actionGroup ref="CliRunReindexUsingCronJobsActionGroup" stepKey="reindexInvalidatedIndices"/> - <actionGroup ref="logout" stepKey="logout"/> + <magentoCron groups="index" stepKey="reindexInvalidatedIndices"/> + <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/> </after> <actionGroup ref="SearchForProductOnBackendActionGroup" stepKey="searchForSimpleProduct"> @@ -63,14 +63,14 @@ <argument name="product" value="$createSimpleProduct$"/> </actionGroup> - <actionGroup ref="AdminProductPageSelectAttributeSet" stepKey="selectAttributeSet"> + <actionGroup ref="AdminProductPageSelectAttributeSetActionGroup" stepKey="selectAttributeSet"> <argument name="attributeSetName" value="$createAttributeSet.attribute_set_name$"/> </actionGroup> <waitForText userInput="$createProductAttribute.default_frontend_label$" stepKey="seeAttributeInForm"/> <fillField selector="{{AdminProductFormSection.attributeRequiredInput($createProductAttribute.attribute_code$)}}" userInput="test" stepKey="fillProductAttributeValue"/> - <actionGroup ref="AdminProductPageSelectAttributeSet" stepKey="selectSecondAttributeSet"> + <actionGroup ref="AdminProductPageSelectAttributeSetActionGroup" stepKey="selectSecondAttributeSet"> <argument name="attributeSetName" value="$createSecondAttributeSet.attribute_set_name$"/> </actionGroup> <actionGroup ref="ExpandAdminProductSectionActionGroup" stepKey="expandContentSection"/> From d0e0605c03b33862d95c085e29b0eb8c365189c2 Mon Sep 17 00:00:00 2001 From: engcom-Echo <engcom-vendorworker-echo@adobe.com> Date: Fri, 3 Jul 2020 11:24:35 +0300 Subject: [PATCH 36/44] fix static --- .../Patch/Data/AddCustomerUpdatedAtAttribute.php | 11 ++++++----- .../Data/AddNonSpecifiedGenderAttributeOption.php | 11 ++++++----- .../Patch/Data/AddSecurityTrackingAttributes.php | 13 +++++++------ .../ConvertValidationRulesFromSerializedToJson.php | 11 ++++++----- .../Data/DefaultCustomerGroupsAndAttributes.php | 11 +++++++---- .../Data/MigrateStoresAllowedCountriesToWebsite.php | 4 +++- .../RemoveCheckoutRegisterAndUpdateAttributes.php | 11 ++++++----- .../UpdateAutocompleteOnStorefrontConfigPath.php | 11 ++++++----- .../Data/UpdateCustomerAttributeInputFilters.php | 11 ++++++----- ...UpdateIdentifierCustomerAttributesVisibility.php | 11 ++++++----- .../Customer/Setup/Patch/Data/UpdateVATNumber.php | 11 ++++++----- .../Patch/Data/UpgradePasswordHashAndAddress.php | 13 ++++++++----- 12 files changed, 73 insertions(+), 56 deletions(-) diff --git a/app/code/Magento/Customer/Setup/Patch/Data/AddCustomerUpdatedAtAttribute.php b/app/code/Magento/Customer/Setup/Patch/Data/AddCustomerUpdatedAtAttribute.php index 77bb515c8e52b..1a8cdb8987db7 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/AddCustomerUpdatedAtAttribute.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/AddCustomerUpdatedAtAttribute.php @@ -3,7 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - declare(strict_types=1); namespace Magento\Customer\Setup\Patch\Data; @@ -42,7 +41,7 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc */ public function apply() { @@ -60,10 +59,12 @@ public function apply() 'system' => false, ] ); + + return $this; } /** - * {@inheritdoc} + * @inheritdoc */ public static function getDependencies() { @@ -73,7 +74,7 @@ public static function getDependencies() } /** - * {@inheritdoc} + * @inheritdoc */ public static function getVersion() { @@ -81,7 +82,7 @@ public static function getVersion() } /** - * {@inheritdoc} + * @inheritdoc */ public function getAliases() { diff --git a/app/code/Magento/Customer/Setup/Patch/Data/AddNonSpecifiedGenderAttributeOption.php b/app/code/Magento/Customer/Setup/Patch/Data/AddNonSpecifiedGenderAttributeOption.php index e958093b89621..36611afc6a2aa 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/AddNonSpecifiedGenderAttributeOption.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/AddNonSpecifiedGenderAttributeOption.php @@ -3,7 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - declare(strict_types=1); namespace Magento\Customer\Setup\Patch\Data; @@ -42,7 +41,7 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc */ public function apply() { @@ -52,10 +51,12 @@ public function apply() $option = ['attribute_id' => $attributeId, 'values' => [3 => 'Not Specified']]; $customerSetup->addAttributeOption($option); + + return $this; } /** - * {@inheritdoc} + * @inheritdoc */ public static function getDependencies() { @@ -65,7 +66,7 @@ public static function getDependencies() } /** - * {@inheritdoc} + * @inheritdoc */ public static function getVersion() { @@ -73,7 +74,7 @@ public static function getVersion() } /** - * {@inheritdoc} + * @inheritdoc */ public function getAliases() { diff --git a/app/code/Magento/Customer/Setup/Patch/Data/AddSecurityTrackingAttributes.php b/app/code/Magento/Customer/Setup/Patch/Data/AddSecurityTrackingAttributes.php index 737ac2b085b34..09611ac1ccca3 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/AddSecurityTrackingAttributes.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/AddSecurityTrackingAttributes.php @@ -3,7 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - declare(strict_types=1); namespace Magento\Customer\Setup\Patch\Data; @@ -42,7 +41,7 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc */ public function apply() { @@ -93,12 +92,14 @@ public function apply() $this->moduleDataSetup->getConnection()->update( $configTable, ['value' => new \Zend_Db_Expr('value*24')], - ['path = ?' => \Magento\Customer\Model\Customer::XML_PATH_CUSTOMER_RESET_PASSWORD_LINK_EXPIRATION_PERIOD] + ['path = ?' => Customer::XML_PATH_CUSTOMER_RESET_PASSWORD_LINK_EXPIRATION_PERIOD] ); + + return $this; } /** - * {@inheritdoc} + * @inheritdoc */ public static function getDependencies() { @@ -108,7 +109,7 @@ public static function getDependencies() } /** - * {@inheritdoc} + * @inheritdoc */ public static function getVersion() { @@ -116,7 +117,7 @@ public static function getVersion() } /** - * {@inheritdoc} + * @inheritdoc */ public function getAliases() { diff --git a/app/code/Magento/Customer/Setup/Patch/Data/ConvertValidationRulesFromSerializedToJson.php b/app/code/Magento/Customer/Setup/Patch/Data/ConvertValidationRulesFromSerializedToJson.php index ed3fb5b00c524..e25fe5803e46c 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/ConvertValidationRulesFromSerializedToJson.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/ConvertValidationRulesFromSerializedToJson.php @@ -3,7 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - declare(strict_types=1); namespace Magento\Customer\Setup\Patch\Data; @@ -42,7 +41,7 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc */ public function apply() { @@ -53,10 +52,12 @@ public function apply() 'attribute_id', 'validate_rules' ); + + return $this; } /** - * {@inheritdoc} + * @inheritdoc */ public static function getDependencies() { @@ -66,7 +67,7 @@ public static function getDependencies() } /** - * {@inheritdoc} + * @inheritdoc */ public static function getVersion() { @@ -74,7 +75,7 @@ public static function getVersion() } /** - * {@inheritdoc} + * @inheritdoc */ public function getAliases() { diff --git a/app/code/Magento/Customer/Setup/Patch/Data/DefaultCustomerGroupsAndAttributes.php b/app/code/Magento/Customer/Setup/Patch/Data/DefaultCustomerGroupsAndAttributes.php index e6dd3f36e8ebd..fccda2ee9dac1 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/DefaultCustomerGroupsAndAttributes.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/DefaultCustomerGroupsAndAttributes.php @@ -44,7 +44,8 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc + * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function apply() @@ -146,10 +147,12 @@ public function apply() ['attribute_id'] ); $migrationSetup->doUpdateClassAliases(); + + return $this; } /** - * {@inheritdoc} + * @inheritdoc */ public static function getDependencies() { @@ -157,7 +160,7 @@ public static function getDependencies() } /** - * {@inheritdoc} + * @inheritdoc */ public static function getVersion() { @@ -165,7 +168,7 @@ public static function getVersion() } /** - * {@inheritdoc} + * @inheritdoc */ public function getAliases() { diff --git a/app/code/Magento/Customer/Setup/Patch/Data/MigrateStoresAllowedCountriesToWebsite.php b/app/code/Magento/Customer/Setup/Patch/Data/MigrateStoresAllowedCountriesToWebsite.php index d041ea920eb5b..1f21c7d4e83ba 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/MigrateStoresAllowedCountriesToWebsite.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/MigrateStoresAllowedCountriesToWebsite.php @@ -3,7 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - declare(strict_types=1); namespace Magento\Customer\Setup\Patch\Data; @@ -53,6 +52,7 @@ public function __construct( /** * @inheritdoc + * * @throws Exception */ public function apply() @@ -67,6 +67,8 @@ public function apply() $this->moduleDataSetup->getConnection()->rollBack(); throw $e; } + + return $this; } /** diff --git a/app/code/Magento/Customer/Setup/Patch/Data/RemoveCheckoutRegisterAndUpdateAttributes.php b/app/code/Magento/Customer/Setup/Patch/Data/RemoveCheckoutRegisterAndUpdateAttributes.php index 7c621c710c463..5dfcf2bf9bf0d 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/RemoveCheckoutRegisterAndUpdateAttributes.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/RemoveCheckoutRegisterAndUpdateAttributes.php @@ -3,7 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - declare(strict_types=1); namespace Magento\Customer\Setup\Patch\Data; @@ -47,7 +46,7 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc */ public function apply() { @@ -99,10 +98,12 @@ public function apply() 'source_model', Address\Attribute\Source\Region::class ); + + return $this; } /** - * {@inheritdoc} + * @inheritdoc */ public static function getDependencies() { @@ -112,7 +113,7 @@ public static function getDependencies() } /** - * {@inheritdoc} + * @inheritdoc */ public static function getVersion() { @@ -120,7 +121,7 @@ public static function getVersion() } /** - * {@inheritdoc} + * @inheritdoc */ public function getAliases() { diff --git a/app/code/Magento/Customer/Setup/Patch/Data/UpdateAutocompleteOnStorefrontConfigPath.php b/app/code/Magento/Customer/Setup/Patch/Data/UpdateAutocompleteOnStorefrontConfigPath.php index 64fef20008f09..8b8092cbb22c6 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/UpdateAutocompleteOnStorefrontConfigPath.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/UpdateAutocompleteOnStorefrontConfigPath.php @@ -3,7 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - declare(strict_types=1); namespace Magento\Customer\Setup\Patch\Data; @@ -33,7 +32,7 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc */ public function apply() { @@ -42,10 +41,12 @@ public function apply() ['path' => Form::XML_PATH_ENABLE_AUTOCOMPLETE], ['path = ?' => 'general/restriction/autocomplete_on_storefront'] ); + + return $this; } /** - * {@inheritdoc} + * @inheritdoc */ public static function getDependencies() { @@ -55,7 +56,7 @@ public static function getDependencies() } /** - * {@inheritdoc} + * @inheritdoc */ public static function getVersion() { @@ -63,7 +64,7 @@ public static function getVersion() } /** - * {@inheritdoc} + * @inheritdoc */ public function getAliases() { diff --git a/app/code/Magento/Customer/Setup/Patch/Data/UpdateCustomerAttributeInputFilters.php b/app/code/Magento/Customer/Setup/Patch/Data/UpdateCustomerAttributeInputFilters.php index 9d6bd2d4f7c69..ff6decb1d2123 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/UpdateCustomerAttributeInputFilters.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/UpdateCustomerAttributeInputFilters.php @@ -3,7 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - declare(strict_types=1); namespace Magento\Customer\Setup\Patch\Data; @@ -41,7 +40,7 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc */ public function apply() { @@ -71,10 +70,12 @@ public function apply() ], ]; $customerSetup->upgradeAttributes($entityAttributes); + + return $this; } /** - * {@inheritdoc} + * @inheritdoc */ public static function getDependencies() { @@ -84,7 +85,7 @@ public static function getDependencies() } /** - * {@inheritdoc} + * @inheritdoc */ public static function getVersion() { @@ -92,7 +93,7 @@ public static function getVersion() } /** - * {@inheritdoc} + * @inheritdoc */ public function getAliases() { diff --git a/app/code/Magento/Customer/Setup/Patch/Data/UpdateIdentifierCustomerAttributesVisibility.php b/app/code/Magento/Customer/Setup/Patch/Data/UpdateIdentifierCustomerAttributesVisibility.php index bfb97c6045c92..8519fab81efc5 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/UpdateIdentifierCustomerAttributesVisibility.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/UpdateIdentifierCustomerAttributesVisibility.php @@ -3,7 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - declare(strict_types=1); namespace Magento\Customer\Setup\Patch\Data; @@ -41,7 +40,7 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc */ public function apply() { @@ -69,10 +68,12 @@ public function apply() ], ]; $customerSetup->upgradeAttributes($entityAttributes); + + return $this; } /** - * {@inheritdoc} + * @inheritdoc */ public static function getDependencies() { @@ -82,7 +83,7 @@ public static function getDependencies() } /** - * {@inheritdoc} + * @inheritdoc */ public static function getVersion() { @@ -90,7 +91,7 @@ public static function getVersion() } /** - * {@inheritdoc} + * @inheritdoc */ public function getAliases() { diff --git a/app/code/Magento/Customer/Setup/Patch/Data/UpdateVATNumber.php b/app/code/Magento/Customer/Setup/Patch/Data/UpdateVATNumber.php index 1fa8614485870..ea3207c7ccb85 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/UpdateVATNumber.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/UpdateVATNumber.php @@ -3,7 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - declare(strict_types=1); namespace Magento\Customer\Setup\Patch\Data; @@ -41,7 +40,7 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc */ public function apply() { @@ -52,10 +51,12 @@ public function apply() 'frontend_label', 'VAT Number' ); + + return $this; } /** - * {@inheritdoc} + * @inheritdoc */ public static function getDependencies() { @@ -65,7 +66,7 @@ public static function getDependencies() } /** - * {@inheritdoc} + * @inheritdoc */ public static function getVersion() { @@ -73,7 +74,7 @@ public static function getVersion() } /** - * {@inheritdoc} + * @inheritdoc */ public function getAliases() { diff --git a/app/code/Magento/Customer/Setup/Patch/Data/UpgradePasswordHashAndAddress.php b/app/code/Magento/Customer/Setup/Patch/Data/UpgradePasswordHashAndAddress.php index cec2de71fb477..5d6e490bead22 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/UpgradePasswordHashAndAddress.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/UpgradePasswordHashAndAddress.php @@ -3,7 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - declare(strict_types=1); namespace Magento\Customer\Setup\Patch\Data; @@ -42,7 +41,7 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc */ public function apply() { @@ -57,9 +56,13 @@ public function apply() ]; $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]); $customerSetup->upgradeAttributes($entityAttributes); + + return $this; } /** + * Password hash upgrade + * * @return void */ private function upgradeHash() @@ -92,7 +95,7 @@ private function upgradeHash() } /** - * {@inheritdoc} + * @inheritdoc */ public static function getDependencies() { @@ -102,7 +105,7 @@ public static function getDependencies() } /** - * {@inheritdoc} + * @inheritdoc */ public static function getVersion() { @@ -110,7 +113,7 @@ public static function getVersion() } /** - * {@inheritdoc} + * @inheritdoc */ public function getAliases() { From 2f8035e5af8f2b85a67eb54e3be119964696b1dc Mon Sep 17 00:00:00 2001 From: Vasya Tsviklinskyi <tsviklinskyi@gmail.com> Date: Fri, 3 Jul 2020 11:29:59 +0300 Subject: [PATCH 37/44] MC-35490: Price sort order not working properly --- .../_files/product_configurable_with_assigned_simples.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_assigned_simples.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_assigned_simples.php index cd8c5392d746a..81a067195e902 100644 --- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_assigned_simples.php +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_assigned_simples.php @@ -16,6 +16,7 @@ use Magento\ConfigurableProduct\Helper\Product\Options\Factory; use Magento\ConfigurableProduct\Model\Product\Type\Configurable; use Magento\Eav\Api\Data\AttributeOptionInterface; +use Magento\Eav\Model\Config; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\Workaround\Override\Fixture\Resolver; @@ -26,6 +27,9 @@ $installer = Bootstrap::getObjectManager()->create(CategorySetup::class); $attributeSetId = $installer->getAttributeSetId('catalog_product', 'Default'); +$eavConfig = Bootstrap::getObjectManager()->get(Config::class); +$attribute = $eavConfig->getAttribute('catalog_product', 'test_configurable'); + $product = Bootstrap::getObjectManager()->create(Product::class); $product->setTypeId(Configurable::TYPE_CODE) ->setAttributeSetId($attributeSetId) From c67166f5425b20c79a9f9a6b51087eaa8a313223 Mon Sep 17 00:00:00 2001 From: "rostyslav.hymon" <rostyslav.hymon@transoftgroup.com> Date: Fri, 3 Jul 2020 14:35:27 +0300 Subject: [PATCH 38/44] MC-35491: Patch Request : Re: Slow query on search_query --- .../testsuite/Magento/CatalogSearch/Block/ResultTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dev/tests/integration/testsuite/Magento/CatalogSearch/Block/ResultTest.php b/dev/tests/integration/testsuite/Magento/CatalogSearch/Block/ResultTest.php index 76a4ff9714ebd..2b6711eeaf99b 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogSearch/Block/ResultTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogSearch/Block/ResultTest.php @@ -12,6 +12,7 @@ use Magento\Framework\View\LayoutInterface; use Magento\Search\Model\QueryFactory; use Magento\TestFramework\Helper\Bootstrap; +use Magento\Search\ViewModel\ConfigProvider; class ResultTest extends \PHPUnit\Framework\TestCase { @@ -25,6 +26,11 @@ class ResultTest extends \PHPUnit\Framework\TestCase */ private $layout; + /** + * @var ConfigProvider + */ + private $configProvider; + /** * @inheritdoc */ @@ -32,6 +38,7 @@ protected function setUp(): void { $this->objectManager = Bootstrap::getObjectManager(); $this->layout = $this->objectManager->get(LayoutInterface::class); + $this->configProvider = $this->objectManager->get(ConfigProvider::class); } public function testSetListOrders() @@ -62,6 +69,7 @@ public function testEscapeSearchText(string $searchValue, string $expectedOutput $searchResultBlock = $this->layout->createBlock(Result::class); /** @var Template $searchBlock */ $searchBlock = $this->layout->createBlock(Template::class); + $searchBlock->setData(['configProvider' => $this->configProvider]); $searchBlock->setTemplate('Magento_Search::form.mini.phtml'); /** @var RequestInterface $request */ $request = $this->objectManager->get(RequestInterface::class); From 9b1284e312a950469d037b7ccbad0285330059a5 Mon Sep 17 00:00:00 2001 From: "rostyslav.hymon" <rostyslav.hymon@transoftgroup.com> Date: Fri, 3 Jul 2020 14:37:39 +0300 Subject: [PATCH 39/44] MC-35491: Patch Request : Re: Slow query on search_query --- .../testsuite/Magento/CatalogSearch/Block/ResultTest.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dev/tests/integration/testsuite/Magento/CatalogSearch/Block/ResultTest.php b/dev/tests/integration/testsuite/Magento/CatalogSearch/Block/ResultTest.php index 2b6711eeaf99b..6d679a5aea7d4 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogSearch/Block/ResultTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogSearch/Block/ResultTest.php @@ -41,7 +41,12 @@ protected function setUp(): void $this->configProvider = $this->objectManager->get(ConfigProvider::class); } - public function testSetListOrders() + /** + * Set list orders test + * + * @return void + */ + public function testSetListOrders(): void { $this->layout->addBlock(Text::class, 'head'); // The tested block is using head block From 42d85ba88ead0942fbab1f38bf5d537e47288af1 Mon Sep 17 00:00:00 2001 From: Serhii Balko <serhii.balko@transoftgroup.com> Date: Fri, 3 Jul 2020 15:57:05 +0300 Subject: [PATCH 40/44] MC-35353: Localised region name is not showing on order page if it is edited --- .../Order/Address/Collection.php | 90 +++++++++++++++- .../Service/V1/OrderAddressUpdateTest.php | 7 +- .../Magento/Sales/Service/V1/OrderGetTest.php | 2 +- .../Order/Address/CollectionTest.php | 101 ++++++++++++++++++ 4 files changed, 192 insertions(+), 8 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Sales/Model/ResourceModel/Order/Address/CollectionTest.php diff --git a/app/code/Magento/Sales/Model/ResourceModel/Order/Address/Collection.php b/app/code/Magento/Sales/Model/ResourceModel/Order/Address/Collection.php index 8af6c03b44275..f2a28b613cfea 100644 --- a/app/code/Magento/Sales/Model/ResourceModel/Order/Address/Collection.php +++ b/app/code/Magento/Sales/Model/ResourceModel/Order/Address/Collection.php @@ -6,12 +6,19 @@ namespace Magento\Sales\Model\ResourceModel\Order\Address; use Magento\Sales\Api\Data\OrderAddressSearchResultInterface; -use \Magento\Sales\Model\ResourceModel\Order\Collection\AbstractCollection; +use Magento\Sales\Model\ResourceModel\Order\Collection\AbstractCollection; +use Magento\Framework\Locale\ResolverInterface; +use Magento\Framework\Data\Collection\EntityFactoryInterface; +use Magento\Framework\Data\Collection\Db\FetchStrategyInterface; +use Magento\Framework\Event\ManagerInterface; +use Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot; +use Magento\Framework\DB\Adapter\AdapterInterface; +use Magento\Framework\Model\ResourceModel\Db\AbstractDb; +use Magento\Framework\App\ObjectManager; +use Psr\Log\LoggerInterface; /** - * Flat sales order payment collection - * - * @author Magento Core Team <core@magentocommerce.com> + * Order addresses collection */ class Collection extends AbstractCollection implements OrderAddressSearchResultInterface { @@ -29,6 +36,44 @@ class Collection extends AbstractCollection implements OrderAddressSearchResultI */ protected $_eventObject = 'order_address_collection'; + /** + * @var ResolverInterface + */ + private $localeResolver; + + /** + * @param EntityFactoryInterface $entityFactory + * @param LoggerInterface $logger + * @param FetchStrategyInterface $fetchStrategy + * @param ManagerInterface $eventManager + * @param Snapshot $entitySnapshot + * @param AdapterInterface|null $connection + * @param AbstractDb|null $resource + * @param ResolverInterface|null $localeResolver + */ + public function __construct( + EntityFactoryInterface $entityFactory, + LoggerInterface $logger, + FetchStrategyInterface $fetchStrategy, + ManagerInterface $eventManager, + Snapshot $entitySnapshot, + AdapterInterface $connection = null, + AbstractDb $resource = null, + ResolverInterface $localeResolver = null + ) { + $this->localeResolver = $localeResolver ?: ObjectManager::getInstance() + ->get(ResolverInterface::class); + parent::__construct( + $entityFactory, + $logger, + $fetchStrategy, + $eventManager, + $entitySnapshot, + $connection, + $resource + ); + } + /** * Model initialization * @@ -42,6 +87,16 @@ protected function _construct() ); } + /** + * @inheritdoc + */ + protected function _initSelect() + { + parent::_initSelect(); + $this->joinRegions(); + return $this; + } + /** * Redeclare after load method for dispatch event * @@ -55,4 +110,31 @@ protected function _afterLoad() return $this; } + + /** + * Join region name table with current locale + * + * @return $this + */ + private function joinRegions() + { + $locale = $this->localeResolver->getLocale(); + $connection = $this->getConnection(); + + $defaultNameExpr = $connection->getIfNullSql( + $connection->quoteIdentifier('rct.default_name'), + $connection->quoteIdentifier('main_table.region') + ); + $expression = $connection->getIfNullSql($connection->quoteIdentifier('rnt.name'), $defaultNameExpr); + + $regionId = $connection->quoteIdentifier('main_table.region_id'); + $condition = $connection->quoteInto("rnt.locale=?", $locale); + $rctTable = $this->getTable('directory_country_region'); + $rntTable = $this->getTable('directory_country_region_name'); + + $this->getSelect() + ->joinLeft(['rct' => $rctTable], "rct.region_id={$regionId}", []) + ->joinLeft(['rnt' => $rntTable], "rnt.region_id={$regionId} AND {$condition}", ['region' => $expression]); + return $this; + } } diff --git a/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/OrderAddressUpdateTest.php b/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/OrderAddressUpdateTest.php index 1096c0dca6530..c5b06285f1fe1 100644 --- a/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/OrderAddressUpdateTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/OrderAddressUpdateTest.php @@ -3,13 +3,14 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Sales\Service\V1; use Magento\Sales\Api\Data\OrderAddressInterface as OrderAddress; use Magento\TestFramework\TestCase\WebapiAbstract; /** - * Class OrderAddressUpdateTest + * Test for address update */ class OrderAddressUpdateTest extends WebapiAbstract { @@ -28,7 +29,7 @@ public function testOrderAddressUpdate() $order = $objectManager->get(\Magento\Sales\Model\Order::class)->loadByIncrementId('100000001'); $address = [ - OrderAddress::REGION => 'CA', + OrderAddress::REGION => 'California', OrderAddress::POSTCODE => '11111', OrderAddress::LASTNAME => 'lastname', OrderAddress::STREET => ['street'], @@ -75,7 +76,7 @@ public function testOrderAddressUpdate() $billingAddress = $actualOrder->getBillingAddress(); $validate = [ - OrderAddress::REGION => 'CA', + OrderAddress::REGION => 'California', OrderAddress::POSTCODE => '11111', OrderAddress::LASTNAME => 'lastname', OrderAddress::STREET => 'street', diff --git a/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/OrderGetTest.php b/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/OrderGetTest.php index 021698f874e55..e28cca72e8fb8 100644 --- a/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/OrderGetTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/OrderGetTest.php @@ -76,7 +76,7 @@ public function testOrderGet(): void 'city' => 'Los Angeles', 'email' => 'customer@null.com', 'postcode' => '11111', - 'region' => 'CA' + 'region' => 'California' ]; $result = $this->makeServiceCall(self::ORDER_INCREMENT_ID); diff --git a/dev/tests/integration/testsuite/Magento/Sales/Model/ResourceModel/Order/Address/CollectionTest.php b/dev/tests/integration/testsuite/Magento/Sales/Model/ResourceModel/Order/Address/CollectionTest.php new file mode 100644 index 0000000000000..52284b3c9ddf9 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Sales/Model/ResourceModel/Order/Address/CollectionTest.php @@ -0,0 +1,101 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\Sales\Model\ResourceModel\Order\Address; + +use Magento\Store\Model\StoreManagerInterface; +use Magento\Sales\Model\Order\Payment; +use Magento\Sales\Model\Order; +use Magento\Sales\Api\Data\OrderAddressInterface as OrderAddress; +use Magento\Backend\Model\Locale\Resolver; +use Magento\Framework\Locale\ResolverInterface; +use Magento\TestFramework\Helper\Bootstrap; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; + +/** + * Test for address collection + * + * @magentoAppArea adminhtml + */ +class CollectionTest extends TestCase +{ + /** + * @var ResolverInterface|MockObject + */ + private $localeResolverMock; + + /** + * @var CollectionFactory + */ + private $addressCollectionFactory; + + /** + * @inheritdoc + */ + protected function setUp(): void + { + $this->localeResolverMock = $this->createMock(ResolverInterface::class); + Bootstrap::getObjectManager()->removeSharedInstance(ResolverInterface::class); + Bootstrap::getObjectManager()->removeSharedInstance(Resolver::class); + Bootstrap::getObjectManager()->addSharedInstance($this->localeResolverMock, ResolverInterface::class); + Bootstrap::getObjectManager()->addSharedInstance($this->localeResolverMock, Resolver::class); + + $addressData = [ + OrderAddress::REGION => 'Alabama', + OrderAddress::REGION_ID => '1', + OrderAddress::POSTCODE => '11111', + OrderAddress::LASTNAME => 'lastname', + OrderAddress::FIRSTNAME => 'firstname', + OrderAddress::STREET => 'street', + OrderAddress::CITY => 'Montgomery', + OrderAddress::EMAIL => 'admin@example.com', + OrderAddress::TELEPHONE => '11111111', + OrderAddress::COUNTRY_ID => 'US' + ]; + $billingAddress = Bootstrap::getObjectManager()->create(OrderAddress::class, ['data' => $addressData]); + $billingAddress->setAddressType('billing'); + $shippingAddress = clone $billingAddress; + $shippingAddress->setId(null)->setAddressType('shipping'); + $payment = Bootstrap::getObjectManager()->create(Payment::class); + $payment->setMethod('payflowpro') + ->setCcExpMonth('5') + ->setCcLast4('0005') + ->setCcType('AE') + ->setCcExpYear('2022'); + $order = Bootstrap::getObjectManager()->create(Order::class); + $order->setIncrementId('100000001') + ->setSubtotal(100) + ->setBaseSubtotal(100) + ->setCustomerEmail('admin@example.com') + ->setCustomerIsGuest(true) + ->setBillingAddress($billingAddress) + ->setShippingAddress($shippingAddress) + ->setStoreId(Bootstrap::getObjectManager()->get(StoreManagerInterface::class)->getStore()->getId()) + ->setPayment($payment); + $order->save(); + + $this->addressCollectionFactory = Bootstrap::getObjectManager()->get(CollectionFactory::class); + } + + /** + * @magentoDataFixture Magento/Directory/_files/region_name_jp.php + */ + public function testCollectionWithJpLocale(): void + { + $locale = 'JA_jp'; + $this->localeResolverMock->method('getLocale')->willReturn($locale); + + $order = Bootstrap::getObjectManager()->create(Order::class) + ->loadByIncrementId('100000001'); + + $collection = $this->addressCollectionFactory->create()->setOrderFilter($order); + foreach ($collection as $address) { + $this->assertEquals('アラバマ', $address->getData(OrderAddress::REGION)); + } + } +} From 7a25cc66fa96e520ecd21bf5d7dad5b609dce5ac Mon Sep 17 00:00:00 2001 From: Oleh Usik <o.usik@atwix.com> Date: Fri, 3 Jul 2020 23:15:53 +0300 Subject: [PATCH 41/44] use actionGroup go to new product attribute page --- .../Mftf/Test/AdminAttributeTextSwatchesCanBeFiledTest.xml | 3 +-- .../Test/Mftf/Test/AdminCreateDropdownProductAttributeTest.xml | 3 +-- .../Mftf/Test/AdminCheckColorUploadChooserVisualSwatchTest.xml | 2 +- .../Swatches/Test/Mftf/Test/AdminCreateImageSwatchTest.xml | 3 +-- .../Swatches/Test/Mftf/Test/AdminCreateTextSwatchTest.xml | 3 +-- .../Test/AdminCreateVisualSwatchWithNonValidOptionsTest.xml | 3 +-- .../Test/Mftf/Test/StorefrontFilterByImageSwatchTest.xml | 3 +-- .../Test/Mftf/Test/StorefrontFilterByTextSwatchTest.xml | 3 +-- .../Test/Mftf/Test/StorefrontFilterByVisualSwatchTest.xml | 3 +-- .../StorefrontSeeProductImagesMatchingProductSwatchesTest.xml | 2 +- 10 files changed, 10 insertions(+), 18 deletions(-) diff --git a/app/code/Magento/Backend/Test/Mftf/Test/AdminAttributeTextSwatchesCanBeFiledTest.xml b/app/code/Magento/Backend/Test/Mftf/Test/AdminAttributeTextSwatchesCanBeFiledTest.xml index 8ac7af096da0a..ef69764a87833 100644 --- a/app/code/Magento/Backend/Test/Mftf/Test/AdminAttributeTextSwatchesCanBeFiledTest.xml +++ b/app/code/Magento/Backend/Test/Mftf/Test/AdminAttributeTextSwatchesCanBeFiledTest.xml @@ -94,8 +94,7 @@ </actionGroup> <!--Navigate to Product attribute page--> - <amOnPage url="{{ProductAttributePage.url}}" stepKey="navigateToNewProductAttributePage"/> - <waitForPageLoad stepKey="waitForPageLoad"/> + <actionGroup ref="AdminNavigateToNewProductAttributePageActionGroup" stepKey="navigateToNewProductAttributePage"/> <fillField userInput="test_label" selector="{{AttributePropertiesSection.DefaultLabel}}" stepKey="fillDefaultLabel"/> <selectOption selector="{{AttributePropertiesSection.InputType}}" userInput="Text Swatch" stepKey="selectInputType"/> <click selector="{{AttributePropertiesSection.addSwatch}}" stepKey="clickAddSwatch"/> diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateDropdownProductAttributeTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateDropdownProductAttributeTest.xml index 88b1c874caadc..b8fec6d5bc001 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateDropdownProductAttributeTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateDropdownProductAttributeTest.xml @@ -27,8 +27,7 @@ <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/> </after> - <amOnPage url="{{ProductAttributePage.url}}" stepKey="navigateToNewProductAttributePage"/> - <waitForPageLoad stepKey="waitForPageLoad"/> + <actionGroup ref="AdminNavigateToNewProductAttributePageActionGroup" stepKey="navigateToNewProductAttributePage"/> <!-- Set attribute properties --> <fillField selector="{{AttributePropertiesSection.DefaultLabel}}" diff --git a/app/code/Magento/Swatches/Test/Mftf/Test/AdminCheckColorUploadChooserVisualSwatchTest.xml b/app/code/Magento/Swatches/Test/Mftf/Test/AdminCheckColorUploadChooserVisualSwatchTest.xml index a4fc0bdcfd1fb..9833ee79a297a 100644 --- a/app/code/Magento/Swatches/Test/Mftf/Test/AdminCheckColorUploadChooserVisualSwatchTest.xml +++ b/app/code/Magento/Swatches/Test/Mftf/Test/AdminCheckColorUploadChooserVisualSwatchTest.xml @@ -19,7 +19,7 @@ <before> <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/> </before> - <amOnPage url="{{ProductAttributePage.url}}" stepKey="addNewProductAttribute"/> + <actionGroup ref="AdminNavigateToNewProductAttributePageActionGroup" stepKey="addNewProductAttribute"/> <selectOption selector="{{AttributePropertiesSection.InputType}}" userInput="{{visualSwatchAttribute.input_type}}" stepKey="fillInputType"/> diff --git a/app/code/Magento/Swatches/Test/Mftf/Test/AdminCreateImageSwatchTest.xml b/app/code/Magento/Swatches/Test/Mftf/Test/AdminCreateImageSwatchTest.xml index e67d0c763308c..a972456e22ac5 100644 --- a/app/code/Magento/Swatches/Test/Mftf/Test/AdminCreateImageSwatchTest.xml +++ b/app/code/Magento/Swatches/Test/Mftf/Test/AdminCreateImageSwatchTest.xml @@ -35,8 +35,7 @@ </after> <!-- Begin creating a new product attribute of type "Image Swatch" --> - <amOnPage url="{{ProductAttributePage.url}}" stepKey="goToNewProductAttributePage"/> - <waitForPageLoad stepKey="waitForNewProductAttributePage"/> + <actionGroup ref="AdminNavigateToNewProductAttributePageActionGroup" stepKey="goToNewProductAttributePage"/> <fillField selector="{{AttributePropertiesSection.DefaultLabel}}" userInput="{{ProductAttributeFrontendLabel.label}}" stepKey="fillDefaultLabel"/> <!-- Select visual swatch --> diff --git a/app/code/Magento/Swatches/Test/Mftf/Test/AdminCreateTextSwatchTest.xml b/app/code/Magento/Swatches/Test/Mftf/Test/AdminCreateTextSwatchTest.xml index 6b2a29d8ec451..6e05e1a4e6c03 100644 --- a/app/code/Magento/Swatches/Test/Mftf/Test/AdminCreateTextSwatchTest.xml +++ b/app/code/Magento/Swatches/Test/Mftf/Test/AdminCreateTextSwatchTest.xml @@ -25,8 +25,7 @@ </after> <!-- Create a new product attribute of type "Text Swatch" --> - <amOnPage url="{{ProductAttributePage.url}}" stepKey="goToNewProductAttributePage"/> - <waitForPageLoad stepKey="waitForNewProductAttributePage"/> + <actionGroup ref="AdminNavigateToNewProductAttributePageActionGroup" stepKey="goToNewProductAttributePage"/> <fillField selector="{{AttributePropertiesSection.DefaultLabel}}" userInput="{{ProductAttributeFrontendLabel.label}}" stepKey="fillDefaultLabel"/> <selectOption selector="{{AttributePropertiesSection.InputType}}" userInput="swatch_text" stepKey="selectInputType"/> <click selector="{{AdminManageSwatchSection.addSwatchText}}" stepKey="clickAddSwatch0"/> diff --git a/app/code/Magento/Swatches/Test/Mftf/Test/AdminCreateVisualSwatchWithNonValidOptionsTest.xml b/app/code/Magento/Swatches/Test/Mftf/Test/AdminCreateVisualSwatchWithNonValidOptionsTest.xml index e93a27d377a52..0d58ba8fc9917 100644 --- a/app/code/Magento/Swatches/Test/Mftf/Test/AdminCreateVisualSwatchWithNonValidOptionsTest.xml +++ b/app/code/Magento/Swatches/Test/Mftf/Test/AdminCreateVisualSwatchWithNonValidOptionsTest.xml @@ -27,8 +27,7 @@ <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/> </after> - <amOnPage url="{{ProductAttributePage.url}}" stepKey="navigateToNewProductAttributePage"/> - <waitForPageLoad stepKey="waitForPageLoad"/> + <actionGroup ref="AdminNavigateToNewProductAttributePageActionGroup" stepKey="navigateToNewProductAttributePage"/> <!-- Set attribute properties --> <fillField selector="{{AttributePropertiesSection.DefaultLabel}}" diff --git a/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByImageSwatchTest.xml b/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByImageSwatchTest.xml index 2ca26d84d45c7..f90190f9961de 100644 --- a/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByImageSwatchTest.xml +++ b/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByImageSwatchTest.xml @@ -34,8 +34,7 @@ </after> <!-- Begin creating a new product attribute --> - <amOnPage url="{{ProductAttributePage.url}}" stepKey="goToNewProductAttributePage"/> - <waitForPageLoad stepKey="waitForNewProductAttributePage"/> + <actionGroup ref="AdminNavigateToNewProductAttributePageActionGroup" stepKey="goToNewProductAttributePage"/> <fillField selector="{{AttributePropertiesSection.DefaultLabel}}" userInput="{{ProductAttributeFrontendLabel.label}}" stepKey="fillDefaultLabel"/> <!-- Select visual swatch --> diff --git a/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByTextSwatchTest.xml b/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByTextSwatchTest.xml index 82dbff950d62f..7218d257ccf88 100644 --- a/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByTextSwatchTest.xml +++ b/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByTextSwatchTest.xml @@ -32,8 +32,7 @@ </after> <!-- Begin creating a new product attribute --> - <amOnPage url="{{ProductAttributePage.url}}" stepKey="goToNewProductAttributePage"/> - <waitForPageLoad stepKey="waitForNewProductAttributePage"/> + <actionGroup ref="AdminNavigateToNewProductAttributePageActionGroup" stepKey="goToNewProductAttributePage"/> <fillField selector="{{AttributePropertiesSection.DefaultLabel}}" userInput="{{ProductAttributeFrontendLabel.label}}" stepKey="fillDefaultLabel"/> <!-- Select text swatch --> diff --git a/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByVisualSwatchTest.xml b/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByVisualSwatchTest.xml index bf820863cf9b6..84cdc6590b11f 100644 --- a/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByVisualSwatchTest.xml +++ b/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByVisualSwatchTest.xml @@ -34,8 +34,7 @@ </after> <!-- Begin creating a new product attribute --> - <amOnPage url="{{ProductAttributePage.url}}" stepKey="goToNewProductAttributePage"/> - <waitForPageLoad stepKey="waitForNewProductAttributePage"/> + <actionGroup ref="AdminNavigateToNewProductAttributePageActionGroup" stepKey="goToNewProductAttributePage"/> <fillField selector="{{AttributePropertiesSection.DefaultLabel}}" userInput="{{ProductAttributeFrontendLabel.label}}" stepKey="fillDefaultLabel"/> <!-- Select visual swatch --> diff --git a/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontSeeProductImagesMatchingProductSwatchesTest.xml b/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontSeeProductImagesMatchingProductSwatchesTest.xml index 43944ceef33ef..27cbb01eafff0 100644 --- a/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontSeeProductImagesMatchingProductSwatchesTest.xml +++ b/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontSeeProductImagesMatchingProductSwatchesTest.xml @@ -38,7 +38,7 @@ </after> <!-- Begin creating a new product attribute --> - <amOnPage url="{{ProductAttributePage.url}}" stepKey="goToNewProductAttributePage"/> + <actionGroup ref="AdminNavigateToNewProductAttributePageActionGroup" stepKey="goToNewProductAttributePage"/> <actionGroup ref="AdminFillProductAttributePropertiesActionGroup" stepKey="fillProductAttributeProperties"> <argument name="attributeName" value="{{VisualSwatchProductAttribute.attribute_code}}"/> From 8ce092ea471a481f7395be246ce90ea010da729a Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy <dpoperechnyy@magento.com> Date: Tue, 7 Jul 2020 12:19:21 -0500 Subject: [PATCH 42/44] MC-31618: Move static config to files - PLUGIN_LIST - Add declaration of strict types; --- .../Interception/PluginListGeneratorTest.php | 1 + .../Interception/ConfigLoaderInterface.php | 7 ++++++- .../Interception/ConfigWriterInterface.php | 7 ++++++- .../Interception/PluginListGenerator.php | 17 ++++++----------- .../Test/Unit/_files/load_scoped_mock_map.php | 1 + .../App/Task/Operation/PluginListGenerator.php | 2 ++ 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php index de2c732615d7c..64188f8251886 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Framework\Interception; diff --git a/lib/internal/Magento/Framework/Interception/ConfigLoaderInterface.php b/lib/internal/Magento/Framework/Interception/ConfigLoaderInterface.php index 23d6a36aa633b..d41461e092726 100644 --- a/lib/internal/Magento/Framework/Interception/ConfigLoaderInterface.php +++ b/lib/internal/Magento/Framework/Interception/ConfigLoaderInterface.php @@ -3,8 +3,12 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Framework\Interception; +use Magento\Framework\Exception\FileSystemException; + /** * Interception configuration loader interface. */ @@ -15,6 +19,7 @@ interface ConfigLoaderInterface * * @param string $cacheId * @return array + * @throws FileSystemException */ - public function load($cacheId); + public function load(string $cacheId): array; } diff --git a/lib/internal/Magento/Framework/Interception/ConfigWriterInterface.php b/lib/internal/Magento/Framework/Interception/ConfigWriterInterface.php index 635833cf4f8d3..9a08eca200fe0 100644 --- a/lib/internal/Magento/Framework/Interception/ConfigWriterInterface.php +++ b/lib/internal/Magento/Framework/Interception/ConfigWriterInterface.php @@ -3,8 +3,12 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Framework\Interception; +use Magento\Framework\Exception\FileSystemException; + /** * Interception config writer interface. */ @@ -15,6 +19,7 @@ interface ConfigWriterInterface * * @param array $scopes * @return void + * @throws FileSystemException */ - public function write($scopes); + public function write(array $scopes): void; } diff --git a/lib/internal/Magento/Framework/Interception/PluginListGenerator.php b/lib/internal/Magento/Framework/Interception/PluginListGenerator.php index 4f794fd5b39c9..effc291bb883b 100644 --- a/lib/internal/Magento/Framework/Interception/PluginListGenerator.php +++ b/lib/internal/Magento/Framework/Interception/PluginListGenerator.php @@ -3,6 +3,8 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Framework\Interception; use Magento\Framework\App\Filesystem\DirectoryList; @@ -143,12 +145,9 @@ public function __construct( } /** - * Write interception configuration for scopes. - * - * @param array $scopes - * @return void + * @inheritdoc */ - public function write($scopes) + public function write(array $scopes): void { foreach ($scopes as $scope) { $this->scopeConfig->setCurrentScope($scope); @@ -198,13 +197,9 @@ public function write($scopes) } /** - * Load interception configuration data per scope. - * - * @param string $cacheId - * @return array - * @throws \Magento\Framework\Exception\FileSystemException + * @inheritdoc */ - public function load($cacheId) + public function load(string $cacheId): array { $file = $this->directoryList->getPath(DirectoryList::GENERATED_METADATA) . '/' . $cacheId . '.' . 'php'; if (file_exists($file)) { diff --git a/lib/internal/Magento/Framework/Interception/Test/Unit/_files/load_scoped_mock_map.php b/lib/internal/Magento/Framework/Interception/Test/Unit/_files/load_scoped_mock_map.php index 3773ea0007590..b5002512dc093 100644 --- a/lib/internal/Magento/Framework/Interception/Test/Unit/_files/load_scoped_mock_map.php +++ b/lib/internal/Magento/Framework/Interception/Test/Unit/_files/load_scoped_mock_map.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); use Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item; use Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer; diff --git a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php index 2db990505e861..c1314ec39c245 100644 --- a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php +++ b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php @@ -3,6 +3,8 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Setup\Module\Di\App\Task\Operation; use Magento\Framework\Config\ScopeInterface; From 49be96fe3bbcf11009cd31b3ecd7e9fabe878859 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy <dpoperechnyy@magento.com> Date: Tue, 7 Jul 2020 15:35:10 -0500 Subject: [PATCH 43/44] MC-31618: Move static config to files - PLUGIN_LIST - Add integration test for multiple scopes; --- .../PluginListGeneratorMultipleScopesTest.php | 131 ++++++++++++++++++ .../Interception/PluginListGeneratorTest.php | 31 +++-- .../Interception/ConfigLoaderInterface.php | 3 - .../Interception/ConfigWriterInterface.php | 3 - 4 files changed, 151 insertions(+), 17 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorMultipleScopesTest.php diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorMultipleScopesTest.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorMultipleScopesTest.php new file mode 100644 index 0000000000000..65f5b9f3919e7 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorMultipleScopesTest.php @@ -0,0 +1,131 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\Framework\Interception; + +use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Filesystem\DriverInterface; +use Magento\TestFramework\Application; +use Magento\TestFramework\Helper\Bootstrap; + +class PluginListGeneratorMultipleScopesTest extends \PHPUnit\Framework\TestCase +{ + /** + * Generated plugin list configs for frontend, adminhtml, graphql scopes + */ + private $cacheIds = [ + 'primary|global|frontend|plugin-list', + 'primary|global|adminhtml|plugin-list', + 'primary|global|graphql|plugin-list' + ]; + + /** + * @var PluginListGenerator + */ + private $model; + + /** + * @var DirectoryList + */ + private $directoryList; + + /** + * @var DriverInterface + */ + private $file; + + /** + * @var Application + */ + private $application; + + /** + * @inheritDoc + */ + protected function setUp(): void + { + $this->application = Bootstrap::getInstance()->getBootstrap()->getApplication(); + $this->directoryList = new DirectoryList(BP, $this->getCustomDirs()); + $this->file = Bootstrap::getObjectManager()->create(DriverInterface::class); + $reader = Bootstrap::getObjectManager()->create( + // phpstan:ignore "Class Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy not found." + \Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy::class + ); + $scopeConfig = Bootstrap::getObjectManager()->create(\Magento\Framework\Config\Scope::class); + $omConfig = Bootstrap::getObjectManager()->create( + \Magento\Framework\Interception\ObjectManager\Config\Developer::class + ); + $relations = Bootstrap::getObjectManager()->create( + \Magento\Framework\ObjectManager\Relations\Runtime::class + ); + $definitions = Bootstrap::getObjectManager()->create( + \Magento\Framework\Interception\Definition\Runtime::class + ); + $classDefinitions = Bootstrap::getObjectManager()->create( + \Magento\Framework\ObjectManager\Definition\Runtime::class + ); + // phpstan:ignore "Class Psr\Log\LoggerInterface\Proxy not found." + $logger = Bootstrap::getObjectManager()->create(\Psr\Log\LoggerInterface\Proxy::class); + $this->model = new PluginListGenerator( + $reader, + $scopeConfig, + $omConfig, + $relations, + $definitions, + $classDefinitions, + $logger, + $this->directoryList, + ['primary', 'global'] + ); + } + + /** + * Test multiple scopes plugin list configuration generation and load. + */ + public function testPluginListMultipleScopesConfigGeneration() + { + $scopes = ['frontend', 'adminhtml', 'graphql']; + $this->model->write($scopes); + + foreach ($this->cacheIds as $cacheId) { + $configData = $this->model->load($cacheId); + $this->assertNotEmpty($configData[0]); + $this->assertNotEmpty($configData[1]); + $this->assertNotEmpty($configData[2]); + } + } + + /** + * Gets customized directory paths + * + * @return array + */ + private function getCustomDirs() + { + $path = DirectoryList::PATH; + $generated = "{$this->application->getTempDir()}/generated"; + + return [ + DirectoryList::GENERATED_METADATA => [$path => "{$generated}/metadata"], + ]; + } + + /** + * @inheritDoc + */ + protected function tearDown(): void + { + foreach ($this->cacheIds as $cacheId) { + $filePath = $this->directoryList->getPath(DirectoryList::GENERATED_METADATA) + . '/' . $cacheId . '.' . 'php'; + + if (file_exists($filePath)) { + $this->file->deleteFile($filePath); + } + } + } +} diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php index 64188f8251886..8f1771759cee0 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorTest.php @@ -46,17 +46,26 @@ protected function setUp(): void { $this->application = Bootstrap::getInstance()->getBootstrap()->getApplication(); $this->directoryList = new DirectoryList(BP, $this->getCustomDirs()); - $this->file = new \Magento\Framework\Filesystem\Driver\File(); - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - $reader = new \Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy($objectManager); - $areaList = $this->createMock(\Magento\Framework\App\AreaList::class); - $areaList->method('getCodes')->willReturn([]); - $scopeConfig = new \Magento\Framework\Config\Scope($areaList, 'global'); - $omConfig = new \Magento\Framework\Interception\ObjectManager\Config\Developer(); - $relations = new \Magento\Framework\ObjectManager\Relations\Runtime(); - $definitions = new \Magento\Framework\Interception\Definition\Runtime(); - $classDefinitions = new \Magento\Framework\ObjectManager\Definition\Runtime(); - $logger = $this->createMock(\Psr\Log\LoggerInterface::class); + $this->file = Bootstrap::getObjectManager()->create(DriverInterface::class); + $reader = Bootstrap::getObjectManager()->create( + // phpstan:ignore "Class Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy not found." + \Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy::class + ); + $scopeConfig = Bootstrap::getObjectManager()->create(\Magento\Framework\Config\Scope::class); + $omConfig = Bootstrap::getObjectManager()->create( + \Magento\Framework\Interception\ObjectManager\Config\Developer::class + ); + $relations = Bootstrap::getObjectManager()->create( + \Magento\Framework\ObjectManager\Relations\Runtime::class + ); + $definitions = Bootstrap::getObjectManager()->create( + \Magento\Framework\Interception\Definition\Runtime::class + ); + $classDefinitions = Bootstrap::getObjectManager()->create( + \Magento\Framework\ObjectManager\Definition\Runtime::class + ); + // phpstan:ignore "Class Psr\Log\LoggerInterface\Proxy not found." + $logger = Bootstrap::getObjectManager()->create(\Psr\Log\LoggerInterface\Proxy::class); $this->model = new PluginListGenerator( $reader, $scopeConfig, diff --git a/lib/internal/Magento/Framework/Interception/ConfigLoaderInterface.php b/lib/internal/Magento/Framework/Interception/ConfigLoaderInterface.php index d41461e092726..2a739f4cf9486 100644 --- a/lib/internal/Magento/Framework/Interception/ConfigLoaderInterface.php +++ b/lib/internal/Magento/Framework/Interception/ConfigLoaderInterface.php @@ -7,8 +7,6 @@ namespace Magento\Framework\Interception; -use Magento\Framework\Exception\FileSystemException; - /** * Interception configuration loader interface. */ @@ -19,7 +17,6 @@ interface ConfigLoaderInterface * * @param string $cacheId * @return array - * @throws FileSystemException */ public function load(string $cacheId): array; } diff --git a/lib/internal/Magento/Framework/Interception/ConfigWriterInterface.php b/lib/internal/Magento/Framework/Interception/ConfigWriterInterface.php index 9a08eca200fe0..9193937b65816 100644 --- a/lib/internal/Magento/Framework/Interception/ConfigWriterInterface.php +++ b/lib/internal/Magento/Framework/Interception/ConfigWriterInterface.php @@ -7,8 +7,6 @@ namespace Magento\Framework\Interception; -use Magento\Framework\Exception\FileSystemException; - /** * Interception config writer interface. */ @@ -19,7 +17,6 @@ interface ConfigWriterInterface * * @param array $scopes * @return void - * @throws FileSystemException */ public function write(array $scopes): void; } From 53dccc7ad9f774d2850beb18d17f1169d5982780 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy <dpoperechnyy@magento.com> Date: Wed, 8 Jul 2020 09:19:35 -0500 Subject: [PATCH 44/44] MC-31618: Move static config to files - PLUGIN_LIST - Enable app isolation for 2 integration tests for them not to initialize global fixtures as it causes fatal errors with missed preferences; --- .../PluginListGeneratorMultipleScopesTest.php | 131 ------------------ .../ObjectManager/Factory/CompiledTest.php | 3 + .../Factory/Dynamic/DeveloperTest.php | 3 + 3 files changed, 6 insertions(+), 131 deletions(-) delete mode 100644 dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorMultipleScopesTest.php diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorMultipleScopesTest.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorMultipleScopesTest.php deleted file mode 100644 index 65f5b9f3919e7..0000000000000 --- a/dev/tests/integration/testsuite/Magento/Framework/Interception/PluginListGeneratorMultipleScopesTest.php +++ /dev/null @@ -1,131 +0,0 @@ -<?php -/** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ -declare(strict_types=1); - -namespace Magento\Framework\Interception; - -use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\Framework\Filesystem\DriverInterface; -use Magento\TestFramework\Application; -use Magento\TestFramework\Helper\Bootstrap; - -class PluginListGeneratorMultipleScopesTest extends \PHPUnit\Framework\TestCase -{ - /** - * Generated plugin list configs for frontend, adminhtml, graphql scopes - */ - private $cacheIds = [ - 'primary|global|frontend|plugin-list', - 'primary|global|adminhtml|plugin-list', - 'primary|global|graphql|plugin-list' - ]; - - /** - * @var PluginListGenerator - */ - private $model; - - /** - * @var DirectoryList - */ - private $directoryList; - - /** - * @var DriverInterface - */ - private $file; - - /** - * @var Application - */ - private $application; - - /** - * @inheritDoc - */ - protected function setUp(): void - { - $this->application = Bootstrap::getInstance()->getBootstrap()->getApplication(); - $this->directoryList = new DirectoryList(BP, $this->getCustomDirs()); - $this->file = Bootstrap::getObjectManager()->create(DriverInterface::class); - $reader = Bootstrap::getObjectManager()->create( - // phpstan:ignore "Class Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy not found." - \Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy::class - ); - $scopeConfig = Bootstrap::getObjectManager()->create(\Magento\Framework\Config\Scope::class); - $omConfig = Bootstrap::getObjectManager()->create( - \Magento\Framework\Interception\ObjectManager\Config\Developer::class - ); - $relations = Bootstrap::getObjectManager()->create( - \Magento\Framework\ObjectManager\Relations\Runtime::class - ); - $definitions = Bootstrap::getObjectManager()->create( - \Magento\Framework\Interception\Definition\Runtime::class - ); - $classDefinitions = Bootstrap::getObjectManager()->create( - \Magento\Framework\ObjectManager\Definition\Runtime::class - ); - // phpstan:ignore "Class Psr\Log\LoggerInterface\Proxy not found." - $logger = Bootstrap::getObjectManager()->create(\Psr\Log\LoggerInterface\Proxy::class); - $this->model = new PluginListGenerator( - $reader, - $scopeConfig, - $omConfig, - $relations, - $definitions, - $classDefinitions, - $logger, - $this->directoryList, - ['primary', 'global'] - ); - } - - /** - * Test multiple scopes plugin list configuration generation and load. - */ - public function testPluginListMultipleScopesConfigGeneration() - { - $scopes = ['frontend', 'adminhtml', 'graphql']; - $this->model->write($scopes); - - foreach ($this->cacheIds as $cacheId) { - $configData = $this->model->load($cacheId); - $this->assertNotEmpty($configData[0]); - $this->assertNotEmpty($configData[1]); - $this->assertNotEmpty($configData[2]); - } - } - - /** - * Gets customized directory paths - * - * @return array - */ - private function getCustomDirs() - { - $path = DirectoryList::PATH; - $generated = "{$this->application->getTempDir()}/generated"; - - return [ - DirectoryList::GENERATED_METADATA => [$path => "{$generated}/metadata"], - ]; - } - - /** - * @inheritDoc - */ - protected function tearDown(): void - { - foreach ($this->cacheIds as $cacheId) { - $filePath = $this->directoryList->getPath(DirectoryList::GENERATED_METADATA) - . '/' . $cacheId . '.' . 'php'; - - if (file_exists($filePath)) { - $this->file->deleteFile($filePath); - } - } - } -} diff --git a/dev/tests/integration/testsuite/Magento/Framework/ObjectManager/Factory/CompiledTest.php b/dev/tests/integration/testsuite/Magento/Framework/ObjectManager/Factory/CompiledTest.php index c620251ca9b67..7d3b9d2089cf9 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/ObjectManager/Factory/CompiledTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/ObjectManager/Factory/CompiledTest.php @@ -14,6 +14,9 @@ use Magento\Framework\ObjectManager\TestAsset\InterfaceImplementation; use Magento\Framework\ObjectManager\TestAsset\TestAssetInterface; +/** + * @magentoAppIsolation enabled + */ class CompiledTest extends AbstractFactoryRuntimeDefinitionsTestCases { /** diff --git a/dev/tests/integration/testsuite/Magento/Framework/ObjectManager/Factory/Dynamic/DeveloperTest.php b/dev/tests/integration/testsuite/Magento/Framework/ObjectManager/Factory/Dynamic/DeveloperTest.php index 7fa7e677e0d8d..c74c00de4ce53 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/ObjectManager/Factory/Dynamic/DeveloperTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/ObjectManager/Factory/Dynamic/DeveloperTest.php @@ -15,6 +15,9 @@ use Magento\Framework\ObjectManager\TestAsset\InterfaceImplementation; use Magento\Framework\ObjectManager\TestAsset\TestAssetInterface; +/** + * @magentoAppIsolation enabled + */ class DeveloperTest extends AbstractFactoryRuntimeDefinitionsTestCases { /**