ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
XmlFragmentTest.php
Go to the documentation of this file.
1<?php
2
3namespace Sabre\Xml\Element;
4
7
9
13 function testDeserialize($input, $expected) {
14
15 $input = <<<BLA
16<?xml version="1.0"?>
17<root xmlns="http://sabredav.org/ns">
18 <fragment>$input</fragment>
19</root>
20BLA;
21
22 $reader = new Reader();
23 $reader->elementMap = [
24 '{http://sabredav.org/ns}fragment' => 'Sabre\\Xml\\Element\\XmlFragment',
25 ];
26 $reader->xml($input);
27
28 $output = $reader->parse();
29
30 $this->assertEquals([
31 'name' => '{http://sabredav.org/ns}root',
32 'value' => [
33 [
34 'name' => '{http://sabredav.org/ns}fragment',
35 'value' => new XmlFragment($expected),
36 'attributes' => [],
37 ],
38 ],
39 'attributes' => [],
40 ], $output);
41
42 }
43
57 function xmlProvider() {
58
59 return [
60 [
61 'hello',
62 'hello',
63 ],
64 [
65 '<element>hello</element>',
66 '<element xmlns="http://sabredav.org/ns">hello</element>'
67 ],
68 [
69 '<element foo="bar">hello</element>',
70 '<element xmlns="http://sabredav.org/ns" foo="bar">hello</element>'
71 ],
72 [
73 '<element x1:foo="bar" xmlns:x1="http://example.org/ns">hello</element>',
74 '<element xmlns:x1="http://example.org/ns" xmlns="http://sabredav.org/ns" x1:foo="bar">hello</element>'
75 ],
76 [
77 '<element xmlns="http://example.org/ns">hello</element>',
78 '<element xmlns="http://example.org/ns">hello</element>',
79 '<x1:element xmlns:x1="http://example.org/ns">hello</x1:element>',
80 ],
81 [
82 '<element xmlns:foo="http://example.org/ns">hello</element>',
83 '<element xmlns:foo="http://example.org/ns" xmlns="http://sabredav.org/ns">hello</element>',
84 '<element>hello</element>',
85 ],
86 [
87 '<foo:element xmlns:foo="http://example.org/ns">hello</foo:element>',
88 '<foo:element xmlns:foo="http://example.org/ns">hello</foo:element>',
89 '<x1:element xmlns:x1="http://example.org/ns">hello</x1:element>',
90 ],
91 [
92 '<foo:element xmlns:foo="http://example.org/ns"><child>hello</child></foo:element>',
93 '<foo:element xmlns:foo="http://example.org/ns" xmlns="http://sabredav.org/ns"><child>hello</child></foo:element>',
94 '<x1:element xmlns:x1="http://example.org/ns"><child>hello</child></x1:element>',
95 ],
96 [
97 '<foo:element xmlns:foo="http://example.org/ns"><child/></foo:element>',
98 '<foo:element xmlns:foo="http://example.org/ns" xmlns="http://sabredav.org/ns"><child/></foo:element>',
99 '<x1:element xmlns:x1="http://example.org/ns"><child/></x1:element>',
100 ],
101 [
102 '<foo:element xmlns:foo="http://example.org/ns"><child a="b"/></foo:element>',
103 '<foo:element xmlns:foo="http://example.org/ns" xmlns="http://sabredav.org/ns"><child a="b"/></foo:element>',
104 '<x1:element xmlns:x1="http://example.org/ns"><child a="b"/></x1:element>',
105 ],
106 ];
107
108 }
109
113 function testSerialize($expectedFallback, $input, $expected = null) {
114
115 if (is_null($expected)) {
116 $expected = $expectedFallback;
117 }
118
119 $writer = new Writer();
120 $writer->namespaceMap = [
121 'http://sabredav.org/ns' => null
122 ];
123 $writer->openMemory();
124 $writer->startDocument('1.0');
125 //$writer->setIndent(true);
126 $writer->write([
127 '{http://sabredav.org/ns}root' => [
128 '{http://sabredav.org/ns}fragment' => new XmlFragment($input),
129 ],
130 ]);
131
132 $output = $writer->outputMemory();
133
134 $expected = <<<XML
135<?xml version="1.0"?>
136<root xmlns="http://sabredav.org/ns"><fragment>$expected</fragment></root>
137XML;
138
139 $this->assertEquals($expected, $output);
140
141 }
142
143}
An exception for terminatinating execution or to throw for unit testing.
testDeserialize($input, $expected)
@dataProvider xmlProvider
xmlProvider()
Data provider for serialize and deserialize tests.
testSerialize($expectedFallback, $input, $expected=null)
@dataProvider xmlProvider
The XmlFragment element allows you to extract a portion of your xml tree, and get a well-formed xml s...
Definition: XmlFragment.php:23
The Reader class expands upon PHP's built-in XMLReader.
Definition: Reader.php:20
The XML Writer class.
Definition: Writer.php:31