Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 73672a2

Browse filesBrowse files
committed
Finish tests
1 parent 2701838 commit 73672a2
Copy full SHA for 73672a2

File tree

2 files changed

+85
-35
lines changed
Filter options

2 files changed

+85
-35
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,6 @@ public function __invoke(Request $request): Response
153153
return $this->redirectAction($request, $route, $request->attributes->getBoolean('permanent', false), $request->attributes->get('ignoreAttributes', false));
154154
}
155155

156-
return $this->urlRedirectAction($request, $request->attributes->get('path'), $request->attributes->getBoolean('permanent', false), $request->attributes->get('scheme'), $request->attributes->getInt('httpPort'), $request->attributes->getInt('httpsPort'));
156+
return $this->urlRedirectAction($request, $request->attributes->get('path'), $request->attributes->getBoolean('permanent', false), $request->attributes->get('scheme'), $request->attributes->get('httpPort'), $request->attributes->get('httpsPort'));
157157
}
158158
}

‎src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php
+84-34Lines changed: 84 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -197,84 +197,132 @@ public function testUrlRedirectDefaultPorts()
197197
$this->assertRedirectUrl($returnValue, $expectedUrl);
198198
}
199199

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+
200221
public function urlRedirectProvider()
201222
{
202223
return array(
203224
// 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),
213242

214243
// 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),
228269
);
229270
}
230271

231272
/**
232273
* @dataProvider urlRedirectProvider
233274
*/
234-
public function testUrlRedirect($scheme, $httpPort, $httpsPort, $requestScheme, $requestPort, $expectedPort)
275+
public function testUrlRedirect($scheme, $httpPort, $httpsPort, $requestScheme, $requestPort, $expectedPort, bool $invoke)
235276
{
236277
$host = 'www.example.com';
237278
$baseUrl = '/base';
238279
$path = '/redirect-path';
239280
$expectedUrl = "$scheme://$host$expectedPort$baseUrl$path";
240281

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);
242284
$controller = $this->createRedirectController();
243285

244-
$returnValue = $controller->urlRedirectAction($request, $path, false, $scheme, $httpPort, $httpsPort);
286+
$returnValue = $invoke ? $controller($request) : $controller->urlRedirectAction($request, $path, false, $scheme, $httpPort, $httpsPort);
245287
$this->assertRedirectUrl($returnValue, $expectedUrl);
246288
}
247289

248290
public function pathQueryParamsProvider()
249291
{
250292
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),
256303
);
257304
}
258305

259306
/**
260307
* @dataProvider pathQueryParamsProvider
261308
*/
262-
public function testPathQueryParams($expectedUrl, $path, $queryString)
309+
public function testPathQueryParams($expectedUrl, $path, $queryString, bool $invoke)
263310
{
264311
$scheme = 'http';
265312
$host = 'www.example.com';
266313
$baseUrl = '/base';
267314
$port = 80;
268315

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);
270318

271319
$controller = $this->createRedirectController();
272320

273-
$returnValue = $controller->urlRedirectAction($request, $path, false, $scheme, $port, null);
321+
$returnValue = $invoke ? $controller($request) : $controller->urlRedirectAction($request, $path, false, $scheme, $port, null);
274322
$this->assertRedirectUrl($returnValue, $expectedUrl);
275323
}
276324

277-
private function createRequestObject($scheme, $host, $port, $baseUrl, $queryString = '')
325+
private function createRequestObject($scheme, $host, $port, $baseUrl, $queryString = '', $attributes = [])
278326
{
279327
$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();
280328
$request
@@ -298,6 +346,8 @@ private function createRequestObject($scheme, $host, $port, $baseUrl, $queryStri
298346
->method('getQueryString')
299347
->will($this->returnValue($queryString));
300348

349+
$request->attributes = new ParameterBag($attributes);
350+
301351
return $request;
302352
}
303353

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.