Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: route options are not merged (outer filter is merged with inner filter) #8033

Merged
merged 7 commits into from
Oct 14, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions tests/system/Router/RouteCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,104 @@ static function ($routes): void {
$this->assertSame($expected, $routes->getRoutes());
}

public function testGroupNestedWithOuterOptionsWithoutInnerOptions(): void
{
$routes = $this->getCollector();

$routes->group(
'admin',
['namespace' => 'Admin', 'filter' => ['csrf']],
static function ($routes) {
$routes->get('dashboard', static function () {
});

$routes->group('profile', static function ($routes) {
$routes->get('/', static function () {
});
});
}
);

$expected = [
'admin/dashboard' => [
'namespace' => 'Admin',
'filter' => ['csrf'],
],
'admin/profile' => [
'namespace' => 'Admin',
'filter' => ['csrf'],
],
];
$this->assertSame($expected, $routes->getRoutesOptions());
}

public function testGroupNestedWithOuterAndInnerOption(): void
{
$routes = $this->getCollector();

$routes->group(
'admin',
['filter' => ['csrf']],
static function ($routes) {
$routes->get('dashboard', static function () {
});

$routes->group(
'profile',
['filter' => ['honeypot']],
static function ($routes) {
$routes->get('/', static function () {
});
}
);
}
);

$expected = [
'admin/dashboard' => [
'filter' => ['csrf'],
],
'admin/profile' => [
'filter' => ['honeypot'],
kenjis marked this conversation as resolved.
Show resolved Hide resolved
],
];
$this->assertSame($expected, $routes->getRoutesOptions());
}

public function testGroupNestedWithoutOuterOptionWithInnerOption(): void
{
$routes = $this->getCollector();

$routes->group(
'admin',
['filter' => 'csrf'],
static function ($routes) {
$routes->get('dashboard', static function () {
});

$routes->group(
'profile',
['namespace' => 'Admin'],
static function ($routes) {
$routes->get('/', static function () {
});
}
);
}
);

$expected = [
'admin/dashboard' => [
'filter' => 'csrf',
],
'admin/profile' => [
'filter' => 'csrf',
'namespace' => 'Admin',
],
];
$this->assertSame($expected, $routes->getRoutesOptions());
}

public function testGroupingWorksWithEmptyStringPrefix(): void
{
$routes = $this->getCollector();
Expand Down