xref: /PHP-8.2/ext/soap/tests/bugs/bug38005.phpt (revision 8b561d33)
1--TEST--
2Bug #38005 (SoapFault faultstring doesn't follow encoding rules)
3--EXTENSIONS--
4soap
5--INI--
6soap.wsdl_cache_enabled=0
7--FILE--
8<?php
9function Test($param=NULL) {
10    return new SoapFault('Test', 'This is our fault: �');
11}
12
13class TestSoapClient extends SoapClient {
14  private $server;
15
16  function __construct($wsdl, $opt) {
17    parent::__construct($wsdl, $opt);
18    $this->server = new SoapServer($wsdl, $opt);
19    $this->server->addFunction('Test');
20  }
21
22  function __doRequest($request, $location, $action, $version, $one_way = 0): ?string {
23    ob_start();
24    $this->server->handle($request);
25    $response = ob_get_contents();
26    ob_end_clean();
27    return $response;
28  }
29}
30
31$client = new TestSoapClient(NULL, array(
32    'encoding' => 'ISO-8859-1',
33    'uri' => "test://",
34    'location' => "test://",
35    'soap_version'=>SOAP_1_2,
36    'trace'=>1,
37    'exceptions'=>0));
38$res = $client->Test();
39echo($res->faultstring."\n");
40echo($client->__getLastResponse());
41?>
42--EXPECT--
43This is our fault: �
44<?xml version="1.0" encoding="UTF-8"?>
45<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"><env:Body><env:Fault><env:Code><env:Value>Test</env:Value></env:Code><env:Reason><env:Text>This is our fault: Ä</env:Text></env:Reason></env:Fault></env:Body></env:Envelope>
46