File: testBasic_attributesToString.phpt

package info (click to toggle)
php-pear 1%3A1.10.1%2Bsubmodules%2Bnotgz-9%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 18,600 kB
  • sloc: php: 51,665; ansic: 38,629; xml: 32,572; yacc: 677; pascal: 452; makefile: 122; sh: 116
file content (118 lines) | stat: -rw-r--r-- 3,631 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
--TEST--
XML_Util::attributesToString() basic tests
--CREDITS--
Chuck Burgess <ashnazg@php.net>
# created for v1.2.0a1 2008-05-04
--FILE--
<?php
require_once 'XML' . DIRECTORY_SEPARATOR . 'Util.php';
echo '=====XML_Util::attributesToString() basic tests=====' . PHP_EOL . PHP_EOL;

$att = array("foo" => "bar", "boo" => "baz");
$sort1 = array(
    'multiline' => true, 
    'indent'    => '----', 
    'linebreak' => "^", 
    'entities'  => XML_UTIL_ENTITIES_XML, 
    'sort'      => true
);
$sort2 = array(
    'multiline' => true, 
    'indent'    => '----', 
    'linebreak' => "^", 
    'entities'  => XML_UTIL_ENTITIES_XML, 
);

echo "TEST:  basic usage" . PHP_EOL;
echo XML_Util::attributesToString($att) . PHP_EOL . PHP_EOL;

echo "TEST:  explicit \$sort = true" . PHP_EOL;
echo XML_Util::attributesToString($att, true) . PHP_EOL . PHP_EOL;

echo "TEST:  explicit \$sort = false" . PHP_EOL;
echo XML_Util::attributesToString($att, false) . PHP_EOL . PHP_EOL;

echo "TEST:  explicit \$multiline = false" . PHP_EOL;
echo XML_Util::attributesToString($att, true, false) . PHP_EOL . PHP_EOL;

echo "TEST:  explicit \$multiline = true" . PHP_EOL;
echo XML_Util::attributesToString($att, true, true) . PHP_EOL . PHP_EOL;

echo "TEST:  explicit \$indent = '        ' (8 spaces)" . PHP_EOL;
echo XML_Util::attributesToString($att, true, true, '        ') . PHP_EOL . PHP_EOL;

echo "TEST:  explicit \$linebreak = '^' (some dummy char)" . PHP_EOL;
echo XML_Util::attributesToString($att, true, true, '^') . PHP_EOL . PHP_EOL;

echo "TEST:  passing \$sort array of options that includes 'sort'" . PHP_EOL;
echo XML_Util::attributesToString($att, $sort1) . PHP_EOL . PHP_EOL;

echo "TEST:  passing \$sort array of options that doesn't include 'sort'" . PHP_EOL;
echo XML_Util::attributesToString($att, $sort2) . PHP_EOL . PHP_EOL;

echo "TEST:  do not replace entities" . PHP_EOL;
$arr = array("foo" => "b@&r", "boo" => "b><z");
echo XML_Util::attributesToString($arr, true, false, '    ', PHP_EOL, 
    XML_UTIL_ENTITIES_NONE) . PHP_EOL . PHP_EOL;

echo "TEST:  replace all XML entities" . PHP_EOL;
$arr = array("foo" => "b@&r", "boo" => "b><z");
echo XML_Util::attributesToString($arr, true, false, '    ', PHP_EOL, 
    XML_UTIL_ENTITIES_XML) . PHP_EOL . PHP_EOL;

echo "TEST:  replace only required XML entities" . PHP_EOL;
$arr = array("foo" => "b@&r", "boo" => "b><z");
echo XML_Util::attributesToString($arr, true, false, '    ', PHP_EOL, 
    XML_UTIL_ENTITIES_XML_REQUIRED) . PHP_EOL . PHP_EOL;

echo "TEST:  replace HTML entities" . PHP_EOL;
$arr = array("foo" => "b@&r", "boo" => "b><z");
echo XML_Util::attributesToString($arr, true, false, '    ', PHP_EOL, 
    XML_UTIL_ENTITIES_HTML) . PHP_EOL . PHP_EOL;
?>
--EXPECT--
=====XML_Util::attributesToString() basic tests=====

TEST:  basic usage
 boo="baz" foo="bar"

TEST:  explicit $sort = true
 boo="baz" foo="bar"

TEST:  explicit $sort = false
 foo="bar" boo="baz"

TEST:  explicit $multiline = false
 boo="baz" foo="bar"

TEST:  explicit $multiline = true
 boo="baz"
    foo="bar"

TEST:  explicit $indent = '        ' (8 spaces)
 boo="baz"
        foo="bar"

TEST:  explicit $linebreak = '^' (some dummy char)
 boo="baz"
^foo="bar"

TEST:  passing $sort array of options that includes 'sort'
 boo="baz"
----foo="bar"

TEST:  passing $sort array of options that doesn't include 'sort'
 boo="baz"
----foo="bar"

TEST:  do not replace entities
 boo="b><z" foo="b@&r"

TEST:  replace all XML entities
 boo="b&gt;&lt;z" foo="b@&amp;r"

TEST:  replace only required XML entities
 boo="b>&lt;z" foo="b@&amp;r"

TEST:  replace HTML entities
 boo="b&gt;&lt;z" foo="b@&amp;r"