示例#1
0
 /**
  * {@inheritdoc}
  */
 public function dispatch(\Magento\Framework\App\RequestInterface $request)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'dispatch');
     if (!$pluginInfo) {
         return parent::dispatch($request);
     } else {
         return $this->___callPlugins('dispatch', func_get_args(), $pluginInfo);
     }
 }
示例#2
0
 public function testGetMethodAllStoresInvalid()
 {
     $this->_routeMock->expects($this->any())->method('getAclResources')->will($this->returnValue(['1']));
     $this->_authorizationMock->expects($this->any())->method('isAllowed')->will($this->returnValue(true));
     $this->storeMock->expects($this->once())->method('getCode')->willReturn('admin');
     $this->_requestMock->expects($this->once())->method('getMethod')->willReturn('get');
     $this->_restController->dispatch($this->_requestMock);
     $this->assertTrue($this->_responseMock->isException());
     $this->assertSame("Cannot perform GET operation with store code 'all'", $this->_responseMock->getException()[0]->getMessage());
 }
示例#3
0
 /**
  * @param array $requestData Data from the request
  * @param array $parameters Data from config about which parameters to override
  * @param array $expectedOverriddenParams Result of overriding $requestData when applying rules from $parameters
  *
  * @dataProvider overrideParmasDataProvider
  */
 public function testOverrideParams($requestData, $parameters, $expectedOverriddenParams)
 {
     $this->_routeMock->expects($this->once())->method('getParameters')->will($this->returnValue($parameters));
     $this->_appStateMock->expects($this->any())->method('isInstalled')->will($this->returnValue(true));
     $this->_authzServiceMock->expects($this->once())->method('isAllowed')->will($this->returnValue(true));
     $this->_requestMock->expects($this->any())->method('getRequestData')->will($this->returnValue($requestData));
     // serializer should expect overridden params
     $this->serializerMock->expects($this->once())->method('getInputData')->with($this->equalTo('Magento\\Webapi\\Controller\\TestService'), $this->equalTo('testMethod'), $this->equalTo($expectedOverriddenParams));
     $this->_restController->dispatch($this->_requestMock);
 }
示例#4
0
 /**
  * @param array $requestData Data from the request
  * @param array $parameters Data from config about which parameters to override
  * @param array $expectedOverriddenParams Result of overriding $requestData when applying rules from $parameters
  * @param int $userId The id of the user invoking the request
  * @param int $userType The type of user invoking the request
  *
  * @dataProvider overrideParmasDataProvider
  */
 public function testOverrideParams($requestData, $parameters, $expectedOverriddenParams, $userId, $userType)
 {
     $this->_routeMock->expects($this->once())->method('getParameters')->will($this->returnValue($parameters));
     $this->_routeMock->expects($this->any())->method('getAclResources')->will($this->returnValue(['1']));
     $this->_authorizationMock->expects($this->once())->method('isAllowed')->will($this->returnValue(true));
     $this->_requestMock->expects($this->any())->method('getRequestData')->will($this->returnValue($requestData));
     $this->userContextMock->expects($this->any())->method('getUserId')->will($this->returnValue($userId));
     $this->userContextMock->expects($this->any())->method('getUserType')->will($this->returnValue($userType));
     // serializer should expect overridden params
     $this->serializerMock->expects($this->once())->method('getInputData')->with($this->equalTo('Magento\\Webapi\\Controller\\TestService'), $this->equalTo('testMethod'), $this->equalTo($expectedOverriddenParams));
     $this->_restController->dispatch($this->_requestMock);
 }
示例#5
0
 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());
 }
示例#6
0
 public function testDispatchAllSchemaRequest()
 {
     $params = [\Magento\Framework\Webapi\Request::REQUEST_PARAM_SERVICES => 'all'];
     $this->_requestMock->expects($this->any())->method('getPathInfo')->willReturn(\Magento\Webapi\Controller\Rest::SCHEMA_PATH);
     $this->_requestMock->expects($this->any())->method('getParam')->will($this->returnValueMap([[\Magento\Framework\Webapi\Request::REQUEST_PARAM_SERVICES, null, 'all']]));
     $this->_requestMock->expects($this->any())->method('getParams')->will($this->returnValue($params));
     $this->_requestMock->expects($this->any())->method('getRequestedServices')->will($this->returnValue('all'));
     $schema = 'Some REST schema content';
     $this->swaggerGeneratorMock->expects($this->any())->method('generate')->willReturn($schema);
     $this->swaggerGeneratorMock->expects($this->once())->method('getListOfServices')->willReturn(['listOfServices']);
     $this->_restController->dispatch($this->_requestMock);
     $this->assertEquals($schema, $this->_responseMock->getBody());
 }