xref: /PHP-8.3/ext/soap/tests/bugs/bug47273.phpt (revision 7f2f0c00)
1--TEST--
2Bug #47273 (Encoding bug in SoapServer->fault)
3--EXTENSIONS--
4soap
5--FILE--
6<?php
7$request1 = <<<EOF
8<?xml version="1.0" encoding="UTF-8"?>
9<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://127.0.0.1:8080/test/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:test1/></SOAP-ENV:Body></SOAP-ENV:Envelope>
10EOF;
11$request2 = <<<EOF
12<?xml version="1.0" encoding="UTF-8"?>
13<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://127.0.0.1:8080/test/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:test2/></SOAP-ENV:Body></SOAP-ENV:Envelope>
14EOF;
15
16class SoapFaultTest
17{
18    public function test1() {
19        //  Test #1
20        return 'Test #1 exception with some special chars: Äßö';
21    }
22    public function test2() {
23        //  Test #2
24    //throw new SoapFault('Server', 'Test #2 exception with some special chars: Äßö');
25        throw new Exception('Test #2 exception with some special chars: Äßö');
26    }
27}
28
29$server = new SoapServer(null, array(
30'uri' => "http://127.0.0.1:8080/test/",
31'encoding' => 'ISO-8859-1'));
32$server->setClass('SoapFaultTest');
33
34try {
35    $server->handle($request1);
36} catch (Exception $e) {
37    $server->fault("Sender", $e->getMessage());
38}
39try {
40        $server->handle($request2);
41} catch (Exception $e) {
42        $server->fault("Sender", $e->getMessage());
43}
44?>
45--EXPECT--
46<?xml version="1.0" encoding="UTF-8"?>
47<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://127.0.0.1:8080/test/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:test1Response><return xsi:type="xsd:string">Test #1 exception with some special chars: Äßö</return></ns1:test1Response></SOAP-ENV:Body></SOAP-ENV:Envelope>
48<?xml version="1.0" encoding="UTF-8"?>
49<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>Sender</faultcode><faultstring>Test #2 exception with some special chars: Äßö</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
50