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

Public Member Functions

 testGetReader ()
 
 testGetWriter ()
 
 testParse ()
 @depends testGetReader More...
 
 testParseStream ()
 @depends testGetReader More...
 
 testExpect ()
 @depends testGetReader More...
 
 testExpectStream ()
 @depends testGetReader More...
 
 testExpectWrong ()
 @depends testGetReader @expectedException \Sabre\Xml\ParseException More...
 
 testWrite ()
 @depends testGetWriter More...
 
 testMapValueObject ()
 
 testMapValueObjectArrayProperty ()
 
 testWriteVoNotFound ()
 @expectedException \InvalidArgumentException More...
 
 testParseClarkNotation ()
 
 testParseClarkNotationFail ()
 @expectedException \InvalidArgumentException More...
 

Detailed Description

Definition at line 5 of file ServiceTest.php.

Member Function Documentation

◆ testExpect()

Sabre\Xml\ServiceTest::testExpect ( )

@depends testGetReader

Definition at line 102 of file ServiceTest.php.

102 {
103
104 $xml = <<<XML
105<root xmlns="http://sabre.io/ns">
106 <child>value</child>
107</root>
108XML;
109 $util = new Service();
110 $result = $util->expect('{http://sabre.io/ns}root', $xml);
111
112 $expected = [
113 [
114 'name' => '{http://sabre.io/ns}child',
115 'value' => 'value',
116 'attributes' => [],
117 ]
118 ];
119
120 $this->assertEquals(
121 $expected,
122 $result
123 );
124 }
$result

References $result, and $xml.

◆ testExpectStream()

Sabre\Xml\ServiceTest::testExpectStream ( )

@depends testGetReader

Definition at line 129 of file ServiceTest.php.

129 {
130
131 $xml = <<<XML
132<root xmlns="http://sabre.io/ns">
133 <child>value</child>
134</root>
135XML;
136
137 $stream = fopen('php://memory', 'r+');
138 fwrite($stream, $xml);
139 rewind($stream);
140
141 $util = new Service();
142 $result = $util->expect('{http://sabre.io/ns}root', $stream);
143
144 $expected = [
145 [
146 'name' => '{http://sabre.io/ns}child',
147 'value' => 'value',
148 'attributes' => [],
149 ]
150 ];
151
152 $this->assertEquals(
153 $expected,
154 $result
155 );
156 }
$stream
PHP stream implementation.

References $result, GuzzleHttp\Psr7\$stream, and $xml.

◆ testExpectWrong()

Sabre\Xml\ServiceTest::testExpectWrong ( )

@depends testGetReader @expectedException \Sabre\Xml\ParseException

Definition at line 162 of file ServiceTest.php.

162 {
163
164 $xml = <<<XML
165<root xmlns="http://sabre.io/ns">
166 <child>value</child>
167</root>
168XML;
169 $util = new Service();
170 $util->expect('{http://sabre.io/ns}error', $xml);
171
172 }

References $xml.

◆ testGetReader()

Sabre\Xml\ServiceTest::testGetReader ( )

Definition at line 7 of file ServiceTest.php.

7 {
8
9 $elems = [
10 '{http://sabre.io/ns}test' => 'Test!',
11 ];
12
13 $util = new Service();
14 $util->elementMap = $elems;
15
16 $reader = $util->getReader();
17 $this->assertInstanceOf('Sabre\\Xml\\Reader', $reader);
18 $this->assertEquals($elems, $reader->elementMap);
19
20 }

References $reader.

◆ testGetWriter()

Sabre\Xml\ServiceTest::testGetWriter ( )

Definition at line 22 of file ServiceTest.php.

22 {
23
24 $ns = [
25 'http://sabre.io/ns' => 's',
26 ];
27
28 $util = new Service();
29 $util->namespaceMap = $ns;
30
31 $writer = $util->getWriter();
32 $this->assertInstanceOf('Sabre\\Xml\\Writer', $writer);
33 $this->assertEquals($ns, $writer->namespaceMap);
34
35 }

◆ testMapValueObject()

Sabre\Xml\ServiceTest::testMapValueObject ( )

Definition at line 201 of file ServiceTest.php.

201 {
202
203 $input = <<<XML
204<?xml version="1.0"?>
205<order xmlns="http://sabredav.org/ns">
206 <id>1234</id>
207 <amount>99.99</amount>
208 <description>black friday deal</description>
209 <status>
210 <id>5</id>
211 <label>processed</label>
212 </status>
213</order>
214
215XML;
216
217 $ns = 'http://sabredav.org/ns';
218 $orderService = new \Sabre\Xml\Service();
219 $orderService->mapValueObject('{' . $ns . '}order', 'Sabre\Xml\Order');
220 $orderService->mapValueObject('{' . $ns . '}status', 'Sabre\Xml\OrderStatus');
221 $orderService->namespaceMap[$ns] = null;
222
223 $order = $orderService->parse($input);
224 $expected = new Order();
225 $expected->id = 1234;
226 $expected->amount = 99.99;
227 $expected->description = 'black friday deal';
228 $expected->status = new OrderStatus();
229 $expected->status->id = 5;
230 $expected->status->label = 'processed';
231
232 $this->assertEquals($expected, $order);
233
234 $writtenXml = $orderService->writeValueObject($order);
235 $this->assertEquals($input, $writtenXml);
236 }

