diff options
author | Roman Tsiupa <draconyster@gmail.com> | 2013-02-26 21:42:48 +0200 |
---|---|---|
committer | Roman Tsiupa <draconyster@gmail.com> | 2013-02-26 21:42:48 +0200 |
commit | 1690da36a5c5ad309de7117f3d8b52f045ebc9bf (patch) | |
tree | a5462fc3e5067ec21aca7b00ce2486d62e2bc944 | |
parent | 83612e2f4311ff943955939b8f3ab46838a7880b (diff) | |
download | PHPixie-1690da36a5c5ad309de7117f3d8b52f045ebc9bf.zip PHPixie-1690da36a5c5ad309de7117f3d8b52f045ebc9bf.tar.gz PHPixie-1690da36a5c5ad309de7117f3d8b52f045ebc9bf.tar.bz2 |
Test for reverse routing
-rw-r--r-- | system/classes/route.php | 19 | ||||
-rw-r--r-- | tests/system/routeTest.php | 13 |
2 files changed, 32 insertions, 0 deletions
diff --git a/system/classes/route.php b/system/classes/route.php index e791155..c1b9457 100644 --- a/system/classes/route.php +++ b/system/classes/route.php @@ -50,11 +50,30 @@ class Route { */ private static $routes = array(); + /** + * Constructs a route. + * + * @param string $name Name of the route + * @param mixed $rule Rule for this route + * @param array $defaults Default parameters for the route + * @return Route Initialized Route + * @access protected + */ protected function __construct($name, $rule, $defaults) { $this->name = $name; $this->rule = $rule; $this->defaults = $defaults; } + + /** + * Generates a url for a route + * + * @param array $params Parameters to substitute in the route + * @param bool $absolute Whether to return an absolute url + * @param string $protocol Protocol to use for absolute url + * @return string Generated url + * @access public + */ public function url($params = array(), $absolute = false, $protocol = 'http') { if (is_callable($this->rule)) throw new Exception("The rule for '{$this->name}' route is a function and cannot be reversed"); diff --git a/tests/system/routeTest.php b/tests/system/routeTest.php index 1cda47b..58d0295 100644 --- a/tests/system/routeTest.php +++ b/tests/system/routeTest.php @@ -107,4 +107,17 @@ class RoteTest extends PHPUnit_Framework_TestCase $this->assertEquals('test', $route-> params['alpha']); $this->assertEquals(123,$route->params['num']); } + + /** + * @covers Route::url + */ + public function testUrl() + { + Route::add('url', '/<controller>/<action>(/<id>)', array( + 'controller' => 'home', + 'action' => 'index' + )); + $route = Route::get('url'); + $this->assertEquals('/home/index/5', $route->url(array('id'=>5))); + } } |