coverity fix
[m6w6/ext-http] / tests / querystring001.phpt
1 --TEST--
2 query string
3 --SKIPIF--
4 <?php
5 include("skipif.inc");
6 ?>
7 --GET--
8 str=abc&num=-123&dec=123.123&bool=1&arr[]=1&arr[]=2&ma[l1][l2]=2&ma[l2][l3][l4]=3
9 --FILE--
10 <?php
11 echo "Test\n";
12
13 printf("\nGlobal instance:\n");
14 $q = http\QueryString::getGlobalInstance();
15 printf("%s\n", $q);
16
17 printf("\nStandard getters:\n");
18 var_dump($q->getString("str"));
19 var_dump($q->getInt("num"));
20 var_dump($q->getFloat("dec"));
21 var_dump($q->getInt("dec"));
22 var_dump($q->getFloat("dec"));
23 var_dump($q->getBool("bool"));
24 var_dump($q->getInt("bool"));
25 var_dump($q->getBool("num"));
26 var_dump($q->getInt("num"));
27 var_dump($q->getArray("arr"));
28 var_dump($q->getArray("ma"));
29 var_dump($q->getObject("arr"));
30 var_dump($q->getObject("ma"));
31
32 $s = $q->toString();
33
34 printf("\nClone modifications do not alter global instance:\n");
35 $q->mod(array("arr" => array(3 => 3)));
36 printf("%s\n", $q);
37
38 printf("\nClone modifications do not alter standard instance:\n");
39 $q2 = new http\QueryString($s);
40 $q3 = $q2->mod(array("arr" => array(3 => 3)));
41 printf("%s\n%s\n", $q2, $q3);
42 #var_dump($q2, $q3);
43
44 printf("\nIterator:\n");
45 $it = new RecursiveIteratorIterator($q2, RecursiveIteratorIterator::SELF_FIRST);
46 foreach ($it as $k => $v) {
47 $i = $it->getDepth()*8;
48 @printf("%{$i}s: %s\n", $k, $v);
49 }
50
51 printf("\nReplace a multi dimensional key:\n");
52 printf("%s\n", $q2->mod(array("ma" => null))->set(array("ma" => array("l1" => false))));
53
54 printf("\nXlate:\n");
55 $qu = new http\QueryString("ü=ö");
56 printf("utf8: %s\n", $qu);
57 printf("latin1: %s\n", method_exists($qu, "xlate") ? $qu->xlate("utf-8", "latin1") : "%FC=%F6");
58
59 printf("\nOffsets:\n");
60 var_dump($q2["ma"]);
61 $q2["ma"] = array("bye");
62 var_dump($q2["ma"]);
63 var_dump(isset($q2["ma"]));
64 unset($q2["ma"]);
65 var_dump(isset($q2["ma"]));
66
67 echo "Done\n";
68 ?>
69 --EXPECTF--
70 Test
71
72 Global instance:
73 str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&ma%5Bl1%5D%5Bl2%5D=2&ma%5Bl2%5D%5Bl3%5D%5Bl4%5D=3
74
75 Standard getters:
76 string(3) "abc"
77 int(-123)
78 float(123.123)
79 int(123)
80 float(123.123)
81 bool(true)
82 int(1)
83 bool(true)
84 int(-123)
85 array(2) {
86 [0]=>
87 string(1) "1"
88 [1]=>
89 string(1) "2"
90 }
91 array(2) {
92 ["l1"]=>
93 array(1) {
94 ["l2"]=>
95 string(1) "2"
96 }
97 ["l2"]=>
98 array(1) {
99 ["l3"]=>
100 array(1) {
101 ["l4"]=>
102 string(1) "3"
103 }
104 }
105 }
106 object(stdClass)#%d (2) {
107 [0]=>
108 string(1) "1"
109 [1]=>
110 string(1) "2"
111 }
112 object(stdClass)#%d (2) {
113 ["l1"]=>
114 array(1) {
115 ["l2"]=>
116 string(1) "2"
117 }
118 ["l2"]=>
119 array(1) {
120 ["l3"]=>
121 array(1) {
122 ["l4"]=>
123 string(1) "3"
124 }
125 }
126 }
127
128 Clone modifications do not alter global instance:
129 str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&ma%5Bl1%5D%5Bl2%5D=2&ma%5Bl2%5D%5Bl3%5D%5Bl4%5D=3
130
131 Clone modifications do not alter standard instance:
132 str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&ma%5Bl1%5D%5Bl2%5D=2&ma%5Bl2%5D%5Bl3%5D%5Bl4%5D=3
133 str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&arr%5B3%5D=3&ma%5Bl1%5D%5Bl2%5D=2&ma%5Bl2%5D%5Bl3%5D%5Bl4%5D=3
134
135 Iterator:
136 str: abc
137 num: -123
138 dec: 123.123
139 bool: 1
140 arr: Array
141 0: 1
142 1: 2
143 ma: Array
144 l1: Array
145 l2: 2
146 l2: Array
147 l3: Array
148 l4: 3
149
150 Replace a multi dimensional key:
151 str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&ma%5Bl1%5D=
152
153 Xlate:
154 utf8: %C3%BC=%C3%B6
155 latin1: %FC=%F6
156
157 Offsets:
158 array(2) {
159 ["l1"]=>
160 array(1) {
161 ["l2"]=>
162 string(1) "2"
163 }
164 ["l2"]=>
165 array(1) {
166 ["l3"]=>
167 array(1) {
168 ["l4"]=>
169 string(1) "3"
170 }
171 }
172 }
173 array(1) {
174 [0]=>
175 string(3) "bye"
176 }
177 bool(true)
178 bool(false)
179 Done