Skip to content

Commit

Permalink
test: Move code to RoutesTest.php
Browse files Browse the repository at this point in the history
  • Loading branch information
neznaika0 committed Nov 8, 2023
1 parent 231a748 commit 4e872f7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 45 deletions.
28 changes: 28 additions & 0 deletions tests/system/Commands/RoutesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,32 @@ public function testRoutesCommandRouteLegacy(): void
EOL;
$this->assertStringContainsString($expected, $this->getBuffer());
}

public function testRoutesCommandWithAnyLocales(): void
{
$routes = $this->getCleanRoutes();
$routes->useSupportedLocalesOnly(false);
$routes->get('{locale}/admin/(:segment)', 'AdminController::index/$1', ['as' => 'admin']);

command('routes');

$expected = <<<'EOL'
| GET | {locale}/admin/([^/]+) | admin | \App\Controllers\AdminController::index/$1 | | toolbar |
EOL;
$this->assertStringContainsString($expected, $this->getBuffer());
}

public function testRoutesCommandWithSupportedLocalesOnly(): void
{
$routes = $this->getCleanRoutes();
$routes->useSupportedLocalesOnly(true);
$routes->get('{locale}/admin/(:segment)', 'AdminController::index/$1', ['as' => 'admin']);

command('routes');

$expected = <<<'EOL'
| GET | {locale}/admin/([^/]+) | admin | \App\Controllers\AdminController::index/$1 | | !toolbar |
EOL;
$this->assertStringContainsString($expected, $this->getBuffer());
}
}
45 changes: 0 additions & 45 deletions tests/system/Commands/Utilities/Routes/FilterFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@ 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 @@ -321,42 +314,4 @@ 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 4e872f7

Please sign in to comment.