Commit d6e21a41 by Taylor Otwell

adding routing tests.

parent f93532d2
<?php
use Laravel\Routing\Router;
class RoutingTest extends PHPUnit_Framework_TestCase {
/**
* Destroy the testing environment.
*/
public function tearDown()
{
Router::$names = array();
Router::$routes = array();
}
/**
* Test the basic routing mechanism.
*
* @group laravel
*/
public function testBasicRouteCanBeRouted()
{
Router::register('GET /', function() {});
Router::register('GET /home', function() {});
$this->assertEquals('GET /', Router::route('GET', '/')->key);
$this->assertEquals('GET /home', Router::route('GET', '/home')->key);
}
/**
* Test that the router can handle basic wildcards.
*
* @group laravel
*/
public function testWildcardRoutesCanBeRouted()
{
Router::register('GET /user/(:num)', function() {});
Router::register('GET /profile/(:any)/(:num)', function() {});
$this->assertNull(Router::route('GET', 'user/1.5'));
$this->assertNull(Router::route('GET', 'user/taylor'));
$this->assertEquals('GET /user/(:num)', Router::route('GET', 'user/1')->key);
$this->assertNull(Router::route('GET', 'profile/1/otwell'));
$this->assertNull(Router::route('POST', 'profile/taylor/1'));
$this->assertNull(Router::route('GET', 'profile/taylor/otwell'));
$this->assertNull(Router::route('GET', 'profile/taylor/1/otwell'));
$this->assertEquals('GET /profile/(:any)/(:num)', Router::route('GET', 'profile/taylor/1')->key);
}
/**
* Test that optional wildcards can be routed.
*
* @group laravel
*/
public function testOptionalWildcardsCanBeRouted()
{
Router::register('GET /user/(:num?)', function() {});
Router::register('GET /profile/(:any)/(:any?)', function() {});
$this->assertNull(Router::route('GET', 'user/taylor'));
$this->assertEquals('GET /user/(:num?)', Router::route('GET', 'user')->key);
$this->assertEquals('GET /user/(:num?)', Router::route('GET', 'user/1')->key);
$this->assertNull(Router::route('GET', 'profile/taylor/otwell/test'));
$this->assertEquals('GET /profile/(:any)/(:any?)', Router::route('GET', 'profile/taylor')->key);
$this->assertEquals('GET /profile/(:any)/(:any?)', Router::route('GET', 'profile/taylor/25')->key);
$this->assertEquals('GET /profile/(:any)/(:any?)', Router::route('GET', 'profile/taylor/otwell')->key);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment