Skip to content

Commit cb6997c

Browse files
ENGCOM-3053: [Forwardport] Correctly convert config integration api resources #18273
- Merge Pull Request #18273 from mage2pratik/magento2:2.3-develop-PR-port-14065 - Merged commits: 1. 6c33d20 2. 0b3fe71 3. 31b7f07 4. 999d8e5 5. 401b423
2 parents 4b0750c + 401b423 commit cb6997c

File tree

6 files changed

+144
-3
lines changed

6 files changed

+144
-3
lines changed

app/code/Magento/Integration/Model/Config/Consolidated/Converter.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,16 @@ public function convert($source)
8080
$result[$integrationName][self::API_RESOURCES][] = $name;
8181
}
8282
}
83+
84+
// Add root resource if any child has been added
85+
if (!empty($result[$integrationName][self::API_RESOURCES])) {
86+
array_unshift($result[$integrationName][self::API_RESOURCES], $allResources[1]['id']);
87+
}
88+
8389
// Remove any duplicates added parents
84-
$result[$integrationName][self::API_RESOURCES] =
85-
array_values(array_unique($result[$integrationName][self::API_RESOURCES]));
90+
$result[$integrationName][self::API_RESOURCES] = array_values(
91+
array_unique($result[$integrationName][self::API_RESOURCES])
92+
);
8693
}
8794
return $result;
8895
}

