@@ -197,84 +197,132 @@ public function testUrlRedirectDefaultPorts()
197
197
$ this ->assertRedirectUrl ($ returnValue , $ expectedUrl );
198
198
}
199
199
200
+ public function testUrlRedirectDefaultPortsInvoke ()
201
+ {
202
+ $ host = 'www.example.com ' ;
203
+ $ baseUrl = '/base ' ;
204
+ $ path = '/redirect-path ' ;
205
+ $ httpPort = 1080 ;
206
+ $ httpsPort = 1443 ;
207
+
208
+ $ expectedUrl = "https:// $ host: $ httpsPort$ baseUrl$ path " ;
209
+ $ request = $ this ->createRequestObject ('http ' , $ host , $ httpPort , $ baseUrl , '' , array ('path ' => $ path , 'permanent ' => false , 'scheme ' => 'https ' , 'httpPort ' => $ httpPort ));
210
+ $ controller = $ this ->createRedirectController (null , $ httpsPort );
211
+ $ returnValue = $ controller ($ request );
212
+ $ this ->assertRedirectUrl ($ returnValue , $ expectedUrl );
213
+
214
+ $ expectedUrl = "http:// $ host: $ httpPort$ baseUrl$ path " ;
215
+ $ request = $ this ->createRequestObject ('https ' , $ host , $ httpPort , $ baseUrl , '' , array ('path ' => $ path , 'permanent ' => false , 'scheme ' => 'http ' ));
216
+ $ controller = $ this ->createRedirectController ($ httpPort );
217
+ $ returnValue = $ controller ($ request );
218
+ $ this ->assertRedirectUrl ($ returnValue , $ expectedUrl );
219
+ }
220
+
200
221
public function urlRedirectProvider ()
201
222
{
202
223
return array (
203
224
// Standard ports
204
- array ('http ' , null , null , 'http ' , 80 , '' ),
205
- array ('http ' , 80 , null , 'http ' , 80 , '' ),
206
- array ('https ' , null , null , 'http ' , 80 , '' ),
207
- array ('https ' , 80 , null , 'http ' , 80 , '' ),
208
-
209
- array ('http ' , null , null , 'https ' , 443 , '' ),
210
- array ('http ' , null , 443 , 'https ' , 443 , '' ),
211
- array ('https ' , null , null , 'https ' , 443 , '' ),
212
- array ('https ' , null , 443 , 'https ' , 443 , '' ),
225
+ array ('http ' , null , null , 'http ' , 80 , '' , false ),
226
+ array ('http ' , null , null , 'http ' , 80 , '' , true ),
227
+ array ('http ' , 80 , null , 'http ' , 80 , '' , false ),
228
+ array ('http ' , 80 , null , 'http ' , 80 , '' , true ),
229
+ array ('https ' , null , null , 'http ' , 80 , '' , false ),
230
+ array ('https ' , null , null , 'http ' , 80 , '' , true ),
231
+ array ('https ' , 80 , null , 'http ' , 80 , '' , false ),
232
+ array ('https ' , 80 , null , 'http ' , 80 , '' , true ),
233
+
234
+ array ('http ' , null , null , 'https ' , 443 , '' , false ),
235
+ array ('http ' , null , null , 'https ' , 443 , '' , true ),
236
+ array ('http ' , null , 443 , 'https ' , 443 , '' , false ),
237
+ array ('http ' , null , 443 , 'https ' , 443 , '' , true ),
238
+ array ('https ' , null , null , 'https ' , 443 , '' , false ),
239
+ array ('https ' , null , null , 'https ' , 443 , '' , true ),
240
+ array ('https ' , null , 443 , 'https ' , 443 , '' , false ),
241
+ array ('https ' , null , 443 , 'https ' , 443 , '' , true ),
213
242
214
243
// Non-standard ports
215
- array ('http ' , null , null , 'http ' , 8080 , ':8080 ' ),
216
- array ('http ' , 4080 , null , 'http ' , 8080 , ':4080 ' ),
217
- array ('http ' , 80 , null , 'http ' , 8080 , '' ),
218
- array ('https ' , null , null , 'http ' , 8080 , '' ),
219
- array ('https ' , null , 8443 , 'http ' , 8080 , ':8443 ' ),
220
- array ('https ' , null , 443 , 'http ' , 8080 , '' ),
221
-
222
- array ('https ' , null , null , 'https ' , 8443 , ':8443 ' ),
223
- array ('https ' , null , 4443 , 'https ' , 8443 , ':4443 ' ),
224
- array ('https ' , null , 443 , 'https ' , 8443 , '' ),
225
- array ('http ' , null , null , 'https ' , 8443 , '' ),
226
- array ('http ' , 8080 , 4443 , 'https ' , 8443 , ':8080 ' ),
227
- array ('http ' , 80 , 4443 , 'https ' , 8443 , '' ),
244
+ array ('http ' , null , null , 'http ' , 8080 , ':8080 ' , false ),
245
+ array ('http ' , null , null , 'http ' , 8080 , ':8080 ' , true ),
246
+ array ('http ' , 4080 , null , 'http ' , 8080 , ':4080 ' , false ),
247
+ array ('http ' , 4080 , null , 'http ' , 8080 , ':4080 ' , true ),
248
+ array ('http ' , 80 , null , 'http ' , 8080 , '' , false ),
249
+ array ('http ' , 80 , null , 'http ' , 8080 , '' , true ),
250
+ array ('https ' , null , null , 'http ' , 8080 , '' , false ),
251
+ array ('https ' , null , null , 'http ' , 8080 , '' , true ),
252
+ array ('https ' , null , 8443 , 'http ' , 8080 , ':8443 ' , false ),
253
+ array ('https ' , null , 8443 , 'http ' , 8080 , ':8443 ' , true ),
254
+ array ('https ' , null , 443 , 'http ' , 8080 , '' , false ),
255
+ array ('https ' , null , 443 , 'http ' , 8080 , '' , true ),
256
+
257
+ array ('https ' , null , null , 'https ' , 8443 , ':8443 ' , false ),
258
+ array ('https ' , null , null , 'https ' , 8443 , ':8443 ' , true ),
259
+ array ('https ' , null , 4443 , 'https ' , 8443 , ':4443 ' , false ),
260
+ array ('https ' , null , 4443 , 'https ' , 8443 , ':4443 ' , true ),
261
+ array ('https ' , null , 443 , 'https ' , 8443 , '' , false ),
262
+ array ('https ' , null , 443 , 'https ' , 8443 , '' , true ),
263
+ array ('http ' , null , null , 'https ' , 8443 , '' , false ),
264
+ array ('http ' , null , null , 'https ' , 8443 , '' , true ),
265
+ array ('http ' , 8080 , 4443 , 'https ' , 8443 , ':8080 ' , false ),
266
+ array ('http ' , 8080 , 4443 , 'https ' , 8443 , ':8080 ' , true ),
267
+ array ('http ' , 80 , 4443 , 'https ' , 8443 , '' , false ),
268
+ array ('http ' , 80 , 4443 , 'https ' , 8443 , '' , true ),
228
269
);
229
270
}
230
271
231
272
/**
232
273
* @dataProvider urlRedirectProvider
233
274
*/
234
- public function testUrlRedirect ($ scheme , $ httpPort , $ httpsPort , $ requestScheme , $ requestPort , $ expectedPort )
275
+ public function testUrlRedirect ($ scheme , $ httpPort , $ httpsPort , $ requestScheme , $ requestPort , $ expectedPort, bool $ invoke )
235
276
{
236
277
$ host = 'www.example.com ' ;
237
278
$ baseUrl = '/base ' ;
238
279
$ path = '/redirect-path ' ;
239
280
$ expectedUrl = "$ scheme:// $ host$ expectedPort$ baseUrl$ path " ;
240
281
241
- $ request = $ this ->createRequestObject ($ requestScheme , $ host , $ requestPort , $ baseUrl );
282
+ $ attributes = $ invoke ? ['path ' => $ path , 'permanent ' => false , 'scheme ' => $ scheme , 'httpPort ' => $ httpPort , 'httpsPort ' => $ httpsPort ] : [];
283
+ $ request = $ this ->createRequestObject ($ requestScheme , $ host , $ requestPort , $ baseUrl , '' , $ attributes );
242
284
$ controller = $ this ->createRedirectController ();
243
285
244
- $ returnValue = $ controller ->urlRedirectAction ($ request , $ path , false , $ scheme , $ httpPort , $ httpsPort );
286
+ $ returnValue = $ invoke ? $ controller ( $ request ) : $ controller ->urlRedirectAction ($ request , $ path , false , $ scheme , $ httpPort , $ httpsPort );
245
287
$ this ->assertRedirectUrl ($ returnValue , $ expectedUrl );
246
288
}
247
289
248
290
public function pathQueryParamsProvider ()
249
291
{
250
292
return array (
251
- array ('http://www.example.com/base/redirect-path ' , '/redirect-path ' , '' ),
252
- array ('http://www.example.com/base/redirect-path?foo=bar ' , '/redirect-path?foo=bar ' , '' ),
253
- array ('http://www.example.com/base/redirect-path?foo=bar ' , '/redirect-path ' , 'foo=bar ' ),
254
- array ('http://www.example.com/base/redirect-path?foo=bar&abc=example ' , '/redirect-path?foo=bar ' , 'abc=example ' ),
255
- array ('http://www.example.com/base/redirect-path?foo=bar&abc=example&baz=def ' , '/redirect-path?foo=bar ' , 'abc=example&baz=def ' ),
293
+ array ('http://www.example.com/base/redirect-path ' , '/redirect-path ' , '' , false ),
294
+ array ('http://www.example.com/base/redirect-path ' , '/redirect-path ' , '' , true ),
295
+ array ('http://www.example.com/base/redirect-path?foo=bar ' , '/redirect-path?foo=bar ' , '' , false ),
296
+ array ('http://www.example.com/base/redirect-path?foo=bar ' , '/redirect-path?foo=bar ' , '' , true ),
297
+ array ('http://www.example.com/base/redirect-path?foo=bar ' , '/redirect-path ' , 'foo=bar ' , false ),
298
+ array ('http://www.example.com/base/redirect-path?foo=bar ' , '/redirect-path ' , 'foo=bar ' , true ),
299
+ array ('http://www.example.com/base/redirect-path?foo=bar&abc=example ' , '/redirect-path?foo=bar ' , 'abc=example ' , false ),
300
+ array ('http://www.example.com/base/redirect-path?foo=bar&abc=example ' , '/redirect-path?foo=bar ' , 'abc=example ' , true ),
301
+ array ('http://www.example.com/base/redirect-path?foo=bar&abc=example&baz=def ' , '/redirect-path?foo=bar ' , 'abc=example&baz=def ' , false ),
302
+ array ('http://www.example.com/base/redirect-path?foo=bar&abc=example&baz=def ' , '/redirect-path?foo=bar ' , 'abc=example&baz=def ' , true ),
256
303
);
257
304
}
258
305
259
306
/**
260
307
* @dataProvider pathQueryParamsProvider
261
308
*/
262
- public function testPathQueryParams ($ expectedUrl , $ path , $ queryString )
309
+ public function testPathQueryParams ($ expectedUrl , $ path , $ queryString, bool $ invoke )
263
310
{
264
311
$ scheme = 'http ' ;
265
312
$ host = 'www.example.com ' ;
266
313
$ baseUrl = '/base ' ;
267
314
$ port = 80 ;
268
315
269
- $ request = $ this ->createRequestObject ($ scheme , $ host , $ port , $ baseUrl , $ queryString );
316
+ $ attributes = $ invoke ? ['path ' => $ path , 'permanent ' => false , 'scheme ' => $ scheme , 'port ' => $ port ] : [];
317
+ $ request = $ this ->createRequestObject ($ scheme , $ host , $ port , $ baseUrl , $ queryString , $ attributes );
270
318
271
319
$ controller = $ this ->createRedirectController ();
272
320
273
- $ returnValue = $ controller ->urlRedirectAction ($ request , $ path , false , $ scheme , $ port , null );
321
+ $ returnValue = $ invoke ? $ controller ( $ request ) : $ controller ->urlRedirectAction ($ request , $ path , false , $ scheme , $ port , null );
274
322
$ this ->assertRedirectUrl ($ returnValue , $ expectedUrl );
275
323
}
276
324
277
- private function createRequestObject ($ scheme , $ host , $ port , $ baseUrl , $ queryString = '' )
325
+ private function createRequestObject ($ scheme , $ host , $ port , $ baseUrl , $ queryString = '' , $ attributes = [] )
278
326
{
279
327
$ request = $ this ->getMockBuilder ('Symfony\Component\HttpFoundation\Request ' )->getMock ();
280
328
$ request
@@ -298,6 +346,8 @@ private function createRequestObject($scheme, $host, $port, $baseUrl, $queryStri
298
346
->method ('getQueryString ' )
299
347
->will ($ this ->returnValue ($ queryString ));
300
348
349
+ $ request ->attributes = new ParameterBag ($ attributes );
350
+
301
351
return $ request ;
302
352
}
303
353
0 commit comments