RouteTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. class RouteTest extends PHPUnit_Framework_TestCase {
  3. public function testSimpleRouteCallbackReturnsResponseInstance()
  4. {
  5. $route = new System\Route('GET /', function() {return 'test';});
  6. $this->assertInstanceOf('System\\Response', $route->call());
  7. $this->assertEquals($route->call()->content, 'test');
  8. }
  9. public function testRouteCallPassesParametersToCallback()
  10. {
  11. $route = new System\Route('GET /', function($parameter) {return $parameter;}, array('test'));
  12. $this->assertEquals($route->call()->content, 'test');
  13. $route = new System\Route('GET /', function($parameter1, $parameter2) {return $parameter1.$parameter2;}, array('test1', 'test2'));
  14. $this->assertEquals($route->call()->content, 'test1test2');
  15. }
  16. public function testRouteCallWithNullBeforeFilterReturnsRouteResponse()
  17. {
  18. $route = new System\Route('GET /', array('before' => 'test', 'do' => function() {return 'route';}));
  19. System\Route\Filter::$filters = array('test' => function() {return null;});
  20. $this->assertEquals($route->call()->content, 'route');
  21. }
  22. public function testRouteCallWithOverridingBeforeFilterReturnsFilterResponse()
  23. {
  24. $route = new System\Route('GET /', array('before' => 'test', 'do' => function() {return 'route';}));
  25. System\Route\Filter::$filters = array('test' => function() {return 'filter';});
  26. $this->assertEquals($route->call()->content, 'filter');
  27. }
  28. public function testRouteAfterFilterIsCalled()
  29. {
  30. $route = new System\Route('GET /', array('after' => 'test', 'do' => function() {return 'route';}));
  31. System\Route\Filter::$filters = array('test' => function() {define('LARAVEL_TEST_AFTER_FILTER', 'ran');});
  32. $route->call();
  33. $this->assertTrue(defined('LARAVEL_TEST_AFTER_FILTER'));
  34. }
  35. public function testRouteAfterFilterDoesNotAffectResponse()
  36. {
  37. $route = new System\Route('GET /', array('after' => 'test', 'do' => function() {return 'route';}));
  38. System\Route\Filter::$filters = array('test' => function() {return 'filter';});
  39. $this->assertEquals($route->call()->content, 'route');
  40. }
  41. }