Skip to content

Commit b8dd442

Browse files
committed
test: add tests for fallback to default controller
1 parent 29e293a commit b8dd442

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

tests/system/Router/AutoRouterImprovedTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,45 @@ public function testAutoRouteFallbackToDefaultMethod()
213213
$this->assertSame(['15'], $params);
214214
}
215215

216+
public function testAutoRouteFallbackToDefaultControllerOneParam()
217+
{
218+
$router = $this->createNewAutoRouter();
219+
220+
[$directory, $controller, $method, $params]
221+
= $router->getRoute('subfolder/15');
222+
223+
$this->assertSame('Subfolder/', $directory);
224+
$this->assertSame('\CodeIgniter\Router\Controllers\Subfolder\Home', $controller);
225+
$this->assertSame('getIndex', $method);
226+
$this->assertSame(['15'], $params);
227+
}
228+
229+
public function testAutoRouteFallbackToDefaultControllerTwoParams()
230+
{
231+
$router = $this->createNewAutoRouter();
232+
233+
[$directory, $controller, $method, $params]
234+
= $router->getRoute('subfolder/15/20');
235+
236+
$this->assertSame('Subfolder/', $directory);
237+
$this->assertSame('\CodeIgniter\Router\Controllers\Subfolder\Home', $controller);
238+
$this->assertSame('getIndex', $method);
239+
$this->assertSame(['15', '20'], $params);
240+
}
241+
242+
public function testAutoRouteFallbackToDefaultControllerNoParams()
243+
{
244+
$router = $this->createNewAutoRouter();
245+
246+
[$directory, $controller, $method, $params]
247+
= $router->getRoute('subfolder');
248+
249+
$this->assertSame('Subfolder/', $directory);
250+
$this->assertSame('\CodeIgniter\Router\Controllers\Subfolder\Home', $controller);
251+
$this->assertSame('getIndex', $method);
252+
$this->assertSame([], $params);
253+
}
254+
216255
public function testAutoRouteRejectsSingleDot()
217256
{
218257
$this->expectException(PageNotFoundException::class);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/**
4+
* This file is part of CodeIgniter 4 framework.
5+
*
6+
* (c) CodeIgniter Foundation <[email protected]>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
namespace CodeIgniter\Router\Controllers\Subfolder;
13+
14+
use CodeIgniter\Controller;
15+
16+
class Home extends Controller
17+
{
18+
public function getIndex($p1 = null, $p2 = null)
19+
{
20+
}
21+
}

0 commit comments

Comments
 (0)