|
14 | 14 | use CodeIgniter\Config\Services;
|
15 | 15 | use CodeIgniter\Exceptions\ConfigException;
|
16 | 16 | use CodeIgniter\HTTP\Response;
|
| 17 | +use CodeIgniter\Router\Exceptions\RedirectException; |
17 | 18 | use CodeIgniter\Router\RouteCollection;
|
18 | 19 | use CodeIgniter\Test\CIUnitTestCase;
|
19 | 20 | use CodeIgniter\Test\Filters\CITestStreamFilter;
|
@@ -570,6 +571,29 @@ public function testRunRedirectionWithPOSTAndHTTPCode301()
|
570 | 571 | $this->assertSame(301, $response->getStatusCode());
|
571 | 572 | }
|
572 | 573 |
|
| 574 | + /** |
| 575 | + * test for deprecated \CodeIgniter\Router\Exceptions\RedirectException for backward compatibility |
| 576 | + */ |
| 577 | + public function testRedirectExceptionDeprecated(): void |
| 578 | + { |
| 579 | + $_SERVER['argv'] = ['index.php', '/']; |
| 580 | + $_SERVER['argc'] = 2; |
| 581 | + |
| 582 | + // Inject mock router. |
| 583 | + $routes = Services::routes(); |
| 584 | + $routes->get('/', static function () { |
| 585 | + throw new RedirectException('redirect-exception', 503); |
| 586 | + }); |
| 587 | + |
| 588 | + $router = Services::router($routes, Services::incomingrequest()); |
| 589 | + Services::injectMock('router', $router); |
| 590 | + |
| 591 | + $response = $this->codeigniter->run($routes, true); |
| 592 | + |
| 593 | + $this->assertSame(503, $response->getStatusCode()); |
| 594 | + $this->assertSame('http://example.com/redirect-exception', $response->getHeaderLine('Location')); |
| 595 | + } |
| 596 | + |
573 | 597 | public function testStoresPreviousURL()
|
574 | 598 | {
|
575 | 599 | $_SERVER['argv'] = ['index.php', '/'];
|
|
0 commit comments