lepisi-pengumuman/_tests/unit/RouterTest.php
Gregorio Chiko Putra 00c5aba77d Huge updates:
1. Redesigned the web
2. Fixed logging in redirect issue
3. Added new route
4. Fixed sql issue on entry
5. Fixed typos
2017-09-14 16:39:53 +07:00

82 lines
2.1 KiB
PHP

<?php
namespace Core;
class RouterTest extends \PHPUnit\Framework\TestCase
{
/**
* Data provider for matchingRouteSuccess
*
* Contains: route, params, $_SERVER['REQUEST_URI'], expected_params
*
* @return array
*/
public function routeProvider()
{
return [
[
'',
['controller' => 'posts', 'action' => 'index'],
'',
['controller' => 'posts', 'action' => 'index']
],
[
'{controller}/{action}',
[],
'/posts/entry',
['controller' => 'posts', 'action' => 'entry']
],
[
'{controller}/{action}/{id:\d+}',
[],
'/posts/edit/3',
['controller' => 'posts', 'action' => 'edit', 'id' => '3']
],
[
'{action}',
['controller' => 'home'],
'/login',
['controller' => 'home', 'action' => 'login']
],
[
'{?status:\d+}',
['controller' => 'posts', 'action' => 'index'],
'/?status=1',
['controller' => 'posts', 'action' => 'index', 'status' => '1']
]
];
}
/**
*
* @test
* @dataProvider routeProvider
*/
public function matchingRouteSuccess($route, $params, $url, $expected_param)
{
$router = new Router();
$router->add($route, $params);
// echo "$route\n$url\n";
// var_dump($router->getRoutes());
$this->assertTrue($router->match($url));
$this->assertEquals($expected_param, $router->getParams());
var_dump($router->getParams());
}
/**
*
* @test
* @dataProvider routeProvider
*/
// public function dispatchingRouteSuccess($route, $params, $url)
// {
// $router = new Router();
// $router->add($route, $params);
//
// $this->assertTrue($router->dispatch($url));
// }
}