CacheHandlerTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Elgg;
  3. class CacheHandlerTest extends \PHPUnit_Framework_TestCase {
  4. /**
  5. * @var \Elgg\CacheHandler
  6. */
  7. protected $handler;
  8. public function setUp() {
  9. $config = (object)array();
  10. $this->handler = new \Elgg\CacheHandler($config);
  11. }
  12. protected function _testParseFail($input) {
  13. $this->assertEquals(array(), $this->handler->parseRequestVar($input));
  14. }
  15. public function testCanParseValidRequest() {
  16. $this->assertEquals(array(
  17. 'ts' => '1234',
  18. 'viewtype' => 'default',
  19. 'view' => 'hel/8lo-wo_rl.d.js',
  20. ), $this->handler->parseRequestVar('1234/default/hel/8lo-wo_rl.d.js'));
  21. }
  22. public function testCantParseDoubleDot() {
  23. $this->_testParseFail('1234/default/hel/8lo-wo_rl..d.js');
  24. }
  25. public function testParserRequiresNumericTs() {
  26. $this->_testParseFail('a1234/default/hel/8lo-wo_rl.d.js');
  27. }
  28. public function testParserRequiresNonEmptyViewtype() {
  29. $this->_testParseFail('1234//hel/8lo-wo_rl.d.js');
  30. }
  31. public function testParserHasCharWhitelist() {
  32. $this->_testParseFail('a1234/default/he~l/8lo-wo_rl.d.js');
  33. }
  34. public function testParseSupportsLeadingSlash() {
  35. $this->assertEquals(array(
  36. 'ts' => '1234',
  37. 'viewtype' => 'default',
  38. 'view' => 'hel/8lo-wo_rl.d.js',
  39. ), $this->handler->parseRequestVar('/1234/default/hel/8lo-wo_rl.d.js'));
  40. }
  41. }