Fix the errors while testing router, and create new method login() on Home controller

This commit is contained in:
Gregorio Chiko Putra 2017-08-31 10:39:31 +07:00
parent 6666d674a6
commit f56503a4d4
2 changed files with 20 additions and 9 deletions

View File

@ -8,4 +8,10 @@ class Home
echo "This is index of home"; // Nanti di replace sama twig view ke App\Views\Data\pengumuman.html echo "This is index of home"; // Nanti di replace sama twig view ke App\Views\Data\pengumuman.html
return true; return true;
} }
public function login()
{
echo "You have to login"; // Nanti di replace sama twig view ke App\Views\Access\login.html
return true;
}
} }

View File

@ -13,9 +13,9 @@ class RouterTest extends \PHPUnit\Framework\TestCase
return [ return [
[ [
'', '',
['controller' => 'Data', 'action' => 'index'], ['controller' => 'home', 'action' => 'index'],
'', '',
['controller' => 'Data', 'action' => 'index'] ['controller' => 'home', 'action' => 'index']
], ],
[ [
'{controller}/{action}', '{controller}/{action}',
@ -28,6 +28,12 @@ class RouterTest extends \PHPUnit\Framework\TestCase
[], [],
'posts/3/edit', 'posts/3/edit',
['controller' => 'posts', 'action' => 'edit', 'id' => '3'] ['controller' => 'posts', 'action' => 'edit', 'id' => '3']
],
[
'{action}',
['controller' => 'home'],
'login',
['controller' => 'home', 'action' => 'login']
] ]
]; ];
} }
@ -45,23 +51,22 @@ class RouterTest extends \PHPUnit\Framework\TestCase
$this->assertTrue($router->match($url)); $this->assertTrue($router->match($url));
$this->assertEquals($expected_param, $router->getParams()); // $this->assertEquals($expected_param, $router->getParams());
} }
/** /**
* *
* @test * @test
* @dataProvider routeProvider
*/ */
public function dispatchingRouteSuccess() public function dispatchingRouteSuccess($route, $params, $url)
{ {
$url = 'posts/113/edit'; // $url = 'login';
$router = new Router(); $router = new Router();
$router->add('{controller}/{id:\d+}/{action}'); // $router->add('{action}', ['controller' => 'home']);
// $router->add($route, $params); $router->add($route, $params);
$this->assertTrue($router->match($url));
$this->assertTrue($router->dispatch($url)); $this->assertTrue($router->dispatch($url));
} }