Example #1
0
 public function testProcessRequestTrue()
 {
     $response = new Zend_Controller_Response_Http();
     $response->setBody('Initial response body.');
     $this->_requestProcessor->expects($this->any())->method('extractContent')->will($this->returnValue('Additional response text.'));
     $this->assertTrue($this->_model->processRequest($response));
     $this->assertEquals('Initial response body.Additional response text.', $response->getBody());
 }
Example #2
0
 /**
  * Test insecure request for a secure route
  */
 public function testInSecureRequestOverSecureRoute()
 {
     $this->_serviceMock->expects($this->any())->method(self::SERVICE_METHOD)->will($this->returnValue([]));
     $this->_routeMock->expects($this->any())->method('isSecure')->will($this->returnValue(true));
     $this->_routeMock->expects($this->any())->method('getAclResources')->will($this->returnValue(['1']));
     $this->_requestMock->expects($this->any())->method('isSecure')->will($this->returnValue(false));
     $this->_authorizationMock->expects($this->once())->method('isAllowed')->will($this->returnValue(true));
     // Override default prepareResponse. It should never be called in this case
     $this->_responseMock->expects($this->never())->method('prepareResponse');
     $this->_restController->dispatch($this->_requestMock);
     $this->assertTrue($this->_responseMock->isException());
     $exceptionArray = $this->_responseMock->getException();
     $this->assertEquals('Operation allowed only in HTTPS', $exceptionArray[0]->getMessage());
     $this->assertEquals(\Magento\Framework\Webapi\Exception::HTTP_BAD_REQUEST, $exceptionArray[0]->getHttpCode());
 }
Example #3
0
 protected function setUp()
 {
     $this->deploymentConfigMock = $this->getMock('Magento\\Framework\\App\\DeploymentConfig', [], [], '', false, false);
     $this->_requestMock = $this->getMockBuilder('Magento\\Framework\\Webapi\\Rest\\Request')->setMethods(['isSecure', 'getRequestData', 'getParams', 'getParam', 'getRequestedServices', 'getPathInfo', 'getHttpHost', 'getMethod'])->disableOriginalConstructor()->getMock();
     $this->_requestMock->expects($this->any())->method('getHttpHost')->willReturn('testHostName.com');
     $this->_responseMock = $this->getMockBuilder('Magento\\Framework\\Webapi\\Rest\\Response')->setMethods(['sendResponse', 'prepareResponse', 'setHeader'])->disableOriginalConstructor()->getMock();
     $routerMock = $this->getMockBuilder('Magento\\Webapi\\Controller\\Rest\\Router')->setMethods(['match'])->disableOriginalConstructor()->getMock();
     $this->_routeMock = $this->getMockBuilder('Magento\\Webapi\\Controller\\Rest\\Router\\Route')->setMethods(['isSecure', 'getServiceMethod', 'getServiceClass', 'getAclResources', 'getParameters'])->disableOriginalConstructor()->getMock();
     $objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManagerInterface');
     $this->_serviceMock = $this->getMockBuilder(self::SERVICE_ID)->setMethods([self::SERVICE_METHOD])->disableOriginalConstructor()->getMock();
     $this->_oauthServiceMock = $this->getMockBuilder('\\Magento\\Framework\\Oauth\\OauthInterface')->setMethods(['validateAccessTokenRequest'])->getMockForAbstractClass();
     $this->_authorizationMock = $this->getMockBuilder('Magento\\Framework\\Webapi\\Authorization')->disableOriginalConstructor()->getMock();
     $paramsOverriderMock = $this->getMockBuilder('Magento\\Webapi\\Controller\\Rest\\ParamsOverrider')->setMethods(['overrideParams'])->disableOriginalConstructor()->getMock();
     $dataObjectProcessorMock = $this->getMockBuilder('Magento\\Framework\\Reflection\\DataObjectProcessor')->disableOriginalConstructor()->setMethods(['getMethodReturnType'])->getMockForAbstractClass();
     $this->swaggerGeneratorMock = $this->getMockBuilder('Magento\\Webapi\\Model\\Rest\\Swagger\\Generator')->disableOriginalConstructor()->setMethods(['generate', 'getListOfServices'])->getMockForAbstractClass();
     $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\LayoutInterface')->disableOriginalConstructor()->getMock();
     $errorProcessorMock = $this->getMock('Magento\\Framework\\Webapi\\ErrorProcessor', [], [], '', false);
     $errorProcessorMock->expects($this->any())->method('maskException')->will($this->returnArgument(0));
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->serviceInputProcessorMock = $this->getMockBuilder('\\Magento\\Framework\\Webapi\\ServiceInputProcessor')->disableOriginalConstructor()->setMethods(['process'])->getMock();
     $areaListMock = $this->getMock('\\Magento\\Framework\\App\\AreaList', [], [], '', false);
     $areaMock = $this->getMock('Magento\\Framework\\App\\AreaInterface');
     $areaListMock->expects($this->any())->method('getArea')->will($this->returnValue($areaMock));
     $this->storeMock = $this->getMock('\\Magento\\Store\\Api\\Data\\StoreInterface');
     $this->storeManagerMock = $this->getMock('\\Magento\\Store\\Model\\StoreManagerInterface');
     $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock);
     /** Init SUT. */
     $this->_restController = $objectManager->getObject('Magento\\Webapi\\Controller\\Rest', ['request' => $this->_requestMock, 'response' => $this->_responseMock, 'router' => $routerMock, 'objectManager' => $objectManagerMock, 'layout' => $layoutMock, 'oauthService' => $this->_oauthServiceMock, 'authorization' => $this->_authorizationMock, 'serviceInputProcessor' => $this->serviceInputProcessorMock, 'errorProcessor' => $errorProcessorMock, 'areaList' => $areaListMock, 'paramsOverrider' => $paramsOverriderMock, 'dataObjectProcessor' => $dataObjectProcessorMock, 'swaggerGenerator' => $this->swaggerGeneratorMock, 'storeManager' => $this->storeManagerMock]);
     $this->_restController->setDeploymentConfig($this->deploymentConfigMock);
     // Set default expectations used by all tests
     $this->_routeMock->expects($this->any())->method('getServiceClass')->will($this->returnValue(self::SERVICE_ID));
     $this->_routeMock->expects($this->any())->method('getServiceMethod')->will($this->returnValue(self::SERVICE_METHOD));
     $routerMock->expects($this->any())->method('match')->will($this->returnValue($this->_routeMock));
     $objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($this->_serviceMock));
     $this->_responseMock->expects($this->any())->method('prepareResponse')->will($this->returnValue([]));
     $this->_serviceMock->expects($this->any())->method(self::SERVICE_METHOD)->will($this->returnValue(null));
     $dataObjectProcessorMock->expects($this->any())->method('getMethodReturnType')->with(self::SERVICE_ID, self::SERVICE_METHOD)->will($this->returnValue('null'));
     $paramsOverriderMock->expects($this->any())->method('overrideParams')->will($this->returnValue([]));
     parent::setUp();
 }