URIDefinitionTest.php 2.4 KB

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