8 use \Magento\Integration\Model\Integration;
41 $this->integrationServiceMock = $this->getMockBuilder(
43 )->disableOriginalConstructor()->setMethods(
50 'findActiveIntegrationByConsumerId',
52 'getSelectedResources' 56 $this->aclRetriever = $this->getMockBuilder(\
Magento\Authorization\Model\Acl\AclRetriever::class)
57 ->disableOriginalConstructor()
62 ->disableOriginalConstructor()
65 $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
67 $this->integrationManager = $objectManagerHelper->getObject(
70 'integrationService' => $this->integrationServiceMock,
71 'aclRetriever' => $this->aclRetriever,
72 'integrationConfig' => $this->configMock
79 unset($this->integrationServiceMock);
80 unset($this->integrationManager);
85 $this->configMock->expects($this->never())->method(
'getIntegrations');
86 $this->integrationManager->processIntegrationConfig([]);
91 $this->configMock->expects(
98 'TestIntegration1' => [
100 'endpoint_url' =>
'http://endpoint.com',
101 'identity_link_url' =>
'http://www.example.com/identity',
107 $intLookupData1 = $this->getMockBuilder(\
Magento\
Integration\Model\Integration::class)
108 ->disableOriginalConstructor()
111 $intLookupData1->expects($this->any())->method(
'getId')->willReturn(1);
112 $intLookupData2 = $this->getMockBuilder(\
Magento\
Integration\Model\Integration::class)
113 ->disableOriginalConstructor()
116 $intLookupData1->expects($this->any())->method(
'getId')->willReturn(
false);
126 $integrationsData2 = [
131 $this->integrationServiceMock->expects(
138 $this->returnValue($intLookupData1)
140 $this->integrationServiceMock->expects($this->once())->method(
'create')->with($integrationsData2);
141 $this->integrationServiceMock->expects(
148 $this->returnValue($intLookupData2)
150 $this->integrationServiceMock->expects($this->at(1))->method(
'update')->with($intUpdateData1);
151 $this->integrationManager->processIntegrationConfig([
'TestIntegration1',
'TestIntegration2']);
165 'TestIntegration1' => [
170 'Magento_Customer::manage',
171 'Magento_Customer::customer' 175 $originalResources = [
176 'Magento_Customer::manage' 179 'Magento_Customer::manage',
180 'Magento_Customer::customer' 183 $integrationObject = $this->getMockBuilder(\
Magento\
Integration\Model\Integration::class)
184 ->disableOriginalConstructor()
189 $this->integrationServiceMock->expects($this->at(0))->method(
'findByName')->with(
'TestIntegration1')->will(
190 $this->returnValue($integrationObject)
192 $this->aclRetriever->expects($this->once())->method(
'getAllowedResourcesByUser')
193 ->willReturn($originalResources);
194 $integrationObject->expects($this->any())->method(
'getId')->willReturn($originalData[
Integration::ID]);
195 $this->integrationServiceMock->expects($this->once())->method(
'update')->willReturn($integrationObject);
197 $integrationObject->expects($this->once())->method(
'getOrigData')->willReturn($originalData);
198 $integrationObject->expects($this->once())->method(
'getData')->willReturn($newResources);
200 $this->integrationServiceMock->expects($this->once())->method(
'create');
202 $this->integrationManager->processConfigBasedIntegrations($integrations);
208 'TestIntegration1' => [
213 'Magento_Customer::manage',
214 'Magento_Customer::customer' 217 'TestIntegration2' => [
224 $integrationObject = $this->getMockBuilder(\
Magento\
Integration\Model\Integration::class)
225 ->disableOriginalConstructor()
230 $this->integrationServiceMock->expects($this->at(0))->method(
'findByName')->with(
'TestIntegration1')->will(
231 $this->returnValue($integrationObject)
233 $integrationObject->expects($this->any())->method(
'getId')->willReturn(
false);
234 $this->integrationServiceMock->expects($this->any())->method(
'create');
237 $this->integrationServiceMock->expects($this->at(2))->method(
'findByName')->with(
'TestIntegration2')->will(
238 $this->returnValue($integrationObject)
241 $this->integrationManager->processConfigBasedIntegrations($integrations);
testProcessIntegrationConfigNoIntegrations()
testProcessConfigBasedIntegrationsCreateNewIntegrations()
testProcessConfigBasedIntegrationsRecreateUpdatedConfigAfterResourceChange()
testProcessIntegrationConfigSuccess()