Skip to content

Commit b793225

Browse files
committed
test: tests for only options in routes configuartion
1 parent 5201fe0 commit b793225

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

tests/Unit/AuthRoutesTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use CodeIgniter\CodeIgniter;
1717
use CodeIgniter\Router\RouteCollection;
1818
use CodeIgniter\Shield\Auth;
19+
use InvalidArgumentException;
1920
use Tests\Support\TestCase;
2021

2122
/**
@@ -65,6 +66,36 @@ public function testRoutesExcept(): void
6566
$this->assertArrayHasKey('auth/a/show', $routes);
6667
}
6768

69+
public function testRoutesOnly(): void
70+
{
71+
$collection = single_service('routes');
72+
$auth = service('auth');
73+
74+
$auth->routes($collection, ['only' => ['login']]);
75+
76+
if (version_compare(CodeIgniter::CI_VERSION, '4.5') >= 0) {
77+
$routes = $collection->getRoutes('GET');
78+
} else {
79+
$routes = $collection->getRoutes('get');
80+
}
81+
82+
$this->assertArrayHasKey('login', $routes);
83+
$this->assertArrayNotHasKey('register', $routes);
84+
$this->assertArrayNotHasKey('login/magic-link', $routes);
85+
$this->assertArrayNotHasKey('logout', $routes);
86+
$this->assertArrayNotHasKey('auth/a/show', $routes);
87+
}
88+
89+
public function testRoutesUseOnlyAndExceptOptionsSimultaneous(): void
90+
{
91+
$this->expectException(InvalidArgumentException::class);
92+
93+
$collection = single_service('routes');
94+
$auth = service('auth');
95+
96+
$auth->routes($collection, ['only' => ['login'], 'except' => ['register']]);
97+
}
98+
6899
public function testRoutesCustomNamespace(): void
69100
{
70101
$collection = single_service('routes');

0 commit comments

Comments
 (0)