示例#1
0
 protected function setUp()
 {
     $this->_consumerFactory = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Consumer\\Factory')->disableOriginalConstructor()->getMock();
     $this->_tokenProviderMock = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Token\\Provider')->disableOriginalConstructor()->getMock();
     $this->_tokenMock = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Token')->disableOriginalConstructor()->setMethods(array('createVerifierToken', 'getType', '__wakeup', 'delete'))->getMock();
     $this->_tokenFactoryMock = $this->getMock('Magento\\Integration\\Model\\Oauth\\Token\\Factory', array(), array(), '', false);
     $this->_consumerMock = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Consumer')->disableOriginalConstructor()->setMethods(array('getData', 'getId', 'load', 'save', 'delete', '__wakeup'))->getMock();
     $this->_consumerData = array('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\Service\V1\Oauth($this->getMock('Magento\\Store\\Model\\StoreManagerInterface', array(), array(), '', false), $this->_consumerFactory, $this->_tokenFactoryMock, $this->getMock('Magento\\Integration\\Helper\\Oauth\\Data', array(), array(), '', false), $this->getMock('Magento\\Framework\\HTTP\\ZendClient', array(), array(), '', false), $this->getMock('Magento\\Framework\\Logger', array(), array(), '', false), $this->getMock('Magento\\Framework\\Oauth\\Helper\\Oauth', array(), array(), '', false), $this->_tokenProviderMock);
     $this->_emptyConsumerMock = $this->getMockBuilder('Magento\\Integration\\Model\\Integration')->disableOriginalConstructor()->setMethods(array('getData', 'load', 'getId', 'save', 'delete', '__wakeup'))->getMock();
     $this->_emptyConsumerMock->expects($this->any())->method('getId')->will($this->returnValue(null));
 }
示例#2
0
 /**
  * Load consumer by id.
  *
  * @param int $consumerId
  * @return ConsumerModel
  * @throws \Magento\Integration\Exception
  */
 protected function _loadConsumerById($consumerId)
 {
     $consumer = $this->_consumerFactory->create()->load($consumerId);
     if (!$consumer->getId()) {
         throw new \Magento\Integration\Exception(__("Consumer with ID '%1' does not exist.", $consumerId));
     }
     return $consumer;
 }
示例#3
0
 /**
  * Get consumer by consumer_id for a given token.
  *
  * @param int $consumerId
  * @return \Magento\Framework\Oauth\ConsumerInterface
  * @throws \Magento\Framework\Oauth\Exception
  */
 protected function _getConsumer($consumerId)
 {
     $consumer = $this->_consumerFactory->create()->load($consumerId);
     if (!$consumer->getId()) {
         throw new \Magento\Framework\Oauth\Exception('A consumer with the ID %1 does not exist', [$consumerId]);
     }
     return $consumer;
 }
示例#4
0
 /**
  * Get Token Consumer
  *
  * @return \Magento\Integration\Model\Oauth\Consumer
  */
 public function getConsumer()
 {
     if (!$this->getData('consumer')) {
         $consumer = $this->_consumerFactory->create()->load($this->getConsumerId());
         $this->setData('consumer', $consumer);
     }
     return $this->getData('consumer');
 }
示例#5
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\\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\\Framework\\Store\\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\Service\V1\Oauth($this->_storeManagerMock, $this->_consumerFactory, $this->_tokenFactory, $this->_dataHelper, $this->_httpClientMock, $this->_loggerMock, $oauthHelperMock, $tokenProviderMock);
 }
示例#6
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);
 }