Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pjsde committed Jun 4, 2022
1 parent e68710b commit 8872eb9
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/system/Router/RouteCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace CodeIgniter\Router;

use CodeIgniter\Config\Services;
use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\Router\Exceptions\RouterException;
use CodeIgniter\Test\CIUnitTestCase;
use Config\Modules;
Expand Down Expand Up @@ -1809,4 +1810,32 @@ public function testGetRegisteredControllersDoesNotReturnClosures()
$expects = [];
$this->assertSame($expects, $routes);
}

public function testSetLocalePattern()
{
$routes = $this->getCollector();
$routes->setDefaultNamespace('App\Controllers');
$routes->setLocalePattern('(en|pt)');

$routes->get('{locale}/products', 'Products::list');

$router = new Router($routes, Services::request());
$x = $router->handle('pt/products');

$this->assertSame('\App\Controllers\Products', $x);
$this->assertSame('pt', $router->getLocale());
$this->assertSame('(en|pt)', $routes->getLocalePattern());
}

public function testRouterHandleWithSetLocaleThrowsPageNotFoundException()
{
$routes = $this->getCollector();
$routes->setDefaultNamespace('App\Controllers');
$routes->setLocalePattern('(en|pt)');
$routes->get('{locale}/products', 'Products::list');
$router = new Router($routes, Services::request());

$this->expectException(PageNotFoundException::class);
$router->handle('fr/products');
}
}

0 comments on commit 8872eb9

Please sign in to comment.