app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/_files/acl.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
return [
77
[],
88
[
9+
'id' => 'Magento_Backend::admin',
10+
'title' => 'Magento Admin (Root)',
911
'children' =>
1012
[
1113
[

app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/_files/integration.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'endpoint_url' => 'http://endpoint.com',
1010
'identity_link_url' => 'http://www.example.com/identity',
1111
'resource' => [
12+
'Magento_Backend::admin',
1213
'Magento_Customer::manageParent',
1314
'Magento_Customer::manage',
1415
'Magento_SalesRule::quoteParent',
@@ -17,6 +18,9 @@
1718
],
1819
'TestIntegration2' => [
1920
'email' => 'test-integration2@magento.com',
20-
'resource' => ['Magento_Sales::sales']
21+
'resource' => [
22+
'Magento_Backend::admin',
23+
'Magento_Sales::sales'
24+
]
2125
]
2226
];

app/code/Magento/Integration/Test/Unit/Model/Config/Consolidated/_files/integration.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<integration name="TestIntegration2">
1919
<email>test-integration2@magento.com</email>
2020
<resources>
21+
<resource name="Magento_Backend::admin" />
2122
<resource name="Magento_Sales::sales" />
2223
</resources>
2324
</integration>

dev/tests/integration/testsuite/Magento/Integration/Model/Config/Consolidated/_files/integration.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'endpoint_url' => 'http://example.com/endpoint1',
1010
'identity_link_url' => 'http://www.example.com/identity1',
1111
'resource' => [
12+
'Magento_Backend::admin',
1213
'Magento_Customer::customer',
1314
'Magento_Customer::manage',
1415
'Magento_Sales::sales',
@@ -26,6 +27,7 @@
2627
'endpoint_url' => 'http://example.com/integration2',
2728
'identity_link_url' => 'http://www.example.com/identity2',
2829
'resource' => [
30+
'Magento_Backend::admin',
2931
'Magento_Sales::sales',
3032
'Magento_Sales::sales_operation',
3133
'Magento_Sales::sales_order',
@@ -40,6 +42,7 @@
4042
'TestIntegration3' => [
4143
'email' => 'test-integration3@example.com',
4244
'resource' => [
45+
'Magento_Backend::admin',
4346
'Magento_Sales::sales',
4447
'Magento_Sales::sales_operation',
4548
'Magento_Sales::sales_order',
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Integration\Model;
8+
9+
/**
10+
* Test class for \Magento\Integration\Model\ConfigBasedIntegrationManager.php.
11+
*/
12+
class ConfigBasedIntegrationManagerTest extends \PHPUnit\Framework\TestCase
13+
{
14+
/**
15+
* @var \PHPUnit_Framework_MockObject_MockObject
16+
*/
17+
protected $consolidatedMock;
18+
19+
/**
20+
* @var \Magento\Integration\Model\ConfigBasedIntegrationManager
21+
*/
22+
protected $integrationManager;
23+
24+
/**
25+
* @var \Magento\Integration\Api\IntegrationServiceInterface
26+
*/
27+
protected $integrationService;
28+
29+
/**
30+
* @var \Magento\TestFramework\ObjectManager
31+
*/
32+
protected $objectManager;
33+
34+
/**
35+
* @inheritdoc
36+
*/
37+
protected function setUp()
38+
{
39+
parent::setUp();
40+
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
41+
$this->consolidatedMock = $this->createMock(\Magento\Integration\Model\ConsolidatedConfig::class);
42+
$this->objectManager->addSharedInstance(
43+
$this->consolidatedMock,
44+
\Magento\Integration\Model\ConsolidatedConfig::class
45+
);
46+
$this->integrationManager = $this->objectManager->create(
47+
\Magento\Integration\Model\ConfigBasedIntegrationManager::class,
48+
[]
49+
);
50+
$this->integrationService = $this->objectManager->create(
51+
\Magento\Integration\Api\IntegrationServiceInterface::class,
52+
[]
53+
);
54+
}
55+
56+
/**
57+
* @inheritdoc
58+
*/
59+
protected function tearDown()
60+
{
61+
$this->objectManager->removeSharedInstance(\Magento\Integration\Model\ConsolidatedConfig::class);
62+
parent::tearDown();
63+
}
64+
65+
/**
66+
* @magentoDbIsolation enabled
67+
*/
68+
public function testProcessConfigBasedIntegrations()
69+
{
70+
$newIntegrations = require __DIR__ . '/Config/Consolidated/_files/integration.php';
71+
$this->consolidatedMock
72+
->expects($this->any())
73+
->method('getIntegrations')
74+
->willReturn($newIntegrations);
75+
76+
// Check that the integrations do not exist already
77+
foreach ($newIntegrations as $integrationName => $integrationData) {
78+
$integration = $this->integrationService->findByName($integrationName);
79+
$this->assertEquals(null, $integration->getId(), 'Integration already exists');
80+
}
81+
82+
// Create new integrations
83+
$this->assertEquals(
84+
$newIntegrations,
85+
$this->integrationManager->processConfigBasedIntegrations($newIntegrations),
86+
'Error processing config based integrations.'
87+
);
88+
$createdIntegrations = [];
89+
90+
// Check that the integrations are new with "inactive" status
91+
foreach ($newIntegrations as $integrationName => $integrationData) {
92+
$integration = $this->integrationService->findByName($integrationName);
93+
$this->assertNotEmpty($integration->getId(), 'Integration was not created');
94+
$this->assertEquals(
95+
$integration::STATUS_INACTIVE,
96+
$integration->getStatus(),
97+
'Integration is not created with "inactive" status'
98+
);
99+
$createdIntegrations[$integrationName] = $integration;
100+
}
101+
102+
// Rerun integration creation with the same data (data has not changed)
103+
$this->assertEquals(
104+
$newIntegrations,
105+
$this->integrationManager->processConfigBasedIntegrations($newIntegrations),
106+
'Error processing config based integrations.'
107+
);
108+
109+
// Check that the integrations are not recreated when data has not actually changed
110+
foreach ($newIntegrations as $integrationName => $integrationData) {
111+
$integration = $this->integrationService->findByName($integrationName);
112+
$this->assertEquals(
113+
$createdIntegrations[$integrationName]->getId(),
114+
$integration->getId(),
115+
'Integration ID has changed'
116+
);
117+
$this->assertEquals(
118+
$createdIntegrations[$integrationName]->getStatus(),
119+
$integration->getStatus(),
120+
'Integration status has changed'
121+
);
122+
}
123+
}
124+
}

0 commit comments

Comments
 (0)