|
10 | 10 | */
|
11 | 11 | class RouteRedirectTest extends TestCase
|
12 | 12 | {
|
13 |
| - public function test_route_redirect() |
| 13 | + /** |
| 14 | + * @dataProvider routeRedirectDataSets |
| 15 | + * |
| 16 | + * @param string $redirectFrom |
| 17 | + * @param string $redirectTo |
| 18 | + * @param string $responseUri |
| 19 | + */ |
| 20 | + public function testRouteRedirect($redirectFrom, $redirectTo, $responseUri) |
14 | 21 | {
|
15 |
| - Route::redirect('from', 'to', 301); |
| 22 | + Route::redirect($redirectFrom, $redirectTo, 301); |
16 | 23 |
|
17 |
| - $response = $this->get('/from'); |
18 |
| - $this->assertEquals(301, $response->getStatusCode()); |
19 |
| - $this->assertEquals('to', $response->headers->get('Location')); |
| 24 | + $response = $this->get($responseUri); |
| 25 | + $response->assertRedirect($redirectTo); |
| 26 | + $response->assertStatus(301); |
20 | 27 | }
|
21 | 28 |
|
22 |
| - public function test_route_redirect_with_params() |
| 29 | + public function routeRedirectDataSets(): array |
23 | 30 | {
|
24 |
| - Route::redirect('from/{param}/{param2?}', 'to', 301); |
25 |
| - |
26 |
| - $response = $this->get('/from/value1/value2'); |
27 |
| - $response->assertRedirect('to'); |
28 |
| - |
29 |
| - $this->assertEquals(301, $response->getStatusCode()); |
30 |
| - $this->assertEquals('to', $response->headers->get('Location')); |
31 |
| - |
32 |
| - $response = $this->get('/from/value1'); |
33 |
| - $response->assertRedirect('to'); |
34 |
| - |
35 |
| - $this->assertEquals(301, $response->getStatusCode()); |
36 |
| - $this->assertEquals('to', $response->headers->get('Location')); |
| 31 | + return [ |
| 32 | + 'route redirect with no parameters' => ['from', 'to', '/from'], |
| 33 | + 'route redirect with one parameter' => ['from/{param}/{param2?}', 'to', '/from/value1'], |
| 34 | + 'route redirect with two parameters' => ['from/{param}/{param2?}', 'to', '/from/value1/value2'], |
| 35 | + ]; |
37 | 36 | }
|
38 | 37 | }
|
0 commit comments