|
25 | 25 |
|
26 | 26 | class HttpUtilsTest extends TestCase
|
27 | 27 | {
|
28 |
| - public function testCreateRedirectResponseWithPath() |
| 28 | + /** |
| 29 | + * @dataProvider validRequestDomainUrls |
| 30 | + */ |
| 31 | + public function testCreateRedirectResponseWithPath(?string $domainRegexp, string $path, string $expectedRedirectUri) |
29 | 32 | {
|
30 |
| - $utils = new HttpUtils($this->getUrlGenerator()); |
31 |
| - $response = $utils->createRedirectResponse($this->getRequest(), '/foobar'); |
| 33 | + $utils = new HttpUtils($this->getUrlGenerator(), null, $domainRegexp); |
| 34 | + $response = $utils->createRedirectResponse($this->getRequest(), $path); |
32 | 35 |
|
33 |
| - $this->assertTrue($response->isRedirect('http://localhost/foobar')); |
| 36 | + $this->assertTrue($response->isRedirect($expectedRedirectUri)); |
34 | 37 | $this->assertEquals(302, $response->getStatusCode());
|
35 | 38 | }
|
36 | 39 |
|
37 |
| - public function testCreateRedirectResponseWithAbsoluteUrl() |
38 |
| - { |
39 |
| - $utils = new HttpUtils($this->getUrlGenerator()); |
40 |
| - $response = $utils->createRedirectResponse($this->getRequest(), 'http://symfony.com/'); |
41 |
| - |
42 |
| - $this->assertTrue($response->isRedirect('http://symfony.com/')); |
43 |
| - } |
44 |
| - |
45 |
| - public function testCreateRedirectResponseWithDomainRegexp() |
| 40 | + public static function validRequestDomainUrls() |
46 | 41 | {
|
47 |
| - $utils = new HttpUtils($this->getUrlGenerator(), null, '#^https?://symfony\.com$#i'); |
48 |
| - $response = $utils->createRedirectResponse($this->getRequest(), 'http://symfony.com/blog'); |
49 |
| - |
50 |
| - $this->assertTrue($response->isRedirect('http://symfony.com/blog')); |
51 |
| - } |
52 |
| - |
53 |
| - public function testCreateRedirectResponseWithRequestsDomain() |
54 |
| - { |
55 |
| - $utils = new HttpUtils($this->getUrlGenerator(), null, '#^https?://%s$#i'); |
56 |
| - $response = $utils->createRedirectResponse($this->getRequest(), 'http://localhost/blog'); |
57 |
| - |
58 |
| - $this->assertTrue($response->isRedirect('http://localhost/blog')); |
| 42 | + return [ |
| 43 | + '/foobar' => [ |
| 44 | + null, |
| 45 | + '/foobar', |
| 46 | + 'http://localhost/foobar', |
| 47 | + ], |
| 48 | + 'http://symfony.com/ without domain regex' => [ |
| 49 | + null, |
| 50 | + 'http://symfony.com/', |
| 51 | + 'http://symfony.com/', |
| 52 | + ], |
| 53 | + 'http://localhost/blog with #^https?://symfony\.com$#i' => [ |
| 54 | + '#^https?://symfony\.com$#i', |
| 55 | + 'http://symfony.com/blog', |
| 56 | + 'http://symfony.com/blog', |
| 57 | + ], |
| 58 | + 'http://localhost/blog with #^https?://%s$#i' => [ |
| 59 | + '#^https?://%s$#i', |
| 60 | + 'http://localhost/blog', |
| 61 | + 'http://localhost/blog', |
| 62 | + ], |
| 63 | + 'custom scheme' => [ |
| 64 | + null, |
| 65 | + 'android-app://com.google.android.gm/', |
| 66 | + 'android-app://com.google.android.gm/', |
| 67 | + ], |
| 68 | + 'custom scheme with all URL components' => [ |
| 69 | + null, |
| 70 | + 'android-app://foo:[email protected]:8080/software/index.html?lite=true#section1', |
| 71 | + 'android-app://foo:[email protected]:8080/software/index.html?lite=true#section1', |
| 72 | + ], |
| 73 | + 'URN #1' => [ |
| 74 | + null, |
| 75 | + 'urn:ietf:rfc:8141', |
| 76 | + 'urn:ietf:rfc:8141', |
| 77 | + ], |
| 78 | + 'URN #2' => [ |
| 79 | + null, |
| 80 | + 'urn:EXAMPLE:a123,z456', |
| 81 | + 'urn:EXAMPLE:a123,z456', |
| 82 | + ], |
| 83 | + ]; |
59 | 84 | }
|
60 | 85 |
|
61 | 86 | /**
|
|
0 commit comments