RouteFilterTest.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php use Laravel\Routing\Filter;
  2. class RouteFilterTest extends PHPUnit_Framework_TestCase {
  3. public function test_simple_filters_can_be_called()
  4. {
  5. $filters = array(
  6. 'simple' => function()
  7. {
  8. return 'simple';
  9. },
  10. 'parameters' => function($one, $two, $three = null)
  11. {
  12. return $one.'|'.$two.'|'.$three;
  13. },
  14. );
  15. Filter::register($filters);
  16. $this->assertEquals(Filter::run(array('simple'), array(), true), 'simple');
  17. $this->assertEquals(Filter::run(array('parameters:1,2'), array(), true), '1|2|');
  18. $this->assertEquals(Filter::run(array('parameters:1,2'), array(3), true), '3|1|2');
  19. }
  20. public function test_after_filters_are_called()
  21. {
  22. $filters = array(
  23. 'after1' => function()
  24. {
  25. define('ROUTE_FILTER_AFTER_1', 1);
  26. },
  27. 'after2' => function()
  28. {
  29. define('ROUTE_FILTER_AFTER_2', 2);
  30. },
  31. );
  32. Filter::register($filters);
  33. Filter::run(array('after1', 'after2'));
  34. $this->assertTrue(defined('ROUTE_FILTER_AFTER_1'));
  35. $this->assertTrue(defined('ROUTE_FILTER_AFTER_2'));
  36. }
  37. }