xref: /PHP-5.5/ext/dom/tests/canonicalization.phpt (revision a7aa62de)
1--TEST--
2Test: Canonicalization - C14N()
3--SKIPIF--
4<?php require_once('skipif.inc'); ?>
5--FILE--
6<?php
7$xml = <<<EOXML
8<?xml version="1.0" encoding="ISO-8859-1" ?>
9<foo xmlns="http://www.example.com/ns/foo"
10     xmlns:fubar="http://www.example.com/ns/fubar" xmlns:test="urn::test"><contain>
11  <bar><test1 /></bar>
12  <bar><test2 /></bar>
13  <fubar:bar xmlns:fubar="http://www.example.com/ns/fubar"><test3 /></fubar:bar>
14  <fubar:bar><test4 /></fubar:bar>
15<!-- this is a comment -->
16</contain>
17</foo>
18EOXML;
19
20$dom = new DOMDocument();
21$dom->loadXML($xml);
22$doc = $dom->documentElement->firstChild;
23
24/* inclusive/without comments first child element of doc element is context. */
25echo $doc->C14N()."\n\n";
26
27/* exclusive/without comments first child element of doc element is context. */
28echo $doc->c14N(TRUE)."\n\n";
29
30/* inclusive/with comments first child element of doc element is context. */
31echo $doc->C14N(FALSE, TRUE)."\n\n";
32
33/* exclusive/with comments first child element of doc element is context. */
34echo $doc->C14N(TRUE, TRUE)."\n\n";
35
36/* exclusive/without comments using xpath query. */
37echo $doc->c14N(TRUE, FALSE, array('query'=>'(//. | //@* | //namespace::*)'))."\n\n";
38
39/* exclusive/without comments first child element of doc element is context.
40   using xpath query with registered namespace.
41   test namespace prefix is also included. */
42echo $doc->c14N(TRUE, FALSE,
43                array('query'=>'(//a:contain | //a:bar | .//namespace::*)',
44                      'namespaces'=>array('a'=>'http://www.example.com/ns/foo')),
45                array('test'))."\n\n";
46
47/* exclusive/without comments first child element of doc element is context.
48   test namespace prefix is also included */
49echo $doc->C14N(TRUE, FALSE, NULL, array('test'));
50?>
51--EXPECTF--
52
53<contain xmlns="http://www.example.com/ns/foo" xmlns:fubar="http://www.example.com/ns/fubar" xmlns:test="urn::test">
54  <bar><test1></test1></bar>
55  <bar><test2></test2></bar>
56  <fubar:bar><test3></test3></fubar:bar>
57  <fubar:bar><test4></test4></fubar:bar>
58
59</contain>
60
61<contain xmlns="http://www.example.com/ns/foo">
62  <bar><test1></test1></bar>
63  <bar><test2></test2></bar>
64  <fubar:bar xmlns:fubar="http://www.example.com/ns/fubar"><test3></test3></fubar:bar>
65  <fubar:bar xmlns:fubar="http://www.example.com/ns/fubar"><test4></test4></fubar:bar>
66
67</contain>
68
69<contain xmlns="http://www.example.com/ns/foo" xmlns:fubar="http://www.example.com/ns/fubar" xmlns:test="urn::test">
70  <bar><test1></test1></bar>
71  <bar><test2></test2></bar>
72  <fubar:bar><test3></test3></fubar:bar>
73  <fubar:bar><test4></test4></fubar:bar>
74<!-- this is a comment -->
75</contain>
76
77<contain xmlns="http://www.example.com/ns/foo">
78  <bar><test1></test1></bar>
79  <bar><test2></test2></bar>
80  <fubar:bar xmlns:fubar="http://www.example.com/ns/fubar"><test3></test3></fubar:bar>
81  <fubar:bar xmlns:fubar="http://www.example.com/ns/fubar"><test4></test4></fubar:bar>
82<!-- this is a comment -->
83</contain>
84
85<foo xmlns="http://www.example.com/ns/foo"><contain>
86  <bar><test1></test1></bar>
87  <bar><test2></test2></bar>
88  <fubar:bar xmlns:fubar="http://www.example.com/ns/fubar"><test3></test3></fubar:bar>
89  <fubar:bar xmlns:fubar="http://www.example.com/ns/fubar"><test4></test4></fubar:bar>
90
91</contain>
92</foo>
93
94<contain xmlns="http://www.example.com/ns/foo" xmlns:test="urn::test"><bar></bar><bar></bar></contain>
95
96<contain xmlns="http://www.example.com/ns/foo" xmlns:test="urn::test">
97  <bar><test1></test1></bar>
98  <bar><test2></test2></bar>
99  <fubar:bar xmlns:fubar="http://www.example.com/ns/fubar"><test3></test3></fubar:bar>
100  <fubar:bar xmlns:fubar="http://www.example.com/ns/fubar"><test4></test4></fubar:bar>
101
102</contain>
103