summaryrefslogtreecommitdiffstats
path: root/1b1435c135c69d81b47f1f0662633867c5c289b5.patch
blob: c0f1741a206e7882d7cdfc105f38e762bcebe10c (plain)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
From 1b1435c135c69d81b47f1f0662633867c5c289b5 Mon Sep 17 00:00:00 2001
From: Michael Wallner <mike@php.net>
Date: Tue, 24 Jan 2017 08:38:58 +0100
Subject: [PATCH] fix querystring object conversion on master

---
 tests/querystring001.phpt   |   1 +
 tests/querystring001_a.phpt | 180 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 181 insertions(+)
 create mode 100644 tests/querystring001_a.phpt

diff --git a/tests/querystring001.phpt b/tests/querystring001.phpt
index 203be33..e2e563d 100644
--- a/tests/querystring001.phpt
+++ b/tests/querystring001.phpt
@@ -3,6 +3,7 @@ query string
 --SKIPIF--
 <?php
 include("skipif.inc");
+version_compare(PHP_VERSION, "7.2.0-dev", "<") or die("skip only for PHP < 7.2.0");
 ?>
 --GET--
 str=abc&num=-123&dec=123.123&bool=1&arr[]=1&arr[]=2&ma[l1][l2]=2&ma[l2][l3][l4]=3
diff --git a/tests/querystring001_a.phpt b/tests/querystring001_a.phpt
new file mode 100644
index 0000000..24994f2
--- /dev/null
+++ b/tests/querystring001_a.phpt
@@ -0,0 +1,180 @@
+--TEST--
+query string
+--SKIPIF--
+<?php
+include("skipif.inc");
+version_compare(PHP_VERSION, "7.2.0-dev", ">=") or die("skip only for PHP >= 7.2.0");
+?>
+--GET--
+str=abc&num=-123&dec=123.123&bool=1&arr[]=1&arr[]=2&ma[l1][l2]=2&ma[l2][l3][l4]=3
+--FILE--
+<?php
+echo "Test\n";
+
+printf("\nGlobal instance:\n");
+$q = http\QueryString::getGlobalInstance();
+printf("%s\n", $q);
+
+printf("\nStandard getters:\n");
+var_dump($q->getString("str"));
+var_dump($q->getInt("num"));
+var_dump($q->getFloat("dec"));
+var_dump($q->getInt("dec"));
+var_dump($q->getFloat("dec"));
+var_dump($q->getBool("bool"));
+var_dump($q->getInt("bool"));
+var_dump($q->getBool("num"));
+var_dump($q->getInt("num"));
+var_dump($q->getArray("arr"));
+var_dump($q->getArray("ma"));
+var_dump($q->getObject("arr"));
+var_dump($q->getObject("ma"));
+
+$s = $q->toString();
+
+printf("\nClone modifications do not alter global instance:\n");
+$q->mod(array("arr" => array(3 => 3)));
+printf("%s\n", $q);
+
+printf("\nClone modifications do not alter standard instance:\n");
+$q2 = new http\QueryString($s);
+$q3 = $q2->mod(array("arr" => array(3 => 3)));
+printf("%s\n%s\n", $q2, $q3);
+#var_dump($q2, $q3);
+
+printf("\nIterator:\n");
+$it = new RecursiveIteratorIterator($q2, RecursiveIteratorIterator::SELF_FIRST);
+foreach ($it as $k => $v) {
+	$i = $it->getDepth()*8;
+	@printf("%{$i}s: %s\n", $k, $v); 
+}
+
+printf("\nReplace a multi dimensional key:\n");
+printf("%s\n", $q2->mod(array("ma" => null))->set(array("ma" => array("l1" => false))));
+
+printf("\nXlate:\n");
+$qu = new http\QueryString("ü=ö");
+printf("utf8:   %s\n", $qu);
+printf("latin1: %s\n", method_exists($qu, "xlate") ? $qu->xlate("utf-8", "latin1") : "%FC=%F6");
+
+printf("\nOffsets:\n");
+var_dump($q2["ma"]);
+$q2["ma"] = array("bye");
+var_dump($q2["ma"]);
+var_dump(isset($q2["ma"]));
+unset($q2["ma"]);
+var_dump(isset($q2["ma"]));
+
+echo "Done\n";
+?>
+--EXPECTF--
+Test
+
+Global instance:
+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
+
+Standard getters:
+string(3) "abc"
+int(-123)
+float(123.123)
+int(123)
+float(123.123)
+bool(true)
+int(1)
+bool(true)
+int(-123)
+array(2) {
+  [0]=>
+  string(1) "1"
+  [1]=>
+  string(1) "2"
+}
+array(2) {
+  ["l1"]=>
+  array(1) {
+    ["l2"]=>
+    string(1) "2"
+  }
+  ["l2"]=>
+  array(1) {
+    ["l3"]=>
+    array(1) {
+      ["l4"]=>
+      string(1) "3"
+    }
+  }
+}
+object(stdClass)#%d (2) {
+  ["0"]=>
+  string(1) "1"
+  ["1"]=>
+  string(1) "2"
+}
+object(stdClass)#%d (2) {
+  ["l1"]=>
+  array(1) {
+    ["l2"]=>
+    string(1) "2"
+  }
+  ["l2"]=>
+  array(1) {
+    ["l3"]=>
+    array(1) {
+      ["l4"]=>
+      string(1) "3"
+    }
+  }
+}
+
+Clone modifications do not alter global instance:
+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
+
+Clone modifications do not alter standard instance:
+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
+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
+
+Iterator:
+str: abc
+num: -123
+dec: 123.123
+bool: 1
+arr: Array
+       0: 1
+       1: 2
+ma: Array
+      l1: Array
+              l2: 2
+      l2: Array
+              l3: Array
+                      l4: 3
+
+Replace a multi dimensional key:
+str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&ma%5Bl1%5D=
+
+Xlate:
+utf8:   %C3%BC=%C3%B6
+latin1: %FC=%F6
+
+Offsets:
+array(2) {
+  ["l1"]=>
+  array(1) {
+    ["l2"]=>
+    string(1) "2"
+  }
+  ["l2"]=>
+  array(1) {
+    ["l3"]=>
+    array(1) {
+      ["l4"]=>
+      string(1) "3"
+    }
+  }
+}
+array(1) {
+  [0]=>
+  string(3) "bye"
+}
+bool(true)
+bool(false)
+Done