/**
  * @param int|null $integrationId
  * @param array $oauthRequest
  * @return void
  */
 public function setupUserId($integrationId, $oauthRequest)
 {
     $integration = $this->getMockBuilder('Magento\\Integration\\Model\\Integration')->disableOriginalConstructor()->setMethods(['getId', '__wakeup'])->getMock();
     $this->integrationService->expects($this->any())->method('findActiveIntegrationByConsumerId')->will($this->returnValue($integration));
     $this->oauthRequestHelper->expects($this->once())->method('prepareRequest')->will($this->returnValue($oauthRequest));
     $this->oauthService->expects($this->any())->method('validateAccessTokenRequest')->will($this->returnValue(1));
     $integration->expects($this->any())->method('getId')->will($this->returnValue($integrationId));
 }
Пример #2
0
 /**
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testAfterProcessConfigBasedIntegrationsSuccess()
 {
     $firstInegrationId = 1;
     $integrationsData1 = ['id' => $firstInegrationId, Integration::NAME => 'TestIntegration1', Integration::EMAIL => '*****@*****.**', 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 => '*****@*****.**', 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]);
 }
Пример #3
0
 public function testProcessIntegrationConfigSuccess()
 {
     $this->_integrationConfigMock->expects($this->once())->method('getIntegrations')->will($this->returnValue(['TestIntegration1' => ['email' => '*****@*****.**', 'endpoint_url' => 'http://endpoint.com', 'identity_link_url' => 'http://www.example.com/identity'], 'TestIntegration2' => ['email' => '*****@*****.**']]));
     $intLookupData1 = new \Magento\Framework\DataObject(['id' => 1, Integration::NAME => 'TestIntegration1', Integration::SETUP_TYPE => 1]);
     $intUpdateData1 = [Integration::ID => 1, Integration::NAME => 'TestIntegration1', Integration::EMAIL => '*****@*****.**', Integration::ENDPOINT => 'http://endpoint.com', Integration::IDENTITY_LINK_URL => 'http://www.example.com/identity', Integration::SETUP_TYPE => 1];
     $integrationsData2 = [Integration::NAME => 'TestIntegration2', Integration::EMAIL => '*****@*****.**', Integration::SETUP_TYPE => 1];
     $this->_integrationServiceMock->expects($this->at(0))->method('findByName')->with('TestIntegration1')->will($this->returnValue($intLookupData1));
     $this->_integrationServiceMock->expects($this->once())->method('create')->with($integrationsData2);
     $this->_integrationServiceMock->expects($this->at(2))->method('findByName')->with('TestIntegration2')->will($this->returnValue(new \Magento\Framework\DataObject([])));
     $this->_integrationServiceMock->expects($this->once())->method('update')->with($intUpdateData1);
     $this->_integrationManager->processIntegrationConfig(['TestIntegration1', 'TestIntegration2']);
 }
Пример #4
0
 public function testProcessIntegrationConfigCreateNewIntegrations()
 {
     $integrations = ['TestIntegration1' => [Integration::EMAIL => '*****@*****.**', Integration::ENDPOINT => 'http://endpoint.com', Integration::IDENTITY_LINK_URL => 'http://www.example.com/identity'], 'TestIntegration2' => [Integration::EMAIL => '*****@*****.**', Integration::ENDPOINT => 'http://endpoint.com', Integration::IDENTITY_LINK_URL => 'http://www.example.com/identity']];
     $newResources = ['Magento_Customer::manage', 'Magento_Customer::customer'];
     $this->_integrationConfigMock->expects($this->once())->method('getIntegrations')->willReturn($newResources);
     $integrationObject = $this->getMockBuilder('Magento\\Integration\\Model\\Integration')->disableOriginalConstructor()->setMethods([])->getMock();
     // Integration1 does not exist, so create it
     $this->_integrationServiceMock->expects($this->at(0))->method('findByName')->with('TestIntegration1')->will($this->returnValue($integrationObject));
     $integrationObject->expects($this->any())->method('getId')->willReturn(false);
     $this->_integrationServiceMock->expects($this->any())->method('create');
     // Integration2 does not exist, so create it
     $this->_integrationServiceMock->expects($this->at(2))->method('findByName')->with('TestIntegration2')->will($this->returnValue($integrationObject));
     $this->_integrationManager->processIntegrationConfig($integrations);
 }
 /**
  * @dataProvider getValidTokenData
  */
 public function testValidToken($userType, $userId, $expectedUserType, $expectedUserId)
 {
     $bearerToken = 'bearer1234';
     $this->request->expects($this->once())->method('getHeader')->with('Authorization')->will($this->returnValue("Bearer {$bearerToken}"));
     $token = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Token')->disableOriginalConstructor()->setMethods(['loadByToken', 'getId', 'getUserType', 'getCustomerId', 'getAdminId', '__wakeup'])->getMock();
     $this->tokenFactory->expects($this->once())->method('create')->will($this->returnValue($token));
     $token->expects($this->once())->method('loadByToken')->with($bearerToken)->will($this->returnSelf());
     $token->expects($this->once())->method('getId')->will($this->returnValue(1));
     $token->expects($this->once())->method('getUserType')->will($this->returnValue($userType));
     $integration = $this->getMockBuilder('Magento\\Integration\\Model\\Integration')->disableOriginalConstructor()->setMethods(['getId', '__wakeup'])->getMock();
     switch ($userType) {
         case UserContextInterface::USER_TYPE_INTEGRATION:
             $integration->expects($this->once())->method('getId')->will($this->returnValue($userId));
             $this->integrationService->expects($this->once())->method('findByConsumerId')->will($this->returnValue($integration));
             break;
         case UserContextInterface::USER_TYPE_ADMIN:
             $token->expects($this->once())->method('getAdminId')->will($this->returnValue($userId));
             break;
         case UserContextInterface::USER_TYPE_CUSTOMER:
             $token->expects($this->once())->method('getCustomerId')->will($this->returnValue($userId));
             break;
     }
     $this->assertEquals($expectedUserType, $this->tokenUserContext->getUserType());
     $this->assertEquals($expectedUserId, $this->tokenUserContext->getUserId());
     /* check again to make sure that the above methods were only called once */
     $this->assertEquals($expectedUserType, $this->tokenUserContext->getUserType());
     $this->assertEquals($expectedUserId, $this->tokenUserContext->getUserId());
 }
