2006-08-12 03:56:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'HTMLPurifier/URISchemeRegistry.php';
|
|
|
|
|
|
|
|
class HTMLPurifier_URISchemeRegistryTest extends UnitTestCase
|
|
|
|
{
|
|
|
|
|
|
|
|
function test() {
|
|
|
|
|
2006-08-12 17:06:14 +00:00
|
|
|
generate_mock_once('HTMLPurifier_URIScheme');
|
|
|
|
|
2007-05-20 18:06:51 +00:00
|
|
|
$config = HTMLPurifier_Config::create(array(
|
|
|
|
'URI.AllowedSchemes' => 'http, telnet',
|
|
|
|
'URI.OverrideAllowedSchemes' => true
|
|
|
|
));
|
2006-10-27 01:20:10 +00:00
|
|
|
$context = new HTMLPurifier_Context();
|
2006-08-12 17:06:14 +00:00
|
|
|
|
|
|
|
$registry = new HTMLPurifier_URISchemeRegistry();
|
2006-10-27 01:20:10 +00:00
|
|
|
$this->assertIsA($registry->getScheme('http', $config, $context), 'HTMLPurifier_URIScheme_http');
|
2006-08-12 03:56:27 +00:00
|
|
|
|
2006-08-12 17:06:14 +00:00
|
|
|
$scheme_http = new HTMLPurifier_URISchemeMock($this);
|
|
|
|
$scheme_telnet = new HTMLPurifier_URISchemeMock($this);
|
|
|
|
$scheme_foobar = new HTMLPurifier_URISchemeMock($this);
|
|
|
|
|
|
|
|
// register a new scheme
|
|
|
|
$registry->register('telnet', $scheme_telnet);
|
2006-10-27 01:20:10 +00:00
|
|
|
$this->assertIdentical($registry->getScheme('telnet', $config, $context), $scheme_telnet);
|
2006-08-12 17:06:14 +00:00
|
|
|
|
|
|
|
// overload a scheme, this is FINAL (forget about defaults)
|
|
|
|
$registry->register('http', $scheme_http);
|
2006-10-27 01:20:10 +00:00
|
|
|
$this->assertIdentical($registry->getScheme('http', $config, $context), $scheme_http);
|
2006-08-12 17:06:14 +00:00
|
|
|
|
|
|
|
// when we register a scheme, it's automatically allowed
|
|
|
|
$registry->register('foobar', $scheme_foobar);
|
2006-10-27 01:20:10 +00:00
|
|
|
$this->assertIdentical($registry->getScheme('foobar', $config, $context), $scheme_foobar);
|
2006-08-12 17:06:14 +00:00
|
|
|
|
2006-08-12 17:12:27 +00:00
|
|
|
// now, test when overriding is not allowed
|
2007-05-20 18:06:51 +00:00
|
|
|
$config = HTMLPurifier_Config::create(array(
|
|
|
|
'URI.AllowedSchemes' => 'http, telnet',
|
|
|
|
'URI.OverrideAllowedSchemes' => false
|
|
|
|
));
|
2006-10-27 01:20:10 +00:00
|
|
|
$this->assertNull($registry->getScheme('foobar', $config, $context));
|
2006-08-12 17:12:27 +00:00
|
|
|
|
|
|
|
// scheme not allowed and never registered
|
2006-10-27 01:20:10 +00:00
|
|
|
$this->assertNull($registry->getScheme('ftp', $config, $context));
|
2006-08-12 03:56:27 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|