Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

50 linhas
1.8KB

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