|
| 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