Skip to content

Commit

Permalink
test: Add test for routes containing {locale}
Browse files Browse the repository at this point in the history
  • Loading branch information
neznaika0 committed Nov 6, 2023
1 parent 4bde417 commit 0ae7e6a
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 additions & 3 deletions tests/system/Commands/Utilities/Routes/FilterFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ protected function setUp(): void
$this->moduleConfig->enabled = false;
}

protected function tearDown(): void
{
parent::tearDown();

$this->resetServices();
}

private function createRouteCollection(array $routes = []): RouteCollection
{
$collection = new RouteCollection(Services::locator(), $this->moduleConfig, new Routing());
Expand Down Expand Up @@ -137,7 +144,7 @@ public function testFindGlobalsFiltersWithRedirectRoute(): void
public function testFindGlobalsAndRouteFilters(): void
{
$collection = $this->createRouteCollection();
$collection->get('admin', ' AdminController::index', ['filter' => 'honeypot']);
$collection->get('admin', 'AdminController::index', ['filter' => 'honeypot']);
$router = $this->createRouter($collection);
$filters = $this->createFilters();

Expand All @@ -155,7 +162,7 @@ public function testFindGlobalsAndRouteFilters(): void
public function testFindGlobalsAndRouteClassnameFilters(): void
{
$collection = $this->createRouteCollection();
$collection->get('admin', ' AdminController::index', ['filter' => InvalidChars::class]);
$collection->get('admin', 'AdminController::index', ['filter' => InvalidChars::class]);
$router = $this->createRouter($collection);
$filters = $this->createFilters();

Expand All @@ -173,7 +180,7 @@ public function testFindGlobalsAndRouteClassnameFilters(): void
public function testFindGlobalsAndRouteMultipleFilters(): void
{
$collection = $this->createRouteCollection();
$collection->get('admin', ' AdminController::index', ['filter' => ['honeypot', InvalidChars::class]]);
$collection->get('admin', 'AdminController::index', ['filter' => ['honeypot', InvalidChars::class]]);
$router = $this->createRouter($collection);
$filters = $this->createFilters();

Expand Down Expand Up @@ -314,4 +321,42 @@ public function testFilterOrderWithOldFilterOrder()
];
$this->assertSame($expected, $filters);
}

public function testFindFiltersWithAnyLocales(): void
{
$collection = $this->createRouteCollection();
$collection->useSupportedLocalesOnly(false);
$collection->get('{locale}/admin/(:segment)', 'AdminController::index/$1');
Services::injectMock('routes', $collection);
$router = $this->createRouter($collection);
$filters = $this->createFilters();
$finder = new FilterFinder($router, $filters);

$filters = $finder->find('{locale}/admin/settings');

$expected = [
'before' => ['csrf'],
'after' => ['toolbar'],
];
$this->assertSame($expected, $filters);
}

public function testFindFiltersWithSupportedLocalesOnly(): void
{
$collection = $this->createRouteCollection();
$collection->useSupportedLocalesOnly(true);
$collection->get('{locale}/admin/(:segment)', 'AdminController::index/$1');
Services::injectMock('routes', $collection);
$router = $this->createRouter($collection);
$filters = $this->createFilters();
$finder = new FilterFinder($router, $filters);

$filters = $finder->find('{locale}/admin/settings');

$expected = [
'before' => ['!csrf'],
'after' => ['!toolbar'],
];
$this->assertSame($expected, $filters);
}
}

0 comments on commit 0ae7e6a

Please sign in to comment.