Пример #6
0
 /**
  * Test the basic Access action.
  */
 public function testAccessAction()
 {
     $this->request->expects($this->any())->method('getMethod')->willReturn('GET');
     $this->helperMock->expects($this->once())->method('getRequestUrl');
     $this->helperMock->expects($this->once())->method('prepareRequest');
     $this->frameworkOauthSvcMock->expects($this->once())->method('getAccessToken')->willReturn(['response']);
     /** @var \Magento\Integration\Model\Oauth\Consumer|\PHPUnit_Framework_MockObject_MockObject */
     $consumerMock = $this->getMock('Magento\\Integration\\Model\\Oauth\\Consumer', [], [], '', false);
     $consumerMock->expects($this->once())->method('getId');
     $this->intOauthServiceMock->expects($this->once())->method('loadConsumerByKey')->willReturn($consumerMock);
     /** @var \Magento\Integration\Model\Integration|\PHPUnit_Framework_MockObject_MockObject */
     $integrationMock = $this->getMock('Magento\\Integration\\Model\\Integration', [], [], '', false);
     $integrationMock->expects($this->once())->method('save')->willReturnSelf();
     $this->integrationServiceMock->expects($this->once())->method('findByConsumerId')->willReturn($integrationMock);
     $this->response->expects($this->once())->method('setBody');
     $this->accessAction->executeInternal();
 }