/** * @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); }
/** * @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); }
/** * Test for getContentType() method. * * @dataProvider providerContentType * @param string $contentTypeHeader 'Content-Type' header value * @param string $contentType Appropriate content type for header value * @param string|boolean $exceptionMessage \Exception message (boolean FALSE if exception is not expected) */ public function testGetContentType($contentTypeHeader, $contentType, $exceptionMessage = false) { $this->_request->expects($this->once())->method('getHeader')->with('Content-Type')->will($this->returnValue($contentTypeHeader)); try { $this->assertEquals($contentType, $this->_request->getContentType()); } catch (\Magento\Webapi\Exception $e) { if ($exceptionMessage) { $this->assertEquals($exceptionMessage, $e->getMessage(), 'Exception message does not match the expected one.'); return; } else { $this->fail('Exception is thrown on valid header: ' . $e->getMessage()); } } if ($exceptionMessage) { $this->fail('Expected exception was not raised.'); } }
/** * @dataProvider invalidFilterDataProvider */ public function testInvalidFilters($invalidFilter) { $this->requestMock->expects($this->any())->method('getParam')->will($this->returnValue($invalidFilter)); $filteredResponse = $this->processor->filter($this->sampleResponseValue); $this->assertEmpty($filteredResponse); }