1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-08-05 05:37:49 +02:00

[1.7.0] Implement DoctypeRegistry. Add transparent constructor to Doctype.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1059 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2007-05-14 22:36:35 +00:00
parent e7b15068c2
commit 6b9c5ec603
4 changed files with 164 additions and 5 deletions

View File

@@ -0,0 +1,80 @@
<?php
require_once 'HTMLPurifier/DoctypeRegistry.php';
class HTMLPurifier_DoctypeRegistryTest extends UnitTestCase
{
function test_register() {
$registry = new HTMLPurifier_DoctypeRegistry();
$d =& $registry->register(
$name = 'XHTML 1.0 Transitional',
$modules = array('module-one', 'module-two'),
$modulesForModes = array(
'lenient' => array('lenient-module'),
),
$aliases = array('X10T')
);
$d2 = new HTMLPurifier_Doctype($name, $modules, $modulesForModes, $aliases);
$this->assertIdentical($d, $d2);
$this->assertReference($d, $registry->get('XHTML 1.0 Transitional'));
// test shorthand
$d =& $registry->register(
$name = 'XHTML 1.0 Strict', 'module', array(), 'X10S'
);
$d2 = new HTMLPurifier_Doctype($name, array('module'), array(), array('X10S'));
$this->assertIdentical($d, $d2);
}
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 &lt;foo&gt; does not exist');
$registry->get('<foo>');
}
function testAliases() {
$registry = new HTMLPurifier_DoctypeRegistry();
$d1 =& $registry->register('Doc1', array(), array(), array('1'));
$this->assertReference($d1, $registry->get('Doc1'));
$this->assertReference($d1, $registry->get('1'));
$d2 =& $registry->register('Doc2', array(), array(), array('2'));
$this->assertReference($d2, $registry->get('Doc2'));
$this->assertReference($d2, $registry->get('2'));
$d3 =& $registry->register('1', array(), array(), array());
// literal name overrides alias
$this->assertReference($d3, $registry->get('1'));
$d4 =& $registry->register('One', array(), array(), array('1'));
$this->assertReference($d4, $registry->get('One'));
// still it overrides
$this->assertReference($d3, $registry->get('1'));
}
}
?>