RouteFilterTest.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. class RouteFilerTest extends PHPUnit_Framework_TestCase {
  3. public static function setUpBeforeClass()
  4. {
  5. $filters = array(
  6. 'test' => function() {return 'test';},
  7. 'vars' => function($var) {return $var;},
  8. 'vars2' => function($var1, $var2) {return $var1.$var2;},
  9. );
  10. System\Route\Filter::$filters = $filters;
  11. }
  12. public static function tearDownAfterClass()
  13. {
  14. System\Route\Filter::$filters = require APP_PATH.'filters'.EXT;
  15. }
  16. /**
  17. * @expectedException Exception
  18. */
  19. public function testCallingUndefinedFilterThrowsException()
  20. {
  21. System\Route\Filter::call('not-found');
  22. }
  23. public function testCallingFilterWithoutOverrideReturnsNull()
  24. {
  25. $this->assertNull(System\Route\Filter::call('test'));
  26. }
  27. public function testCallingFilterWithOverrideReturnsResult()
  28. {
  29. $this->assertEquals(System\Route\Filter::call('test', array(), true), 'test');
  30. }
  31. public function testCallingFilterWithParametersPassesParametersToFilter()
  32. {
  33. $this->assertEquals(System\Route\Filter::call('vars', array('test'), true), 'test');
  34. $this->assertEquals(System\Route\Filter::call('vars2', array('test1', 'test2'), true), 'test1test2');
  35. }
  36. }