diff --git a/app/code/Magento/AdminNotification/etc/acl.xml b/app/code/Magento/AdminNotification/etc/acl.xml index f044e9fd1e97e..930ad776058f4 100644 --- a/app/code/Magento/AdminNotification/etc/acl.xml +++ b/app/code/Magento/AdminNotification/etc/acl.xml @@ -11,11 +11,11 @@ - - - - - + + + + + diff --git a/app/code/Magento/AdminNotification/etc/adminhtml/menu.xml b/app/code/Magento/AdminNotification/etc/adminhtml/menu.xml index d3829d8b5fefa..6c407fadf9b6d 100644 --- a/app/code/Magento/AdminNotification/etc/adminhtml/menu.xml +++ b/app/code/Magento/AdminNotification/etc/adminhtml/menu.xml @@ -7,6 +7,6 @@ --> - + diff --git a/app/code/Magento/Backend/etc/acl.xml b/app/code/Magento/Backend/etc/acl.xml index 15f22c515b39e..53e0830adf1be 100644 --- a/app/code/Magento/Backend/etc/acl.xml +++ b/app/code/Magento/Backend/etc/acl.xml @@ -8,39 +8,39 @@ - - - - - - - - + + + + + + + + - - - - + + + + - - - + + + - - + + - - - - - + + + + + - - - + + + - + diff --git a/app/code/Magento/Backend/etc/adminhtml/menu.xml b/app/code/Magento/Backend/etc/adminhtml/menu.xml index 821b79cf65956..1b8e5aaab412f 100644 --- a/app/code/Magento/Backend/etc/adminhtml/menu.xml +++ b/app/code/Magento/Backend/etc/adminhtml/menu.xml @@ -7,26 +7,26 @@ --> - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + diff --git a/app/code/Magento/Backend/etc/menu.xsd b/app/code/Magento/Backend/etc/menu.xsd index 5ba2e6a84e93e..b16af76636ab0 100644 --- a/app/code/Magento/Backend/etc/menu.xsd +++ b/app/code/Magento/Backend/etc/menu.xsd @@ -30,6 +30,7 @@ + @@ -49,6 +50,7 @@ + @@ -64,7 +66,6 @@ - diff --git a/app/code/Magento/Backup/etc/acl.xml b/app/code/Magento/Backup/etc/acl.xml index 8fea71f5f11e7..fcab4b8712e72 100644 --- a/app/code/Magento/Backup/etc/acl.xml +++ b/app/code/Magento/Backup/etc/acl.xml @@ -11,8 +11,8 @@ - - + + diff --git a/app/code/Magento/Backup/etc/adminhtml/menu.xml b/app/code/Magento/Backup/etc/adminhtml/menu.xml index 0940441771aec..9ba452b627198 100644 --- a/app/code/Magento/Backup/etc/adminhtml/menu.xml +++ b/app/code/Magento/Backup/etc/adminhtml/menu.xml @@ -7,6 +7,6 @@ --> - + diff --git a/app/code/Magento/Catalog/etc/acl.xml b/app/code/Magento/Catalog/etc/acl.xml index 0fc34da258444..61c5143eecf93 100644 --- a/app/code/Magento/Catalog/etc/acl.xml +++ b/app/code/Magento/Catalog/etc/acl.xml @@ -9,22 +9,22 @@ - - - - + + + + - + - - - + + + diff --git a/app/code/Magento/Catalog/etc/adminhtml/menu.xml b/app/code/Magento/Catalog/etc/adminhtml/menu.xml index 53db61bd3a1cc..879b4fa40202b 100644 --- a/app/code/Magento/Catalog/etc/adminhtml/menu.xml +++ b/app/code/Magento/Catalog/etc/adminhtml/menu.xml @@ -7,12 +7,12 @@ --> - - - - - + + + + + - + diff --git a/app/code/Magento/CatalogInventory/etc/acl.xml b/app/code/Magento/CatalogInventory/etc/acl.xml index 9f04d41794fbd..6c5e63dd6898a 100644 --- a/app/code/Magento/CatalogInventory/etc/acl.xml +++ b/app/code/Magento/CatalogInventory/etc/acl.xml @@ -12,7 +12,7 @@ - + diff --git a/app/code/Magento/CatalogRule/etc/acl.xml b/app/code/Magento/CatalogRule/etc/acl.xml index 727d4eec7490a..d778911a302fa 100644 --- a/app/code/Magento/CatalogRule/etc/acl.xml +++ b/app/code/Magento/CatalogRule/etc/acl.xml @@ -10,8 +10,8 @@ - - + + diff --git a/app/code/Magento/CatalogRule/etc/adminhtml/menu.xml b/app/code/Magento/CatalogRule/etc/adminhtml/menu.xml index a5531bee0041a..4e9dcdcc80cdd 100644 --- a/app/code/Magento/CatalogRule/etc/adminhtml/menu.xml +++ b/app/code/Magento/CatalogRule/etc/adminhtml/menu.xml @@ -7,7 +7,7 @@ --> - - + + diff --git a/app/code/Magento/CheckoutAgreements/etc/acl.xml b/app/code/Magento/CheckoutAgreements/etc/acl.xml index 06c32f5d30f67..a33f0f4c9b2fc 100644 --- a/app/code/Magento/CheckoutAgreements/etc/acl.xml +++ b/app/code/Magento/CheckoutAgreements/etc/acl.xml @@ -11,7 +11,7 @@ - + diff --git a/app/code/Magento/CheckoutAgreements/etc/adminhtml/menu.xml b/app/code/Magento/CheckoutAgreements/etc/adminhtml/menu.xml index 70d40348d61f8..1c59a2c4dfb29 100644 --- a/app/code/Magento/CheckoutAgreements/etc/adminhtml/menu.xml +++ b/app/code/Magento/CheckoutAgreements/etc/adminhtml/menu.xml @@ -7,6 +7,6 @@ --> - + diff --git a/app/code/Magento/Cms/etc/acl.xml b/app/code/Magento/Cms/etc/acl.xml index 9037ac5a40870..887ee04e5b93d 100644 --- a/app/code/Magento/Cms/etc/acl.xml +++ b/app/code/Magento/Cms/etc/acl.xml @@ -11,18 +11,18 @@ - - - + + + - - + + - + diff --git a/app/code/Magento/Cms/etc/adminhtml/menu.xml b/app/code/Magento/Cms/etc/adminhtml/menu.xml index cdebb7efa5365..6ef1eff9cb3d0 100644 --- a/app/code/Magento/Cms/etc/adminhtml/menu.xml +++ b/app/code/Magento/Cms/etc/adminhtml/menu.xml @@ -7,7 +7,7 @@ --> - - + + diff --git a/app/code/Magento/Config/Test/Unit/Model/_files/acl.xml b/app/code/Magento/Config/Test/Unit/Model/_files/acl.xml index c07d5d58db67c..e703ab278cef1 100644 --- a/app/code/Magento/Config/Test/Unit/Model/_files/acl.xml +++ b/app/code/Magento/Config/Test/Unit/Model/_files/acl.xml @@ -8,11 +8,11 @@ - - - - - + + + + + diff --git a/app/code/Magento/Config/etc/acl.xml b/app/code/Magento/Config/etc/acl.xml index 71150bfaed99f..1246dccc10807 100644 --- a/app/code/Magento/Config/etc/acl.xml +++ b/app/code/Magento/Config/etc/acl.xml @@ -11,17 +11,17 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/app/code/Magento/Config/etc/adminhtml/menu.xml b/app/code/Magento/Config/etc/adminhtml/menu.xml index d7bf04d92e424..c329f4f57d868 100644 --- a/app/code/Magento/Config/etc/adminhtml/menu.xml +++ b/app/code/Magento/Config/etc/adminhtml/menu.xml @@ -7,6 +7,6 @@ --> - + diff --git a/app/code/Magento/Contact/etc/acl.xml b/app/code/Magento/Contact/etc/acl.xml index 4eeba1de35337..68a326a80fc97 100644 --- a/app/code/Magento/Contact/etc/acl.xml +++ b/app/code/Magento/Contact/etc/acl.xml @@ -12,7 +12,7 @@ - + diff --git a/app/code/Magento/CurrencySymbol/etc/acl.xml b/app/code/Magento/CurrencySymbol/etc/acl.xml index 4303892275523..3d26c37e0cd70 100644 --- a/app/code/Magento/CurrencySymbol/etc/acl.xml +++ b/app/code/Magento/CurrencySymbol/etc/acl.xml @@ -10,9 +10,9 @@ - - - + + + diff --git a/app/code/Magento/CurrencySymbol/etc/adminhtml/menu.xml b/app/code/Magento/CurrencySymbol/etc/adminhtml/menu.xml index 1db0f3239f959..55d6955a80517 100644 --- a/app/code/Magento/CurrencySymbol/etc/adminhtml/menu.xml +++ b/app/code/Magento/CurrencySymbol/etc/adminhtml/menu.xml @@ -8,8 +8,8 @@ - - - + + + diff --git a/app/code/Magento/Customer/etc/acl.xml b/app/code/Magento/Customer/etc/acl.xml index 1980480ee0da2..0ca1ea1c6367c 100644 --- a/app/code/Magento/Customer/etc/acl.xml +++ b/app/code/Magento/Customer/etc/acl.xml @@ -9,18 +9,18 @@ - - - + + + - + - + diff --git a/app/code/Magento/Customer/etc/adminhtml/menu.xml b/app/code/Magento/Customer/etc/adminhtml/menu.xml index 29a851643c581..39a8d609c86bb 100644 --- a/app/code/Magento/Customer/etc/adminhtml/menu.xml +++ b/app/code/Magento/Customer/etc/adminhtml/menu.xml @@ -7,9 +7,9 @@ --> - - - - + + + + diff --git a/app/code/Magento/Downloadable/etc/acl.xml b/app/code/Magento/Downloadable/etc/acl.xml index ef97ae3672908..63efdc93d9c0c 100644 --- a/app/code/Magento/Downloadable/etc/acl.xml +++ b/app/code/Magento/Downloadable/etc/acl.xml @@ -12,7 +12,7 @@ - + diff --git a/app/code/Magento/Downloadable/etc/adminhtml/menu.xml b/app/code/Magento/Downloadable/etc/adminhtml/menu.xml index 9fbdfc29378bc..62b280f46fe06 100644 --- a/app/code/Magento/Downloadable/etc/adminhtml/menu.xml +++ b/app/code/Magento/Downloadable/etc/adminhtml/menu.xml @@ -7,6 +7,6 @@ --> - + diff --git a/app/code/Magento/Email/etc/acl.xml b/app/code/Magento/Email/etc/acl.xml index 874398f61a17e..071f2eb426d5c 100644 --- a/app/code/Magento/Email/etc/acl.xml +++ b/app/code/Magento/Email/etc/acl.xml @@ -10,8 +10,8 @@ - - + + diff --git a/app/code/Magento/Email/etc/adminhtml/menu.xml b/app/code/Magento/Email/etc/adminhtml/menu.xml index 055e00759ab94..6d5aa82abc537 100644 --- a/app/code/Magento/Email/etc/adminhtml/menu.xml +++ b/app/code/Magento/Email/etc/adminhtml/menu.xml @@ -7,6 +7,6 @@ --> - + diff --git a/app/code/Magento/EncryptionKey/etc/acl.xml b/app/code/Magento/EncryptionKey/etc/acl.xml index 706eefb6adb49..ec78e7e85e36e 100644 --- a/app/code/Magento/EncryptionKey/etc/acl.xml +++ b/app/code/Magento/EncryptionKey/etc/acl.xml @@ -11,7 +11,7 @@ - + diff --git a/app/code/Magento/EncryptionKey/etc/adminhtml/menu.xml b/app/code/Magento/EncryptionKey/etc/adminhtml/menu.xml index c525fe1c4b55e..be17227d50b36 100644 --- a/app/code/Magento/EncryptionKey/etc/adminhtml/menu.xml +++ b/app/code/Magento/EncryptionKey/etc/adminhtml/menu.xml @@ -7,6 +7,6 @@ --> - + diff --git a/app/code/Magento/GoogleAnalytics/etc/acl.xml b/app/code/Magento/GoogleAnalytics/etc/acl.xml index 30e9bf1c8f4ff..54904f9fdbaf4 100644 --- a/app/code/Magento/GoogleAnalytics/etc/acl.xml +++ b/app/code/Magento/GoogleAnalytics/etc/acl.xml @@ -12,7 +12,7 @@ - + diff --git a/app/code/Magento/ImportExport/etc/acl.xml b/app/code/Magento/ImportExport/etc/acl.xml index 1bb96e00ef370..57fb27af6cc3c 100644 --- a/app/code/Magento/ImportExport/etc/acl.xml +++ b/app/code/Magento/ImportExport/etc/acl.xml @@ -11,9 +11,9 @@ - - - + + + diff --git a/app/code/Magento/ImportExport/etc/adminhtml/menu.xml b/app/code/Magento/ImportExport/etc/adminhtml/menu.xml index d8dea48c5940f..51aadfbd99b34 100644 --- a/app/code/Magento/ImportExport/etc/adminhtml/menu.xml +++ b/app/code/Magento/ImportExport/etc/adminhtml/menu.xml @@ -7,8 +7,8 @@ --> - - - + + + diff --git a/app/code/Magento/Indexer/etc/acl.xml b/app/code/Magento/Indexer/etc/acl.xml index 7fcb2a4a91144..4c4c81ea38207 100644 --- a/app/code/Magento/Indexer/etc/acl.xml +++ b/app/code/Magento/Indexer/etc/acl.xml @@ -11,8 +11,8 @@ - - + + diff --git a/app/code/Magento/Indexer/etc/adminhtml/menu.xml b/app/code/Magento/Indexer/etc/adminhtml/menu.xml index cfc7847543179..d0dd74fb54c49 100644 --- a/app/code/Magento/Indexer/etc/adminhtml/menu.xml +++ b/app/code/Magento/Indexer/etc/adminhtml/menu.xml @@ -7,6 +7,6 @@ --> - + diff --git a/app/code/Magento/Integration/Model/Cache/TypeConsolidated.php b/app/code/Magento/Integration/Model/Cache/TypeConsolidated.php new file mode 100644 index 0000000000000..e84b054512d11 --- /dev/null +++ b/app/code/Magento/Integration/Model/Cache/TypeConsolidated.php @@ -0,0 +1,30 @@ +get(self::TYPE_IDENTIFIER), self::CACHE_TAG); + } +} diff --git a/app/code/Magento/Integration/Model/Config.php b/app/code/Magento/Integration/Model/Config.php index ca04dfc378f06..63358576835e3 100644 --- a/app/code/Magento/Integration/Model/Config.php +++ b/app/code/Magento/Integration/Model/Config.php @@ -11,6 +11,7 @@ * Integration Config Model. * * This is a parent class for storing information about Integrations. + * @deprecated */ class Config { diff --git a/app/code/Magento/Integration/Model/Config/Consolidated/Converter.php b/app/code/Magento/Integration/Model/Config/Consolidated/Converter.php new file mode 100644 index 0000000000000..73a33826b63ef --- /dev/null +++ b/app/code/Magento/Integration/Model/Config/Consolidated/Converter.php @@ -0,0 +1,137 @@ +resourceProvider = $resourceProvider; + } + + /** + * {@inheritdoc} + */ + public function convert($source) + { + $result = []; + $allResources = $this->resourceProvider->getAclResources(); + $hashAclResourcesTree = $this->hashResources($allResources[1]['children']); + /** @var \DOMNodeList $integrations */ + $integrations = $source->getElementsByTagName('integration'); + /** @var \DOMElement $integration */ + foreach ($integrations as $integration) { + if ($integration->nodeType != XML_ELEMENT_NODE) { + continue; + } + $integrationName = $integration->attributes->getNamedItem('name')->nodeValue; + $result[$integrationName] = []; + $result[$integrationName][self::API_RESOURCES] = []; + + /** @var \DOMElement $email */ + $email = $integration->getElementsByTagName('email')->item(0)->nodeValue; + /** @var \DOMNodeList $resources */ + $resources = $integration->getElementsByTagName('resource'); + $result[$integrationName][self::KEY_EMAIL] = $email; + if ($integration->getElementsByTagName('endpoint_url')->length) { + /** @var \DOMElement $endpointUrl */ + $endpointUrl = $integration->getElementsByTagName('endpoint_url')->item(0)->nodeValue; + $result[$integrationName][self::KEY_AUTHENTICATION_ENDPOINT_URL] = $endpointUrl; + } + if ($integration->getElementsByTagName('identity_link_url')->length) { + /** @var \DOMElement $identityLinkUrl */ + $identityLinkUrl = $integration->getElementsByTagName('identity_link_url')->item(0)->nodeValue; + $result[$integrationName][self::KEY_IDENTITY_LINKING_URL] = $identityLinkUrl; + } + /** @var \DOMElement $resource */ + foreach ($resources as $resource) { + if ($resource->nodeType != XML_ELEMENT_NODE) { + continue; + } + $resource = $resource->attributes->getNamedItem('name')->nodeValue; + $resourceNames = $this->addParentsToResource($hashAclResourcesTree, $resource); + foreach ($resourceNames as $name) { + $result[$integrationName][self::API_RESOURCES][] = $name; + } + } + // Remove any duplicates added parents + $result[$integrationName][self::API_RESOURCES] = + array_values(array_unique($result[$integrationName][self::API_RESOURCES])); + } + return $result; + } + + /** + * Make ACL resource array return a hash with parent-resource-name => [children-resources-names] representation + * + * @param array $resources + * @return array + */ + private function hashResources(array $resources) + { + $output = []; + foreach ($resources as $resource) { + if (isset($resource['children'])) { + $item = $this->hashResources($resource['children']); + } else { + $item = []; + } + $output[$resource['id']] = $item; + } + return $output; + } + + /** + * Find parents names of a node in an ACL resource hash and add them to returned array + * + * @param array $resourcesHash + * @param string $nodeName + * @return array + */ + private function addParentsToResource(array $resourcesHash, $nodeName) + { + $output = []; + foreach ($resourcesHash as $resource => $children) { + if ($resource == $nodeName) { + $output = [$resource]; + break; + } + if (!empty($children)) { + $names = $this->addParentsToResource($children, $nodeName); + if (!empty($names)) { + $output = array_merge([$resource], $names); + break; + } else { + continue; + } + } + } + return $output; + } +} diff --git a/app/code/Magento/Integration/Model/Config/Consolidated/Reader.php b/app/code/Magento/Integration/Model/Config/Consolidated/Reader.php new file mode 100644 index 0000000000000..44d5be7af5269 --- /dev/null +++ b/app/code/Magento/Integration/Model/Config/Consolidated/Reader.php @@ -0,0 +1,55 @@ + 'name', + '/config/integration/resources/resource' => 'name', + '/config/integration/' + ]; + + /** + * @param \Magento\Framework\Config\FileResolverInterface $fileResolver + * @param Converter $converter + * @param SchemaLocator $schemaLocator + * @param \Magento\Framework\Config\ValidationStateInterface $validationState + * @param string $fileName + * @param array $idAttributes + * @param string $domDocumentClass + * @param string $defaultScope + */ + public function __construct( + \Magento\Framework\Config\FileResolverInterface $fileResolver, + \Magento\Integration\Model\Config\Consolidated\Converter $converter, + \Magento\Integration\Model\Config\Consolidated\SchemaLocator $schemaLocator, + \Magento\Framework\Config\ValidationStateInterface $validationState, + $fileName = 'integration.xml', + $idAttributes = [], + $domDocumentClass = 'Magento\Framework\Config\Dom', + $defaultScope = 'global' + ) { + parent::__construct( + $fileResolver, + $converter, + $schemaLocator, + $validationState, + $fileName, + $idAttributes, + $domDocumentClass, + $defaultScope + ); + } +} diff --git a/app/code/Magento/Integration/Model/Config/Consolidated/SchemaLocator.php b/app/code/Magento/Integration/Model/Config/Consolidated/SchemaLocator.php new file mode 100644 index 0000000000000..5cfbf750085b2 --- /dev/null +++ b/app/code/Magento/Integration/Model/Config/Consolidated/SchemaLocator.php @@ -0,0 +1,58 @@ +getModuleDir(Dir::MODULE_ETC_DIR, 'Magento_Integration'); + $this->_schema = $etcDir . '/integration/integration.xsd'; + $this->_perFileSchema = $etcDir . '/integration/integration_file.xsd'; + } + + /** + * Get path to merged config schema + * + * @return string|null + */ + public function getSchema() + { + return $this->_schema; + } + + /** + * Get path to per file validation schema + * + * @return string|null + */ + public function getPerFileSchema() + { + return $this->_perFileSchema; + } +} diff --git a/app/code/Magento/Integration/Model/Config/Converter.php b/app/code/Magento/Integration/Model/Config/Converter.php index fb23ea4a106ac..ea8b9113cc748 100644 --- a/app/code/Magento/Integration/Model/Config/Converter.php +++ b/app/code/Magento/Integration/Model/Config/Converter.php @@ -7,6 +7,8 @@ /** * Converter of integration.xml content into array format. + * + * @deprecated */ class Converter implements \Magento\Framework\Config\ConverterInterface { diff --git a/app/code/Magento/Integration/Model/Config/Integration/Converter.php b/app/code/Magento/Integration/Model/Config/Integration/Converter.php index dc4894d170edb..bc90277557e8e 100644 --- a/app/code/Magento/Integration/Model/Config/Integration/Converter.php +++ b/app/code/Magento/Integration/Model/Config/Integration/Converter.php @@ -7,6 +7,8 @@ /** * Converter of api.xml content into array format. + * + * @deprecated */ class Converter implements \Magento\Framework\Config\ConverterInterface { @@ -19,28 +21,12 @@ class Converter implements \Magento\Framework\Config\ConverterInterface /**#@-*/ - /** @var \Magento\Framework\Acl\AclResource\ProviderInterface */ - protected $resourceProvider; - - /** - * Initialize dependencies. - * - * @param \Magento\Framework\Acl\AclResource\ProviderInterface $resourceProvider - */ - public function __construct( - \Magento\Framework\Acl\AclResource\ProviderInterface $resourceProvider - ) { - $this->resourceProvider = $resourceProvider; - } - /** * {@inheritdoc} */ public function convert($source) { $result = []; - $allResources = $this->resourceProvider->getAclResources(); - $hashAclResourcesTree = $this->hashResources($allResources[1]['children']); /** @var \DOMNodeList $integrations */ $integrations = $source->getElementsByTagName('integration'); /** @var \DOMElement $integration */ @@ -59,63 +45,9 @@ public function convert($source) continue; } $resource = $resource->attributes->getNamedItem('name')->nodeValue; - $resourceNames = $this->addParentsToResource($hashAclResourcesTree, $resource); - foreach ($resourceNames as $name) { - $result[$integrationName][self::API_RESOURCES][] = $name; - } + $result[$integrationName][self::API_RESOURCES][] = $resource; } - // Remove any duplicates added parents - $result[$integrationName][self::API_RESOURCES] = - array_unique($result[$integrationName][self::API_RESOURCES]); } return $result; } - - /** - * Make ACL resource array return a hash with parent-resource-name => [children-resources-names] representation - * - * @param array $resources - * @return array - */ - private function hashResources(array $resources) - { - $output = []; - foreach ($resources as $resource) { - if (isset($resource['children'])) { - $item = $this->hashResources($resource['children']); - } else { - $item = []; - } - $output[$resource['id']] = $item; - } - return $output; - } - - /** - * Find parents names of a node in an ACL resource hash and add them to returned array - * - * @param array $resourcesHash - * @param string $nodeName - * @return array - */ - private function addParentsToResource(array $resourcesHash, $nodeName) - { - $output = []; - foreach ($resourcesHash as $resource => $children) { - if ($resource == $nodeName) { - $output = [$resource]; - break; - } - if (!empty($children)) { - $names = $this->addParentsToResource($children, $nodeName); - if (!empty($names)) { - $output = array_merge([$resource], $names); - break; - } else { - continue; - } - } - } - return $output; - } } diff --git a/app/code/Magento/Integration/Model/Config/Integration/Reader.php b/app/code/Magento/Integration/Model/Config/Integration/Reader.php index dc6e2c8bbd5a8..bf0359c3cdc86 100644 --- a/app/code/Magento/Integration/Model/Config/Integration/Reader.php +++ b/app/code/Magento/Integration/Model/Config/Integration/Reader.php @@ -9,6 +9,7 @@ * Service config data reader. * * @codeCoverageIgnore + * @deprecated */ class Reader extends \Magento\Framework\Config\Reader\Filesystem { diff --git a/app/code/Magento/Integration/Model/Config/Integration/SchemaLocator.php b/app/code/Magento/Integration/Model/Config/Integration/SchemaLocator.php index b448904f0907d..87e2a3f4e08c4 100644 --- a/app/code/Magento/Integration/Model/Config/Integration/SchemaLocator.php +++ b/app/code/Magento/Integration/Model/Config/Integration/SchemaLocator.php @@ -9,6 +9,8 @@ /** * Integration config schema locator. + * + * @deprecated */ class SchemaLocator implements \Magento\Framework\Config\SchemaLocatorInterface { diff --git a/app/code/Magento/Integration/Model/Config/Reader.php b/app/code/Magento/Integration/Model/Config/Reader.php index dfd44ac74c714..bdf098c0ba724 100644 --- a/app/code/Magento/Integration/Model/Config/Reader.php +++ b/app/code/Magento/Integration/Model/Config/Reader.php @@ -7,6 +7,8 @@ /** * Service config data reader. + * + * @deprecated */ class Reader extends \Magento\Framework\Config\Reader\Filesystem { @@ -26,7 +28,6 @@ class Reader extends \Magento\Framework\Config\Reader\Filesystem * @param array $idAttributes * @param string $domDocumentClass * @param string $defaultScope - * @param string $filename */ public function __construct( \Magento\Framework\Config\FileResolverInterface $fileResolver, diff --git a/app/code/Magento/Integration/Model/Config/SchemaLocator.php b/app/code/Magento/Integration/Model/Config/SchemaLocator.php index a4f26b644688f..93c4110f27932 100644 --- a/app/code/Magento/Integration/Model/Config/SchemaLocator.php +++ b/app/code/Magento/Integration/Model/Config/SchemaLocator.php @@ -9,6 +9,8 @@ /** * Integration config schema locator. + * + * @deprecated */ class SchemaLocator implements \Magento\Framework\Config\SchemaLocatorInterface { diff --git a/app/code/Magento/Integration/Model/ConfigBasedIntegrationManager.php b/app/code/Magento/Integration/Model/ConfigBasedIntegrationManager.php index f3591b60bc611..b961253ad7116 100644 --- a/app/code/Magento/Integration/Model/ConfigBasedIntegrationManager.php +++ b/app/code/Magento/Integration/Model/ConfigBasedIntegrationManager.php @@ -23,46 +23,88 @@ class ConfigBasedIntegrationManager protected $integrationService; /** - * Integration config - * - * @var IntegrationConfig + * @var AclRetriever */ - protected $integrationConfig; + protected $aclRetriever; /** - * @var AclRetriever + * Integration config + * + * @var Config */ - protected $aclRetriever; + protected $integrationConfig; /** - * @param IntegrationConfig $integrationConfig * @param \Magento\Integration\Api\IntegrationServiceInterface $integrationService * @param AclRetriever $aclRetriever + * @param Config $integrationConfig */ public function __construct( - IntegrationConfig $integrationConfig, \Magento\Integration\Api\IntegrationServiceInterface $integrationService, - AclRetriever $aclRetriever + AclRetriever $aclRetriever, + Config $integrationConfig ) { $this->integrationService = $integrationService; - $this->integrationConfig = $integrationConfig; $this->aclRetriever = $aclRetriever; + $this->integrationConfig = $integrationConfig; + } + + /** + * Process integrations from config files for the given array of integration names + * + * @param array $integrationNames + * @return array + * @deprecated + */ + public function processIntegrationConfig(array $integrationNames) + { + if (empty($integrationNames)) { + return []; + } + /** @var array $integrations */ + $integrations = $this->integrationConfig->getIntegrations(); + foreach ($integrationNames as $name) { + $integrationDetails = $integrations[$name]; + $integrationData = [Integration::NAME => $name]; + if (isset($integrationDetails[Converter::KEY_EMAIL])) { + $integrationData[Integration::EMAIL] = $integrationDetails[Converter::KEY_EMAIL]; + } + if (isset($integrationDetails[Converter::KEY_AUTHENTICATION_ENDPOINT_URL])) { + $integrationData[Integration::ENDPOINT] = + $integrationDetails[Converter::KEY_AUTHENTICATION_ENDPOINT_URL]; + } + if (isset($integrationDetails[Converter::KEY_IDENTITY_LINKING_URL])) { + $integrationData[Integration::IDENTITY_LINK_URL] = + $integrationDetails[Converter::KEY_IDENTITY_LINKING_URL]; + } + $integrationData[Integration::SETUP_TYPE] = Integration::TYPE_CONFIG; + // If it already exists, update it + $integration = $this->integrationService->findByName($name); + if ($integration->getId()) { + //If Integration already exists, update it. + //For now we will just overwrite the integration with same name but we will need a long term solution + $integrationData[Integration::ID] = $integration->getId(); + $this->integrationService->update($integrationData); + } else { + $this->integrationService->create($integrationData); + } + } + return $integrationNames; } /** * Process integrations from config files for the given array of integration names + * to be used with consolidated integration config * * @param array $integrations * @return array */ - public function processIntegrationConfig(array $integrations) + public function processConfigBasedIntegrations(array $integrations) { if (empty($integrations)) { return []; } - /** @var array $integrationsResource */ - $integrationsResource = $this->integrationConfig->getIntegrations(); foreach (array_keys($integrations) as $name) { $integrationDetails = $integrations[$name]; $integrationData = [Integration::NAME => $name]; @@ -78,8 +120,8 @@ public function processIntegrationConfig(array $integrations) $integrationData[Integration::IDENTITY_LINK_URL] = $integrationDetails[Converter::KEY_IDENTITY_LINKING_URL]; } - if (isset($integrationsResource[$name]['resource'])) { - $integrationData['resource'] = $integrationsResource[$name]['resource']; + if (isset($integrationDetails[$name]['resource'])) { + $integrationData['resource'] = $integrationDetails[$name]['resource']; } $integrationData[Integration::SETUP_TYPE] = Integration::TYPE_CONFIG; diff --git a/app/code/Magento/Integration/Model/ConsolidatedConfig.php b/app/code/Magento/Integration/Model/ConsolidatedConfig.php new file mode 100644 index 0000000000000..20860e625dae0 --- /dev/null +++ b/app/code/Magento/Integration/Model/ConsolidatedConfig.php @@ -0,0 +1,66 @@ +configCacheType = $configCacheType; + $this->configReader = $configReader; + } + + /** + * Return integrations loaded from cache if enabled or from files merged previously + * + * @return array + */ + public function getIntegrations() + { + if (null === $this->integrations) { + $integrations = $this->configCacheType->load(self::CACHE_ID); + if ($integrations && is_string($integrations)) { + $this->integrations = unserialize($integrations); + } else { + $this->integrations = $this->configReader->read(); + $this->configCacheType->save( + serialize($this->integrations), + self::CACHE_ID, + [TypeConsolidated::CACHE_TAG] + ); + } + } + return $this->integrations; + } +} diff --git a/app/code/Magento/Integration/Model/IntegrationConfig.php b/app/code/Magento/Integration/Model/IntegrationConfig.php index e1487cd1efffa..0fc10e7cc2e2c 100644 --- a/app/code/Magento/Integration/Model/IntegrationConfig.php +++ b/app/code/Magento/Integration/Model/IntegrationConfig.php @@ -13,6 +13,7 @@ * Integration Api Config Model. * * This is a parent class for storing information about Integrations. + * @deprecated */ class IntegrationConfig { diff --git a/app/code/Magento/Integration/Model/Message/RecreatedIntegration.php b/app/code/Magento/Integration/Model/Message/RecreatedIntegration.php index b1b93eaec33e8..d3b6ada0d9e34 100644 --- a/app/code/Magento/Integration/Model/Message/RecreatedIntegration.php +++ b/app/code/Magento/Integration/Model/Message/RecreatedIntegration.php @@ -8,6 +8,7 @@ use Magento\Framework\UrlInterface; use Magento\Integration\Model\Config; +use Magento\Integration\Model\ConsolidatedConfig; use Magento\Integration\Model\Integration; use Magento\Integration\Api\IntegrationServiceInterface; @@ -32,17 +33,25 @@ class RecreatedIntegration implements \Magento\Framework\Notification\MessageInt */ protected $integrationService; + /** + * @var ConsolidatedConfig + */ + protected $consolidatedConfig; + /** * @param Config $integrationConfig * @param UrlInterface $urlBuilder * @param IntegrationServiceInterface $integrationService + * @param ConsolidatedConfig $consolidatedConfig */ public function __construct( Config $integrationConfig, UrlInterface $urlBuilder, - IntegrationServiceInterface $integrationService + IntegrationServiceInterface $integrationService, + ConsolidatedConfig $consolidatedConfig ) { $this->integrationConfig = $integrationConfig; + $this->consolidatedConfig = $consolidatedConfig; $this->urlBuilder = $urlBuilder; $this->integrationService = $integrationService; } @@ -54,7 +63,7 @@ public function __construct( */ public function isDisplayed() { - foreach (array_keys($this->integrationConfig->getIntegrations()) as $name) { + foreach (array_keys($this->consolidatedConfig->getIntegrations()) as $name) { $integration = $this->integrationService->findByName($name); if ($integration->getStatus() == Integration::STATUS_RECREATED) { return true; diff --git a/app/code/Magento/Integration/Model/Plugin/Integration.php b/app/code/Magento/Integration/Model/Plugin/Integration.php index 8282e2147bebe..cfe501083cd49 100644 --- a/app/code/Magento/Integration/Model/Plugin/Integration.php +++ b/app/code/Magento/Integration/Model/Plugin/Integration.php @@ -11,7 +11,8 @@ use Magento\Integration\Model\Integration as IntegrationModel; use Magento\Integration\Api\AuthorizationServiceInterface; use Magento\Integration\Api\IntegrationServiceInterface; -use Magento\Integration\Model\IntegrationConfig as IntegrationApiConfig; +use Magento\Integration\Model\IntegrationConfig; +use Magento\Integration\Model\ConsolidatedConfig; /** * Plugin for \Magento\Integration\Model\IntegrationService. @@ -24,28 +25,30 @@ class Integration /** @var AclRetriever */ protected $aclRetriever; - /** - * Integration config - * - * @var IntegrationApiConfig - */ - protected $integrationApiConfig; + /** @var IntegrationConfig */ + protected $integrationConfig; + + /** @var ConsolidatedConfig */ + protected $consolidatedConfig; /** * Initialize dependencies. * * @param AuthorizationServiceInterface $integrationAuthorizationService * @param AclRetriever $aclRetriever - * @param IntegrationApiConfig $integrationApiConfig + * @param IntegrationConfig $integrationConfig + * @param ConsolidatedConfig $consolidatedConfig */ public function __construct( AuthorizationServiceInterface $integrationAuthorizationService, AclRetriever $aclRetriever, - IntegrationApiConfig $integrationApiConfig + IntegrationConfig $integrationConfig, + ConsolidatedConfig $consolidatedConfig ) { $this->integrationAuthorizationService = $integrationAuthorizationService; $this->aclRetriever = $aclRetriever; - $this->integrationApiConfig = $integrationApiConfig; + $this->integrationConfig = $integrationConfig; + $this->consolidatedConfig = $consolidatedConfig; } /** @@ -107,9 +110,16 @@ public function afterGet(IntegrationServiceInterface $subject, $integration) */ protected function _addAllowedResources(IntegrationModel $integration) { + $integrations = array_merge( + $this->integrationConfig->getIntegrations(), + $this->consolidatedConfig->getIntegrations() + ); if ($integration->getId()) { if ($integration->getSetupType() == IntegrationModel::TYPE_CONFIG) { - $integration->setData('resource', $this->getIntegrationApiResource($integration)); + $integration->setData( + 'resource', + $integrations[$integration->getData('name')]['resource'] + ); } else { $integration->setData( 'resource', @@ -161,21 +171,4 @@ public function afterDelete(IntegrationServiceInterface $subject, array $integra $this->integrationAuthorizationService->removePermissions($integrationId); return $integrationData; } - - /** - * Return available resourses for integration model - * - * @param IntegrationModel $integration - * @return string[] - */ - private function getIntegrationApiResource(IntegrationModel $integration) - { - $resources = []; - $integrationResources = $this->integrationApiConfig->getIntegrations(); - $integrationName = $integration->getData('name'); - if (!empty($integrationResources[$integrationName]['resource'])) { - $resources = $integrationResources[$integrationName]['resource']; - } - return $resources; - } } diff --git a/app/code/Magento/Integration/Setup/Recurring.php b/app/code/Magento/Integration/Setup/Recurring.php index 04ccccc7ae1b5..140a5b3353dac 100644 --- a/app/code/Magento/Integration/Setup/Recurring.php +++ b/app/code/Magento/Integration/Setup/Recurring.php @@ -7,7 +7,7 @@ namespace Magento\Integration\Setup; use Magento\Integration\Model\ConfigBasedIntegrationManager; -use Magento\Integration\Model\Config; +use Magento\Integration\Model\ConsolidatedConfig; use Magento\Framework\Setup\InstallSchemaInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\SchemaSetupInterface; @@ -24,7 +24,7 @@ class Recurring implements InstallSchemaInterface private $integrationManager; /** - * @var Config + * @var ConsolidatedConfig */ private $integrationConfig; @@ -32,11 +32,11 @@ class Recurring implements InstallSchemaInterface * Initialize dependencies * * @param ConfigBasedIntegrationManager $integrationManager - * @param Config $integrationConfig + * @param ConsolidatedConfig $integrationConfig */ public function __construct( ConfigBasedIntegrationManager $integrationManager, - Config $integrationConfig + ConsolidatedConfig $integrationConfig ) { $this->integrationManager = $integrationManager; $this->integrationConfig = $integrationConfig; @@ -47,6 +47,6 @@ public function __construct( */ public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) { - $this->integrationManager->processIntegrationConfig($this->integrationConfig->getIntegrations()); + $this->integrationManager->processConfigBasedIntegrations($this->integrationConfig->getIntegrations()); } } diff --git a/app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/ConverterTest.php b/app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/ConverterTest.php new file mode 100644 index 0000000000000..3d38596185b73 --- /dev/null +++ b/app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/ConverterTest.php @@ -0,0 +1,48 @@ +resourceProviderMock = $this->getMockBuilder('Magento\Framework\Acl\AclResource\ProviderInterface') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->model = $objectManagerHelper->getObject( + 'Magento\Integration\Model\Config\Consolidated\Converter', + [ + 'resourceProvider' => $this->resourceProviderMock + ] + ); + } + + public function testConvert() + { + $aclResources = require __DIR__ . '/_files/acl.php'; + $inputData = new \DOMDocument(); + $inputData->load(__DIR__ . '/_files/integration.xml'); + $expectedResult = require __DIR__ . '/_files/integration.php'; + $this->resourceProviderMock->expects($this->once())->method('getAclResources')->willReturn($aclResources); + + $this->assertEquals($expectedResult, $this->model->convert($inputData)); + } +} diff --git a/app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/SchemaLocatorTest.php b/app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/SchemaLocatorTest.php new file mode 100644 index 0000000000000..defdbc0fe02c8 --- /dev/null +++ b/app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/SchemaLocatorTest.php @@ -0,0 +1,43 @@ +moduleDir = 'moduleDirectory'; + $this->moduleReader = $this->getMock('Magento\Framework\Module\Dir\Reader', [], [], '', false); + $this->moduleReader->expects($this->any()) + ->method('getModuleDir') + ->willReturn($this->moduleDir); + $this->schemaLocator = new SchemaLocator($this->moduleReader); + } + + public function testGetSchema() + { + $this->assertEquals($this->moduleDir . '/integration/integration.xsd', $this->schemaLocator->getSchema()); + } + + public function testGetPerFileSchema() + { + $this->assertEquals( + $this->moduleDir . '/integration/integration_file.xsd', + $this->schemaLocator->getPerFileSchema() + ); + } +} diff --git a/app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/XsdTest.php b/app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/XsdTest.php new file mode 100644 index 0000000000000..1d71938dedd8b --- /dev/null +++ b/app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/XsdTest.php @@ -0,0 +1,455 @@ +markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033'); + } + $urnResolver = new \Magento\Framework\Config\Dom\UrnResolver(); + $this->schemaFile = $urnResolver->getRealPath( + 'urn:magento:module:Magento_Integration:etc/integration/integration.xsd' + ); + } + + /** + * @param string $fixtureXml + * @param array $expectedErrors + * @dataProvider exemplarXmlDataProvider + */ + public function testExemplarXml($fixtureXml, array $expectedErrors) + { + $validationStateMock = $this->getMock('\Magento\Framework\Config\ValidationStateInterface', [], [], '', false); + $validationStateMock->method('isValidationRequired') + ->willReturn(true); + $messageFormat = '%message%'; + $dom = new \Magento\Framework\Config\Dom($fixtureXml, $validationStateMock, [], null, null, $messageFormat); + $actualResult = $dom->validate($this->schemaFile, $actualErrors); + $this->assertEquals(empty($expectedErrors), $actualResult, "Validation result is invalid."); + $this->assertEquals($expectedErrors, $actualErrors, "Validation errors does not match."); + } + + /** + * @return array + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function exemplarXmlDataProvider() + { + return [ + /** Valid configurations */ + 'valid' => [ + ' + + test-integration@magento.com + https://endpoint.url + http://www.example.com/identity + + + + + + ', + [], + ], + 'valid with several entities' => [ + ' + + test-integration1@magento.com + http://endpoint.url + http://www.example.com/identity + + + + + + + test-integration2@magento.com + + + + + ', + [], + ], + /** Missing required elements */ + 'empty root node' => [ + '', + ["Element 'config': Missing child element(s). Expected is ( integration )."], + ], + 'empty integration' => [ + ' + + ', + ["Element 'integration': Missing child element(s)." . + " Expected is one of ( email, endpoint_url, identity_link_url, resources )."], + ], + 'integration without email' => [ + ' + + http://endpoint.url + http://www.example.com/identity + + + + + + ', + ["Element 'integration': Missing child element(s). Expected is ( email )."], + ], + 'empty resources' => [ + ' + + test-integration1@magento.com + http://endpoint.url + http://www.example.com/identity + + + + ', + ["Element 'resources': Missing child element(s). Expected is ( resource )."], + ], + /** Empty nodes */ + 'empty email' => [ + ' + + + http://endpoint.url + http://www.example.com/identity + + + + + + ', + [ + "Element 'email': [facet 'pattern'] The value '' is not " . + "accepted by the pattern '[^@]+@[^\.]+\..+'.", + "Element 'email': '' is not a valid value of the atomic type 'emailType'." + ], + ], + 'endpoint_url is empty' => [ + ' + + test-integration1@magento.com + + + + + + + ', + [ + "Element 'endpoint_url': [facet 'minLength'] The value has a length of '0'; this underruns" . + " the allowed minimum length of '4'.", + "Element 'endpoint_url': '' is not a valid value of the atomic type 'urlType'." + ], + ], + 'identity_link_url is empty' => [ + ' + + test-integration1@magento.com + http://endpoint.url + + + + + + + ', + [ + "Element 'identity_link_url': [facet 'minLength'] The value has a length of '0'; this underruns" . + " the allowed minimum length of '4'.", + "Element 'identity_link_url': '' is not a valid value of the atomic type 'urlType'." + ], + ], + /** Invalid structure */ + 'irrelevant root node' => [ + '', + ["Element 'integration': No matching global declaration available for the validation root."], + ], + 'irrelevant node in root' => [ + ' + + test-integration1@magento.com + http://endpoint.url + http://www.example.com/identity + + + + + + + ', + ["Element 'invalid': This element is not expected. Expected is ( integration )."], + ], + 'irrelevant node in integration' => [ + ' + + test-integration1@magento.com + http://endpoint.url + http://www.example.com/identity + + + + + + + ', + ["Element 'invalid': This element is not expected."], + ], + 'irrelevant node in resources' => [ + ' + + test-integration1@magento.com + http://endpoint.url + http://www.example.com/identity + + + + + + + ', + ["Element 'invalid': This element is not expected. Expected is ( resource )."], + ], + 'irrelevant node in resource' => [ + ' + + test-integration1@magento.com + http://endpoint.url + http://www.example.com/identity + + + + + + + + ', + [ + "Element 'resource': Element content is not allowed, " . + "because the content type is a simple type definition." + ], + ], + /** Excessive attributes */ + 'invalid attribute in root' => [ + ' + + test-integration1@magento.com + http://endpoint.url + http://www.example.com/identity + + + + + + ', + ["Element 'config', attribute 'invalid': The attribute 'invalid' is not allowed."], + ], + 'invalid attribute in integration' => [ + ' + + test-integration1@magento.com + http://endpoint.url + http://www.example.com/identity + + + + + + ', + ["Element 'integration', attribute 'invalid': The attribute 'invalid' is not allowed."], + ], + 'invalid attribute in email' => [ + ' + + test-integration1@magento.com + http://endpoint.url + http://www.example.com/identity + + + + + + ', + ["Element 'email', attribute 'invalid': The attribute 'invalid' is not allowed."], + ], + 'invalid attribute in resources' => [ + ' + + test-integration1@magento.com + http://endpoint.url + http://www.example.com/identity + + + + + + ', + ["Element 'resources', attribute 'invalid': The attribute 'invalid' is not allowed."], + ], + 'invalid attribute in resource' => [ + ' + + test-integration1@magento.com + http://endpoint.url + http://www.example.com/identity + + + + + + ', + ["Element 'resource', attribute 'invalid': The attribute 'invalid' is not allowed."], + ], + 'invalid attribute in endpoint_url' => [ + ' + + test-integration1@magento.com + http://endpoint.url + http://www.example.com/identity + + + + + + ', + ["Element 'endpoint_url', attribute 'invalid': The attribute 'invalid' is not allowed."], + ], + 'invalid attribute in identity_link_url' => [ + ' + + test-integration1@magento.com + http://endpoint.url + http://endpoint.url + + + + + + ', + ["Element 'identity_link_url', attribute 'invalid': The attribute 'invalid' is not allowed."], + ], + /** Missing or empty required attributes */ + 'integration without name' => [ + ' + + test-integration1@magento.com + http://endpoint.url + http://www.example.com/identity + + + + + + ', + ["Element 'integration': The attribute 'name' is required but missing."], + ], + 'integration with empty name' => [ + ' + + test-integration1@magento.com + http://endpoint.url + http://www.example.com/identity + + + + + + ', + [ + "Element 'integration', attribute 'name': [facet 'minLength'] The value '' has a length of '0'; " . + "this underruns the allowed minimum length of '2'.", + "Element 'integration', attribute 'name': " . + "'' is not a valid value of the atomic type 'integrationNameType'." + ], + ], + 'resource without name' => [ + ' + + test-integration1@magento.com + http://endpoint.url + http://www.example.com/identity + + + + + + ', + ["Element 'resource': The attribute 'name' is required but missing."], + ], + 'resource with empty name' => [ + ' + + test-integration1@magento.com + http://endpoint.url + http://www.example.com/identity + + + + + + ', + [ + "Element 'resource', attribute 'name': [facet 'pattern'] " . + "The value '' is not accepted by the pattern '.+_.+::.+'.", + "Element 'resource', attribute 'name': '' " . + "is not a valid value of the atomic type 'resourceNameType'." + ], + ], + /** Invalid values */ + 'invalid email' => [ + ' + + invalid + http://endpoint.url + http://www.example.com/identity + + + + + + ', + [ + "Element 'email': [facet 'pattern'] The value 'invalid' " . + "is not accepted by the pattern '[^@]+@[^\.]+\..+'.", + "Element 'email': 'invalid' is not a valid value of the atomic type 'emailType'." + ], + ], + /** Invalid values */ + 'resource with invalid name' => [ + ' + + test-integration1@magento.com + http://endpoint.url + http://www.example.com/identity + + + + + + ', + [ + "Element 'resource', attribute 'name': [facet 'pattern'] " . + "The value 'customer_manage' is not accepted by the pattern '.+_.+::.+'.", + "Element 'resource', attribute 'name': 'customer_manage' " . + "is not a valid value of the atomic type 'resourceNameType'." + ], + ] + ]; + } +} diff --git a/app/code/Magento/Integration/Test/Unit/Model/Config/Integration/_files/acl.php b/app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/_files/acl.php similarity index 100% rename from app/code/Magento/Integration/Test/Unit/Model/Config/Integration/_files/acl.php rename to app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/_files/acl.php diff --git a/app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/_files/integration.php b/app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/_files/integration.php new file mode 100644 index 0000000000000..da2c9e0c33e0f --- /dev/null +++ b/app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/_files/integration.php @@ -0,0 +1,22 @@ + [ + 'email' => 'test-integration1@magento.com', + 'endpoint_url' => 'http://endpoint.com', + 'identity_link_url' => 'http://www.example.com/identity', + 'resource' => [ + 'Magento_Customer::manageParent', + 'Magento_Customer::manage', + 'Magento_SalesRule::quoteParent', + 'Magento_SalesRule::quote' + ] + ], + 'TestIntegration2' => [ + 'email' => 'test-integration2@magento.com', + 'resource' => ['Magento_Sales::sales'] + ] +]; diff --git a/app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/_files/integration.xml b/app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/_files/integration.xml new file mode 100644 index 0000000000000..6f7c064c74e85 --- /dev/null +++ b/app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/_files/integration.xml @@ -0,0 +1,24 @@ + + + + + test-integration1@magento.com + http://endpoint.com + http://www.example.com/identity + + + + + + + test-integration2@magento.com + + + + + diff --git a/app/code/Magento/Integration/Test/Unit/Model/Config/ConverterTest.php b/app/code/Magento/Integration/Test/Unit/Model/Config/ConverterTest.php index bd70ec1d78437..dcd8115f0fae6 100644 --- a/app/code/Magento/Integration/Test/Unit/Model/Config/ConverterTest.php +++ b/app/code/Magento/Integration/Test/Unit/Model/Config/ConverterTest.php @@ -7,7 +7,6 @@ use \Magento\Integration\Model\Config\Converter; - /** * Test for conversion of integration XML config into array representation. */ @@ -16,18 +15,18 @@ class ConverterTest extends \PHPUnit_Framework_TestCase /** * @var Converter */ - protected $_model; + protected $model; public function setUp() { - $this->_model = new Converter(); + $this->model = new Converter(); } public function testConvert() { $inputData = new \DOMDocument(); - $inputData->load(__DIR__ . '/_files/integration.xml'); + $inputData->load(__DIR__ . '/_files/config.xml'); $expectedResult = require __DIR__ . '/_files/integration.php'; - $this->assertEquals($expectedResult, $this->_model->convert($inputData)); + $this->assertEquals($expectedResult, $this->model->convert($inputData)); } } diff --git a/app/code/Magento/Integration/Test/Unit/Model/Config/Integration/ConverterTest.php b/app/code/Magento/Integration/Test/Unit/Model/Config/Integration/ConverterTest.php index 310d985be1f3a..cbcd394068753 100644 --- a/app/code/Magento/Integration/Test/Unit/Model/Config/Integration/ConverterTest.php +++ b/app/code/Magento/Integration/Test/Unit/Model/Config/Integration/ConverterTest.php @@ -5,42 +5,28 @@ */ namespace Magento\Integration\Test\Unit\Model\Config\Integration; +use \Magento\Integration\Model\Config\Integration\Converter; + /** * Test for conversion of integration API XML config into array representation. */ class ConverterTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\Integration\Model\Config\Integration\Converter + * @var Converter */ protected $model; - /** @var \Magento\Framework\Acl\AclResource\ProviderInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $resourceProviderMock; - public function setUp() { - $this->resourceProviderMock = $this->getMockBuilder('Magento\Framework\Acl\AclResource\ProviderInterface') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->model = $objectManagerHelper->getObject( - 'Magento\Integration\Model\Config\Integration\Converter', - [ - 'resourceProvider' => $this->resourceProviderMock - ] - ); + $this->model = new Converter(); } public function testConvert() { - $aclResources = require __DIR__ . '/_files/acl.php'; $inputData = new \DOMDocument(); $inputData->load(__DIR__ . '/_files/api.xml'); $expectedResult = require __DIR__ . '/_files/api.php'; - $this->resourceProviderMock->expects($this->once())->method('getAclResources')->willReturn($aclResources); - $this->assertEquals($expectedResult, $this->model->convert($inputData)); } } diff --git a/app/code/Magento/Integration/Test/Unit/Model/Config/Integration/XsdTest.php b/app/code/Magento/Integration/Test/Unit/Model/Config/Integration/XsdTest.php index ac04c8e1df0ca..79039e2fede94 100644 --- a/app/code/Magento/Integration/Test/Unit/Model/Config/Integration/XsdTest.php +++ b/app/code/Magento/Integration/Test/Unit/Model/Config/Integration/XsdTest.php @@ -13,7 +13,7 @@ class XsdTest extends \PHPUnit_Framework_TestCase /** * @var string */ - protected $_schemaFile; + protected $schemaFile; protected function setUp() { @@ -21,7 +21,7 @@ protected function setUp() $this->markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033'); } $urnResolver = new \Magento\Framework\Config\Dom\UrnResolver(); - $this->_schemaFile = $urnResolver->getRealPath( + $this->schemaFile = $urnResolver->getRealPath( 'urn:magento:module:Magento_Integration:etc/integration/api.xsd' ); } @@ -38,7 +38,7 @@ public function testExemplarXml($fixtureXml, array $expectedErrors) ->willReturn(true); $messageFormat = '%message%'; $dom = new \Magento\Framework\Config\Dom($fixtureXml, $validationStateMock, [], null, null, $messageFormat); - $actualResult = $dom->validate($this->_schemaFile, $actualErrors); + $actualResult = $dom->validate($this->schemaFile, $actualErrors); $this->assertEquals(empty($expectedErrors), $actualResult, "Validation result is invalid."); $this->assertEquals($expectedErrors, $actualErrors, "Validation errors does not match."); } diff --git a/app/code/Magento/Integration/Test/Unit/Model/Config/Integration/_files/api.php b/app/code/Magento/Integration/Test/Unit/Model/Config/Integration/_files/api.php index cc2e6b97c32c0..4eb189e625cd4 100644 --- a/app/code/Magento/Integration/Test/Unit/Model/Config/Integration/_files/api.php +++ b/app/code/Magento/Integration/Test/Unit/Model/Config/Integration/_files/api.php @@ -6,11 +6,11 @@ return [ 'TestIntegration1' => [ 'resource' => [ - 'Magento_Customer::manageParent', 'Magento_Customer::manage', - 'Magento_SalesRule::quoteParent', - 'Magento_SalesRule::quote' + 'Magento_Customer::online', + 'Magento_Sales::capture', + 'Magento_SalesRule::quote', ], ], - 'TestIntegration2' => ['resource' => ['Magento_Sales::sales']] + 'TestIntegration2' => ['resource' => ['Magento_Catalog::product_read']] ]; diff --git a/app/code/Magento/Integration/Test/Unit/Model/Config/Integration/_files/api.xml b/app/code/Magento/Integration/Test/Unit/Model/Config/Integration/_files/api.xml index cce8c63668116..7a9b177618b8f 100644 --- a/app/code/Magento/Integration/Test/Unit/Model/Config/Integration/_files/api.xml +++ b/app/code/Magento/Integration/Test/Unit/Model/Config/Integration/_files/api.xml @@ -11,12 +11,14 @@ in etc/acl.xml of modules and subsequently mapped to web APIs in webapi.xml. --> + + - + diff --git a/app/code/Magento/Integration/Test/Unit/Model/Config/XsdTest.php b/app/code/Magento/Integration/Test/Unit/Model/Config/XsdTest.php index 271dcee56dd02..c1bff77e053a1 100644 --- a/app/code/Magento/Integration/Test/Unit/Model/Config/XsdTest.php +++ b/app/code/Magento/Integration/Test/Unit/Model/Config/XsdTest.php @@ -13,7 +13,7 @@ class XsdTest extends \PHPUnit_Framework_TestCase /** * @var string */ - protected $_schemaFile; + protected $schemaFile; protected function setUp() { @@ -21,7 +21,7 @@ protected function setUp() $this->markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033'); } $urnResolver = new \Magento\Framework\Config\Dom\UrnResolver(); - $this->_schemaFile = $urnResolver->getRealPath( + $this->schemaFile = $urnResolver->getRealPath( 'urn:magento:module:Magento_Integration:etc/integration/config.xsd' ); } @@ -38,7 +38,7 @@ public function testExemplarXml($fixtureXml, array $expectedErrors) ->willReturn(true); $messageFormat = '%message%'; $dom = new \Magento\Framework\Config\Dom($fixtureXml, $validationStateMock, [], null, null, $messageFormat); - $actualResult = $dom->validate($this->_schemaFile, $actualErrors); + $actualResult = $dom->validate($this->schemaFile, $actualErrors); $this->assertEquals(empty($expectedErrors), $actualResult, "Validation result is invalid."); $this->assertEquals($expectedErrors, $actualErrors, "Validation errors does not match."); } diff --git a/app/code/Magento/Integration/Test/Unit/Model/Config/_files/integration.xml b/app/code/Magento/Integration/Test/Unit/Model/Config/_files/config.xml similarity index 100% rename from app/code/Magento/Integration/Test/Unit/Model/Config/_files/integration.xml rename to app/code/Magento/Integration/Test/Unit/Model/Config/_files/config.xml diff --git a/app/code/Magento/Integration/Test/Unit/Model/ConfigTest.php b/app/code/Magento/Integration/Test/Unit/Model/ConsolidatedConfigTest.php similarity index 69% rename from app/code/Magento/Integration/Test/Unit/Model/ConfigTest.php rename to app/code/Magento/Integration/Test/Unit/Model/ConsolidatedConfigTest.php index fecb6c0c0b36d..b1bb285274890 100644 --- a/app/code/Magento/Integration/Test/Unit/Model/ConfigTest.php +++ b/app/code/Magento/Integration/Test/Unit/Model/ConsolidatedConfigTest.php @@ -5,13 +5,13 @@ */ namespace Magento\Integration\Test\Unit\Model; -use Magento\Integration\Model\Config; -use Magento\Integration\Model\Cache\Type; +use Magento\Integration\Model\ConsolidatedConfig as Config; +use Magento\Integration\Model\Cache\TypeConsolidated as Type; /** - * Unit test for \Magento\Integration\Model\Config + * Unit test for \Magento\Integration\Model\ConsolidatedConfig */ -class ConfigTest extends \PHPUnit_Framework_TestCase +class ConsolidatedConfigTest extends \PHPUnit_Framework_TestCase { /** * Integration config model @@ -26,21 +26,25 @@ class ConfigTest extends \PHPUnit_Framework_TestCase protected $configCacheTypeMock; /** - * @var \Magento\Integration\Model\Config\Reader|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Integration\Model\Config\Consolidated\Reader|\PHPUnit_Framework_MockObject_MockObject */ protected $configReaderMock; public function setUp() { - $this->configCacheTypeMock = $this->getMockBuilder('Magento\Integration\Model\Cache\Type') + $this->configCacheTypeMock = $this->getMockBuilder('Magento\Integration\Model\Cache\TypeConsolidated') ->disableOriginalConstructor() ->getMock(); - $this->configReaderMock = $this->getMockBuilder('Magento\Integration\Model\Config\Reader') + $this->configReaderMock = $this->getMockBuilder('Magento\Integration\Model\Config\Consolidated\Reader') ->disableOriginalConstructor() ->getMock(); - $this->configModel = new Config( - $this->configCacheTypeMock, - $this->configReaderMock + $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->configModel = $objectManagerHelper->getObject( + 'Magento\Integration\Model\ConsolidatedConfig', + [ + 'configCacheType' => $this->configCacheTypeMock, + 'configReader' => $this->configReaderMock + ] ); } diff --git a/app/code/Magento/Integration/Test/Unit/Model/ManagerTest.php b/app/code/Magento/Integration/Test/Unit/Model/ManagerTest.php index 08b8ebad31de0..3bfb4cffd2d24 100644 --- a/app/code/Magento/Integration/Test/Unit/Model/ManagerTest.php +++ b/app/code/Magento/Integration/Test/Unit/Model/ManagerTest.php @@ -17,36 +17,28 @@ class ManagerTest extends \PHPUnit_Framework_TestCase * * @var \Magento\Integration\Api\IntegrationServiceInterface */ - protected $_integrationServiceMock; + protected $integrationServiceMock; /** - * Integration config - * - * @var \Magento\Integration\Model\IntegrationConfig + * @var \Magento\Authorization\Model\Acl\AclRetriever */ - protected $_integrationConfigMock; + protected $aclRetriever; /** - * @var \Magento\Authorization\Model\Acl\AclRetriever + * @var \Magento\Integration\Model\Config */ - protected $aclRetriever; + protected $configMock; /** * Integration config * * @var \Magento\Integration\Model\ConfigBasedIntegrationManager */ - protected $_integrationManager; + protected $integrationManager; public function setUp() { - $this->_integrationConfigMock = $this->getMockBuilder( - '\Magento\Integration\Model\IntegrationConfig' - )->disableOriginalConstructor()->setMethods( - ['getIntegrations'] - )->getMock(); - - $this->_integrationServiceMock = $this->getMockBuilder( + $this->integrationServiceMock = $this->getMockBuilder( '\Magento\Integration\Api\IntegrationServiceInterface' )->disableOriginalConstructor()->setMethods( [ @@ -66,27 +58,100 @@ public function setUp() ->setMethods([]) ->getMock(); - $this->_integrationManager = new \Magento\Integration\Model\ConfigBasedIntegrationManager( - $this->_integrationConfigMock, - $this->_integrationServiceMock, - $this->aclRetriever + $this->configMock = $this->getMockBuilder('Magento\Integration\Model\Config') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + + $this->integrationManager = $objectManagerHelper->getObject( + 'Magento\Integration\Model\ConfigBasedIntegrationManager', + [ + 'integrationService' => $this->integrationServiceMock, + 'aclRetriever' => $this->aclRetriever, + 'integrationConfig' => $this->configMock + ] ); } public function tearDown() { - unset($this->_integrationConfigMock); - unset($this->_integrationServiceMock); - unset($this->_integrationManager); + unset($this->integrationServiceMock); + unset($this->integrationManager); } public function testProcessIntegrationConfigNoIntegrations() { - $this->_integrationConfigMock->expects($this->never())->method('getIntegrations'); - $this->_integrationManager->processIntegrationConfig([]); + $this->configMock->expects($this->never())->method('getIntegrations'); + $this->integrationManager->processIntegrationConfig([]); } - public function testProcessIntegrationConfigRecreateUpdatedConfigAfterResourceChange() + public function testProcessIntegrationConfigSuccess() + { + $this->configMock->expects( + $this->once() + )->method( + 'getIntegrations' + )->will( + $this->returnValue( + [ + 'TestIntegration1' => [ + 'email' => 'test-integration1@magento.com', + 'endpoint_url' => 'http://endpoint.com', + 'identity_link_url' => 'http://www.example.com/identity', + ], + 'TestIntegration2' => ['email' => 'test-integration2@magento.com'], + ] + ) + ); + $intLookupData1 = $this->getMockBuilder('Magento\Integration\Model\Integration') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $intLookupData1->expects($this->any())->method('getId')->willReturn(1); + $intLookupData2 = $this->getMockBuilder('Magento\Integration\Model\Integration') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $intLookupData1->expects($this->any())->method('getId')->willReturn(false); + + $intUpdateData1 = [ + Integration::ID => 1, + Integration::NAME => 'TestIntegration1', + Integration::EMAIL => 'test-integration1@magento.com', + Integration::ENDPOINT => 'http://endpoint.com', + Integration::IDENTITY_LINK_URL => 'http://www.example.com/identity', + Integration::SETUP_TYPE => 1, + ]; + $integrationsData2 = [ + Integration::NAME => 'TestIntegration2', + Integration::EMAIL => 'test-integration2@magento.com', + Integration::SETUP_TYPE => 1, + ]; + $this->integrationServiceMock->expects( + $this->at(0) + )->method( + 'findByName' + )->with( + 'TestIntegration1' + )->will( + $this->returnValue($intLookupData1) + ); + $this->integrationServiceMock->expects($this->once())->method('create')->with($integrationsData2); + $this->integrationServiceMock->expects( + $this->at(2) + )->method( + 'findByName' + )->with( + 'TestIntegration2' + )->will( + $this->returnValue($intLookupData2) + ); + $this->integrationServiceMock->expects($this->at(1))->method('update')->with($intUpdateData1); + $this->integrationManager->processIntegrationConfig(['TestIntegration1', 'TestIntegration2']); + } + + public function testProcessConfigBasedIntegrationsRecreateUpdatedConfigAfterResourceChange() { $originalData = [ Integration::ID => 1, @@ -101,6 +166,10 @@ public function testProcessIntegrationConfigRecreateUpdatedConfigAfterResourceCh Integration::EMAIL => 'test-integration1@magento.com', Integration::ENDPOINT => 'http://endpoint.com', Integration::IDENTITY_LINK_URL => 'http://www.example.com/identity', + 'resources' => [ + 'Magento_Customer::manage', + 'Magento_Customer::customer' + ] ] ]; $originalResources = [ @@ -111,36 +180,39 @@ public function testProcessIntegrationConfigRecreateUpdatedConfigAfterResourceCh 'Magento_Customer::customer' ]; - $this->_integrationConfigMock->expects($this->once())->method('getIntegrations')->willReturn($newResources); $integrationObject = $this->getMockBuilder('Magento\Integration\Model\Integration') ->disableOriginalConstructor() ->setMethods([]) ->getMock(); // Integration already exists, so update with new data and recreate - $this->_integrationServiceMock->expects($this->at(0))->method('findByName')->with('TestIntegration1')->will( + $this->integrationServiceMock->expects($this->at(0))->method('findByName')->with('TestIntegration1')->will( $this->returnValue($integrationObject) ); $this->aclRetriever->expects($this->once())->method('getAllowedResourcesByUser') ->willReturn($originalResources); $integrationObject->expects($this->any())->method('getId')->willReturn($originalData[Integration::ID]); - $this->_integrationServiceMock->expects($this->once())->method('update')->willReturn($integrationObject); + $this->integrationServiceMock->expects($this->once())->method('update')->willReturn($integrationObject); $integrationObject->expects($this->once())->method('getOrigData')->willReturn($originalData); $integrationObject->expects($this->once())->method('getData')->willReturn($newResources); - $this->_integrationServiceMock->expects($this->once())->method('create'); + $this->integrationServiceMock->expects($this->once())->method('create'); - $this->_integrationManager->processIntegrationConfig($integrations); + $this->integrationManager->processConfigBasedIntegrations($integrations); } - public function testProcessIntegrationConfigCreateNewIntegrations() + public function testProcessConfigBasedIntegrationsCreateNewIntegrations() { $integrations = [ 'TestIntegration1' => [ Integration::EMAIL => 'test-integration1@magento.com', Integration::ENDPOINT => 'http://endpoint.com', Integration::IDENTITY_LINK_URL => 'http://www.example.com/identity', + 'resources' => [ + 'Magento_Customer::manage', + 'Magento_Customer::customer' + ] ], 'TestIntegration2' => [ Integration::EMAIL => 'test-integration2@magento.com', @@ -148,29 +220,24 @@ public function testProcessIntegrationConfigCreateNewIntegrations() Integration::IDENTITY_LINK_URL => 'http://www.example.com/identity', ] ]; - $newResources = [ - 'Magento_Customer::manage', - 'Magento_Customer::customer' - ]; - $this->_integrationConfigMock->expects($this->once())->method('getIntegrations')->willReturn($newResources); $integrationObject = $this->getMockBuilder('Magento\Integration\Model\Integration') ->disableOriginalConstructor() ->setMethods([]) ->getMock(); // Integration1 does not exist, so create it - $this->_integrationServiceMock->expects($this->at(0))->method('findByName')->with('TestIntegration1')->will( + $this->integrationServiceMock->expects($this->at(0))->method('findByName')->with('TestIntegration1')->will( $this->returnValue($integrationObject) ); $integrationObject->expects($this->any())->method('getId')->willReturn(false); - $this->_integrationServiceMock->expects($this->any())->method('create'); + $this->integrationServiceMock->expects($this->any())->method('create'); // Integration2 does not exist, so create it - $this->_integrationServiceMock->expects($this->at(2))->method('findByName')->with('TestIntegration2')->will( + $this->integrationServiceMock->expects($this->at(2))->method('findByName')->with('TestIntegration2')->will( $this->returnValue($integrationObject) ); - $this->_integrationManager->processIntegrationConfig($integrations); + $this->integrationManager->processConfigBasedIntegrations($integrations); } } diff --git a/app/code/Magento/Integration/Test/Unit/Model/Plugin/IntegrationTest.php b/app/code/Magento/Integration/Test/Unit/Model/Plugin/IntegrationTest.php index 41b8f23a5acf8..7893554d52267 100644 --- a/app/code/Magento/Integration/Test/Unit/Model/Plugin/IntegrationTest.php +++ b/app/code/Magento/Integration/Test/Unit/Model/Plugin/IntegrationTest.php @@ -37,7 +37,12 @@ class IntegrationTest extends \PHPUnit_Framework_TestCase /** * @var \Magento\Integration\Model\IntegrationConfig|\PHPUnit_Framework_MockObject_MockObject */ - protected $integrationConfig; + protected $integrationConfigMock; + + /** + * @var \Magento\Integration\Model\ConsolidatedConfig|\PHPUnit_Framework_MockObject_MockObject + */ + protected $consolidatedConfigMock; public function setUp() { @@ -56,15 +61,25 @@ public function setUp() '', false ); - $this->integrationConfig = $this->getMockBuilder('Magento\Integration\Model\IntegrationConfig') + $this->integrationConfigMock = $this->getMockBuilder('Magento\Integration\Model\IntegrationConfig') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $this->consolidatedConfigMock = $this->getMockBuilder('Magento\Integration\Model\ConsolidatedConfig') ->disableOriginalConstructor() ->setMethods([]) ->getMock(); - $this->integrationPlugin = new \Magento\Integration\Model\Plugin\Integration( - $this->integrationAuthServiceMock, - $this->aclRetrieverMock, - $this->integrationConfig + $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + + $this->integrationPlugin = $objectManagerHelper->getObject( + 'Magento\Integration\Model\Plugin\Integration', + [ + 'integrationAuthorizationService' => $this->integrationAuthServiceMock, + 'aclRetriever' => $this->aclRetrieverMock, + 'integrationConfig' => $this->integrationConfigMock, + 'consolidatedConfig' => $this->consolidatedConfigMock + ] ); } @@ -193,6 +208,24 @@ public function testAfterGet() $integrationModelMock->expects($this->once()) ->method('setData') ->with('resource', ['testResource']); + $deprecatedIntegrationsData = [ + Integration::ID => $integrationId, + Integration::NAME => 'TestIntegration1', + Integration::EMAIL => 'test-integration1@magento.com', + Integration::ENDPOINT => 'http://endpoint.com', + Integration::SETUP_TYPE => 1, + 'resource' => ['testResource'] + ]; + $consolidatedIntegrationsData = [ + Integration::ID => 2, + Integration::NAME => 'TestIntegration2', + Integration::EMAIL => 'test-integration2@magento.com', + Integration::ENDPOINT => 'http://endpoint2.com', + Integration::SETUP_TYPE => 1, + 'resource' => ['testResource'] + ]; + $this->integrationConfigMock->method('getIntegrations')->willReturn($deprecatedIntegrationsData); + $this->consolidatedConfigMock->method('getIntegrations')->willReturn($consolidatedIntegrationsData); $this->aclRetrieverMock->expects($this->once()) ->method('getAllowedResourcesByUser') diff --git a/app/code/Magento/Integration/etc/adminhtml/menu.xml b/app/code/Magento/Integration/etc/adminhtml/menu.xml index ad3b0221b7190..e8efbcb55eec5 100644 --- a/app/code/Magento/Integration/etc/adminhtml/menu.xml +++ b/app/code/Magento/Integration/etc/adminhtml/menu.xml @@ -9,7 +9,7 @@ --> - - + + diff --git a/app/code/Magento/Integration/etc/integration/api.xsd b/app/code/Magento/Integration/etc/integration/api.xsd index 6c094206510ce..45cb5030bd0ae 100644 --- a/app/code/Magento/Integration/etc/integration/api.xsd +++ b/app/code/Magento/Integration/etc/integration/api.xsd @@ -6,6 +6,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ + @deprecated --> @@ -42,4 +43,4 @@ - + \ No newline at end of file diff --git a/app/code/Magento/Integration/etc/integration/config.xsd b/app/code/Magento/Integration/etc/integration/config.xsd index b65f0b6b1385a..0ad99a3274acc 100644 --- a/app/code/Magento/Integration/etc/integration/config.xsd +++ b/app/code/Magento/Integration/etc/integration/config.xsd @@ -6,6 +6,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ + @deprecated --> @@ -37,4 +38,4 @@ - + \ No newline at end of file diff --git a/app/code/Magento/Integration/etc/integration/integration.xsd b/app/code/Magento/Integration/etc/integration/integration.xsd new file mode 100644 index 0000000000000..88bf2a9dd45b0 --- /dev/null +++ b/app/code/Magento/Integration/etc/integration/integration.xsd @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/app/code/Magento/Integration/etc/integration/integration_base.xsd b/app/code/Magento/Integration/etc/integration/integration_base.xsd new file mode 100644 index 0000000000000..51e1301706c55 --- /dev/null +++ b/app/code/Magento/Integration/etc/integration/integration_base.xsd @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/code/Magento/Integration/etc/integration/integration_file.xsd b/app/code/Magento/Integration/etc/integration/integration_file.xsd new file mode 100644 index 0000000000000..8a256fc59499c --- /dev/null +++ b/app/code/Magento/Integration/etc/integration/integration_file.xsd @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/app/code/Magento/Multishipping/etc/acl.xml b/app/code/Magento/Multishipping/etc/acl.xml index b38af4af7b4e1..b9341e54ae6c9 100644 --- a/app/code/Magento/Multishipping/etc/acl.xml +++ b/app/code/Magento/Multishipping/etc/acl.xml @@ -12,7 +12,7 @@ - + diff --git a/app/code/Magento/NewRelicReporting/etc/acl.xml b/app/code/Magento/NewRelicReporting/etc/acl.xml index 4395fd3f25af2..a236e660fad55 100644 --- a/app/code/Magento/NewRelicReporting/etc/acl.xml +++ b/app/code/Magento/NewRelicReporting/etc/acl.xml @@ -12,7 +12,7 @@ - + diff --git a/app/code/Magento/Newsletter/etc/acl.xml b/app/code/Magento/Newsletter/etc/acl.xml index f8e0ee8fb5dd4..58876ce48ba25 100644 --- a/app/code/Magento/Newsletter/etc/acl.xml +++ b/app/code/Magento/Newsletter/etc/acl.xml @@ -11,20 +11,20 @@ - - - + + + - + - + diff --git a/app/code/Magento/Newsletter/etc/adminhtml/menu.xml b/app/code/Magento/Newsletter/etc/adminhtml/menu.xml index 960be7637049f..bf917dc46f532 100644 --- a/app/code/Magento/Newsletter/etc/adminhtml/menu.xml +++ b/app/code/Magento/Newsletter/etc/adminhtml/menu.xml @@ -7,9 +7,9 @@ --> - - - - + + + + diff --git a/app/code/Magento/Payment/etc/acl.xml b/app/code/Magento/Payment/etc/acl.xml index 62de8778edd0f..be44217b991d9 100644 --- a/app/code/Magento/Payment/etc/acl.xml +++ b/app/code/Magento/Payment/etc/acl.xml @@ -12,8 +12,8 @@ - - + + diff --git a/app/code/Magento/Paypal/etc/acl.xml b/app/code/Magento/Paypal/etc/acl.xml index c719b821c45f0..33cdfcbae5b2b 100644 --- a/app/code/Magento/Paypal/etc/acl.xml +++ b/app/code/Magento/Paypal/etc/acl.xml @@ -12,25 +12,25 @@ - + - - - + + + - - - - - + + + + + diff --git a/app/code/Magento/Paypal/etc/adminhtml/menu.xml b/app/code/Magento/Paypal/etc/adminhtml/menu.xml index ec8bdb6321abc..dea4c68f06482 100644 --- a/app/code/Magento/Paypal/etc/adminhtml/menu.xml +++ b/app/code/Magento/Paypal/etc/adminhtml/menu.xml @@ -7,7 +7,7 @@ --> - - + + diff --git a/app/code/Magento/Persistent/etc/acl.xml b/app/code/Magento/Persistent/etc/acl.xml index 73913931ae4bd..4e14da649f4b4 100644 --- a/app/code/Magento/Persistent/etc/acl.xml +++ b/app/code/Magento/Persistent/etc/acl.xml @@ -12,7 +12,7 @@ - + diff --git a/app/code/Magento/Quote/etc/acl.xml b/app/code/Magento/Quote/etc/acl.xml index f0a2f1ff04dd8..b11fd4fe9d896 100644 --- a/app/code/Magento/Quote/etc/acl.xml +++ b/app/code/Magento/Quote/etc/acl.xml @@ -9,8 +9,8 @@ - - + + diff --git a/app/code/Magento/Reports/etc/acl.xml b/app/code/Magento/Reports/etc/acl.xml index 6d6972fd73412..ac482c24acdc9 100644 --- a/app/code/Magento/Reports/etc/acl.xml +++ b/app/code/Magento/Reports/etc/acl.xml @@ -9,46 +9,46 @@ - - - - - + + + + + - + - - - + + + - - - - - - - + + + + + + + - - - - + + + + - - - - - - + + + + + + - - + + - + diff --git a/app/code/Magento/Reports/etc/adminhtml/menu.xml b/app/code/Magento/Reports/etc/adminhtml/menu.xml index 91fd6188b2898..43e970c15461a 100644 --- a/app/code/Magento/Reports/etc/adminhtml/menu.xml +++ b/app/code/Magento/Reports/etc/adminhtml/menu.xml @@ -7,28 +7,28 @@ --> - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/code/Magento/Review/etc/acl.xml b/app/code/Magento/Review/etc/acl.xml index ed1e37e4a5325..d9f5263ec91ca 100644 --- a/app/code/Magento/Review/etc/acl.xml +++ b/app/code/Magento/Review/etc/acl.xml @@ -11,12 +11,12 @@ - + - + diff --git a/app/code/Magento/Review/etc/adminhtml/menu.xml b/app/code/Magento/Review/etc/adminhtml/menu.xml index efe0000761a34..c8b691f0f0361 100644 --- a/app/code/Magento/Review/etc/adminhtml/menu.xml +++ b/app/code/Magento/Review/etc/adminhtml/menu.xml @@ -7,10 +7,10 @@ --> - - - - - + + + + + diff --git a/app/code/Magento/Rss/etc/acl.xml b/app/code/Magento/Rss/etc/acl.xml index 99402b2743e56..8abd85dd27307 100644 --- a/app/code/Magento/Rss/etc/acl.xml +++ b/app/code/Magento/Rss/etc/acl.xml @@ -12,7 +12,7 @@ - + diff --git a/app/code/Magento/Sales/etc/acl.xml b/app/code/Magento/Sales/etc/acl.xml index 2f233ff8ecb82..77526fcb3de26 100644 --- a/app/code/Magento/Sales/etc/acl.xml +++ b/app/code/Magento/Sales/etc/acl.xml @@ -9,41 +9,41 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - + + + + + - + - - + + diff --git a/app/code/Magento/Sales/etc/adminhtml/menu.xml b/app/code/Magento/Sales/etc/adminhtml/menu.xml index 2865c6d5cbd95..2267bf1cb7da4 100644 --- a/app/code/Magento/Sales/etc/adminhtml/menu.xml +++ b/app/code/Magento/Sales/etc/adminhtml/menu.xml @@ -7,13 +7,13 @@ --> - - - - - - - - + + + + + + + + diff --git a/app/code/Magento/SalesRule/etc/acl.xml b/app/code/Magento/SalesRule/etc/acl.xml index 12465ff88680a..9bb1868a49de5 100644 --- a/app/code/Magento/SalesRule/etc/acl.xml +++ b/app/code/Magento/SalesRule/etc/acl.xml @@ -11,13 +11,13 @@ - + - + diff --git a/app/code/Magento/SalesRule/etc/adminhtml/menu.xml b/app/code/Magento/SalesRule/etc/adminhtml/menu.xml index 4436cd819f5d4..c7833f63af098 100644 --- a/app/code/Magento/SalesRule/etc/adminhtml/menu.xml +++ b/app/code/Magento/SalesRule/etc/adminhtml/menu.xml @@ -7,6 +7,6 @@ --> - + diff --git a/app/code/Magento/Search/etc/acl.xml b/app/code/Magento/Search/etc/acl.xml index 6a6501d32d6b6..6a6dce1cd6319 100644 --- a/app/code/Magento/Search/etc/acl.xml +++ b/app/code/Magento/Search/etc/acl.xml @@ -11,8 +11,8 @@ - - + + diff --git a/app/code/Magento/Search/etc/adminhtml/menu.xml b/app/code/Magento/Search/etc/adminhtml/menu.xml index 6af451a5f6de5..3d82348c9e065 100644 --- a/app/code/Magento/Search/etc/adminhtml/menu.xml +++ b/app/code/Magento/Search/etc/adminhtml/menu.xml @@ -7,7 +7,7 @@ --> - - + + diff --git a/app/code/Magento/Shipping/etc/acl.xml b/app/code/Magento/Shipping/etc/acl.xml index fc1d7770fc71e..7aa2fc24b827f 100644 --- a/app/code/Magento/Shipping/etc/acl.xml +++ b/app/code/Magento/Shipping/etc/acl.xml @@ -12,9 +12,9 @@ - - - + + + diff --git a/app/code/Magento/Sitemap/etc/acl.xml b/app/code/Magento/Sitemap/etc/acl.xml index f9dbac4905edf..9bf15efee1e76 100644 --- a/app/code/Magento/Sitemap/etc/acl.xml +++ b/app/code/Magento/Sitemap/etc/acl.xml @@ -11,13 +11,13 @@ - + - + diff --git a/app/code/Magento/Sitemap/etc/adminhtml/menu.xml b/app/code/Magento/Sitemap/etc/adminhtml/menu.xml index 2af5e332683a3..2296152d021b5 100644 --- a/app/code/Magento/Sitemap/etc/adminhtml/menu.xml +++ b/app/code/Magento/Sitemap/etc/adminhtml/menu.xml @@ -7,6 +7,6 @@ --> - + diff --git a/app/code/Magento/Store/App/Action/Plugin/Context.php b/app/code/Magento/Store/App/Action/Plugin/Context.php index 6e3e3f4e4f551..fa97656e7698f 100644 --- a/app/code/Magento/Store/App/Action/Plugin/Context.php +++ b/app/code/Magento/Store/App/Action/Plugin/Context.php @@ -7,6 +7,7 @@ namespace Magento\Store\App\Action\Plugin; use Magento\Framework\App\Http\Context as HttpContext; +use Magento\Framework\Phrase; use Magento\Store\Api\StoreCookieManagerInterface; use Magento\Store\Api\StoreResolverInterface; use Magento\Store\Model\StoreManagerInterface; @@ -77,12 +78,19 @@ public function aroundDispatch( /** @var \Magento\Store\Model\Store $defaultStore */ $defaultStore = $this->storeManager->getWebsite()->getDefaultStore(); - $requestedStoreCode = $this->httpRequest->getParam( + $storeCode = $this->httpRequest->getParam( StoreResolverInterface::PARAM_NAME, $this->storeCookieManager->getStoreCodeFromCookie() ); + + if (is_array($storeCode)) { + if (!isset($storeCode['_data']['code'])) { + throw new \InvalidArgumentException(new Phrase('Invalid store parameter.')); + } + $storeCode = $storeCode['_data']['code']; + } /** @var \Magento\Store\Model\Store $currentStore */ - $currentStore = $requestedStoreCode ? $this->storeManager->getStore($requestedStoreCode) : $defaultStore; + $currentStore = $storeCode ? $this->storeManager->getStore($storeCode) : $defaultStore; $this->httpContext->setValue( StoreManagerInterface::CONTEXT_STORE, diff --git a/app/code/Magento/Store/Model/StoreResolver.php b/app/code/Magento/Store/Model/StoreResolver.php index b87a5aabf6f71..ae1297749aa84 100644 --- a/app/code/Magento/Store/Model/StoreResolver.php +++ b/app/code/Magento/Store/Model/StoreResolver.php @@ -85,6 +85,12 @@ public function getCurrentStoreId() list($stores, $defaultStoreId) = $this->getStoresData(); $storeCode = $this->request->getParam(self::PARAM_NAME, $this->storeCookieManager->getStoreCodeFromCookie()); + if (is_array($storeCode)) { + if (!isset($storeCode['_data']['code'])) { + throw new \InvalidArgumentException(__('Invalid store parameter.')); + } + $storeCode = $storeCode['_data']['code']; + } if ($storeCode) { try { $store = $this->getRequestedStoreByCode($storeCode); diff --git a/app/code/Magento/Store/Test/Unit/App/Action/Plugin/ContextTest.php b/app/code/Magento/Store/Test/Unit/App/Action/Plugin/ContextTest.php index e6c679b2dd4d2..7bfe5e759160a 100644 --- a/app/code/Magento/Store/Test/Unit/App/Action/Plugin/ContextTest.php +++ b/app/code/Magento/Store/Test/Unit/App/Action/Plugin/ContextTest.php @@ -159,34 +159,41 @@ public function setUp() ->will($this->returnValue($this->websiteMock)); $this->storeManager->method('getDefaultStoreView') ->willReturn($this->storeMock); - $this->storeManager->method('getStore') - ->willReturn($this->currentStoreMock); + $this->websiteMock->expects($this->once()) ->method('getDefaultStore') ->will($this->returnValue($this->storeMock)); + + $this->storeCookieManager->expects($this->once()) + ->method('getStoreCodeFromCookie') + ->will($this->returnValue('storeCookie')); + $this->currentStoreMock->expects($this->any()) + ->method('getDefaultCurrencyCode') + ->will($this->returnValue(self::CURRENCY_CURRENT_STORE)); + } + + public function testAroundDispatchCurrencyFromSession() + { $this->storeMock->expects($this->once()) ->method('getDefaultCurrencyCode') ->will($this->returnValue(self::CURRENCY_DEFAULT)); + $this->storeMock->expects($this->once()) ->method('getCode') ->willReturn('default'); $this->currentStoreMock->expects($this->once()) ->method('getCode') ->willReturn('custom_store'); - $this->storeCookieManager->expects($this->once()) - ->method('getStoreCodeFromCookie') - ->will($this->returnValue('storeCookie')); + $this->httpRequestMock->expects($this->once()) ->method('getParam') ->with($this->equalTo('___store')) ->will($this->returnValue('default')); - $this->currentStoreMock->expects($this->any()) - ->method('getDefaultCurrencyCode') - ->will($this->returnValue(self::CURRENCY_CURRENT_STORE)); - } - public function testAroundDispatchCurrencyFromSession() - { + $this->storeManager->method('getStore') + ->with('default') + ->willReturn($this->currentStoreMock); + $this->sessionMock->expects($this->any()) ->method('getCurrencyCode') ->will($this->returnValue(self::CURRENCY_SESSION)); @@ -207,6 +214,26 @@ public function testAroundDispatchCurrencyFromSession() public function testDispatchCurrentStoreCurrency() { + $this->storeMock->expects($this->once()) + ->method('getDefaultCurrencyCode') + ->will($this->returnValue(self::CURRENCY_DEFAULT)); + + $this->storeMock->expects($this->once()) + ->method('getCode') + ->willReturn('default'); + $this->currentStoreMock->expects($this->once()) + ->method('getCode') + ->willReturn('custom_store'); + + $this->httpRequestMock->expects($this->once()) + ->method('getParam') + ->with($this->equalTo('___store')) + ->will($this->returnValue('default')); + + $this->storeManager->method('getStore') + ->with('default') + ->willReturn($this->currentStoreMock); + $this->httpContextMock->expects($this->at(0)) ->method('setValue') ->with(StoreManagerInterface::CONTEXT_STORE, 'custom_store', 'default'); @@ -220,4 +247,78 @@ public function testDispatchCurrentStoreCurrency() $this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock) ); } + + public function testDispatchStoreParameterIsArray() + { + $this->storeMock->expects($this->once()) + ->method('getDefaultCurrencyCode') + ->will($this->returnValue(self::CURRENCY_DEFAULT)); + + $this->storeMock->expects($this->once()) + ->method('getCode') + ->willReturn('default'); + $this->currentStoreMock->expects($this->once()) + ->method('getCode') + ->willReturn('custom_store'); + + $store = [ + '_data' => [ + 'code' => 500, + ] + ]; + + $this->httpRequestMock->expects($this->once()) + ->method('getParam') + ->with($this->equalTo('___store')) + ->will($this->returnValue($store)); + + $this->storeManager->expects($this->once()) + ->method('getStore') + ->with('500') + ->willReturn($this->currentStoreMock); + + $this->httpContextMock->expects($this->at(0)) + ->method('setValue') + ->with(StoreManagerInterface::CONTEXT_STORE, 'custom_store', 'default'); + /** Make sure that current currency is taken from current store if no value is provided in session */ + $this->httpContextMock->expects($this->at(1)) + ->method('setValue') + ->with(Context::CONTEXT_CURRENCY, self::CURRENCY_CURRENT_STORE, self::CURRENCY_DEFAULT); + + $result = $this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock); + $this->assertEquals( + 'ExpectedValue', + $result + ); + } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Invalid store parameter. + */ + public function testDispatchStoreParameterIsInvalidArray() + { + $this->storeMock->expects($this->never()) + ->method('getDefaultCurrencyCode') + ->will($this->returnValue(self::CURRENCY_DEFAULT)); + + $this->storeMock->expects($this->never()) + ->method('getCode') + ->willReturn('default'); + $this->currentStoreMock->expects($this->never()) + ->method('getCode') + ->willReturn('custom_store'); + + $store = [ + 'some' => [ + 'code' => 500, + ] + ]; + + $this->httpRequestMock->expects($this->once()) + ->method('getParam') + ->with($this->equalTo('___store')) + ->will($this->returnValue($store)); + $this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock); + } } diff --git a/app/code/Magento/Tax/etc/acl.xml b/app/code/Magento/Tax/etc/acl.xml index 3096b19afc9de..2795e4766220c 100644 --- a/app/code/Magento/Tax/etc/acl.xml +++ b/app/code/Magento/Tax/etc/acl.xml @@ -10,10 +10,10 @@ - + - + diff --git a/app/code/Magento/Tax/etc/adminhtml/menu.xml b/app/code/Magento/Tax/etc/adminhtml/menu.xml index 8b866075e2b77..34a4f5d03a27f 100644 --- a/app/code/Magento/Tax/etc/adminhtml/menu.xml +++ b/app/code/Magento/Tax/etc/adminhtml/menu.xml @@ -7,8 +7,8 @@ --> - - - + + + diff --git a/app/code/Magento/Theme/etc/acl.xml b/app/code/Magento/Theme/etc/acl.xml index 53b6cfce87591..a5a4ef4f0f346 100644 --- a/app/code/Magento/Theme/etc/acl.xml +++ b/app/code/Magento/Theme/etc/acl.xml @@ -11,7 +11,7 @@ - + diff --git a/app/code/Magento/Theme/etc/adminhtml/menu.xml b/app/code/Magento/Theme/etc/adminhtml/menu.xml index 69dc22be1ee14..46eb3e0d8802e 100644 --- a/app/code/Magento/Theme/etc/adminhtml/menu.xml +++ b/app/code/Magento/Theme/etc/adminhtml/menu.xml @@ -7,6 +7,6 @@ --> - + diff --git a/app/code/Magento/UrlRewrite/etc/adminhtml/acl.xml b/app/code/Magento/UrlRewrite/etc/adminhtml/acl.xml index 61cf6d3e6873b..02b1c1ac69a63 100644 --- a/app/code/Magento/UrlRewrite/etc/adminhtml/acl.xml +++ b/app/code/Magento/UrlRewrite/etc/adminhtml/acl.xml @@ -11,7 +11,7 @@ - + diff --git a/app/code/Magento/UrlRewrite/etc/adminhtml/menu.xml b/app/code/Magento/UrlRewrite/etc/adminhtml/menu.xml index 17a614b1c25f4..8b2b9186fbcdc 100644 --- a/app/code/Magento/UrlRewrite/etc/adminhtml/menu.xml +++ b/app/code/Magento/UrlRewrite/etc/adminhtml/menu.xml @@ -7,7 +7,7 @@ --> - diff --git a/app/code/Magento/User/Model/ResourceModel/User.php b/app/code/Magento/User/Model/ResourceModel/User.php index 6f782c75f3108..39e12ce74c5ab 100644 --- a/app/code/Magento/User/Model/ResourceModel/User.php +++ b/app/code/Magento/User/Model/ResourceModel/User.php @@ -149,9 +149,12 @@ public function hasAssigned2Role($user) $select = $connection->select(); $select->from($this->getTable('authorization_role')) ->where('parent_id > :parent_id') - ->where('user_id = :user_id'); + ->where('user_id = :user_id') + ->where('user_type = :user_type'); - $binds = ['parent_id' => 0, 'user_id' => $userId]; + $binds = ['parent_id' => 0, 'user_id' => $userId, + 'user_type' => UserContextInterface::USER_TYPE_ADMIN + ]; return $connection->fetchAll($select, $binds); } else { @@ -292,9 +295,13 @@ public function getRoles(\Magento\Framework\Model\AbstractModel $user) ['role_id'] )->where( "{$table}.user_id = :user_id" + )->where( + "{$table}.user_type = :user_type" ); - $binds = ['user_id' => (int)$user->getId()]; + $binds = ['user_id' => (int)$user->getId(), + 'user_type' => UserContextInterface::USER_TYPE_ADMIN + ]; $roles = $connection->fetchCol($select, $binds); diff --git a/app/code/Magento/User/Test/Unit/Model/ResourceModel/UserTest.php b/app/code/Magento/User/Test/Unit/Model/ResourceModel/UserTest.php index d056004dbcd3a..025f77ac60537 100644 --- a/app/code/Magento/User/Test/Unit/Model/ResourceModel/UserTest.php +++ b/app/code/Magento/User/Test/Unit/Model/ResourceModel/UserTest.php @@ -193,7 +193,7 @@ public function testGetRolesReturnFilledArray() $this->dbAdapterMock->expects($this->once())->method('select')->willReturn($this->selectMock); $this->selectMock->expects($this->once())->method('from')->willReturn($this->selectMock); $this->selectMock->expects($this->once())->method('joinLeft')->willReturn($this->selectMock); - $this->selectMock->expects($this->once())->method('where')->willReturn($this->selectMock); + $this->selectMock->expects($this->atLeastOnce())->method('where')->willReturn($this->selectMock); $this->dbAdapterMock->expects($this->once())->method('fetchCol')->willReturn([1, 2, 3]); $this->assertEquals([1, 2, 3], $this->model->getRoles($this->userMock)); } @@ -206,7 +206,7 @@ public function testGetRolesFetchRowFailure() $this->dbAdapterMock->expects($this->once())->method('select')->willReturn($this->selectMock); $this->selectMock->expects($this->once())->method('from')->willReturn($this->selectMock); $this->selectMock->expects($this->once())->method('joinLeft')->willReturn($this->selectMock); - $this->selectMock->expects($this->once())->method('where')->willReturn($this->selectMock); + $this->selectMock->expects($this->atLeastOnce())->method('where')->willReturn($this->selectMock); $this->dbAdapterMock->expects($this->once())->method('fetchCol')->willReturn(false); $this->assertEquals([], $this->model->getRoles($this->userMock)); } diff --git a/app/code/Magento/User/etc/acl.xml b/app/code/Magento/User/etc/acl.xml index 03a14efa959fb..5ae1a3467efd1 100644 --- a/app/code/Magento/User/etc/acl.xml +++ b/app/code/Magento/User/etc/acl.xml @@ -10,10 +10,10 @@ - - - - + + + + diff --git a/app/code/Magento/User/etc/adminhtml/menu.xml b/app/code/Magento/User/etc/adminhtml/menu.xml index a07c1a7b28343..e0cf27e8cba56 100644 --- a/app/code/Magento/User/etc/adminhtml/menu.xml +++ b/app/code/Magento/User/etc/adminhtml/menu.xml @@ -7,9 +7,9 @@ --> - - - - + + + + diff --git a/app/code/Magento/Variable/etc/acl.xml b/app/code/Magento/Variable/etc/acl.xml index 145f32d0eb66a..d77854913a7a0 100644 --- a/app/code/Magento/Variable/etc/acl.xml +++ b/app/code/Magento/Variable/etc/acl.xml @@ -11,7 +11,7 @@ - + diff --git a/app/code/Magento/Variable/etc/adminhtml/menu.xml b/app/code/Magento/Variable/etc/adminhtml/menu.xml index 1b455c7d218d8..9aa91f1f3964e 100644 --- a/app/code/Magento/Variable/etc/adminhtml/menu.xml +++ b/app/code/Magento/Variable/etc/adminhtml/menu.xml @@ -7,6 +7,6 @@ --> - + diff --git a/app/code/Magento/Webapi/Model/Plugin/Manager.php b/app/code/Magento/Webapi/Model/Plugin/Manager.php index 25b2b1abb39cc..074227609bd46 100644 --- a/app/code/Magento/Webapi/Model/Plugin/Manager.php +++ b/app/code/Magento/Webapi/Model/Plugin/Manager.php @@ -15,13 +15,6 @@ */ class Manager { - /** - * API Integration config - * - * @var IntegrationConfig - */ - protected $_integrationConfig; - /** * Integration service * @@ -34,52 +27,89 @@ class Manager */ protected $integrationAuthorizationService; + /** + * API Integration config + * + * @var IntegrationConfig + */ + protected $integrationConfig; + /** * Construct Setup plugin instance * - * @param IntegrationConfig $integrationConfig * @param IntegrationAuthorizationInterface $integrationAuthorizationService * @param \Magento\Integration\Api\IntegrationServiceInterface $integrationService + * @param IntegrationConfig $integrationConfig */ public function __construct( - IntegrationConfig $integrationConfig, IntegrationAuthorizationInterface $integrationAuthorizationService, - \Magento\Integration\Api\IntegrationServiceInterface $integrationService + \Magento\Integration\Api\IntegrationServiceInterface $integrationService, + IntegrationConfig $integrationConfig ) { - $this->_integrationConfig = $integrationConfig; $this->integrationAuthorizationService = $integrationAuthorizationService; $this->_integrationService = $integrationService; + $this->integrationConfig = $integrationConfig; } /** * Process integration resource permissions after the integration is created * * @param ConfigBasedIntegrationManager $subject - * @param array $integrations integrations passed as array from the invocation chain + * @param string[] $integrationNames Name of integrations passed as array from the invocation chain * - * @return array + * @return string[] * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @deprecated */ public function afterProcessIntegrationConfig( ConfigBasedIntegrationManager $subject, - $integrations + $integrationNames ) { - if (empty($integrations)) { + if (empty($integrationNames)) { return []; } - /** @var array $integrationsResource */ - $integrationsResource = $this->_integrationConfig->getIntegrations(); - foreach (array_keys($integrations) as $name) { - if (isset($integrationsResource[$name])) { + /** @var array $integrations */ + $integrations = $this->integrationConfig->getIntegrations(); + foreach ($integrationNames as $name) { + if (isset($integrations[$name])) { $integration = $this->_integrationService->findByName($name); if ($integration->getId()) { $this->integrationAuthorizationService->grantPermissions( $integration->getId(), - $integrationsResource[$name]['resource'] + $integrations[$name]['resource'] ); } } } + return $integrationNames; + } + + /** + * Process integration resource permissions after the integration is created + * + * @param ConfigBasedIntegrationManager $subject + * @param array $integrations integrations passed as array from the invocation chain + * + * @return array + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterProcessConfigBasedIntegrations( + ConfigBasedIntegrationManager $subject, + $integrations + ) { + if (empty($integrations)) { + return []; + } + + foreach (array_keys($integrations) as $name) { + $integration = $this->_integrationService->findByName($name); + if ($integration->getId()) { + $this->integrationAuthorizationService->grantPermissions( + $integration->getId(), + $integrations[$name]['resource'] + ); + } + } return $integrations; } } diff --git a/app/code/Magento/Webapi/Test/Unit/Model/Plugin/ManagerTest.php b/app/code/Magento/Webapi/Test/Unit/Model/Plugin/ManagerTest.php index b1b296751d26e..8a0d8944673b2 100644 --- a/app/code/Magento/Webapi/Test/Unit/Model/Plugin/ManagerTest.php +++ b/app/code/Magento/Webapi/Test/Unit/Model/Plugin/ManagerTest.php @@ -9,13 +9,6 @@ class ManagerTest extends \PHPUnit_Framework_TestCase { - /** - * API Integration config - * - * @var \Magento\Integration\Model\IntegrationConfig|\PHPUnit_Framework_MockObject_MockObject - */ - protected $integrationConfigMock; - /** * Integration service mock * @@ -42,14 +35,13 @@ class ManagerTest extends \PHPUnit_Framework_TestCase */ protected $subjectMock; + /** + * @var \Magento\Integration\Model\IntegrationConfig|\PHPUnit_Framework_MockObject_MockObject + */ + protected $integrationConfigMock; + public function setUp() { - $this->integrationConfigMock = $this->getMockBuilder( - '\Magento\Integration\Model\IntegrationConfig' - )->disableOriginalConstructor()->setMethods( - ['getIntegrations'] - )->getMock(); - $this->integrationServiceMock = $this->getMockBuilder( '\Magento\Integration\Api\IntegrationServiceInterface' )->disableOriginalConstructor()->setMethods( @@ -82,10 +74,16 @@ public function setUp() '', false ); + + $this->integrationConfigMock = $this->getMockBuilder('Magento\Integration\Model\IntegrationConfig') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $this->apiSetupPlugin = new \Magento\Webapi\Model\Plugin\Manager( - $this->integrationConfigMock, $this->integrationAuthorizationServiceMock, - $this->integrationServiceMock + $this->integrationServiceMock, + $this->integrationConfigMock ); } @@ -121,14 +119,74 @@ public function testAfterProcessIntegrationConfigSuccess() ] ) ); + $firstInegrationId = 1; + $integrationsData1 = new \Magento\Framework\DataObject( + [ + 'id' => $firstInegrationId, + Integration::NAME => 'TestIntegration1', + Integration::EMAIL => 'test-integration1@magento.com', + Integration::ENDPOINT => 'http://endpoint.com', + Integration::SETUP_TYPE => 1, + ] + ); + $secondIntegrationId = 2; + $integrationsData2 = new \Magento\Framework\DataObject( + [ + 'id' => $secondIntegrationId, + Integration::NAME => 'TestIntegration2', + Integration::EMAIL => 'test-integration2@magento.com', + Integration::SETUP_TYPE => 1, + ] + ); + $this->integrationServiceMock->expects( + $this->at(0) + )->method( + 'findByName' + )->with( + 'TestIntegration1' + )->will( + $this->returnValue($integrationsData1) + ); + $this->integrationServiceMock->expects( + $this->at(1) + )->method( + 'findByName' + )->with( + 'TestIntegration2' + )->will( + $this->returnValue($integrationsData2) + ); + $this->apiSetupPlugin->afterProcessIntegrationConfig( + $this->subjectMock, + ['TestIntegration1', 'TestIntegration2'] + ); + } + public function testAfterProcessConfigBasedIntegrationsNoIntegrations() + { + $this->integrationServiceMock->expects($this->never())->method('findByName'); + $this->apiSetupPlugin->afterProcessConfigBasedIntegrations($this->subjectMock, []); + } + + /** + * @return void + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function testAfterProcessConfigBasedIntegrationsSuccess() + { $firstInegrationId = 1; $integrationsData1 = [ 'id' => $firstInegrationId, Integration::NAME => 'TestIntegration1', Integration::EMAIL => 'test-integration1@magento.com', Integration::ENDPOINT => 'http://endpoint.com', - Integration::SETUP_TYPE => 1 + Integration::SETUP_TYPE => 1, + 'resource' => [ + 'Magento_Customer::manage', + 'Magento_Customer::online', + 'Magento_Sales::create', + 'Magento_SalesRule::quote', + ] ]; $integrationsData1Object = new \Magento\Framework\DataObject($integrationsData1); @@ -137,7 +195,8 @@ public function testAfterProcessIntegrationConfigSuccess() 'id' => $secondIntegrationId, Integration::NAME => 'TestIntegration2', Integration::EMAIL => 'test-integration2@magento.com', - Integration::SETUP_TYPE => 1 + Integration::SETUP_TYPE => 1, + 'resource' => ['Magento_Catalog::product_read'] ]; $integrationsData2Object = new \Magento\Framework\DataObject($integrationsData2); @@ -161,7 +220,7 @@ public function testAfterProcessIntegrationConfigSuccess() $this->returnValue($integrationsData2Object) ); - $this->apiSetupPlugin->afterProcessIntegrationConfig( + $this->apiSetupPlugin->afterProcessConfigBasedIntegrations( $this->subjectMock, ['TestIntegration1' => $integrationsData1, 'TestIntegration2' => $integrationsData2] ); diff --git a/app/code/Magento/Webapi/Test/Unit/Model/_files/acl.xml b/app/code/Magento/Webapi/Test/Unit/Model/_files/acl.xml index f685888467611..2522010b92185 100644 --- a/app/code/Magento/Webapi/Test/Unit/Model/_files/acl.xml +++ b/app/code/Magento/Webapi/Test/Unit/Model/_files/acl.xml @@ -9,11 +9,11 @@ - - - - - + + + + + diff --git a/app/code/Magento/Widget/etc/acl.xml b/app/code/Magento/Widget/etc/acl.xml index 7e28df60dba3a..0f353f760b2a4 100644 --- a/app/code/Magento/Widget/etc/acl.xml +++ b/app/code/Magento/Widget/etc/acl.xml @@ -11,7 +11,7 @@ - + diff --git a/app/code/Magento/Widget/etc/adminhtml/menu.xml b/app/code/Magento/Widget/etc/adminhtml/menu.xml index b280759071fdc..8058b6f1e98f0 100644 --- a/app/code/Magento/Widget/etc/adminhtml/menu.xml +++ b/app/code/Magento/Widget/etc/adminhtml/menu.xml @@ -7,6 +7,6 @@ --> - + diff --git a/app/code/Magento/Wishlist/etc/acl.xml b/app/code/Magento/Wishlist/etc/acl.xml index 06c9725f281a6..1eddb82191102 100644 --- a/app/code/Magento/Wishlist/etc/acl.xml +++ b/app/code/Magento/Wishlist/etc/acl.xml @@ -12,7 +12,7 @@ - + diff --git a/dev/tests/api-functional/_files/Magento/TestModuleIntegrationFromConfig/etc/integration.xml b/dev/tests/api-functional/_files/Magento/TestModuleIntegrationFromConfig/etc/integration.xml new file mode 100644 index 0000000000000..1d588f1ac9464 --- /dev/null +++ b/dev/tests/api-functional/_files/Magento/TestModuleIntegrationFromConfig/etc/integration.xml @@ -0,0 +1,17 @@ + + + + + test-integration@magento.com + http://example.com/endpoint1 + + + + + + diff --git a/dev/tests/api-functional/_files/Magento/TestModuleIntegrationFromConfig/etc/integration/config.xml b/dev/tests/api-functional/_files/Magento/TestModuleIntegrationFromConfig/etc/integration/config.xml deleted file mode 100644 index 1c70eb6250b3b..0000000000000 --- a/dev/tests/api-functional/_files/Magento/TestModuleIntegrationFromConfig/etc/integration/config.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - test-integration@magento.com - http://example.com/endpoint1 - - \ No newline at end of file diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeRepositoryTest.php index c57d73035b1a5..41032701784ce 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeRepositoryTest.php @@ -81,8 +81,59 @@ public function testCreate() { $attributeCode = 'label_attr_code3df4tr3'; $attribute = $this->createAttribute($attributeCode); - $this->assertArrayHasKey('attribute_id', $attribute); - $this->assertEquals($attributeCode, $attribute['attribute_code']); + + $expectedData = [ + 'attribute_code' => $attributeCode, + 'frontend_labels' => [ + [ + 'store_id' => 0, + 'label' => 'front_lbl' + ], + ], + 'is_required' => true, + "default_value" => "", + "frontend_input" => "select", + "is_visible_on_front" => true, + "is_searchable" => true, + "is_visible_in_advanced_search" => true, + "is_filterable" => true, + "is_filterable_in_search" => true, + "options" => [ + [ + "label" => "string", + "value" => "string", + "sort_order" => 0, + "is_default" => true, + "store_labels" => [ + [ + "store_id" => 0, + "label" => "Red" + ], + [ + "store_id" => 1, + "label" => "Blue" + ], + [ + "store_id" => 2, + "label" => "Yellow" + ] + ] + ] + ] + ]; + + $this->assertEquals($attribute['options'], $expectedData['options']); + $this->assertEquals($attribute['attribute_code'], $expectedData['attribute_code']); + $this->assertEquals($attribute['frontend_labels'], $expectedData['frontend_labels']); + $this->assertEquals($attribute['is_required'], $expectedData['is_required']); + $this->assertEquals($attribute['default_value'], $expectedData['default_value']); + $this->assertEquals($attribute['frontend_input'], $expectedData['frontend_input']); + $this->assertEquals($attribute['is_filterable'], $expectedData['is_filterable']); + $this->assertEquals($attribute['is_filterable_in_search'], $expectedData['is_filterable_in_search']); + $this->assertEquals( + $attribute['is_visible_in_advanced_search'], + $expectedData['is_visible_in_advanced_search'] + ); } /** @@ -200,11 +251,41 @@ protected function createAttribute($attributeCode) 'attribute' => [ 'attribute_code' => $attributeCode, 'frontend_labels' => [ - ['store_id' => 0, 'label' => 'front_lbl'], + [ + 'store_id' => 0, + 'label' => 'front_lbl' + ], ], - 'default_value' => 'default value', - 'frontend_input' => 'textarea', 'is_required' => true, + "default_value" => "", + "frontend_input" => "select", + "is_visible_on_front" => true, + "is_searchable" => true, + "is_visible_in_advanced_search" => true, + "is_filterable" => true, + "is_filterable_in_search" => true, + "options" => [ + [ + "label" => "string", + "value" => "string", + "sort_order" => 0, + "is_default" => true, + "store_labels" => [ + [ + "store_id" => 0, + "label" => "Red" + ], + [ + "store_id" => 1, + "label" => "Blue" + ], + [ + "store_id" => 2, + "label" => "Yellow" + ] + ] + ] + ] ], ]; diff --git a/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Consolidated/ReaderTest.php b/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Consolidated/ReaderTest.php new file mode 100644 index 0000000000000..7ed221f51fe0c --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Consolidated/ReaderTest.php @@ -0,0 +1,47 @@ +fileResolverMock = $this->getMockBuilder('Magento\Framework\Config\FileResolverInterface') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $this->configReader = $objectManager->create( + 'Magento\Integration\Model\Config\Consolidated\Reader', + ['fileResolver' => $this->fileResolverMock] + ); + } + + public function testRead() + { + $configFiles = [ + file_get_contents(realpath(__DIR__ . '/_files/integrationA.xml')), + file_get_contents(realpath(__DIR__ . '/_files/integrationB.xml')) + ]; + $this->fileResolverMock->expects($this->any())->method('get')->will($this->returnValue($configFiles)); + + $expectedResult = require __DIR__ . '/_files/integration.php'; + $this->assertEquals($expectedResult, $this->configReader->read(), 'Error happened during config reading.'); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Consolidated/_files/integration.php b/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Consolidated/_files/integration.php new file mode 100644 index 0000000000000..fc945704cb65c --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Consolidated/_files/integration.php @@ -0,0 +1,53 @@ + [ + 'email' => 'test-integration1@example.com', + 'endpoint_url' => 'http://example.com/endpoint1', + 'identity_link_url' => 'http://www.example.com/identity1', + 'resource' => [ + 'Magento_Customer::customer', + 'Magento_Customer::manage', + 'Magento_Sales::sales', + 'Magento_Sales::sales_operation', + 'Magento_Sales::sales_order', + 'Magento_Sales::actions', + 'Magento_Sales::capture', + 'Magento_Backend::marketing', + 'Magento_CatalogRule::promo', + 'Magento_SalesRule::quote' + ] + ], + 'TestIntegration2' => [ + 'email' => 'test-integration2@example.com', + 'endpoint_url' => 'http://example.com/integration2', + 'identity_link_url' => 'http://www.example.com/identity2', + 'resource' => [ + 'Magento_Sales::sales', + 'Magento_Sales::sales_operation', + 'Magento_Sales::sales_order', + 'Magento_Sales::actions', + 'Magento_Sales::capture', + 'Magento_Backend::stores', + 'Magento_Backend::stores_settings', + 'Magento_Config::config', + 'Magento_SalesRule::config_promo' + ] + ], + 'TestIntegration3' => [ + 'email' => 'test-integration3@example.com', + 'resource' => [ + 'Magento_Sales::sales', + 'Magento_Sales::sales_operation', + 'Magento_Sales::sales_order', + 'Magento_Sales::actions', + 'Magento_Sales::create', + 'Magento_Backend::marketing', + 'Magento_CatalogRule::promo', + 'Magento_SalesRule::quote' + ] + ] +]; diff --git a/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Consolidated/_files/integrationA.xml b/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Consolidated/_files/integrationA.xml new file mode 100644 index 0000000000000..8f7886f9f2049 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Consolidated/_files/integrationA.xml @@ -0,0 +1,32 @@ + + + + + test-integration1@example.com + http://example.com/endpoint1 + http://www.example.com/identity1 + + + + + + + + test-integration2@example.com + + + + + + test-integration3@example.com + + + + + + diff --git a/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Consolidated/_files/integrationB.xml b/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Consolidated/_files/integrationB.xml new file mode 100644 index 0000000000000..deb7209b52001 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Consolidated/_files/integrationB.xml @@ -0,0 +1,17 @@ + + + + + + http://example.com/integration2 + http://www.example.com/identity2 + + + + + diff --git a/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Integration/_files/api.php b/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Integration/_files/api.php index ea849222e9279..ca93839568d51 100644 --- a/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Integration/_files/api.php +++ b/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Integration/_files/api.php @@ -6,41 +6,16 @@ return [ 'TestIntegration1' => [ 'resource' => [ - 'Magento_Customer::customer', 'Magento_Customer::manage', - 'Magento_Sales::sales', - 'Magento_Sales::sales_operation', - 'Magento_Sales::sales_order', - 'Magento_Sales::actions', + 'Magento_Customer::online', 'Magento_Sales::capture', - 'Magento_Backend::marketing', - 'Magento_CatalogRule::promo', - 'Magento_SalesRule::quote' + 'Magento_SalesRule::quote', ], ], 'TestIntegration2' => [ - 'resource' => [ - 'Magento_Sales::sales', - 'Magento_Sales::sales_operation', - 'Magento_Sales::sales_order', - 'Magento_Sales::actions', - 'Magento_Sales::capture', - 'Magento_Backend::stores', - 'Magento_Backend::stores_settings', - 'Magento_Config::config', - 'Magento_SalesRule::config_promo' - ], + 'resource' => ['Magento_Catalog::product_read', 'Magento_SalesRule::config_promo'], ], 'TestIntegration3' => [ - 'resource' => [ - 'Magento_Sales::sales', - 'Magento_Sales::sales_operation', - 'Magento_Sales::sales_order', - 'Magento_Sales::actions', - 'Magento_Sales::create', - 'Magento_Backend::marketing', - 'Magento_CatalogRule::promo', - 'Magento_SalesRule::quote' - ], + 'resource' => ['Magento_Catalog::product_read', 'Magento_Sales::create', 'Magento_SalesRule::quote'], ] ]; diff --git a/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Integration/_files/apiA.xml b/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Integration/_files/apiA.xml index f33218c57e6ae..7a9b177618b8f 100644 --- a/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Integration/_files/apiA.xml +++ b/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Integration/_files/apiA.xml @@ -11,13 +11,14 @@ in etc/acl.xml of modules and subsequently mapped to web APIs in webapi.xml. --> + - + diff --git a/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Integration/_files/apiB.xml b/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Integration/_files/apiB.xml index 9092c8bd0088a..5e4c600480c2d 100644 --- a/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Integration/_files/apiB.xml +++ b/dev/tests/integration/testsuite/Magento/Integration/Model/Config/Integration/_files/apiB.xml @@ -14,6 +14,7 @@ + diff --git a/dev/tests/integration/testsuite/Magento/Integration/Model/Config/ReaderTest.php b/dev/tests/integration/testsuite/Magento/Integration/Model/Config/ReaderTest.php index d044da947d1dc..792699ea16334 100644 --- a/dev/tests/integration/testsuite/Magento/Integration/Model/Config/ReaderTest.php +++ b/dev/tests/integration/testsuite/Magento/Integration/Model/Config/ReaderTest.php @@ -33,8 +33,8 @@ protected function setUp() public function testRead() { $configFiles = [ - file_get_contents(realpath(__DIR__ . '/_files/integrationA.xml')), - file_get_contents(realpath(__DIR__ . '/_files/integrationB.xml')), + file_get_contents(realpath(__DIR__ . '/_files/configA.xml')), + file_get_contents(realpath(__DIR__ . '/_files/configB.xml')), ]; $this->_fileResolverMock->expects($this->any())->method('get')->will($this->returnValue($configFiles)); diff --git a/dev/tests/integration/testsuite/Magento/Integration/Model/Config/_files/integrationA.xml b/dev/tests/integration/testsuite/Magento/Integration/Model/Config/_files/configA.xml similarity index 100% rename from dev/tests/integration/testsuite/Magento/Integration/Model/Config/_files/integrationA.xml rename to dev/tests/integration/testsuite/Magento/Integration/Model/Config/_files/configA.xml diff --git a/dev/tests/integration/testsuite/Magento/Integration/Model/Config/_files/integrationB.xml b/dev/tests/integration/testsuite/Magento/Integration/Model/Config/_files/configB.xml similarity index 100% rename from dev/tests/integration/testsuite/Magento/Integration/Model/Config/_files/integrationB.xml rename to dev/tests/integration/testsuite/Magento/Integration/Model/Config/_files/configB.xml diff --git a/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/expectedPhrases.csv b/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/expectedPhrases.csv index 967c244c1306b..b20a54d1bc0dc 100644 --- a/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/expectedPhrases.csv +++ b/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/expectedPhrases.csv @@ -9,12 +9,12 @@ "first part of concat second part with two placeholders %1, %2","first part of concat second part with two placeholders %1, %2" "first part of concat second part third part with one placeholder %1","first part of concat second part third part with one placeholder %1" "first part of concat second part third part with two placeholders %1, %2","first part of concat second part third part with two placeholders %1, %2" -"string with escaped 'single quotes'","string with escaped 'single quotes'" -"string with placeholder in escaped single quotes '%1'","string with placeholder in escaped single quotes '%1'" +"string with escaped \'single quotes\'","string with escaped \'single quotes\'" +"string with placeholder in escaped single quotes \'%1\'","string with placeholder in escaped single quotes \'%1\'" "string with ""double quotes""","string with ""double quotes""" "string with placeholder in double quotes ""%1""","string with placeholder in double quotes ""%1""" "string with 'single quotes'","string with 'single quotes'" "string with placeholder in single quotes '%1'","string with placeholder in single quotes '%1'" -"string with escaped ""double quotes""","string with escaped ""double quotes""" -"string with placeholder in escaped double quotes ""%1""","string with placeholder in escaped double quotes ""%1""" -"string that's got an unclosed single quote in it","string that's got an unclosed single quote in it" +"string with escaped \"double quotes\"","string with escaped \"double quotes\"" +"string with placeholder in escaped double quotes \"%1\"","string with placeholder in escaped double quotes \"%1\"" +"string that\'s got an unclosed single quote in it","string that\'s got an unclosed single quote in it" diff --git a/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/phrases/TestPhrases.php b/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/phrases/TestPhrases.php index 8b9f786eedc57..e877724dd955a 100644 --- a/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/phrases/TestPhrases.php +++ b/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/phrases/TestPhrases.php @@ -29,7 +29,8 @@ public function awesomeFunction() // Phrase objects $phraseObjects = [ // Single concatenation - new Phrase('first part' . ' second part'), + new Phrase('first part' + . ' second part'), new Phrase('first part' . ' second part' . ' third part'), // Multiple concatenation diff --git a/dev/tests/integration/testsuite/Magento/Setup/Module/I18n/Parser/Adapter/JsTest.php b/dev/tests/integration/testsuite/Magento/Setup/Module/I18n/Parser/Adapter/JsTest.php new file mode 100644 index 0000000000000..0b06f64a24d5f --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Setup/Module/I18n/Parser/Adapter/JsTest.php @@ -0,0 +1,53 @@ +jsPhraseCollector = $objectManager->create( + 'Magento\Setup\Module\I18n\Parser\Adapter\Js' + ); + } + + public function testParse() + { + $file = __DIR__ . '/_files/jsPhrasesForTest.js'; + $this->jsPhraseCollector->parse($file); + $expectation = [ + [ + 'phrase' => 'text double quote', + 'file' => $file, + 'line' => 1, + 'quote' => '"' + ], + [ + 'phrase' => 'text single quote', + 'file' => $file, + 'line' => 2, + 'quote' => '\'' + ], + [ + 'phrase' => 'text "some', + 'file' => $file, + 'line' => 3, + 'quote' => '\'' + ] + ]; + $this->assertEquals($expectation, $this->jsPhraseCollector->getPhrases()); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Setup/Module/I18n/Parser/Adapter/XmlTest.php b/dev/tests/integration/testsuite/Magento/Setup/Module/I18n/Parser/Adapter/XmlTest.php new file mode 100644 index 0000000000000..64cc04347b950 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Setup/Module/I18n/Parser/Adapter/XmlTest.php @@ -0,0 +1,71 @@ +xmlPhraseCollector = $objectManager->create( + 'Magento\Setup\Module\I18n\Parser\Adapter\Xml' + ); + } + + public function testParse() + { + $file = __DIR__ . '/_files/xmlPhrasesForTest.xml'; + $this->xmlPhraseCollector->parse($file); + $expectation = [ + [ + 'phrase' => 'Name only', + 'file' => $file, + 'line' => '', + 'quote' => '' + ], + [ + 'phrase' => 'Name and title space delimiter', + 'file' => $file, + 'line' => '', + 'quote' => '' + ], + [ + 'phrase' => 'title1', + 'file' => $file, + 'line' => '', + 'quote' => '' + ], + [ + 'phrase' => 'title2', + 'file' => $file, + 'line' => '', + 'quote' => '' + ], + [ + 'phrase' => 'Name only in sub node', + 'file' => $file, + 'line' => '', + 'quote' => '' + ], + [ + 'phrase' => 'Text outside of attribute', + 'file' => $file, + 'line' => '', + 'quote' => '' + ] + ]; + $this->assertEquals($expectation, $this->xmlPhraseCollector->getPhrases()); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Setup/Module/I18n/Parser/Adapter/_files/jsPhrasesForTest.js b/dev/tests/integration/testsuite/Magento/Setup/Module/I18n/Parser/Adapter/_files/jsPhrasesForTest.js new file mode 100644 index 0000000000000..1e1afeeec8752 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Setup/Module/I18n/Parser/Adapter/_files/jsPhrasesForTest.js @@ -0,0 +1,3 @@ +$t("text double quote"); +$t('text single quote'); +$t('text "some'); diff --git a/dev/tests/integration/testsuite/Magento/Setup/Module/I18n/Parser/Adapter/_files/xmlPhrasesForTest.xml b/dev/tests/integration/testsuite/Magento/Setup/Module/I18n/Parser/Adapter/_files/xmlPhrasesForTest.xml new file mode 100644 index 0000000000000..d86ad72265b09 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Setup/Module/I18n/Parser/Adapter/_files/xmlPhrasesForTest.xml @@ -0,0 +1,17 @@ + + + + + + + + Name only in sub node + This shouldn't be picked up + + Text outside of attribute + diff --git a/lib/internal/Magento/Framework/Acl/etc/acl.xsd b/lib/internal/Magento/Framework/Acl/etc/acl.xsd index 19cc714573de8..6e5dc8d0fd70c 100644 --- a/lib/internal/Magento/Framework/Acl/etc/acl.xsd +++ b/lib/internal/Magento/Framework/Acl/etc/acl.xsd @@ -49,6 +49,7 @@ + diff --git a/lib/internal/Magento/Framework/Api/DataObjectHelper.php b/lib/internal/Magento/Framework/Api/DataObjectHelper.php index 70a7b79c71b8b..a0b0e1a058afe 100644 --- a/lib/internal/Magento/Framework/Api/DataObjectHelper.php +++ b/lib/internal/Magento/Framework/Api/DataObjectHelper.php @@ -137,7 +137,7 @@ protected function _setDataValues($dataObject, array $data, $interfaceName) } /** - * @param ExtensibleDataInterface $dataObject + * @param mixed $dataObject * @param string $getterMethodName * @param string $methodName * @param array $value @@ -145,7 +145,7 @@ protected function _setDataValues($dataObject, array $data, $interfaceName) * @return $this */ protected function setComplexValue( - ExtensibleDataInterface $dataObject, + $dataObject, $getterMethodName, $methodName, array $value, diff --git a/lib/internal/Magento/Framework/Translate.php b/lib/internal/Magento/Framework/Translate.php index d88f4686ee9e4..86559185ca8b2 100644 --- a/lib/internal/Magento/Framework/Translate.php +++ b/lib/internal/Magento/Framework/Translate.php @@ -332,7 +332,7 @@ protected function _loadPackTranslation() protected function _loadDbTranslation() { $data = $this->_translateResource->getTranslationArray(null, $this->getLocale()); - $this->_addData($data); + $this->_addData(array_map("htmlspecialchars_decode", $data)); return $this; } diff --git a/setup/src/Magento/Setup/Module/I18n/Dictionary/Phrase.php b/setup/src/Magento/Setup/Module/I18n/Dictionary/Phrase.php index 582ca2fcc2919..388ece942db64 100644 --- a/setup/src/Magento/Setup/Module/I18n/Dictionary/Phrase.php +++ b/setup/src/Magento/Setup/Module/I18n/Dictionary/Phrase.php @@ -270,8 +270,9 @@ private function getCompiledString($string) { $encloseQuote = $this->getQuote() == Phrase::QUOTE_DOUBLE ? Phrase::QUOTE_DOUBLE : Phrase::QUOTE_SINGLE; //find all occurrences of ' and ", with no \ before it. - preg_match_all('/(? * */ - const HTML_FILTER = "/i18n:\s?'(?.*)'/i"; + const HTML_FILTER = "/i18n:\s?'(?[^'\\\\]*(?:\\\\.[^'\\\\]*)*)'/i"; /** * {@inheritdoc} diff --git a/setup/src/Magento/Setup/Module/I18n/Parser/Adapter/Js.php b/setup/src/Magento/Setup/Module/I18n/Parser/Adapter/Js.php index 98b45bf38541f..36589fc4bc8ee 100644 --- a/setup/src/Magento/Setup/Module/I18n/Parser/Adapter/Js.php +++ b/setup/src/Magento/Setup/Module/I18n/Parser/Adapter/Js.php @@ -28,6 +28,14 @@ protected function _parse() $this->_addPhrase($quote . $results[$i][2] . $quote, $lineNumber); } } + + preg_match_all('/\\$t\(\s*([\'"])(.*?[^\\\])\1.*?[),]/', $fileRow, $results, PREG_SET_ORDER); + for ($i = 0; $i < count($results); $i++) { + if (isset($results[$i][2])) { + $quote = $results[$i][1]; + $this->_addPhrase($quote . $results[$i][2] . $quote, $lineNumber); + } + } } fclose($fileHandle); } diff --git a/setup/src/Magento/Setup/Module/I18n/Parser/Adapter/Xml.php b/setup/src/Magento/Setup/Module/I18n/Parser/Adapter/Xml.php index dd20f551d5535..78fa737334080 100644 --- a/setup/src/Magento/Setup/Module/I18n/Parser/Adapter/Xml.php +++ b/setup/src/Magento/Setup/Module/I18n/Parser/Adapter/Xml.php @@ -33,6 +33,13 @@ protected function _parse() if ($phrase) { $this->_addPhrase($phrase); } + $elementAttributes = $element->attributes(); + if (isset($elementAttributes[$value])) { + $phrase = (string)$elementAttributes[$value]; + if ($phrase) { + $this->_addPhrase($phrase); + } + } } } } diff --git a/setup/src/Magento/Setup/Test/Unit/Module/I18n/Parser/Adapter/HtmlTest.php b/setup/src/Magento/Setup/Test/Unit/Module/I18n/Parser/Adapter/HtmlTest.php index 8a3a1392b7198..b0bee4db8e8f0 100644 --- a/setup/src/Magento/Setup/Test/Unit/Module/I18n/Parser/Adapter/HtmlTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Module/I18n/Parser/Adapter/HtmlTest.php @@ -39,14 +39,62 @@ public function testParse() [ 'phrase' => 'Phrase 1', 'file' => $this->_testFile, - 'line' => null, - 'quote' => Phrase::QUOTE_SINGLE, + 'line' => '', + 'quote' => '\'', ], [ 'phrase' => 'Phrase 2 with %a_lot of extra info for the brilliant %customer_name.', 'file' => $this->_testFile, - 'line' => null, - 'quote' => Phrase::QUOTE_DOUBLE + 'line' => '', + 'quote' => '"', + ], + [ + 'phrase' => 'This is test data', + 'file' => $this->_testFile, + 'line' => '', + 'quote' => '', + ], + [ + 'phrase' => 'This is test data at right side of attr', + 'file' => $this->_testFile, + 'line' => '', + 'quote' => '', + ], + [ + 'phrase' => 'This is \\\' test \\\' data', + 'file' => $this->_testFile, + 'line' => '', + 'quote' => '', + ], + [ + 'phrase' => 'This is \\" test \\" data', + 'file' => $this->_testFile, + 'line' => '', + 'quote' => '', + ], + [ + 'phrase' => 'This is test data with a quote after', + 'file' => $this->_testFile, + 'line' => '', + 'quote' => '', + ], + [ + 'phrase' => 'This is test data with space after ', + 'file' => $this->_testFile, + 'line' => '', + 'quote' => '', + ], + [ + 'phrase' => '\\\'', + 'file' => $this->_testFile, + 'line' => '', + 'quote' => '', + ], + [ + 'phrase' => '\\\\\\\\ ', + 'file' => $this->_testFile, + 'line' => '', + 'quote' => '', ], ]; diff --git a/setup/src/Magento/Setup/Test/Unit/Module/I18n/Parser/Adapter/_files/email.html b/setup/src/Magento/Setup/Test/Unit/Module/I18n/Parser/Adapter/_files/email.html index 673743e8d54f3..97e4f97f74e36 100644 --- a/setup/src/Magento/Setup/Test/Unit/Module/I18n/Parser/Adapter/_files/email.html +++ b/setup/src/Magento/Setup/Test/Unit/Module/I18n/Parser/Adapter/_files/email.html @@ -20,5 +20,14 @@ %customer_name=$customer_name }} + + + + + + + + +