protected function setUp()
 {
     $this->_requestMock = $this->getMock('\\Magento\\Framework\\App\\RequestInterface');
     /** Initialize SUT. */
     $details = ['param1' => 'value1', 'param2' => 2];
     $code = 111;
     $webapiException = new \Magento\Framework\Webapi\Exception(__('Soap fault reason.'), $code, \Magento\Framework\Webapi\Exception::HTTP_INTERNAL_ERROR, $details);
     $this->_soapServerMock = $this->getMockBuilder('Magento\\Webapi\\Model\\Soap\\Server')->disableOriginalConstructor()->getMock();
     $this->_soapServerMock->expects($this->any())->method('generateUri')->will($this->returnValue(self::WSDL_URL));
     $this->_localeResolverMock = $this->getMockBuilder('Magento\\Framework\\Locale\\Resolver')->disableOriginalConstructor()->getMock();
     $this->_localeResolverMock->expects($this->any())->method('getLocale')->will($this->returnValue('en_US'));
     $this->_appStateMock = $this->getMock('\\Magento\\Framework\\App\\State', [], [], '', false);
     $this->_soapFault = new \Magento\Webapi\Model\Soap\Fault($this->_requestMock, $this->_soapServerMock, $webapiException, $this->_localeResolverMock, $this->_appStateMock);
     parent::setUp();
 }
Exemplo n.º 2
0
    /**
     * Test handling exception during dispatch.
     */
    public function testDispatchWithException()
    {
        $exceptionMessage = 'some error message';
        $exception = new \Magento\Framework\Webapi\Exception(__($exceptionMessage));
        $this->_soapServerMock->expects($this->any())->method('handle')->will($this->throwException($exception));
        $this->_errorProcessorMock->expects($this->any())->method('maskException')->will($this->returnValue($exception));
        $encoding = "utf-8";
        $this->_soapServerMock->expects($this->any())->method('getApiCharset')->will($this->returnValue($encoding));
        $this->_soapController->dispatch($this->_requestMock);
        $expectedMessage = <<<EXPECTED_MESSAGE
<?xml version="1.0" encoding="{$encoding}"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" >
   <env:Body>
      <env:Fault>
         <env:Code>
            <env:Value>env:Sender</env:Value>
         </env:Code>
         <env:Reason>
            <env:Text xml:lang="en">some error message</env:Text>
         </env:Reason>
      </env:Fault>
   </env:Body>
</env:Envelope>
EXPECTED_MESSAGE;
        $this->assertXmlStringEqualsXmlString($expectedMessage, $this->_responseMock->getBody());
    }
Exemplo n.º 3
0
 /**
  * Test generate uri with wsdl param as true
  */
 public function testGenerateUriWithNoWsdlParam()
 {
     $param = "testModule1AllSoapAndRest:V1,testModule2AllSoapNoRest:V1";
     $serviceKey = \Magento\Webapi\Model\Soap\Server::REQUEST_PARAM_SERVICES;
     $this->_requestMock->expects($this->any())->method('getParam')->will($this->returnValue($param));
     $expectedResult = "http://magento.com/soap/storeCode?{$serviceKey}={$param}";
     $actualResult = $this->_soapServer->generateUri(false);
     $this->assertEquals($expectedResult, urldecode($actualResult), 'URI (without WSDL param) generated is invalid.');
 }
Exemplo n.º 4
0
    /**
     * Generate SOAP fault message in XML format.
     *
     * @param string $reason Human-readable explanation of the fault
     * @param string $code SOAP fault code
     * @param array|null $details Detailed reason message(s)
     * @return string
     */
    public function getSoapFaultMessage($reason, $code, $details = null)
    {
        $detailXml = $this->_generateDetailXml($details);
        $language = $this->getLanguage();
        $detailsNamespace = !empty($detailXml) ? 'xmlns:m="' . urlencode($this->_soapServer->generateUri(true)) . '"' : '';
        $reason = htmlentities($reason);
        $message = <<<FAULT_MESSAGE
<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" {$detailsNamespace}>
   <env:Body>
      <env:Fault>
         <env:Code>
            <env:Value>env:{$code}</env:Value>
         </env:Code>
         <env:Reason>
            <env:Text xml:lang="{$language}">{$reason}</env:Text>
         </env:Reason>
         {$detailXml}
      </env:Fault>
   </env:Body>
</env:Envelope>
FAULT_MESSAGE;
        return $message;
    }
Exemplo n.º 5
0
 /**
  * Replace WSDL xml encoding from config, if present, else default to UTF-8 and set it to the response object.
  *
  * @param string $responseBody
  * @return $this
  */
 protected function _setResponseBody($responseBody)
 {
     $this->_response->setBody(preg_replace('/<\\?xml version="([^\\"]+)"([^\\>]+)>/i', '<?xml version="$1" encoding="' . $this->_soapServer->getApiCharset() . '"?>', $responseBody));
     return $this;
 }