/** * @return void */ protected function setUp() { $this->_consumerFactory = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\ConsumerFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->_tokenProviderMock = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Token\\Provider')->disableOriginalConstructor()->getMock(); $this->_tokenMock = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Token')->disableOriginalConstructor()->setMethods(['createVerifierToken', 'getType', '__wakeup', 'delete'])->getMock(); $this->_tokenFactoryMock = $this->getMock('Magento\\Integration\\Model\\Oauth\\TokenFactory', ['create'], [], '', false); $this->_tokenFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->_tokenMock)); $this->_consumerMock = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Consumer')->disableOriginalConstructor()->setMethods(['getData', 'getId', 'load', 'save', 'delete', '__wakeup'])->getMock(); $this->_consumerData = ['entity_id' => self::VALUE_CONSUMER_ID, 'key' => self::VALUE_CONSUMER_KEY, 'secret' => 'iuyytrfdsdfbnnhbmkkjlkjl', 'created_at' => '', 'updated_at' => '', 'callback_url' => '', 'rejected_callback_url' => '']; $this->_consumerFactory->expects($this->any())->method('create')->will($this->returnValue($this->_consumerMock)); $this->_service = new \Magento\Integration\Model\OauthService($this->getMock('Magento\\Store\\Model\\StoreManagerInterface', [], [], '', false), $this->_consumerFactory, $this->_tokenFactoryMock, $this->getMock('Magento\\Integration\\Helper\\Oauth\\Data', [], [], '', false), $this->getMock('Magento\\Framework\\HTTP\\ZendClient', [], [], '', false), $this->getMock('Psr\\Log\\LoggerInterface'), $this->getMock('Magento\\Framework\\Oauth\\Helper\\Oauth', [], [], '', false), $this->_tokenProviderMock); $this->_emptyConsumerMock = $this->getMockBuilder('Magento\\Integration\\Model\\Integration')->disableOriginalConstructor()->setMethods(['getData', 'load', 'getId', 'save', 'delete', '__wakeup'])->getMock(); $this->_emptyConsumerMock->expects($this->any())->method('getId')->will($this->returnValue(null)); }
/** * @expectedException \Magento\Framework\Oauth\Exception * @expectedExceptionMessage A consumer having the specified key does not exist */ public function testGetConsumerByKeyNonExistentConsumer() { $consumerKeyString = '12345678901234567890123456789012'; $consumerId = null; $this->consumerFactoryMock->expects($this->once())->method('create')->willReturn($this->consumerMock); $this->consumerMock->expects($this->once())->method('loadByKey')->with($consumerKeyString)->willReturnSelf(); $this->consumerMock->expects($this->once())->method('getId')->willReturn($consumerId); $this->tokenProvider->getConsumerByKey($consumerKeyString); }
protected function setUp() { $this->_consumerFactory = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\ConsumerFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->_consumerMock = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Consumer')->disableOriginalConstructor()->getMock(); $this->_consumerFactory->expects($this->any())->method('create')->will($this->returnValue($this->_consumerMock)); $this->_tokenFactory = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\TokenFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->_tokenMock = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Token')->disableOriginalConstructor()->getMock(); $this->_tokenFactory->expects($this->any())->method('create')->will($this->returnValue($this->_tokenMock)); $this->_storeManagerMock = $this->getMockBuilder('Magento\\Store\\Model\\StoreManagerInterface')->disableOriginalConstructor()->getMockForAbstractClass(); $this->_storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $this->_storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($this->_storeMock)); $this->_dataHelper = $this->getMockBuilder('Magento\\Integration\\Helper\\Oauth\\Data')->disableOriginalConstructor()->getMock(); $oauthHelperMock = $this->getMockBuilder('Magento\\Framework\\Oauth\\Helper\\Oauth')->disableOriginalConstructor()->getMock(); $tokenProviderMock = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Token\\Provider')->disableOriginalConstructor()->getMock(); $this->_httpClientMock = $this->getMockBuilder('Magento\\Framework\\HTTP\\ZendClient')->disableOriginalConstructor()->getMock(); $this->_loggerMock = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->getMock(); $this->_oauthService = new \Magento\Integration\Model\OauthService($this->_storeManagerMock, $this->_consumerFactory, $this->_tokenFactory, $this->_dataHelper, $this->_httpClientMock, $this->_loggerMock, $oauthHelperMock, $tokenProviderMock); }
public function setUp() { $this->_consumerFactory = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\ConsumerFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->_consumerMock = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Consumer')->disableOriginalConstructor()->setMethods(['getCreatedAt', 'loadByKey', 'load', 'getId', 'getSecret', 'getCallbackUrl', 'save', 'getData', 'isValidForTokenExchange', '__wakeup'])->getMock(); $this->_consumerFactory->expects($this->any())->method('create')->will($this->returnValue($this->_consumerMock)); $this->_nonceFactory = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\NonceFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->_tokenFactory = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\TokenFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->_tokenMock = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Token')->disableOriginalConstructor()->setMethods(['getId', 'load', 'getType', 'createRequestToken', 'getToken', 'getSecret', 'createVerifierToken', 'getVerifier', 'getConsumerId', 'convertToAccess', 'getRevoked', 'getResource', 'loadByConsumerIdAndUserType', '__wakeup'])->getMock(); $this->_tokenFactory->expects($this->any())->method('create')->will($this->returnValue($this->_tokenMock)); $this->_oauthHelperMock = $this->getMockBuilder('Magento\\Framework\\Oauth\\Helper\\Oauth')->setConstructorArgs([new \Magento\Framework\Math\Random()])->getMock(); $this->_httpUtilityMock = $this->getMockBuilder('Zend_Oauth_Http_Utility')->setMethods(['sign'])->getMock(); $this->_dateMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\DateTime')->disableOriginalConstructor()->getMock(); $this->_loggerMock = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->disableOriginalConstructor()->getMock(); $nonceGenerator = new \Magento\Integration\Model\Oauth\Nonce\Generator($this->_oauthHelperMock, $this->_nonceFactory, $this->_dateMock); $tokenProvider = new \Magento\Integration\Model\Oauth\Token\Provider($this->_consumerFactory, $this->_tokenFactory, $this->_loggerMock); $this->_oauth = new \Magento\Framework\Oauth\Oauth($this->_oauthHelperMock, $nonceGenerator, $tokenProvider, $this->_httpUtilityMock); $this->_oauthToken = $this->_generateRandomString(\Magento\Framework\Oauth\Helper\Oauth::LENGTH_TOKEN); $this->_oauthSecret = $this->_generateRandomString(\Magento\Framework\Oauth\Helper\Oauth::LENGTH_TOKEN_SECRET); $this->_oauthVerifier = $this->_generateRandomString(\Magento\Framework\Oauth\Helper\Oauth::LENGTH_TOKEN_VERIFIER); }