123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Webapi\Test\Unit\Model\Plugin;
- use Magento\Integration\Model\Integration;
- class ManagerTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * Integration service mock
- *
- * @var \Magento\Integration\Api\IntegrationServiceInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $integrationServiceMock;
- /**
- * Authorization service mock
- *
- * @var \Magento\Integration\Api\AuthorizationServiceInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $integrationAuthorizationServiceMock;
- /**
- * API setup plugin
- *
- * @var \Magento\Webapi\Model\Plugin\Manager
- */
- protected $apiSetupPlugin;
- /**
- * @var \Magento\Integration\Model\ConfigBasedIntegrationManager|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $subjectMock;
- /**
- * @var \Magento\Integration\Model\IntegrationConfig|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $integrationConfigMock;
- protected function setUp()
- {
- $this->integrationServiceMock = $this->getMockBuilder(
- \Magento\Integration\Api\IntegrationServiceInterface::class
- )->disableOriginalConstructor()->setMethods(
- [
- 'findByName',
- 'update',
- 'create',
- 'get',
- 'findByConsumerId',
- 'findActiveIntegrationByConsumerId',
- 'delete',
- 'getSelectedResources'
- ]
- )->getMock();
- $this->integrationAuthorizationServiceMock = $this->getMockBuilder(
- \Magento\Integration\Api\AuthorizationServiceInterface::class
- )->disableOriginalConstructor()->setMethods(
- [
- 'grantPermissions',
- 'grantAllPermissions',
- 'removePermissions'
- ]
- )->getMock();
- $this->subjectMock = $this->createMock(\Magento\Integration\Model\ConfigBasedIntegrationManager::class);
- $this->integrationConfigMock = $this->getMockBuilder(\Magento\Integration\Model\IntegrationConfig::class)
- ->disableOriginalConstructor()
- ->setMethods([])
- ->getMock();
- $this->apiSetupPlugin = new \Magento\Webapi\Model\Plugin\Manager(
- $this->integrationAuthorizationServiceMock,
- $this->integrationServiceMock,
- $this->integrationConfigMock
- );
- }
- public function testAfterProcessIntegrationConfigNoIntegrations()
- {
- $this->integrationConfigMock->expects($this->never())->method('getIntegrations');
- $this->integrationServiceMock->expects($this->never())->method('findByName');
- $this->apiSetupPlugin->afterProcessIntegrationConfig($this->subjectMock, []);
- }
- /**
- * @return void
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function testAfterProcessIntegrationConfigSuccess()
- {
- $testIntegration1Resource = [
- 'Magento_Customer::manage',
- 'Magento_Customer::online',
- 'Magento_Sales::create',
- 'Magento_SalesRule::quote',
- ];
- $testIntegration2Resource = ['Magento_Catalog::product_read'];
- $this->integrationConfigMock->expects(
- $this->once()
- )->method(
- 'getIntegrations'
- )->will(
- $this->returnValue(
- [
- 'TestIntegration1' => ['resource' => $testIntegration1Resource],
- 'TestIntegration2' => ['resource' => $testIntegration2Resource],
- ]
- )
- );
- $firstIntegrationId = 1;
- $integrationsData1 = new \Magento\Framework\DataObject(
- [
- 'id' => $firstIntegrationId,
- Integration::NAME => 'TestIntegration1',
- Integration::EMAIL => 'test-integration1@magento.com',
- Integration::ENDPOINT => 'http://endpoint.com',
- Integration::SETUP_TYPE => 1,
- ]
- );
- $secondIntegrationId = 2;
- $integrationsData2 = new \Magento\Framework\DataObject(
- [
- 'id' => $secondIntegrationId,
- Integration::NAME => 'TestIntegration2',
- Integration::EMAIL => 'test-integration2@magento.com',
- Integration::SETUP_TYPE => 1,
- ]
- );
- $this->integrationServiceMock->expects(
- $this->at(0)
- )->method(
- 'findByName'
- )->with(
- 'TestIntegration1'
- )->will(
- $this->returnValue($integrationsData1)
- );
- $this->integrationServiceMock->expects(
- $this->at(1)
- )->method(
- 'findByName'
- )->with(
- 'TestIntegration2'
- )->will(
- $this->returnValue($integrationsData2)
- );
- $this->apiSetupPlugin->afterProcessIntegrationConfig(
- $this->subjectMock,
- ['TestIntegration1', 'TestIntegration2']
- );
- }
- public function testAfterProcessConfigBasedIntegrationsNoIntegrations()
- {
- $this->integrationServiceMock->expects($this->never())->method('findByName');
- $this->apiSetupPlugin->afterProcessConfigBasedIntegrations($this->subjectMock, []);
- }
- /**
- * @return void
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function testAfterProcessConfigBasedIntegrationsSuccess()
- {
- $firstIntegrationId = 1;
- $integrationsData1 = [
- 'id' => $firstIntegrationId,
- Integration::NAME => 'TestIntegration1',
- Integration::EMAIL => 'test-integration1@magento.com',
- Integration::ENDPOINT => 'http://endpoint.com',
- Integration::SETUP_TYPE => 1,
- 'resource' => [
- 'Magento_Customer::manage',
- 'Magento_Customer::online',
- 'Magento_Sales::create',
- 'Magento_SalesRule::quote',
- ]
- ];
- $integrationsData1Object = new \Magento\Framework\DataObject($integrationsData1);
- $secondIntegrationId = 2;
- $integrationsData2 = [
- 'id' => $secondIntegrationId,
- Integration::NAME => 'TestIntegration2',
- Integration::EMAIL => 'test-integration2@magento.com',
- Integration::SETUP_TYPE => 1,
- 'resource' => ['Magento_Catalog::product_read']
- ];
- $integrationsData2Object = new \Magento\Framework\DataObject($integrationsData2);
- $this->integrationServiceMock->expects(
- $this->at(0)
- )->method(
- 'findByName'
- )->with(
- 'TestIntegration1'
- )->will(
- $this->returnValue($integrationsData1Object)
- );
- $this->integrationServiceMock->expects(
- $this->at(1)
- )->method(
- 'findByName'
- )->with(
- 'TestIntegration2'
- )->will(
- $this->returnValue($integrationsData2Object)
- );
- $this->apiSetupPlugin->afterProcessConfigBasedIntegrations(
- $this->subjectMock,
- ['TestIntegration1' => $integrationsData1, 'TestIntegration2' => $integrationsData2]
- );
- }
- }
|