예제 #1
0
 protected function setUp()
 {
     $this->_consumerFactory = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Consumer\\Factory')->disableOriginalConstructor()->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\\Token\\Factory')->disableOriginalConstructor()->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('Magento\\Framework\\Logger')->disableOriginalConstructor()->setMethods(array('logException'))->getMock();
     $this->_oauthService = new \Magento\Integration\Service\V1\Oauth($this->_storeManagerMock, $this->_consumerFactory, $this->_tokenFactory, $this->_dataHelper, $this->_httpClientMock, $this->_loggerMock, $oauthHelperMock, $tokenProviderMock);
 }
예제 #2
0
 public function testCreateAccessTokenInvalidConsumerId()
 {
     $this->_consumerMock->expects($this->any())->method('load')->with(0)->will($this->returnValue($this->_consumerMock));
     $this->_tokenProviderMock->expects($this->any())->method('getIntegrationTokenByConsumerId')->will($this->throwException(new \Magento\Framework\Oauth\Exception('A token with consumer ID 0 does not exist')));
     $this->_tokenMock->expects($this->never())->method('delete');
     $this->_tokenFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->_tokenMock));
     $this->_tokenMock->expects($this->once())->method('createVerifierToken');
     $this->_tokenProviderMock->expects($this->once())->method('createRequestToken');
     $this->_tokenProviderMock->expects($this->once())->method('getAccessToken');
     $this->assertTrue($this->_service->createAccessToken(0, false));
 }
예제 #3
0
 public function setUp()
 {
     $this->_consumerFactory = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Consumer\\Factory')->disableOriginalConstructor()->getMock();
     $this->_consumerMock = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Consumer')->disableOriginalConstructor()->setMethods(array('getCreatedAt', 'loadByKey', 'load', 'getId', 'getSecret', 'getCallbackUrl', 'save', 'getData', '__wakeup'))->getMock();
     $this->_consumerFactory->expects($this->any())->method('create')->will($this->returnValue($this->_consumerMock));
     $this->_nonceFactory = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Nonce\\Factory')->disableOriginalConstructor()->getMock();
     $this->_tokenFactory = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Token\\Factory')->disableOriginalConstructor()->getMock();
     $this->_tokenMock = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Token')->disableOriginalConstructor()->setMethods(array('getId', 'load', 'getType', 'createRequestToken', 'getToken', 'getSecret', 'createVerifierToken', 'getVerifier', 'getConsumerId', 'convertToAccess', 'getRevoked', '__wakeup'))->getMock();
     $this->_tokenFactory->expects($this->any())->method('create')->will($this->returnValue($this->_tokenMock));
     $this->_oauthHelperMock = $this->getMockBuilder('Magento\\Framework\\Oauth\\Helper\\Oauth')->setConstructorArgs(array(new \Magento\Framework\Math\Random()))->getMock();
     $this->_dataHelperMock = $this->getMockBuilder('Magento\\Integration\\Helper\\Oauth\\Data')->disableOriginalConstructor()->getMock();
     $this->_httpUtilityMock = $this->getMockBuilder('Zend_Oauth_Http_Utility')->setMethods(array('sign'))->getMock();
     $this->_dateMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\DateTime')->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->_dataHelperMock, $this->_dateMock);
     $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);
 }