ILIAS
release_5-4 Revision v5.4.26-12-gabc799a52e6
◀ ilDoc Overview
KeyValueTest.php
Go to the documentation of this file.
1
<?
php
2
3
namespace
Sabre\Xml\Deserializer
;
4
5
use
6
Sabre\Xml\Reader
;
7
8
class
KeyValueTest
extends
\PHPUnit_Framework_TestCase
{
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 & bar</elem5>
21
</elem3>
22
</
struct
>
23
</root>
24
BLA;
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
}
Reader
$input
$input
Definition:
bench_manipulatevcard.php:18
Sabre\Xml\Deserializer\KeyValueTest\testKeyValue
testKeyValue()
Definition:
KeyValueTest.php:10
Sabre\VObject\$output
$output
Definition:
mergeduplicates.php:36
$reader
$reader
Definition:
scanCallStructure.php:5
Sabre\Xml\Deserializer\KeyValueTest
Definition:
KeyValueTest.php:8
PHPUnit_Framework_TestCase
Sabre\Xml\Deserializer\keyValue
keyValue(Reader $reader, $namespace=null)
This class provides a number of 'deserializer' helper functions.
Definition:
functions.php:61
Sabre\Xml\Reader
The Reader class expands upon PHP's built-in XMLReader.
Definition:
Reader.php:20
Sabre\Xml\Deserializer
Definition:
functions.php:3
Sabre\Xml\Deserializer\KeyValueTest\testKeyValueLoop
testKeyValueLoop()
Definition:
KeyValueTest.php:66
php
libs
composer
vendor
sabre
xml
tests
Sabre
Xml
Deserializer
KeyValueTest.php
Generated on Thu Jan 16 2025 19:01:54 for ILIAS by
1.8.13 (using
Doxyfile
)