Prepended constants with C_ to avoid reserved words as per https://www.php.net/manual...
[htmlpurifier/darkodev.git] / tests / HTMLPurifier / URISchemeRegistryTest.php
blob5988d4655c6ef1d84b52c632a17926281dda7f01
1 <?php
3 class HTMLPurifier_URISchemeRegistryTest extends HTMLPurifier_Harness
6 public function test()
8 generate_mock_once('HTMLPurifier_URIScheme');
10 $config = HTMLPurifier_Config::create(array(
11 'URI.AllowedSchemes' => 'http, telnet',
12 'URI.OverrideAllowedSchemes' => true
13 ));
14 $context = new HTMLPurifier_Context();
16 $registry = new HTMLPurifier_URISchemeRegistry();
17 $this->assertIsA($registry->getScheme('http', $config, $context), 'HTMLPurifier_URIScheme_http');
19 $scheme_http = new HTMLPurifier_URISchemeMock();
20 $scheme_telnet = new HTMLPurifier_URISchemeMock();
21 $scheme_foobar = new HTMLPurifier_URISchemeMock();
23 // register a new scheme
24 $registry->register('telnet', $scheme_telnet);
25 $this->assertIdentical($registry->getScheme('telnet', $config, $context), $scheme_telnet);
27 // overload a scheme, this is FINAL (forget about defaults)
28 $registry->register('http', $scheme_http);
29 $this->assertIdentical($registry->getScheme('http', $config, $context), $scheme_http);
31 // when we register a scheme, it's automatically allowed
32 $registry->register('foobar', $scheme_foobar);
33 $this->assertIdentical($registry->getScheme('foobar', $config, $context), $scheme_foobar);
35 // now, test when overriding is not allowed
36 $config = HTMLPurifier_Config::create(array(
37 'URI.AllowedSchemes' => 'http, telnet',
38 'URI.OverrideAllowedSchemes' => false
39 ));
40 $this->assertNull($registry->getScheme('foobar', $config, $context));
42 // scheme not allowed and never registered
43 $this->assertNull($registry->getScheme('ftp', $config, $context));
49 // vim: et sw=4 sts=4