You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.0 KiB

  1. <?php
  2. /*
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage UnitTests
  7. * @since 2011-10-31
  8. *
  9. * Unit tests for Router class
  10. */
  11. require_once dirname(__FILE__) . '/../../../classes/Env.class.php';
  12. require_once dirname(__FILE__) . '/../../../app/router/Route.php';
  13. require_once dirname(__FILE__) . '/../../../app/router/Router.php';
  14. class RouterTest extends PHPUnit_Framework_TestCase
  15. {
  16. public function testGetRouteFirst()
  17. {
  18. $router = new Router();
  19. $this->assertNull($router->getRoute());
  20. $this->assertNull($router->getRouteName());
  21. }
  22. public function testRouterCycle()
  23. {
  24. $router = new Router();
  25. $router->add('user', 'user/account/:id', 'user');
  26. $route = $router->route('user/account/213');
  27. $this->assertSame(1, count($route->getParams()));
  28. $this->assertSame(array('id' => '213'), $route->getParams());
  29. $this->assertSame('user', $router->getRouteName());
  30. }
  31. public function testRouterMultipleRoutes()
  32. {
  33. $router = new Router();
  34. $router->add('user', 'user/account/:id', 'user');
  35. $router->add('sale', 'sale/order/:id', 'user');
  36. $route = $router->route('user/account/213');
  37. $this->assertSame('user', $router->getRouteName());
  38. $this->assertSame(1, count($route->getParams()));
  39. $this->assertSame(array('id' => '213'), $route->getParams());
  40. $route = $router->route('sale/order/22');
  41. $this->assertSame('sale', $router->getRouteName());
  42. $this->assertSame(array('id' => '22'), $route->getParams());
  43. }
  44. public function testRouteNotmatch()
  45. {
  46. $router = new Router();
  47. $router->add('user', 'user/account/:id', 'user');
  48. $this->assertFalse($router->route('user/info/213'));
  49. }
  50. public function testSetDefaultLayout()
  51. {
  52. $router = new Router();
  53. $router->setDefaultLayout('userLayout');
  54. $this->assertAttributeEquals('userLayout', 'default_layout', $router);
  55. }
  56. }