/** * @expectedException \Magento\Framework\Oauth\Exception * @expectedExceptionMessage Cannot create request token because consumer token is not a verifier token */ public function testCreateRequestTokenIncorrectType() { $consumerId = 1; $tokenId = 1; $tokenMock = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Token')->setMethods(['loadByConsumerIdAndUserType', 'getId', 'getType', 'createRequestToken'])->disableOriginalConstructor()->getMock(); $tokenMock->expects($this->once())->method('loadByConsumerIdAndUserType')->with($consumerId, UserContextInterface::USER_TYPE_INTEGRATION); $this->tokenFactoryMock->expects($this->once())->method('create')->willReturn($tokenMock); $tokenMock->expects($this->any())->method('getId')->willReturn($tokenId); $tokenMock->expects($this->any())->method('getType')->willReturn('incorrectType'); $this->consumerMock->expects($this->once())->method('getId')->willReturn($consumerId); $this->tokenProvider->createRequestToken($this->consumerMock); }
/** * {@inheritdoc} */ public function createAccessToken($consumerId, $clearExistingToken = false) { try { $consumer = $this->_consumerFactory->create()->load($consumerId); $existingToken = $this->_tokenProvider->getIntegrationTokenByConsumerId($consumer->getId()); if ($existingToken && $clearExistingToken) { $existingToken->delete(); unset($existingToken); } } catch (\Exception $e) { } if (!isset($existingToken)) { $consumer = $this->_consumerFactory->create()->load($consumerId); $this->_tokenFactory->create()->createVerifierToken($consumerId); $this->_tokenProvider->createRequestToken($consumer); $this->_tokenProvider->getAccessToken($consumer); return true; } return false; }