1--TEST--
2SOAP customized Content-Type, eg. SwA use case
3--SKIPIF--
4<?php
5    require_once('skipif.inc');
6
7    if (!file_exists(__DIR__ . "/../../../sapi/cli/tests/php_cli_server.inc")) {
8        echo "skip sapi/cli/tests/php_cli_server.inc required but not found";
9    }
10?>
11--CONFLICTS--
12server
13--FILE--
14<?php
15
16include __DIR__ . "/../../../sapi/cli/tests/php_cli_server.inc";
17
18$args = substr(PHP_OS, 0, 3) == 'WIN'
19    ? ["-d", "extension_dir=" . ini_get("extension_dir"), "-d", "extension=php_soap.dll"] : [];
20$code = <<<'PHP'
21/* Receive */
22$content = trim(file_get_contents("php://input")) . PHP_EOL;
23PHP;
24
25php_cli_server_start($code, null, $args);
26
27$client = new soapclient(NULL, [
28  'location' => 'http://' . PHP_CLI_SERVER_ADDRESS,
29  'uri' => 'misc-uri',
30  'soap_version' => SOAP_1_2,
31  'user_agent' => 'Vincent JARDIN, test headers',
32  'trace' => true, /* record the headers before sending */
33  'stream_context' => stream_context_create([
34    'http' => [
35      'header' => sprintf("MIME-Version: 1.0\r\n"),
36      'content_type' => sprintf("Multipart/Related")
37    ],
38  ]),
39]);
40
41$client->__soapCall("foo", [ 'arg1' => "XXXbar"]);
42
43$headers = $client->__getLastRequestHeaders();
44
45if (strpos($headers, 'Multipart/Related; action="misc-uri#foo"') === FALSE)
46  printf("Content-Type NOK %s" . PHP_EOL, $headers);
47else
48  printf("Content-Type OK" . PHP_EOL);
49
50/*
51 * In case of an empty content-type, let's fallback to the default content.
52 */
53$client2 = new soapclient(NULL, [
54  'location' => 'http://' . PHP_CLI_SERVER_ADDRESS,
55  'uri' => 'misc-uri',
56  'soap_version' => SOAP_1_2,
57  'user_agent' => 'Vincent JARDIN, test headers',
58  'trace' => true, /* record the headers before sending */
59  'stream_context' => stream_context_create([
60    'http' => [
61      'header' => sprintf("MIME-Version: 1.0\r\n"),
62      'content_type' => sprintf("")
63    ],
64  ]),
65]);
66
67$client2->__soapCall("foo", [ 'arg1' => "XXXbar"]);
68
69$headers = $client2->__getLastRequestHeaders();
70
71if (strpos($headers, 'Content-Type: application/soap+xml; charset=utf-8; action="misc-uri#foo"') === FALSE)
72  printf("Content-Type Default NOK %s" . PHP_EOL, $headers);
73else
74  printf("Content-Type Default OK" . PHP_EOL);
75?>
76--EXPECT--
77Content-Type OK
78Content-Type Default OK
79