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