|
16 | 16 | use CodeIgniter\CodeIgniter; |
17 | 17 | use CodeIgniter\Router\RouteCollection; |
18 | 18 | use CodeIgniter\Shield\Auth; |
| 19 | +use InvalidArgumentException; |
19 | 20 | use Tests\Support\TestCase; |
20 | 21 |
|
21 | 22 | /** |
@@ -65,6 +66,36 @@ public function testRoutesExcept(): void |
65 | 66 | $this->assertArrayHasKey('auth/a/show', $routes); |
66 | 67 | } |
67 | 68 |
|
| 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 | + |
68 | 99 | public function testRoutesCustomNamespace(): void |
69 | 100 | { |
70 | 101 | $collection = single_service('routes'); |
|
0 commit comments