2006-08-12 03:56:27 +00:00
|
|
|
<?php
|
|
|
|
|
2007-08-01 14:06:59 +00:00
|
|
|
class HTMLPurifier_URISchemeRegistryTest extends HTMLPurifier_Harness
|
2006-08-12 03:56:27 +00:00
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-12 03:56:27 +00:00
|
|
|
function test() {
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-12 17:06:14 +00:00
|
|
|
generate_mock_once('HTMLPurifier_URIScheme');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
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();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
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');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-26 15:40:04 +00:00
|
|
|
$scheme_http = new HTMLPurifier_URISchemeMock();
|
|
|
|
$scheme_telnet = new HTMLPurifier_URISchemeMock();
|
|
|
|
$scheme_foobar = new HTMLPurifier_URISchemeMock();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-12 17:06:14 +00:00
|
|
|
// 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);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
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);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
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);
|
2008-12-06 07:28:20 +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));
|
2008-12-06 07:28:20 +00:00
|
|
|
|
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));
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-12 03:56:27 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-12 03:56:27 +00:00
|
|
|
}
|
|
|
|
|