예제 #1
0
 public function testBeforeSave()
 {
     $this->consumerMock->expects($this->once())->method('setUpdatedAt');
     $this->assertInstanceOf(
         'Magento\Integration\Model\ResourceModel\Oauth\Consumer',
         $this->consumerResource->_beforeSave($this->consumerMock)
     );
 }
예제 #2
0
 protected function tearDown()
 {
     parent::tearDown();
     $this->_oAuthClients = [];
     if (isset(self::$_consumer)) {
         self::$_consumer->delete();
         self::$_token->delete();
     }
 }
예제 #3
0
 public function testGetAccessSuccess()
 {
     $this->_consumerMock->expects($this->any())->method('load')->with(self::VALUE_CONSUMER_ID)->will($this->returnValue($this->_consumerMock));
     $this->_tokenMock->expects($this->once())->method('getType')->will($this->returnValue(Token::TYPE_ACCESS));
     $this->_tokenProviderMock->expects($this->any())->method('getIntegrationTokenByConsumerId')->will($this->returnValue($this->_tokenMock));
     $this->assertEquals($this->_service->getAccessToken(self::VALUE_CONSUMER_ID), $this->_tokenMock);
 }
예제 #4
0
 public function testPostToConsumer()
 {
     $consumerId = 1;
     $key = $this->_generateRandomString(\Magento\Framework\Oauth\Helper\Oauth::LENGTH_CONSUMER_KEY);
     $secret = $this->_generateRandomString(\Magento\Framework\Oauth\Helper\Oauth::LENGTH_CONSUMER_SECRET);
     $oauthVerifier = $this->_generateRandomString(\Magento\Framework\Oauth\Helper\Oauth::LENGTH_TOKEN_VERIFIER);
     $consumerData = ['entity_id' => $consumerId, 'key' => $key, 'secret' => $secret];
     $this->_consumerMock->expects($this->once())->method('load')->with($this->equalTo($consumerId))->will($this->returnSelf());
     $this->_consumerMock->expects($this->once())->method('getId')->will($this->returnValue($consumerId));
     $this->_consumerMock->expects($this->once())->method('getData')->will($this->returnValue($consumerData));
     $this->_httpClientMock->expects($this->once())->method('setUri')->with('http://www.magento.com')->will($this->returnSelf());
     $this->_httpClientMock->expects($this->once())->method('setParameterPost')->will($this->returnSelf());
     $this->_tokenMock->expects($this->once())->method('createVerifierToken')->with($consumerId)->will($this->returnSelf());
     $this->_tokenMock->expects($this->any())->method('getVerifier')->will($this->returnValue($oauthVerifier));
     $this->_dataHelper->expects($this->once())->method('getConsumerPostMaxRedirects')->will($this->returnValue(5));
     $this->_dataHelper->expects($this->once())->method('getConsumerPostTimeout')->will($this->returnValue(120));
     $verifier = $this->_oauthService->postToConsumer($consumerId, 'http://www.magento.com');
     $this->assertEquals($oauthVerifier, $verifier, 'Checking Oauth Verifier');
 }
예제 #5
0
 public function testGetConsumerExpirationPeriodExpired()
 {
     $dateHelperMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\DateTime')->disableOriginalConstructor()->getMock();
     $dateHelperMock->expects($this->at(0))->method('gmtTimestamp')->willReturn(time());
     $dateHelperMock->expects($this->at(1))->method('gmtTimestamp')->willReturn(time() - 1000);
     $dateHelper = new \ReflectionProperty('Magento\\Integration\\Model\\Oauth\\Consumer', '_dateHelper');
     $dateHelper->setAccessible(true);
     $dateHelper->setValue($this->consumerModel, $dateHelperMock);
     $this->consumerModel->setUpdatedAt(time());
     $this->assertFalse($this->consumerModel->isValidForTokenExchange());
 }
예제 #6
0
 public function testGetConsumerExpirationPeriodExpired()
 {
     $this->resourceMock->expects($this->once())->method('getTimeInSecondsSinceCreation')->will($this->returnValue(400));
     $this->consumerModel->setCreatedAt(time());
     $this->assertFalse($this->consumerModel->isValidForTokenExchange());
 }
예제 #7
0
 public function testLoadActiveIntegrationByConsumerId()
 {
     $integration = $this->integration->getResource()->selectActiveIntegrationByConsumerId($this->consumer->getId());
     $this->assertEquals($this->integration->getId(), $integration['integration_id']);
 }
예제 #8
0
 /**
  * \Magento\Framework\Oauth\OauthInterface::ERR_CONSUMER_KEY_REJECTED
  *
  * @expectedException \Magento\Framework\Oauth\Exception
  */
 public function testGetRequestTokenNoConsumer()
 {
     $this->_consumerMock->expects($this->any())->method('loadByKey')->will($this->returnValue(new \Magento\Framework\Object()));
     $this->_oauth->getRequestToken($this->_getRequestTokenParams(), self::REQUEST_URL);
 }