URISchemeRegistryTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. class HTMLPurifier_URISchemeRegistryTest extends HTMLPurifier_Harness
  3. {
  4. function test() {
  5. generate_mock_once('HTMLPurifier_URIScheme');
  6. $config = HTMLPurifier_Config::create(array(
  7. 'URI.AllowedSchemes' => 'http, telnet',
  8. 'URI.OverrideAllowedSchemes' => true
  9. ));
  10. $context = new HTMLPurifier_Context();
  11. $registry = new HTMLPurifier_URISchemeRegistry();
  12. $this->assertIsA($registry->getScheme('http', $config, $context), 'HTMLPurifier_URIScheme_http');
  13. $scheme_http = new HTMLPurifier_URISchemeMock();
  14. $scheme_telnet = new HTMLPurifier_URISchemeMock();
  15. $scheme_foobar = new HTMLPurifier_URISchemeMock();
  16. // register a new scheme
  17. $registry->register('telnet', $scheme_telnet);
  18. $this->assertIdentical($registry->getScheme('telnet', $config, $context), $scheme_telnet);
  19. // overload a scheme, this is FINAL (forget about defaults)
  20. $registry->register('http', $scheme_http);
  21. $this->assertIdentical($registry->getScheme('http', $config, $context), $scheme_http);
  22. // when we register a scheme, it's automatically allowed
  23. $registry->register('foobar', $scheme_foobar);
  24. $this->assertIdentical($registry->getScheme('foobar', $config, $context), $scheme_foobar);
  25. // now, test when overriding is not allowed
  26. $config = HTMLPurifier_Config::create(array(
  27. 'URI.AllowedSchemes' => 'http, telnet',
  28. 'URI.OverrideAllowedSchemes' => false
  29. ));
  30. $this->assertNull($registry->getScheme('foobar', $config, $context));
  31. // scheme not allowed and never registered
  32. $this->assertNull($registry->getScheme('ftp', $config, $context));
  33. }
  34. }
  35. // vim: et sw=4 sts=4