You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.5KB

  1. <?php
  2. class HTMLPurifier_URIDefinitionTest extends HTMLPurifier_URIHarness
  3. {
  4. protected function createFilterMock($expect = true, $result = true, $post = false, $setup = true)
  5. {
  6. static $i = 0;
  7. generate_mock_once('HTMLPurifier_URIFilter');
  8. $mock = new HTMLPurifier_URIFilterMock();
  9. if ($expect) $mock->expectOnce('filter');
  10. else $mock->expectNever('filter');
  11. $mock->setReturnValue('filter', $result);
  12. $mock->setReturnValue('prepare', $setup);
  13. $mock->name = $i++;
  14. $mock->post = $post;
  15. return $mock;
  16. }
  17. public function test_filter()
  18. {
  19. $def = new HTMLPurifier_URIDefinition();
  20. $def->addFilter($this->createFilterMock(), $this->config);
  21. $def->addFilter($this->createFilterMock(), $this->config);
  22. $uri = $this->createURI('test');
  23. $this->assertTrue($def->filter($uri, $this->config, $this->context));
  24. }
  25. public function test_filter_earlyAbortIfFail()
  26. {
  27. $def = new HTMLPurifier_URIDefinition();
  28. $def->addFilter($this->createFilterMock(true, false), $this->config);
  29. $def->addFilter($this->createFilterMock(false), $this->config); // never called
  30. $uri = $this->createURI('test');
  31. $this->assertFalse($def->filter($uri, $this->config, $this->context));
  32. }
  33. public function test_setupMemberVariables_collisionPrecedenceIsHostBaseScheme()
  34. {
  35. $this->config->set('URI.Host', $host = 'example.com');
  36. $this->config->set('URI.Base', $base = 'http://sub.example.com/foo/bar.html');
  37. $this->config->set('URI.DefaultScheme', 'ftp');
  38. $def = new HTMLPurifier_URIDefinition();
  39. $def->setup($this->config);
  40. $this->assertIdentical($def->host, $host);
  41. $this->assertIdentical($def->base, $this->createURI($base));
  42. $this->assertIdentical($def->defaultScheme, 'http'); // not ftp!
  43. }
  44. public function test_setupMemberVariables_onlyScheme()
  45. {
  46. $this->config->set('URI.DefaultScheme', 'ftp');
  47. $def = new HTMLPurifier_URIDefinition();
  48. $def->setup($this->config);
  49. $this->assertIdentical($def->defaultScheme, 'ftp');
  50. }
  51. public function test_setupMemberVariables_onlyBase()
  52. {
  53. $this->config->set('URI.Base', 'http://sub.example.com/foo/bar.html');
  54. $def = new HTMLPurifier_URIDefinition();
  55. $def->setup($this->config);
  56. $this->assertIdentical($def->host, 'sub.example.com');
  57. }
  58. }
  59. // vim: et sw=4 sts=4