xref: /php-src/ext/soap/tests/schema/schema086.phpt (revision b34b4d54)
1--TEST--
2SOAP XML Schema 86: DateTimeInterface date/time types
3--EXTENSIONS--
4soap
5xml
6--FILE--
7<?php
8include "test_schema.inc";
9$schema = <<<EOF
10    <complexType name="testType">
11        <sequence>
12            <element name="dateTime" type="dateTime"/>
13            <element name="time" type="time"/>
14            <element name="date" type="date"/>
15            <element name="gYearMonth" type="gYearMonth"/>
16            <element name="gYear" type="gYear"/>
17            <element name="gMonthDay" type="gMonthDay"/>
18            <element name="gDay" type="gDay"/>
19            <element name="gMonth" type="gMonth"/>
20        </sequence>
21    </complexType>
22EOF;
23
24$test_dates = [
25    new DateTime("2023-10-14 13:37:42.1234+02:00"),
26    new DateTimeImmutable("2023-10-14 13:37:42.1234+02:00"),
27    new DateTime("2023-10-14 13:37:42.1234Z"),
28];
29
30foreach ($test_dates as $date) {
31    test_schema($schema,'type="tns:testType"',array(
32        'dateTime' => $date,
33        'time' => $date,
34        'date' => $date,
35        'gYearMonth' => $date,
36        'gYear' => $date,
37        'gMonthDay' => $date,
38        'gDay' => $date,
39        'gMonth' => $date
40    ));
41}
42echo "ok";
43?>
44--EXPECTF--
45<?xml version="1.0" encoding="UTF-8"?>
46<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://test-uri/" 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:test><testParam xsi:type="ns1:testType"><dateTime xsi:type="xsd:dateTime">2023-10-14T13:37:42.123400+02:00</dateTime><time xsi:type="xsd:time">13:37:42.123400+02:00</time><date xsi:type="xsd:date">2023-10-14+02:00</date><gYearMonth xsi:type="xsd:gYearMonth">2023-10+02:00</gYearMonth><gYear xsi:type="xsd:gYear">2023+02:00</gYear><gMonthDay xsi:type="xsd:gMonthDay">--10-14+02:00</gMonthDay><gDay xsi:type="xsd:gDay">---14+02:00</gDay><gMonth xsi:type="xsd:gMonth">--10--+02:00</gMonth></testParam></ns1:test></SOAP-ENV:Body></SOAP-ENV:Envelope>
47object(stdClass)#%d (8) {
48  ["dateTime"]=>
49  string(32) "2023-10-14T13:37:42.123400+02:00"
50  ["time"]=>
51  string(21) "13:37:42.123400+02:00"
52  ["date"]=>
53  string(16) "2023-10-14+02:00"
54  ["gYearMonth"]=>
55  string(13) "2023-10+02:00"
56  ["gYear"]=>
57  string(10) "2023+02:00"
58  ["gMonthDay"]=>
59  string(13) "--10-14+02:00"
60  ["gDay"]=>
61  string(11) "---14+02:00"
62  ["gMonth"]=>
63  string(12) "--10--+02:00"
64}
65<?xml version="1.0" encoding="UTF-8"?>
66<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://test-uri/" 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:test><testParam xsi:type="ns1:testType"><dateTime xsi:type="xsd:dateTime">2023-10-14T13:37:42.123400+02:00</dateTime><time xsi:type="xsd:time">13:37:42.123400+02:00</time><date xsi:type="xsd:date">2023-10-14+02:00</date><gYearMonth xsi:type="xsd:gYearMonth">2023-10+02:00</gYearMonth><gYear xsi:type="xsd:gYear">2023+02:00</gYear><gMonthDay xsi:type="xsd:gMonthDay">--10-14+02:00</gMonthDay><gDay xsi:type="xsd:gDay">---14+02:00</gDay><gMonth xsi:type="xsd:gMonth">--10--+02:00</gMonth></testParam></ns1:test></SOAP-ENV:Body></SOAP-ENV:Envelope>
67object(stdClass)#9 (8) {
68  ["dateTime"]=>
69  string(32) "2023-10-14T13:37:42.123400+02:00"
70  ["time"]=>
71  string(21) "13:37:42.123400+02:00"
72  ["date"]=>
73  string(16) "2023-10-14+02:00"
74  ["gYearMonth"]=>
75  string(13) "2023-10+02:00"
76  ["gYear"]=>
77  string(10) "2023+02:00"
78  ["gMonthDay"]=>
79  string(13) "--10-14+02:00"
80  ["gDay"]=>
81  string(11) "---14+02:00"
82  ["gMonth"]=>
83  string(12) "--10--+02:00"
84}
85<?xml version="1.0" encoding="UTF-8"?>
86<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://test-uri/" 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:test><testParam xsi:type="ns1:testType"><dateTime xsi:type="xsd:dateTime">2023-10-14T13:37:42.123400Z</dateTime><time xsi:type="xsd:time">13:37:42.123400Z</time><date xsi:type="xsd:date">2023-10-14Z</date><gYearMonth xsi:type="xsd:gYearMonth">2023-10Z</gYearMonth><gYear xsi:type="xsd:gYear">2023Z</gYear><gMonthDay xsi:type="xsd:gMonthDay">--10-14Z</gMonthDay><gDay xsi:type="xsd:gDay">---14Z</gDay><gMonth xsi:type="xsd:gMonth">--10--Z</gMonth></testParam></ns1:test></SOAP-ENV:Body></SOAP-ENV:Envelope>
87object(stdClass)#8 (8) {
88  ["dateTime"]=>
89  string(27) "2023-10-14T13:37:42.123400Z"
90  ["time"]=>
91  string(16) "13:37:42.123400Z"
92  ["date"]=>
93  string(11) "2023-10-14Z"
94  ["gYearMonth"]=>
95  string(8) "2023-10Z"
96  ["gYear"]=>
97  string(5) "2023Z"
98  ["gMonthDay"]=>
99  string(8) "--10-14Z"
100  ["gDay"]=>
101  string(6) "---14Z"
102  ["gMonth"]=>
103  string(7) "--10--Z"
104}
105ok
106