Source for file RouterTest.php
Documentation is available at RouterTest.php
* File for the RouterTest class
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @copyright (c) Walter O. Haas 2006
* @version $Id: RouterTest.php 192 2006-03-27 22:02:53Z haas $
* @author Walt Haas <haas@xmission.com>
require_once 'testenv.php';
// Call RouterTest::main() if this source file is executed directly.
if (!defined("PHPUnit2_MAIN_METHOD")) {
define("PHPUnit2_MAIN_METHOD", "RouterTest::main");
require_once "PHPUnit2/Framework/TestCase.php";
require_once "PHPUnit2/Framework/TestSuite.php";
// You may remove the following line when all tests have been implemented.
require_once "PHPUnit2/Framework/IncompleteTestError.php";
require_once "router.php";
* Generated by PHPUnit2_Util_Skeleton on 2006-03-01 at 15:31:34.
class RouterTest extends PHPUnit2_Framework_TestCase {
* Runs the test methods of this class.
public static function main() {
require_once "PHPUnit2/TextUI/TestRunner.php";
$suite = new PHPUnit2_Framework_TestSuite("RouterTest");
$result = PHPUnit2_TextUI_TestRunner::run($suite);
* Sets up the fixture, for example, open a network connection.
* This method is called before a test is executed.
protected function setUp() {
* Tears down the fixture, for example, close a network connection.
* This method is called after a test is executed.
* Test build_route_regexp().
// Two abstract route components
$regexp = $r->build_route_regexp(':foo/:bar');
$this->assertEquals($regexp,
'^[a-z0-9_\-]+\/[a-z0-9_\-]+$');
// Three abstract route components
$regexp = $r->build_route_regexp(':foo/:bar/:mumble');
$this->assertEquals($regexp,
'^[a-z0-9_\-]+\/[a-z0-9_\-]+\/[a-z0-9_\-]+$');
// Abstract, concrete, abstract route components
$regexp = $r->build_route_regexp(':foo/bar/:mumble');
$this->assertEquals($regexp,
'^[a-z0-9_\-]+\/bar\/[a-z0-9_\-]+$');
// Two concrete route components
$regexp = $r->build_route_regexp('foo/bar');
$this->assertEquals($regexp,
* Test default route table
// Should find default route
$route = $r->find_route('a/b/mumble');
$this->assertEquals(':controller/:action/:id', $route['path']);
$this->assertNull($route['params']);
* Test route table with one simple entry besides default
$r->connect(':foo/:bar/mumble', array('mumble route'));
// Params not an array ignored, null is stored
$r->connect(':controller/:action/:id', 'not-an-array');
$route = $r->find_route('a/b/mumble');
$this->assertEquals(':foo/:bar/mumble', $route['path']);
$this->assertEquals(array('mumble route'), $route['params']);
$selected = $r->get_selected_route();
$this->assertEquals(':foo/:bar/mumble', $selected['path']);
$this->assertEquals(array('mumble route'), $selected['params']);
$route = $r->find_route('a/b/c');
$this->assertEquals(':controller/:action/:id', $route['path']);
$this->assertNull($route['params']);
$selected = $r->get_selected_route();
$this->assertEquals(':controller/:action/:id', $selected['path']);
$this->assertNull($selected['params']);
* Test route table with one regexp entry besides default
$r->connect(':foo/:bar/\?(catalog|part)number=.*',
$r->connect(':controller/:action/:id', array('default route'));
$route = $r->find_route('a/b/?catalognumber=17');
$this->assertEquals(':foo/:bar/\?(catalog|part)number=.*',
$this->assertEquals(array('number route'), $route['params']);
$route = $r->find_route('a/b/?partnumber=123-456');
$this->assertEquals(':foo/:bar/\?(catalog|part)number=.*',
$this->assertEquals(array('number route'), $route['params']);
$route = $r->find_route('a/b/?personnumber=156');
$this->assertEquals(':controller/:action/:id', $route['path']);
$this->assertEquals(array('default route'), $route['params']);
* Test route table with route with empty path
// Build route table with only an empty path
$r->connect('', array('empty route'));
$route = $r->find_route('');
$this->assertEquals('', $route['path']);
$this->assertEquals(array('empty route'), $route['params']);
// This route shouldn't match anything
$route = $r->find_route('mumble/foo');
$this->assertNull($route);
// Call RouterTest::main() if this source file is executed directly.
// -- set Emacs parameters --
// c-hanging-comment-ender-p: nil
|