ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
KeyValueTest.php
Go to the documentation of this file.
1<?php
2
4
5use
7
9
10 function testKeyValue() {
11
12 $input = <<<BLA
13<?xml version="1.0"?>
14<root xmlns="http://sabredav.org/ns">
15 <struct>
16 <elem1 />
17 <elem2>hi</elem2>
18 <elem3 xmlns="http://sabredav.org/another-ns">
19 <elem4>foo</elem4>
20 <elem5>foo &amp; bar</elem5>
21 </elem3>
22 </struct>
23</root>
24BLA;
25
26 $reader = new Reader();
27 $reader->elementMap = [
28 '{http://sabredav.org/ns}struct' => function(Reader $reader) {
29 return keyValue($reader, 'http://sabredav.org/ns');
30 }
31 ];
32 $reader->xml($input);
33 $output = $reader->parse();
34
35 $this->assertEquals([
36 'name' => '{http://sabredav.org/ns}root',
37 'value' => [
38 [
39 'name' => '{http://sabredav.org/ns}struct',
40 'value' => [
41 'elem1' => null,
42 'elem2' => 'hi',
43 '{http://sabredav.org/another-ns}elem3' => [
44 [
45 'name' => '{http://sabredav.org/another-ns}elem4',
46 'value' => 'foo',
47 'attributes' => [],
48 ],
49 [
50 'name' => '{http://sabredav.org/another-ns}elem5',
51 'value' => 'foo & bar',
52 'attributes' => [],
53 ],
54 ]
55 ],
56 'attributes' => [],
57 ]
58 ],
59 'attributes' => [],
60 ], $output);
61 }
62
66 function testKeyValueLoop() {
67
75 $invalid_xml = '
76 <foo ft="PRNTING" Ppt="YES" AutoClose="YES" SkipUnverified="NO" Test="NO">
77 <Package ID="1">
78 <MailClass>NONE</MailClass>
79 <PackageType>ENVELOPE</PackageType>
80 <WeightOz>1</WeightOz>
81 <FleetType>DC</FleetType>
82 <Package ID="2">
83 <MailClass>NONE</MailClass>
84 <PackageType>ENVELOPE</PackageType>
85 <WeightOz>1</WeightOz>
86 <FleetType>DC/FleetType>
87 </Package>
88 </foo>';
89 $reader = new Reader();
90
91 $reader->xml($invalid_xml);
92 $reader->elementMap = [
93
94 '{}Package' => function($reader) {
95 $recipient = [];
96 // Borrowing a parser from the KeyValue class.
97 $keyValue = keyValue($reader);
98
99 if (isset($keyValue['{}WeightOz'])){
100 $recipient['referenceId'] = $keyValue['{}WeightOz'];
101 }
102
103 return $recipient;
104 },
105 ];
106
107 $reader->parse();
108
109
110 }
111
112}
An exception for terminatinating execution or to throw for unit testing.
testKeyValueLoop()
@expectedException \Sabre\Xml\LibXMLException
The Reader class expands upon PHP's built-in XMLReader.
Definition: Reader.php:20
keyValue(Reader $reader, $namespace=null)
This class provides a number of 'deserializer' helper functions.
Definition: functions.php:61