From 6c33d206e999554ff26e45ed3ab6d30e70adf1aa Mon Sep 17 00:00:00 2001 From: Ricards Z Date: Mon, 12 Mar 2018 18:55:08 +0200 Subject: [PATCH 1/5] Correctly convert config integration api resources --- .../Integration/Model/Config/Consolidated/Converter.php | 6 ++++++ .../Test/Unit/Model/Config/Consolidated/_files/acl.php | 2 ++ .../Unit/Model/Config/Consolidated/_files/integration.php | 6 +++++- .../Unit/Model/Config/Consolidated/_files/integration.xml | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Integration/Model/Config/Consolidated/Converter.php b/app/code/Magento/Integration/Model/Config/Consolidated/Converter.php index 674a97a68d065..2c5bf5fd4ac82 100644 --- a/app/code/Magento/Integration/Model/Config/Consolidated/Converter.php +++ b/app/code/Magento/Integration/Model/Config/Consolidated/Converter.php @@ -80,6 +80,12 @@ public function convert($source) $result[$integrationName][self::API_RESOURCES][] = $name; } } + + // Add root resource if any child has been added + if (! empty($result[$integrationName][self::API_RESOURCES])) { + array_unshift($result[$integrationName][self::API_RESOURCES], $allResources[1]['id']); + } + // Remove any duplicates added parents $result[$integrationName][self::API_RESOURCES] = array_values(array_unique($result[$integrationName][self::API_RESOURCES])); diff --git a/app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/_files/acl.php b/app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/_files/acl.php index 5b7bbace5a65d..42b62acaba5b4 100644 --- a/app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/_files/acl.php +++ b/app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/_files/acl.php @@ -6,6 +6,8 @@ return [ [], [ + 'id' => 'Magento_Backend::admin', + 'title' => 'Magento Admin (Root)', 'children' => [ [ 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 index 54e05d5ef9017..0293492c77658 100644 --- 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 @@ -9,6 +9,7 @@ 'endpoint_url' => 'http://endpoint.com', 'identity_link_url' => 'http://www.example.com/identity', 'resource' => [ + 'Magento_Backend::admin', 'Magento_Customer::manageParent', 'Magento_Customer::manage', 'Magento_SalesRule::quoteParent', @@ -17,6 +18,9 @@ ], 'TestIntegration2' => [ 'email' => 'test-integration2@magento.com', - 'resource' => ['Magento_Sales::sales'] + 'resource' => [ + 'Magento_Backend::admin', + '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 index 585fabc24299d..f8bcf3fc4a2ce 100644 --- 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 @@ -18,6 +18,7 @@ test-integration2@magento.com + From 0b3fe71e45d9126c60e00f5333ca208bba01c990 Mon Sep 17 00:00:00 2001 From: Ricards Z Date: Tue, 13 Mar 2018 10:07:52 +0200 Subject: [PATCH 2/5] Fixed broken integration test and added additional integration test --- .../Consolidated/_files/integration.php | 3 + .../ConfigBasedIntegrationManagerTest.php | 110 ++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/Integration/Model/ConfigBasedIntegrationManagerTest.php 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 index cc2841f1acf2c..d72a1359dfa52 100644 --- 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 @@ -9,6 +9,7 @@ 'endpoint_url' => 'http://example.com/endpoint1', 'identity_link_url' => 'http://www.example.com/identity1', 'resource' => [ + 'Magento_Backend::admin', 'Magento_Customer::customer', 'Magento_Customer::manage', 'Magento_Sales::sales', @@ -26,6 +27,7 @@ 'endpoint_url' => 'http://example.com/integration2', 'identity_link_url' => 'http://www.example.com/identity2', 'resource' => [ + 'Magento_Backend::admin', 'Magento_Sales::sales', 'Magento_Sales::sales_operation', 'Magento_Sales::sales_order', @@ -40,6 +42,7 @@ 'TestIntegration3' => [ 'email' => 'test-integration3@example.com', 'resource' => [ + 'Magento_Backend::admin', 'Magento_Sales::sales', 'Magento_Sales::sales_operation', 'Magento_Sales::sales_order', diff --git a/dev/tests/integration/testsuite/Magento/Integration/Model/ConfigBasedIntegrationManagerTest.php b/dev/tests/integration/testsuite/Magento/Integration/Model/ConfigBasedIntegrationManagerTest.php new file mode 100644 index 0000000000000..b45b9906e2844 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Integration/Model/ConfigBasedIntegrationManagerTest.php @@ -0,0 +1,110 @@ +consolidatedConfigMock = $this->createMock(\Magento\Integration\Model\ConsolidatedConfig::class); + $objectManager->addSharedInstance( + $this->consolidatedConfigMock, + \Magento\Integration\Model\ConsolidatedConfig::class + ); + $this->integrationManager = $objectManager->create( + \Magento\Integration\Model\ConfigBasedIntegrationManager::class, + [] + ); + $this->integrationService = $objectManager->create( + \Magento\Integration\Api\IntegrationServiceInterface::class, + [] + ); + } + + /** + * @magentoDbIsolation enabled + */ + public function testProcessConfigBasedIntegrations() + { + $newIntegrations = require __DIR__ . '/Config/Consolidated/_files/integration.php'; + $this->consolidatedConfigMock + ->expects($this->any()) + ->method('getIntegrations') + ->willReturn($newIntegrations); + + // Check that the integrations do not exist already + foreach ($newIntegrations as $integrationName => $integrationData) { + $integration = $this->integrationService->findByName($integrationName); + $this->assertEquals(null, $integration->getId(), 'Integration already exists'); + } + + // Create new integrations + $this->assertEquals( + $newIntegrations, + $this->integrationManager->processConfigBasedIntegrations($newIntegrations), + 'Error processing config based integrations.' + ); + $createdIntegrations = []; + + // Check that the integrations are new with "inactive" status + foreach ($newIntegrations as $integrationName => $integrationData) { + $integration = $this->integrationService->findByName($integrationName); + $this->assertNotEmpty($integration->getId(), 'Integration was not created'); + $this->assertEquals( + $integration::STATUS_INACTIVE, + $integration->getStatus(), + 'Integration is not created with "inactive" status' + ); + $createdIntegrations[$integrationName] = $integration; + } + + // Rerun integration creation + $this->assertEquals( + $newIntegrations, + $this->integrationManager->processConfigBasedIntegrations($newIntegrations), + 'Error processing config based integrations.' + ); + + // Check that the integrations are not recreated when data has not actually changed + foreach ($newIntegrations as $integrationName => $integrationData) { + $integration = $this->integrationService->findByName($integrationName); + $this->assertEquals( + $createdIntegrations[$integrationName]->getId(), + $integration->getId(), + 'Integration ID has changed' + ); + $this->assertEquals( + $createdIntegrations[$integrationName]->getStatus(), + $integration->getStatus(), + 'Integration status has changed' + ); + } + } +} From 31b7f072622fe738ec26cfc5c576ac429e8b6337 Mon Sep 17 00:00:00 2001 From: Ricards Z Date: Tue, 13 Mar 2018 10:11:14 +0200 Subject: [PATCH 3/5] Updated comment --- .../Integration/Model/ConfigBasedIntegrationManagerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/integration/testsuite/Magento/Integration/Model/ConfigBasedIntegrationManagerTest.php b/dev/tests/integration/testsuite/Magento/Integration/Model/ConfigBasedIntegrationManagerTest.php index b45b9906e2844..9042354fabb5d 100644 --- a/dev/tests/integration/testsuite/Magento/Integration/Model/ConfigBasedIntegrationManagerTest.php +++ b/dev/tests/integration/testsuite/Magento/Integration/Model/ConfigBasedIntegrationManagerTest.php @@ -85,7 +85,7 @@ public function testProcessConfigBasedIntegrations() $createdIntegrations[$integrationName] = $integration; } - // Rerun integration creation + // Rerun integration creation with the same data (data has not changed) $this->assertEquals( $newIntegrations, $this->integrationManager->processConfigBasedIntegrations($newIntegrations), From 999d8e56b8aa8a4e943692321acbfb3fbb2b5ed1 Mon Sep 17 00:00:00 2001 From: Ricards Z Date: Wed, 14 Mar 2018 09:23:14 +0200 Subject: [PATCH 4/5] Minor refactoring to update code quality --- .../ConfigBasedIntegrationManagerTest.php | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Integration/Model/ConfigBasedIntegrationManagerTest.php b/dev/tests/integration/testsuite/Magento/Integration/Model/ConfigBasedIntegrationManagerTest.php index 9042354fabb5d..af1ee643866f6 100644 --- a/dev/tests/integration/testsuite/Magento/Integration/Model/ConfigBasedIntegrationManagerTest.php +++ b/dev/tests/integration/testsuite/Magento/Integration/Model/ConfigBasedIntegrationManagerTest.php @@ -14,7 +14,7 @@ class ConfigBasedIntegrationManagerTest extends \PHPUnit\Framework\TestCase /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $consolidatedConfigMock; + protected $consolidatedMock; /** * @var \Magento\Integration\Model\ConfigBasedIntegrationManager @@ -26,35 +26,49 @@ class ConfigBasedIntegrationManagerTest extends \PHPUnit\Framework\TestCase */ protected $integrationService; + /** + * @var \Magento\TestFramework\ObjectManager + */ + protected $objectManager; + + /** + * @inheritdoc + */ protected function setUp() { parent::setUp(); - /** - * @var $objectManager \Magento\TestFramework\ObjectManager - */ - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - $this->consolidatedConfigMock = $this->createMock(\Magento\Integration\Model\ConsolidatedConfig::class); - $objectManager->addSharedInstance( - $this->consolidatedConfigMock, + $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $this->consolidatedMock = $this->createMock(\Magento\Integration\Model\ConsolidatedConfig::class); + $this->objectManager->addSharedInstance( + $this->consolidatedMock, \Magento\Integration\Model\ConsolidatedConfig::class ); - $this->integrationManager = $objectManager->create( + $this->integrationManager = $this->objectManager->create( \Magento\Integration\Model\ConfigBasedIntegrationManager::class, [] ); - $this->integrationService = $objectManager->create( + $this->integrationService = $this->objectManager->create( \Magento\Integration\Api\IntegrationServiceInterface::class, [] ); } + /** + * @inheritdoc + */ + protected function tearDown() + { + $this->objectManager->removeSharedInstance(\Magento\Integration\Model\ConsolidatedConfig::class); + parent::tearDown(); + } + /** * @magentoDbIsolation enabled */ public function testProcessConfigBasedIntegrations() { $newIntegrations = require __DIR__ . '/Config/Consolidated/_files/integration.php'; - $this->consolidatedConfigMock + $this->consolidatedMock ->expects($this->any()) ->method('getIntegrations') ->willReturn($newIntegrations); From 401b42318d39e1ebf1973051cea15d0ae85ce02e Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Tue, 7 Aug 2018 11:42:07 +0300 Subject: [PATCH 5/5] Fixed code styles issues --- .../Integration/Model/Config/Consolidated/Converter.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Integration/Model/Config/Consolidated/Converter.php b/app/code/Magento/Integration/Model/Config/Consolidated/Converter.php index 2c5bf5fd4ac82..a2fbd0ffbb496 100644 --- a/app/code/Magento/Integration/Model/Config/Consolidated/Converter.php +++ b/app/code/Magento/Integration/Model/Config/Consolidated/Converter.php @@ -82,13 +82,14 @@ public function convert($source) } // Add root resource if any child has been added - if (! empty($result[$integrationName][self::API_RESOURCES])) { + if (!empty($result[$integrationName][self::API_RESOURCES])) { array_unshift($result[$integrationName][self::API_RESOURCES], $allResources[1]['id']); } // Remove any duplicates added parents - $result[$integrationName][self::API_RESOURCES] = - array_values(array_unique($result[$integrationName][self::API_RESOURCES])); + $result[$integrationName][self::API_RESOURCES] = array_values( + array_unique($result[$integrationName][self::API_RESOURCES]) + ); } return $result; }