Skip to content

Commit 5815a20

Browse files
committed
Fixed broken integration test and added additional integration test
1 parent 89a0a09 commit 5815a20

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

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' => '[email protected]',
4244
'resource' => [
45+
'Magento_Backend::admin',
4346
'Magento_Sales::sales',
4447
'Magento_Sales::sales_operation',
4548
'Magento_Sales::sales_order',
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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 $consolidatedConfigMock;
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+
protected function setUp()
30+
{
31+
parent::setUp();
32+
/**
33+
* @var $objectManager \Magento\TestFramework\ObjectManager
34+
*/
35+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
36+
$this->consolidatedConfigMock = $this->createMock(\Magento\Integration\Model\ConsolidatedConfig::class);
37+
$objectManager->addSharedInstance(
38+
$this->consolidatedConfigMock,
39+
\Magento\Integration\Model\ConsolidatedConfig::class
40+
);
41+
$this->integrationManager = $objectManager->create(
42+
\Magento\Integration\Model\ConfigBasedIntegrationManager::class,
43+
[]
44+
);
45+
$this->integrationService = $objectManager->create(
46+
\Magento\Integration\Api\IntegrationServiceInterface::class,
47+
[]
48+
);
49+
}
50+
51+
/**
52+
* @magentoDbIsolation enabled
53+
*/
54+
public function testProcessConfigBasedIntegrations()
55+
{
56+
$newIntegrations = require __DIR__ . '/Config/Consolidated/_files/integration.php';
57+
$this->consolidatedConfigMock
58+
->expects($this->any())
59+
->method('getIntegrations')
60+
->willReturn($newIntegrations);
61+
62+
// Check that the integrations do not exist already
63+
foreach ($newIntegrations as $integrationName => $integrationData) {
64+
$integration = $this->integrationService->findByName($integrationName);
65+
$this->assertEquals(null, $integration->getId(), 'Integration already exists');
66+
}
67+
68+
// Create new integrations
69+
$this->assertEquals(
70+
$newIntegrations,
71+
$this->integrationManager->processConfigBasedIntegrations($newIntegrations),
72+
'Error processing config based integrations.'
73+
);
74+
$createdIntegrations = [];
75+
76+
// Check that the integrations are new with "inactive" status
77+
foreach ($newIntegrations as $integrationName => $integrationData) {
78+
$integration = $this->integrationService->findByName($integrationName);
79+
$this->assertNotEmpty($integration->getId(), 'Integration was not created');
80+
$this->assertEquals(
81+
$integration::STATUS_INACTIVE,
82+
$integration->getStatus(),
83+
'Integration is not created with "inactive" status'
84+
);
85+
$createdIntegrations[$integrationName] = $integration;
86+
}
87+
88+
// Rerun integration creation
89+
$this->assertEquals(
90+
$newIntegrations,
91+
$this->integrationManager->processConfigBasedIntegrations($newIntegrations),
92+
'Error processing config based integrations.'
93+
);
94+
95+
// Check that the integrations are not recreated when data has not actually changed
96+
foreach ($newIntegrations as $integrationName => $integrationData) {
97+
$integration = $this->integrationService->findByName($integrationName);
98+
$this->assertEquals(
99+
$createdIntegrations[$integrationName]->getId(),
100+
$integration->getId(),
101+
'Integration ID has changed'
102+
);
103+
$this->assertEquals(
104+
$createdIntegrations[$integrationName]->getStatus(),
105+
$integration->getStatus(),
106+
'Integration status has changed'
107+
);
108+
}
109+
}
110+
}

0 commit comments

Comments
 (0)