ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\Xml\Element\XmlFragmentTest Class Reference
+ Inheritance diagram for Sabre\Xml\Element\XmlFragmentTest:
+ Collaboration diagram for Sabre\Xml\Element\XmlFragmentTest:

Public Member Functions

 testDeserialize ($input, $expected)
 @dataProvider xmlProvider More...
 
 xmlProvider ()
 Data provider for serialize and deserialize tests. More...
 
 testSerialize ($expectedFallback, $input, $expected=null)
 @dataProvider xmlProvider More...
 

Detailed Description

Definition at line 8 of file XmlFragmentTest.php.

Member Function Documentation

◆ testDeserialize()

Sabre\Xml\Element\XmlFragmentTest::testDeserialize (   $input,
  $expected 
)

@dataProvider xmlProvider

Definition at line 13 of file XmlFragmentTest.php.

13 {
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 }

References $input, Sabre\VObject\$output, and $reader.

◆ testSerialize()

Sabre\Xml\Element\XmlFragmentTest::testSerialize (   $expectedFallback,
  $input,
  $expected = null 
)

@dataProvider xmlProvider

Definition at line 113 of file XmlFragmentTest.php.

113 {
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 }

References $input, and Sabre\VObject\$output.

◆ xmlProvider()

Sabre\Xml\Element\XmlFragmentTest::xmlProvider ( )

Data provider for serialize and deserialize tests.

Returns three items per test:

  1. Input data for the reader.
  2. Expected output for XmlFragment deserializer
  3. Expected output after serializing that value again.

If 3 is not set, use 1 for 3.

Returns
void

Definition at line 57 of file XmlFragmentTest.php.

57 {
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 }

The documentation for this class was generated from the following file: