| 1 |
lars |
1 |
--TEST--
|
|
|
2 |
XML_Util::attributesToString() basic tests
|
|
|
3 |
--CREDITS--
|
|
|
4 |
Chuck Burgess <ashnazg@php.net>
|
|
|
5 |
# created for v1.2.0a1 2008-05-04
|
|
|
6 |
--FILE--
|
|
|
7 |
<?php
|
|
|
8 |
require_once 'XML' . DIRECTORY_SEPARATOR . 'Util.php';
|
|
|
9 |
echo '=====XML_Util::attributesToString() basic tests=====' . PHP_EOL . PHP_EOL;
|
|
|
10 |
|
|
|
11 |
$att = array("foo" => "bar", "boo" => "baz");
|
|
|
12 |
$sort1 = array(
|
|
|
13 |
'multiline' => true,
|
|
|
14 |
'indent' => '----',
|
|
|
15 |
'linebreak' => "^",
|
|
|
16 |
'entities' => XML_UTIL_ENTITIES_XML,
|
|
|
17 |
'sort' => true
|
|
|
18 |
);
|
|
|
19 |
$sort2 = array(
|
|
|
20 |
'multiline' => true,
|
|
|
21 |
'indent' => '----',
|
|
|
22 |
'linebreak' => "^",
|
|
|
23 |
'entities' => XML_UTIL_ENTITIES_XML,
|
|
|
24 |
);
|
|
|
25 |
|
|
|
26 |
echo "TEST: basic usage" . PHP_EOL;
|
|
|
27 |
echo XML_Util::attributesToString($att) . PHP_EOL . PHP_EOL;
|
|
|
28 |
|
|
|
29 |
echo "TEST: explicit \$sort = true" . PHP_EOL;
|
|
|
30 |
echo XML_Util::attributesToString($att, true) . PHP_EOL . PHP_EOL;
|
|
|
31 |
|
|
|
32 |
echo "TEST: explicit \$sort = false" . PHP_EOL;
|
|
|
33 |
echo XML_Util::attributesToString($att, false) . PHP_EOL . PHP_EOL;
|
|
|
34 |
|
|
|
35 |
echo "TEST: explicit \$multiline = false" . PHP_EOL;
|
|
|
36 |
echo XML_Util::attributesToString($att, true, false) . PHP_EOL . PHP_EOL;
|
|
|
37 |
|
|
|
38 |
echo "TEST: explicit \$multiline = true" . PHP_EOL;
|
|
|
39 |
echo XML_Util::attributesToString($att, true, true) . PHP_EOL . PHP_EOL;
|
|
|
40 |
|
|
|
41 |
echo "TEST: explicit \$indent = ' ' (8 spaces)" . PHP_EOL;
|
|
|
42 |
echo XML_Util::attributesToString($att, true, true, ' ') . PHP_EOL . PHP_EOL;
|
|
|
43 |
|
|
|
44 |
echo "TEST: explicit \$linebreak = '^' (some dummy char)" . PHP_EOL;
|
|
|
45 |
echo XML_Util::attributesToString($att, true, true, '^') . PHP_EOL . PHP_EOL;
|
|
|
46 |
|
|
|
47 |
echo "TEST: passing \$sort array of options that includes 'sort'" . PHP_EOL;
|
|
|
48 |
echo XML_Util::attributesToString($att, $sort1) . PHP_EOL . PHP_EOL;
|
|
|
49 |
|
|
|
50 |
echo "TEST: passing \$sort array of options that doesn't include 'sort'" . PHP_EOL;
|
|
|
51 |
echo XML_Util::attributesToString($att, $sort2) . PHP_EOL . PHP_EOL;
|
|
|
52 |
|
|
|
53 |
echo "TEST: do not replace entities" . PHP_EOL;
|
|
|
54 |
$arr = array("foo" => "b@&r", "boo" => "b><z");
|
|
|
55 |
echo XML_Util::attributesToString($arr, true, false, ' ', PHP_EOL,
|
|
|
56 |
XML_UTIL_ENTITIES_NONE) . PHP_EOL . PHP_EOL;
|
|
|
57 |
|
|
|
58 |
echo "TEST: replace all XML entities" . PHP_EOL;
|
|
|
59 |
$arr = array("foo" => "b@&r", "boo" => "b><z");
|
|
|
60 |
echo XML_Util::attributesToString($arr, true, false, ' ', PHP_EOL,
|
|
|
61 |
XML_UTIL_ENTITIES_XML) . PHP_EOL . PHP_EOL;
|
|
|
62 |
|
|
|
63 |
echo "TEST: replace only required XML entities" . PHP_EOL;
|
|
|
64 |
$arr = array("foo" => "b@&r", "boo" => "b><z");
|
|
|
65 |
echo XML_Util::attributesToString($arr, true, false, ' ', PHP_EOL,
|
|
|
66 |
XML_UTIL_ENTITIES_XML_REQUIRED) . PHP_EOL . PHP_EOL;
|
|
|
67 |
|
|
|
68 |
echo "TEST: replace HTML entities" . PHP_EOL;
|
|
|
69 |
$arr = array("foo" => "b@&r", "boo" => "b><z");
|
|
|
70 |
echo XML_Util::attributesToString($arr, true, false, ' ', PHP_EOL,
|
|
|
71 |
XML_UTIL_ENTITIES_HTML) . PHP_EOL . PHP_EOL;
|
|
|
72 |
?>
|
|
|
73 |
--EXPECT--
|
|
|
74 |
=====XML_Util::attributesToString() basic tests=====
|
|
|
75 |
|
|
|
76 |
TEST: basic usage
|
|
|
77 |
boo="baz" foo="bar"
|
|
|
78 |
|
|
|
79 |
TEST: explicit $sort = true
|
|
|
80 |
boo="baz" foo="bar"
|
|
|
81 |
|
|
|
82 |
TEST: explicit $sort = false
|
|
|
83 |
foo="bar" boo="baz"
|
|
|
84 |
|
|
|
85 |
TEST: explicit $multiline = false
|
|
|
86 |
boo="baz" foo="bar"
|
|
|
87 |
|
|
|
88 |
TEST: explicit $multiline = true
|
|
|
89 |
boo="baz"
|
|
|
90 |
foo="bar"
|
|
|
91 |
|
|
|
92 |
TEST: explicit $indent = ' ' (8 spaces)
|
|
|
93 |
boo="baz"
|
|
|
94 |
foo="bar"
|
|
|
95 |
|
|
|
96 |
TEST: explicit $linebreak = '^' (some dummy char)
|
|
|
97 |
boo="baz"
|
|
|
98 |
^foo="bar"
|
|
|
99 |
|
|
|
100 |
TEST: passing $sort array of options that includes 'sort'
|
|
|
101 |
boo="baz"
|
|
|
102 |
----foo="bar"
|
|
|
103 |
|
|
|
104 |
TEST: passing $sort array of options that doesn't include 'sort'
|
|
|
105 |
boo="baz"
|
|
|
106 |
----foo="bar"
|
|
|
107 |
|
|
|
108 |
TEST: do not replace entities
|
|
|
109 |
boo="b><z" foo="b@&r"
|
|
|
110 |
|
|
|
111 |
TEST: replace all XML entities
|
|
|
112 |
boo="b><z" foo="b@&r"
|
|
|
113 |
|
|
|
114 |
TEST: replace only required XML entities
|
|
|
115 |
boo="b><z" foo="b@&r"
|
|
|
116 |
|
|
|
117 |
TEST: replace HTML entities
|
|
|
118 |
boo="b><z" foo="b@&r"
|