@@ -60,61 +60,76 @@ public static function urlProvider() {
60
60
[
61
61
'http://example.com/test.html ' ,
62
62
'http://example.com/test.html ' ,
63
+ [],
63
64
null ,
64
65
'Null options '
65
66
],
66
67
[
67
68
'http://example.com/test.html ' ,
68
69
'http://example.com/test.html ' ,
69
70
[],
71
+ [],
70
72
'Simple string '
71
73
],
72
74
[
73
75
'http://example.com/test.html ' ,
74
76
'/test.html ' ,
77
+ [],
75
78
['host ' => 'example.com ' ],
76
79
'host name option ' ,
77
80
],
78
81
[
79
82
'https://example.com/test.html ' ,
80
83
'/test.html ' ,
84
+ [],
81
85
['host ' => 'example.com ' , 'scheme ' => 'https ' ],
82
86
'HTTPS ' ,
83
87
],
84
88
[
85
89
'http://example.com:8080/test.html ' ,
86
90
'/test.html ' ,
91
+ [],
87
92
['host ' => 'example.com ' , 'port ' => '8080 ' ],
88
93
'Non standard port ' ,
89
94
],
90
95
[
91
96
'http://example.com/test.html ' ,
92
97
'/test.html ' ,
98
+ [],
93
99
['host ' => 'example.com ' , 'port ' => '80 ' ],
94
100
'standard port, does not display '
95
101
],
96
102
[
97
103
'https://example.com/test.html ' ,
98
104
'/test.html ' ,
105
+ [],
99
106
['host ' => 'example.com ' , 'scheme ' => 'https ' , 'port ' => '443 ' ],
100
107
'standard port, does not display '
101
108
],
102
109
[
103
110
'http://example.com/test.html ' ,
104
111
'http://example.com/test.html ' ,
112
+ [],
105
113
['host ' => 'example.com ' , 'scheme ' => 'https ' ],
106
114
'options do not duplicate '
107
115
],
116
+ [
117
+ 'http://example.com/search?q=hi+there&cat%5Bid%5D%5B0%5D=2&cat%5Bid%5D%5B1%5D=3 ' ,
118
+ 'http://example.com/search ' ,
119
+ ['q ' => 'hi there ' , 'cat ' => ['id ' => [2 , 3 ]]],
120
+ [],
121
+ 'query string data. '
122
+ ],
108
123
];
109
124
}
110
125
111
126
/**
112
127
* @dataProvider urlProvider
113
128
*/
114
- public function testBuildUrl ($ expected , $ url , $ opts ) {
129
+ public function testBuildUrl ($ expected , $ url , $ query , $ opts ) {
115
130
$ http = new Client ();
116
131
117
- $ result = $ http ->buildUrl ($ url , $ opts );
132
+ $ result = $ http ->buildUrl ($ url , $ query , $ opts );
118
133
$ this ->assertEquals ($ expected , $ result );
119
134
}
120
135
@@ -179,4 +194,31 @@ public function testGetSimpleWithHeadersAndCookies() {
179
194
$ this ->assertSame ($ result , $ response );
180
195
}
181
196
197
+ /**
198
+ * test get request with querystring data
199
+ *
200
+ * @return void
201
+ */
202
+ public function testGetQuerystring () {
203
+ $ response = new Response ();
204
+
205
+ $ mock = $ this ->getMock ('Cake\Network\Http\Adapter\Stream ' , ['send ' ]);
206
+ $ mock ->expects ($ this ->once ())
207
+ ->method ('send ' )
208
+ ->with ($ this ->logicalAnd (
209
+ $ this ->isInstanceOf ('Cake\Network\Http\Request ' ),
210
+ $ this ->attributeEqualTo ('_url ' , 'http://cakephp.org/search?q=hi+there&Category%5Bid%5D%5B0%5D=2&Category%5Bid%5D%5B1%5D=3 ' )
211
+ ))
212
+ ->will ($ this ->returnValue ($ response ));
213
+
214
+ $ http = new Client ([
215
+ 'host ' => 'cakephp.org ' ,
216
+ 'adapter ' => $ mock
217
+ ]);
218
+ $ result = $ http ->get ('/search ' , [
219
+ 'q ' => 'hi there ' ,
220
+ 'Category ' => ['id ' => [2 , 3 ]]
221
+ ]);
222
+ $ this ->assertSame ($ result , $ response );
223
+ }
182
224
}
0 commit comments