From cae2ae3128c745e5017cebcb97060481e20beb2a Mon Sep 17 00:00:00 2001 From: Anton Grebnev Date: Mon, 31 Oct 2011 19:59:00 +0400 Subject: [PATCH] Router class tested --- tests/app/router/RouterTest.php | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/app/router/RouterTest.php diff --git a/tests/app/router/RouterTest.php b/tests/app/router/RouterTest.php new file mode 100644 index 0000000..142ddae --- /dev/null +++ b/tests/app/router/RouterTest.php @@ -0,0 +1,64 @@ + + * @link http://netmonsters.ru + * @package Majestic + * @subpackage UnitTests + * @since 2011-10-31 + * + * Unit tests for Router class + */ + +require_once dirname(__FILE__) . '/../../../classes/Env.class.php'; +require_once dirname(__FILE__) . '/../../../app/router/Route.php'; +require_once dirname(__FILE__) . '/../../../app/router/Router.php'; + +class RouterTest extends PHPUnit_Framework_TestCase +{ + public function testGetRouteFirst() + { + $router = new Router(); + $this->assertNull($router->getRoute()); + $this->assertNull($router->getRouteName()); + } + + public function testRouterCycle() + { + $router = new Router(); + $router->add('user', 'user/account/:id', 'user'); + $route = $router->route('user/account/213'); + $this->assertEquals(1, count($route->getParams())); + $this->assertEquals(array('id' => 213), $route->getParams()); + $this->assertEquals('user', $router->getRouteName()); + } + + public function testRouterMultipleRoutes() + { + $router = new Router(); + $router->add('user', 'user/account/:id', 'user'); + $router->add('sale', 'sale/order/:id', 'user'); + $route = $router->route('user/account/213'); + $this->assertEquals('user', $router->getRouteName()); + $this->assertEquals(1, count($route->getParams())); + $this->assertEquals(array('id' => 213), $route->getParams()); + $route = $router->route('sale/order/22'); + $this->assertEquals('sale', $router->getRouteName()); + $this->assertEquals(array('id' => 22), $route->getParams()); + } + + public function testRouteNotmatch() + { + $router = new Router(); + $router->add('user', 'user/account/:id', 'user'); + $this->assertFalse($router->route('user/info/213')); + + } + + public function testSetDefaultLayout() + { + $router = new Router(); + $router->setDefaultLayout('userLayout'); + $this->assertAttributeEquals('userLayout', 'default_layout', $router); + } +}