mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-09-19 18:55:19 +00:00
fac747bdbd
With minor corrections. Signed-off-by: Marcus Bointon <marcus@synchromedia.co.uk> Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
78 lines
2.2 KiB
PHP
78 lines
2.2 KiB
PHP
<?php
|
|
|
|
class HTMLPurifier_DoctypeRegistryTest extends HTMLPurifier_Harness
|
|
{
|
|
|
|
public function test_register()
|
|
{
|
|
$registry = new HTMLPurifier_DoctypeRegistry();
|
|
|
|
$d = $registry->register(
|
|
$name = 'XHTML 1.0 Transitional',
|
|
$xml = true,
|
|
$modules = array('module-one', 'module-two'),
|
|
$tidyModules = array('lenient-module'),
|
|
$aliases = array('X10T')
|
|
);
|
|
|
|
$d2 = new HTMLPurifier_Doctype($name, $xml, $modules, $tidyModules, $aliases);
|
|
|
|
$this->assertIdentical($d, $d2);
|
|
$this->assertSame($d, $registry->get('XHTML 1.0 Transitional'));
|
|
|
|
// test shorthand
|
|
$d = $registry->register(
|
|
$name = 'XHTML 1.0 Strict', true, 'module', 'Tidy', 'X10S'
|
|
);
|
|
$d2 = new HTMLPurifier_Doctype($name, true, array('module'), array('Tidy'), array('X10S'));
|
|
|
|
$this->assertIdentical($d, $d2);
|
|
|
|
}
|
|
|
|
public function test_get()
|
|
{
|
|
// see also alias and register tests
|
|
|
|
$registry = new HTMLPurifier_DoctypeRegistry();
|
|
|
|
$this->expectError('Doctype XHTML 2.0 does not exist');
|
|
$registry->get('XHTML 2.0');
|
|
|
|
// prevent XSS
|
|
$this->expectError('Doctype <foo> does not exist');
|
|
$registry->get('<foo>');
|
|
|
|
}
|
|
|
|
public function testAliases()
|
|
{
|
|
$registry = new HTMLPurifier_DoctypeRegistry();
|
|
|
|
$d1 = $registry->register('Doc1', true, array(), array(), array('1'));
|
|
|
|
$this->assertSame($d1, $registry->get('Doc1'));
|
|
$this->assertSame($d1, $registry->get('1'));
|
|
|
|
$d2 = $registry->register('Doc2', true, array(), array(), array('2'));
|
|
|
|
$this->assertSame($d2, $registry->get('Doc2'));
|
|
$this->assertSame($d2, $registry->get('2'));
|
|
|
|
$d3 = $registry->register('1', true, array(), array(), array());
|
|
|
|
// literal name overrides alias
|
|
$this->assertSame($d3, $registry->get('1'));
|
|
|
|
$d4 = $registry->register('One', true, array(), array(), array('1'));
|
|
|
|
$this->assertSame($d4, $registry->get('One'));
|
|
// still it overrides
|
|
$this->assertSame($d3, $registry->get('1'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// vim: et sw=4 sts=4
|