lepisi-pengumuman/_tests/unit/RouterTest.php

69 lines
1.5 KiB
PHP

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