added tests to main repository.

This commit is contained in:
Taylor Otwell
2011-07-13 22:27:14 -05:00
parent cffbcd010d
commit d3398db56f
11 changed files with 587 additions and 1 deletions

55
tests/suite/RouteTest.php Normal file
View File

@@ -0,0 +1,55 @@
<?php
class RouteTest extends PHPUnit_Framework_TestCase {
public function testSimpleRouteCallbackReturnsResponseInstance()
{
$route = new System\Route('GET /', function() {return 'test';});
$this->assertInstanceOf('System\\Response', $route->call());
$this->assertEquals($route->call()->content, 'test');
}
public function testRouteCallPassesParametersToCallback()
{
$route = new System\Route('GET /', function($parameter) {return $parameter;}, array('test'));
$this->assertEquals($route->call()->content, 'test');
$route = new System\Route('GET /', function($parameter1, $parameter2) {return $parameter1.$parameter2;}, array('test1', 'test2'));
$this->assertEquals($route->call()->content, 'test1test2');
}
public function testRouteCallWithNullBeforeFilterReturnsRouteResponse()
{
$route = new System\Route('GET /', array('before' => 'test', 'do' => function() {return 'route';}));
System\Route\Filter::$filters = array('test' => function() {return null;});
$this->assertEquals($route->call()->content, 'route');
}
public function testRouteCallWithOverridingBeforeFilterReturnsFilterResponse()
{
$route = new System\Route('GET /', array('before' => 'test', 'do' => function() {return 'route';}));
System\Route\Filter::$filters = array('test' => function() {return 'filter';});
$this->assertEquals($route->call()->content, 'filter');
}
public function testRouteAfterFilterIsCalled()
{
$route = new System\Route('GET /', array('after' => 'test', 'do' => function() {return 'route';}));
System\Route\Filter::$filters = array('test' => function() {define('LARAVEL_TEST_AFTER_FILTER', 'ran');});
$route->call();
$this->assertTrue(defined('LARAVEL_TEST_AFTER_FILTER'));
}
public function testRouteAfterFilterDoesNotAffectResponse()
{
$route = new System\Route('GET /', array('after' => 'test', 'do' => function() {return 'route';}));
System\Route\Filter::$filters = array('test' => function() {return 'filter';});
$this->assertEquals($route->call()->content, 'route');
}
}