/** * Test the basic Request action. */ public function testRequestAction() { $this->request->expects($this->any())->method('getMethod')->willReturn('GET'); $this->helperMock->expects($this->once())->method('getRequestUrl'); $this->helperMock->expects($this->once())->method('prepareRequest'); $this->frameworkOauthSvcMock->expects($this->once())->method('getRequestToken')->willReturn(['response']); $this->response->expects($this->once())->method('setBody'); $this->requestAction->execute(); }
public function testAuthorizationFailed() { $this->_authorizationMock->expects($this->once())->method('isAllowed')->will($this->returnValue(false)); $this->_oauthServiceMock->expects($this->any())->method('validateAccessTokenRequest')->will($this->returnValue('fred')); $this->_routeMock->expects($this->any())->method('getAclResources')->will($this->returnValue(['5', '6'])); $this->_restController->dispatch($this->_requestMock); /** Ensure that response contains proper error message. */ $expectedMsg = 'Consumer is not authorized to access 5, 6'; AuthorizationException::NOT_AUTHORIZED; $this->assertTrue($this->_responseMock->isException()); $exceptionArray = $this->_responseMock->getException(); $this->assertEquals($expectedMsg, $exceptionArray[0]->getMessage()); }
/** * Test the basic Access action. */ public function testAccessAction() { $this->request->expects($this->any())->method('getMethod')->willReturn('GET'); $this->helperMock->expects($this->once())->method('getRequestUrl'); $this->helperMock->expects($this->once())->method('prepareRequest'); $this->frameworkOauthSvcMock->expects($this->once())->method('getAccessToken')->willReturn(['response']); /** @var \Magento\Integration\Model\Oauth\Consumer|\PHPUnit_Framework_MockObject_MockObject */ $consumerMock = $this->getMock('Magento\\Integration\\Model\\Oauth\\Consumer', [], [], '', false); $consumerMock->expects($this->once())->method('getId'); $this->intOauthServiceMock->expects($this->once())->method('loadConsumerByKey')->willReturn($consumerMock); /** @var \Magento\Integration\Model\Integration|\PHPUnit_Framework_MockObject_MockObject */ $integrationMock = $this->getMock('Magento\\Integration\\Model\\Integration', [], [], '', false); $integrationMock->expects($this->once())->method('save')->willReturnSelf(); $this->integrationServiceMock->expects($this->once())->method('findByConsumerId')->willReturn($integrationMock); $this->response->expects($this->once())->method('setBody'); $this->accessAction->executeInternal(); }