References $input.

◆ testMapValueObjectArrayProperty()

Sabre\Xml\ServiceTest::testMapValueObjectArrayProperty ( )

Definition at line 238 of file ServiceTest.php.

238 {
239
240 $input = <<<XML
241<?xml version="1.0"?>
242<order xmlns="http://sabredav.org/ns">
243 <id>1234</id>
244 <amount>99.99</amount>
245 <description>black friday deal</description>
246 <status>
247 <id>5</id>
248 <label>processed</label>
249 </status>
250 <link>http://example.org/</link>
251 <link>http://example.com/</link>
252</order>
253
254XML;
255
256 $ns = 'http://sabredav.org/ns';
257 $orderService = new \Sabre\Xml\Service();
258 $orderService->mapValueObject('{' . $ns . '}order', 'Sabre\Xml\Order');
259 $orderService->mapValueObject('{' . $ns . '}status', 'Sabre\Xml\OrderStatus');
260 $orderService->namespaceMap[$ns] = null;
261
262 $order = $orderService->parse($input);
263 $expected = new Order();
264 $expected->id = 1234;
265 $expected->amount = 99.99;
266 $expected->description = 'black friday deal';
267 $expected->status = new OrderStatus();
268 $expected->status->id = 5;
269 $expected->status->label = 'processed';
270 $expected->link = ['http://example.org/', 'http://example.com/'];
271
272 $this->assertEquals($expected, $order);
273
274 $writtenXml = $orderService->writeValueObject($order);
275 $this->assertEquals($input, $writtenXml);
276 }
static http()
Fetches the global http state from ILIAS.

References $input, and ILIAS\FileDelivery\http().

+ Here is the call graph for this function:

◆ testParse()

Sabre\Xml\ServiceTest::testParse ( )

@depends testGetReader

Definition at line 40 of file ServiceTest.php.

40 {
41
42 $xml = <<<XML
43<root xmlns="http://sabre.io/ns">
44 <child>value</child>
45</root>
46XML;
47 $util = new Service();
48 $result = $util->parse($xml, null, $rootElement);
49 $this->assertEquals('{http://sabre.io/ns}root', $rootElement);
50
51 $expected = [
52 [
53 'name' => '{http://sabre.io/ns}child',
54 'value' => 'value',
55 'attributes' => [],
56 ]
57 ];
58
59 $this->assertEquals(
60 $expected,
62 );
63
64 }

References $result, and $xml.

◆ testParseClarkNotation()

Sabre\Xml\ServiceTest::testParseClarkNotation ( )

Definition at line 288 of file ServiceTest.php.

288 {
289
290 $this->assertEquals([
291 'http://sabredav.org/ns',
292 'elem',
293 ], Service::parseClarkNotation('{http://sabredav.org/ns}elem'));
294
295 }
static parseClarkNotation($str)
Parses a clark-notation string, and returns the namespace and element name components.
Definition: Service.php:274

References Sabre\Xml\Service\parseClarkNotation().

+ Here is the call graph for this function:

◆ testParseClarkNotationFail()

Sabre\Xml\ServiceTest::testParseClarkNotationFail ( )

@expectedException \InvalidArgumentException

Definition at line 300 of file ServiceTest.php.

300 {
301
302 Service::parseClarkNotation('http://sabredav.org/ns}elem');
303
304 }

References Sabre\Xml\Service\parseClarkNotation().

+ Here is the call graph for this function:

◆ testParseStream()

Sabre\Xml\ServiceTest::testParseStream ( )

@depends testGetReader

Definition at line 69 of file ServiceTest.php.

69 {
70
71 $xml = <<<XML
72<root xmlns="http://sabre.io/ns">
73 <child>value</child>
74</root>
75XML;
76 $stream = fopen('php://memory', 'r+');
77 fwrite($stream, $xml);
78 rewind($stream);
79
80 $util = new Service();
81 $result = $util->parse($stream, null, $rootElement);
82 $this->assertEquals('{http://sabre.io/ns}root', $rootElement);
83
84 $expected = [
85 [
86 'name' => '{http://sabre.io/ns}child',
87 'value' => 'value',
88 'attributes' => [],
89 ]
90 ];
91
92 $this->assertEquals(
93 $expected,
95 );
96
97 }

References $result, GuzzleHttp\Psr7\$stream, and $xml.

◆ testWrite()

Sabre\Xml\ServiceTest::testWrite ( )

@depends testGetWriter

Definition at line 177 of file ServiceTest.php.

177 {
178
179 $util = new Service();
180 $util->namespaceMap = [
181 'http://sabre.io/ns' => 's',
182 ];
183 $result = $util->write('{http://sabre.io/ns}root', [
184 '{http://sabre.io/ns}child' => 'value',
185 ]);
186
187 $expected = <<<XML
188<?xml version="1.0"?>
189<s:root xmlns:s="http://sabre.io/ns">
190 <s:child>value</s:child>
191</s:root>
192
193XML;
194 $this->assertEquals(
195 $expected,
196 $result
197 );
198
199 }

References $result.

◆ testWriteVoNotFound()

Sabre\Xml\ServiceTest::testWriteVoNotFound ( )

@expectedException \InvalidArgumentException

Definition at line 281 of file ServiceTest.php.

281 {
282
283 $service = new Service();
284 $service->writeValueObject(new \StdClass());
285
286 }

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