1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-08-08 15:16:54 +02:00

Release 1.5.0, merged in r688-867.

- LanguageFactory::instance() declared static
- HTMLModuleManagerTest pass by reference bug fixed, merge back into trunk scheduled

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/branches/strict@869 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2007-03-24 01:04:06 +00:00
parent cec7a1c087
commit dd2fd06591
130 changed files with 4324 additions and 1385 deletions

View File

@@ -1,14 +1,14 @@
<?php
require_once 'HTMLPurifier/AttrDefHarness.php';
require_once 'HTMLPurifier/AttrDef/BackgroundPosition.php';
require_once 'HTMLPurifier/AttrDef/CSS/BackgroundPosition.php';
class HTMLPurifier_AttrDef_BackgroundPositionTest extends HTMLPurifier_AttrDefHarness
class HTMLPurifier_AttrDef_CSS_BackgroundPositionTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_BackgroundPosition();
$this->def = new HTMLPurifier_AttrDef_CSS_BackgroundPosition();
// explicitly cited in spec
$this->assertDef('0% 0%');

View File

@@ -1,14 +1,15 @@
<?php
require_once 'HTMLPurifier/AttrDefHarness.php';
require_once 'HTMLPurifier/AttrDef/Background.php';
require_once 'HTMLPurifier/AttrDef/CSS/Background.php';
class HTMLPurifier_AttrDef_BackgroundTest extends HTMLPurifier_AttrDefHarness
class HTMLPurifier_AttrDef_CSS_BackgroundTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_Background(HTMLPurifier_Config::createDefault());
$config = HTMLPurifier_Config::createDefault();
$this->def = new HTMLPurifier_AttrDef_CSS_Background($config);
$valid = '#333 url(chess.png) repeat fixed 50% top';
$this->assertDef($valid);

View File

@@ -1,14 +1,14 @@
<?php
require_once 'HTMLPurifier/AttrDef/Border.php';
require_once 'HTMLPurifier/AttrDef/PixelsTest.php';
require_once 'HTMLPurifier/AttrDef/CSS/Border.php';
class HTMLPurifier_AttrDef_BorderTest extends HTMLPurifier_AttrDef_PixelsTest
class HTMLPurifier_AttrDef_CSS_BorderTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_Border(HTMLPurifier_Config::createDefault());
$config = HTMLPurifier_Config::createDefault();
$this->def = new HTMLPurifier_AttrDef_CSS_Border($config);
$this->assertDef('thick solid red', 'thick solid #F00');
$this->assertDef('thick solid');

View File

@@ -1,14 +1,14 @@
<?php
require_once 'HTMLPurifier/AttrDef/Color.php';
require_once 'HTMLPurifier/AttrDef/CSS/Color.php';
require_once 'HTMLPurifier/AttrDefHarness.php';
class HTMLPurifier_AttrDef_ColorTest extends HTMLPurifier_AttrDefHarness
class HTMLPurifier_AttrDef_CSS_ColorTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_Color();
$this->def = new HTMLPurifier_AttrDef_CSS_Color();
$this->assertDef('#F00');
$this->assertDef('#808080');

View File

@@ -1,20 +1,20 @@
<?php
require_once 'HTMLPurifier/AttrDef/Composite.php';
require_once 'HTMLPurifier/AttrDef/CSS/Composite.php';
require_once 'HTMLPurifier/AttrDefHarness.php';
class HTMLPurifier_AttrDef_Composite_Testable extends
HTMLPurifier_AttrDef_Composite
class HTMLPurifier_AttrDef_CSS_Composite_Testable extends
HTMLPurifier_AttrDef_CSS_Composite
{
// we need to pass by ref to get the mocks in
function HTMLPurifier_AttrDef_Composite_Testable(&$defs) {
function HTMLPurifier_AttrDef_CSS_Composite_Testable(&$defs) {
$this->defs =& $defs;
}
}
class HTMLPurifier_AttrDef_CompositeTest extends HTMLPurifier_AttrDefHarness
class HTMLPurifier_AttrDef_CSS_CompositeTest extends HTMLPurifier_AttrDefHarness
{
var $def1, $def2;
@@ -32,7 +32,7 @@ class HTMLPurifier_AttrDef_CompositeTest extends HTMLPurifier_AttrDefHarness
$def1 = new HTMLPurifier_AttrDefMock($this);
$def2 = new HTMLPurifier_AttrDefMock($this);
$defs = array(&$def1, &$def2);
$def = new HTMLPurifier_AttrDef_Composite_Testable($defs);
$def = new HTMLPurifier_AttrDef_CSS_Composite_Testable($defs);
$input = 'FOOBAR';
$output = 'foobar';
$def1_params = array($input, $config, $context);
@@ -51,7 +51,7 @@ class HTMLPurifier_AttrDef_CompositeTest extends HTMLPurifier_AttrDefHarness
$def1 = new HTMLPurifier_AttrDefMock($this);
$def2 = new HTMLPurifier_AttrDefMock($this);
$defs = array(&$def1, &$def2);
$def = new HTMLPurifier_AttrDef_Composite_Testable($defs);
$def = new HTMLPurifier_AttrDef_CSS_Composite_Testable($defs);
$input = 'BOOMA';
$output = 'booma';
$def_params = array($input, $config, $context);
@@ -71,7 +71,7 @@ class HTMLPurifier_AttrDef_CompositeTest extends HTMLPurifier_AttrDefHarness
$def1 = new HTMLPurifier_AttrDefMock($this);
$def2 = new HTMLPurifier_AttrDefMock($this);
$defs = array(&$def1, &$def2);
$def = new HTMLPurifier_AttrDef_Composite_Testable($defs);
$def = new HTMLPurifier_AttrDef_CSS_Composite_Testable($defs);
$input = 'BOOMA';
$output = false;
$def_params = array($input, $config, $context);

View File

@@ -1,14 +1,14 @@
<?php
require_once 'HTMLPurifier/AttrDefHarness.php';
require_once 'HTMLPurifier/AttrDef/FontFamily.php';
require_once 'HTMLPurifier/AttrDef/CSS/FontFamily.php';
class HTMLPurifier_AttrDef_FontFamilyTest extends HTMLPurifier_AttrDefHarness
class HTMLPurifier_AttrDef_CSS_FontFamilyTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_FontFamily();
$this->def = new HTMLPurifier_AttrDef_CSS_FontFamily();
$this->assertDef('Gill, Helvetica, sans-serif');
$this->assertDef('\'Times New Roman\', serif');

View File

@@ -1,14 +1,15 @@
<?php
require_once 'HTMLPurifier/AttrDefHarness.php';
require_once 'HTMLPurifier/AttrDef/Font.php';
require_once 'HTMLPurifier/AttrDef/CSS/Font.php';
class HTMLPurifier_AttrDef_FontTest extends HTMLPurifier_AttrDefHarness
class HTMLPurifier_AttrDef_CSS_FontTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_Font(HTMLPurifier_Config::createDefault());
$config = HTMLPurifier_Config::createDefault();
$this->def = new HTMLPurifier_AttrDef_CSS_Font($config);
// hodgepodge of usage cases from W3C spec, but " -> '
$this->assertDef('12px/14px sans-serif');

View File

@@ -1,14 +1,14 @@
<?php
require_once 'HTMLPurifier/AttrDef/CSSLength.php';
require_once 'HTMLPurifier/AttrDef/CSS/Length.php';
require_once 'HTMLPurifier/AttrDefHarness.php';
class HTMLPurifier_AttrDef_CSSLengthTest extends HTMLPurifier_AttrDefHarness
class HTMLPurifier_AttrDef_CSS_LengthTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_CSSLength();
$this->def = new HTMLPurifier_AttrDef_CSS_Length();
$this->assertDef('0');
$this->assertDef('0px');
@@ -31,7 +31,7 @@ class HTMLPurifier_AttrDef_CSSLengthTest extends HTMLPurifier_AttrDefHarness
function testNonNegative() {
$this->def = new HTMLPurifier_AttrDef_CSSLength(true);
$this->def = new HTMLPurifier_AttrDef_CSS_Length(true);
$this->assertDef('3cm');
$this->assertDef('-3mm', false);

View File

@@ -1,14 +1,15 @@
<?php
require_once 'HTMLPurifier/AttrDefHarness.php';
require_once 'HTMLPurifier/AttrDef/ListStyle.php';
require_once 'HTMLPurifier/AttrDef/CSS/ListStyle.php';
class HTMLPurifier_AttrDef_ListStyleTest extends HTMLPurifier_AttrDefHarness
class HTMLPurifier_AttrDef_CSS_ListStyleTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_ListStyle(HTMLPurifier_Config::createDefault());
$config = HTMLPurifier_Config::createDefault();
$this->def = new HTMLPurifier_AttrDef_CSS_ListStyle($config);
$this->assertDef('lower-alpha');
$this->assertDef('upper-roman inside');

View File

@@ -1,16 +1,16 @@
<?php
require_once 'HTMLPurifier/AttrDef/Multiple.php';
require_once 'HTMLPurifier/AttrDef/CSS/Multiple.php';
require_once 'HTMLPurifier/AttrDefHarness.php';
// borrowed for the sakes of this test
require_once 'HTMLPurifier/AttrDef/Integer.php';
class HTMLPurifier_AttrDef_MultipleTest extends HTMLPurifier_AttrDefHarness
class HTMLPurifier_AttrDef_CSS_MultipleTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_Multiple(
$this->def = new HTMLPurifier_AttrDef_CSS_Multiple(
new HTMLPurifier_AttrDef_Integer()
);

View File

@@ -1,14 +1,14 @@
<?php
require_once 'HTMLPurifier/AttrDef/Number.php';
require_once 'HTMLPurifier/AttrDef/CSS/Number.php';
require_once 'HTMLPurifier/AttrDefHarness.php';
class HTMLPurifier_AttrDef_NumberTest extends HTMLPurifier_AttrDefHarness
class HTMLPurifier_AttrDef_CSS_NumberTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_Number();
$this->def = new HTMLPurifier_AttrDef_CSS_Number();
$this->assertDef('0');
$this->assertDef('34');
@@ -29,7 +29,7 @@ class HTMLPurifier_AttrDef_NumberTest extends HTMLPurifier_AttrDefHarness
function testNonNegative() {
$this->def = new HTMLPurifier_AttrDef_Number(true);
$this->def = new HTMLPurifier_AttrDef_CSS_Number(true);
$this->assertDef('23');
$this->assertDef('-12', false);

View File

@@ -1,14 +1,14 @@
<?php
require_once 'HTMLPurifier/AttrDef/Percentage.php';
require_once 'HTMLPurifier/AttrDef/CSS/Percentage.php';
require_once 'HTMLPurifier/AttrDefHarness.php';
class HTMLPurifier_AttrDef_PercentageTest extends HTMLPurifier_AttrDefHarness
class HTMLPurifier_AttrDef_CSS_PercentageTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_Percentage();
$this->def = new HTMLPurifier_AttrDef_CSS_Percentage();
$this->assertDef('10%');
$this->assertDef('1.607%');

View File

@@ -1,14 +1,14 @@
<?php
require_once 'HTMLPurifier/AttrDefHarness.php';
require_once 'HTMLPurifier/AttrDef/TextDecoration.php';
require_once 'HTMLPurifier/AttrDef/CSS/TextDecoration.php';
class HTMLPurifier_AttrDef_TextDecorationTest extends HTMLPurifier_AttrDefHarness
class HTMLPurifier_AttrDef_CSS_TextDecorationTest extends HTMLPurifier_AttrDefHarness
{
function testCaseInsensitive() {
$this->def = new HTMLPurifier_AttrDef_TextDecoration();
$this->def = new HTMLPurifier_AttrDef_CSS_TextDecoration();
$this->assertDef('underline');
$this->assertDef('overline');

View File

@@ -1,14 +1,14 @@
<?php
require_once 'HTMLPurifier/AttrDef/CSSURI.php';
require_once 'HTMLPurifier/AttrDef/CSS/URI.php';
require_once 'HTMLPurifier/AttrDefHarness.php';
class HTMLPurifier_AttrDef_CSSURITest extends HTMLPurifier_AttrDefHarness
class HTMLPurifier_AttrDef_CSS_URITest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_CSSURI();
$this->def = new HTMLPurifier_AttrDef_CSS_URI();
$this->assertDef('', false);

View File

@@ -1,16 +0,0 @@
<?php
require_once 'HTMLPurifier/AttrDef/Email/SimpleCheck.php';
require_once 'HTMLPurifier/AttrDef/EmailHarness.php';
class HTMLPurifier_AttrDef_Email_SimpleCheckTest
extends HTMLPurifier_AttrDef_EmailHarness
{
function setUp() {
$this->def = new HTMLPurifier_AttrDef_Email_SimpleCheck();
}
}
?>

View File

@@ -1,10 +1,10 @@
<?php
require_once 'HTMLPurifier/AttrDefHarness.php';
require_once 'HTMLPurifier/AttrDef/ID.php';
require_once 'HTMLPurifier/AttrDef/HTML/ID.php';
require_once 'HTMLPurifier/IDAccumulator.php';
class HTMLPurifier_AttrDef_IDTest extends HTMLPurifier_AttrDefHarness
class HTMLPurifier_AttrDef_HTML_IDTest extends HTMLPurifier_AttrDefHarness
{
function setUp() {
@@ -12,7 +12,8 @@ class HTMLPurifier_AttrDef_IDTest extends HTMLPurifier_AttrDefHarness
$id_accumulator = new HTMLPurifier_IDAccumulator();
$this->context->register('IDAccumulator', $id_accumulator);
$this->def = new HTMLPurifier_AttrDef_ID();
$this->config->set('Attr', 'EnableID', true);
$this->def = new HTMLPurifier_AttrDef_HTML_ID();
}
@@ -74,6 +75,26 @@ class HTMLPurifier_AttrDef_IDTest extends HTMLPurifier_AttrDefHarness
}
// reference functionality is disabled for now
function disabled_testIDReference() {
$this->def = new HTMLPurifier_AttrDef_HTML_ID(true);
$this->assertDef('good_id');
$this->assertDef('good_id'); // duplicates okay
$this->assertDef('<b>', false);
$this->def = new HTMLPurifier_AttrDef_HTML_ID();
$this->assertDef('good_id');
$this->assertDef('good_id', false); // duplicate now not okay
$this->def = new HTMLPurifier_AttrDef_HTML_ID(true);
$this->assertDef('good_id'); // reference still okay
}
}
?>

View File

@@ -1,13 +1,13 @@
<?php
require_once 'HTMLPurifier/AttrDef/PixelsTest.php';
require_once 'HTMLPurifier/AttrDef/Length.php';
require_once 'HTMLPurifier/AttrDef/HTML/PixelsTest.php';
require_once 'HTMLPurifier/AttrDef/HTML/Length.php';
class HTMLPurifier_AttrDef_LengthTest extends HTMLPurifier_AttrDef_PixelsTest
class HTMLPurifier_AttrDef_HTML_LengthTest extends HTMLPurifier_AttrDef_HTML_PixelsTest
{
function setup() {
$this->def = new HTMLPurifier_AttrDef_Length();
$this->def = new HTMLPurifier_AttrDef_HTML_Length();
}
function test() {

View File

@@ -1,13 +1,13 @@
<?php
require_once 'HTMLPurifier/AttrDef/LengthTest.php';
require_once 'HTMLPurifier/AttrDef/Length.php';
require_once 'HTMLPurifier/AttrDef/HTML/LengthTest.php';
require_once 'HTMLPurifier/AttrDef/HTML/MultiLength.php';
class HTMLPurifier_AttrDef_MultiLengthTest extends HTMLPurifier_AttrDef_LengthTest
class HTMLPurifier_AttrDef_HTML_MultiLengthTest extends HTMLPurifier_AttrDef_HTML_LengthTest
{
function setup() {
$this->def = new HTMLPurifier_AttrDef_MultiLength();
$this->def = new HTMLPurifier_AttrDef_HTML_MultiLength();
}
function test() {
@@ -16,7 +16,7 @@ class HTMLPurifier_AttrDef_MultiLengthTest extends HTMLPurifier_AttrDef_LengthTe
parent::test();
$this->assertDef('*');
$this->assertDef('1*');
$this->assertDef('1*', '*');
$this->assertDef('56*');
$this->assertDef('**', false); // plain old bad

View File

@@ -1,15 +1,14 @@
<?php
require_once 'HTMLPurifier/AttrDefHarness.php';
require_once 'HTMLPurifier/AttrDef/Class.php';
require_once 'HTMLPurifier/Config.php';
require_once 'HTMLPurifier/AttrDef/HTML/Nmtokens.php';
class HTMLPurifier_AttrDef_ClassTest extends HTMLPurifier_AttrDefHarness
class HTMLPurifier_AttrDef_HTML_NmtokensTest extends HTMLPurifier_AttrDefHarness
{
function testDefault() {
$this->def = new HTMLPurifier_AttrDef_Class();
$this->def = new HTMLPurifier_AttrDef_HTML_Nmtokens();
$this->assertDef('valid');
$this->assertDef('a0-_');

View File

@@ -1,13 +1,13 @@
<?php
require_once 'HTMLPurifier/AttrDefHarness.php';
require_once 'HTMLPurifier/AttrDef/Pixels.php';
require_once 'HTMLPurifier/AttrDef/HTML/Pixels.php';
class HTMLPurifier_AttrDef_PixelsTest extends HTMLPurifier_AttrDefHarness
class HTMLPurifier_AttrDef_HTML_PixelsTest extends HTMLPurifier_AttrDefHarness
{
function setup() {
$this->def = new HTMLPurifier_AttrDef_Pixels();
$this->def = new HTMLPurifier_AttrDef_HTML_Pixels();
}
function test() {

View File

@@ -54,6 +54,8 @@ class HTMLPurifier_AttrDef_LangTest extends HTMLPurifier_AttrDefHarness
// Also note that this test-case tests fix-behavior: chop
// off subtags until you get a valid language code.
$this->assertDef('en-a', 'en');
// however, x is a reserved single-letter subtag that is allowed
$this->assertDef('en-x', 'en-x');
// 2-8 chars are permitted, but have special meaning that cannot
// be checked without maintaining country code lookup tables (for
// two characters) or special registration tables (for all above).

View File

@@ -0,0 +1,16 @@
<?php
require_once 'HTMLPurifier/AttrDef/URI/Email/SimpleCheck.php';
require_once 'HTMLPurifier/AttrDef/URI/EmailHarness.php';
class HTMLPurifier_AttrDef_URI_Email_SimpleCheckTest
extends HTMLPurifier_AttrDef_URI_EmailHarness
{
function setUp() {
$this->def = new HTMLPurifier_AttrDef_URI_Email_SimpleCheck();
}
}
?>

View File

@@ -1,9 +1,9 @@
<?php
require_once 'HTMLPurifier/AttrDef/Email.php';
require_once 'HTMLPurifier/AttrDef/URI/Email.php';
require_once 'HTMLPurifier/AttrDefHarness.php';
class HTMLPurifier_AttrDef_EmailHarness extends HTMLPurifier_AttrDefHarness
class HTMLPurifier_AttrDef_URI_EmailHarness extends HTMLPurifier_AttrDefHarness
{
/**

View File

@@ -1,17 +1,17 @@
<?php
require_once 'HTMLPurifier/AttrDefHarness.php';
require_once 'HTMLPurifier/AttrDef/Host.php';
require_once 'HTMLPurifier/AttrDef/URI/Host.php';
// takes a URI formatted host and validates it
class HTMLPurifier_AttrDef_HostTest extends HTMLPurifier_AttrDefHarness
class HTMLPurifier_AttrDef_URI_HostTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_Host();
$this->def = new HTMLPurifier_AttrDef_URI_Host();
$this->assertDef('[2001:DB8:0:0:8:800:200C:417A]'); // IPv6
$this->assertDef('124.15.6.89'); // IPv4

View File

@@ -1,17 +1,17 @@
<?php
require_once 'HTMLPurifier/AttrDefHarness.php';
require_once 'HTMLPurifier/AttrDef/IPv4.php';
require_once 'HTMLPurifier/AttrDef/URI/IPv4.php';
// IPv4 test case is spliced from Feyd's IPv6 implementation
// we ought to disallow non-routable addresses
class HTMLPurifier_AttrDef_IPv4Test extends HTMLPurifier_AttrDefHarness
class HTMLPurifier_AttrDef_URI_IPv4Test extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_IPv4();
$this->def = new HTMLPurifier_AttrDef_URI_IPv4();
$this->assertDef('127.0.0.1'); // standard IPv4, loopback, non-routable
$this->assertDef('0.0.0.0'); // standard IPv4, unspecified, non-routable

View File

@@ -1,17 +1,17 @@
<?php
require_once 'HTMLPurifier/AttrDefHarness.php';
require_once 'HTMLPurifier/AttrDef/IPv6.php';
require_once 'HTMLPurifier/AttrDef/URI/IPv6.php';
// test case is from Feyd's IPv6 implementation
// we ought to disallow non-routable addresses
class HTMLPurifier_AttrDef_IPv6Test extends HTMLPurifier_AttrDefHarness
class HTMLPurifier_AttrDef_URI_IPv6Test extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_IPv6();
$this->def = new HTMLPurifier_AttrDef_URI_IPv6();
$this->assertDef('2001:DB8:0:0:8:800:200C:417A'); // unicast, full
$this->assertDef('FF01:0:0:0:0:0:0:101'); // multicast, full

View File

@@ -15,17 +15,17 @@ class HTMLPurifier_ChildDef_ChameleonTest extends HTMLPurifier_ChildDefHarness
$this->assertResult(
'<b>Allowed.</b>', true,
array(), array('ParentType' => 'inline')
array(), array('IsInline' => true)
);
$this->assertResult(
'<div>Not allowed.</div>', '',
array(), array('ParentType' => 'inline')
array(), array('IsInline' => true)
);
$this->assertResult(
'<div>Allowed.</div>', true,
array(), array('ParentType' => 'block')
array(), array('IsInline' => false)
);
}

View File

@@ -9,7 +9,7 @@ extends HTMLPurifier_ChildDefHarness
function test() {
$this->obj = new HTMLPurifier_ChildDef_StrictBlockquote();
$this->obj = new HTMLPurifier_ChildDef_StrictBlockquote('div | p');
$this->assertResult('');
$this->assertResult('<p>Valid</p>');

View File

@@ -41,14 +41,14 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase
function tearDown() {
// testing is done, restore the old copy
HTMLPurifier_ConfigSchema::instance($this->old_copy);
tally_errors();
tally_errors($this);
}
function test_defineNamespace() {
CS::defineNamespace('http', $d = 'This is an internet protocol.');
$this->assertIdentical($this->our_copy->info_namespace, array(
'http' => new HTMLPurifier_ConfigEntity_Namespace($d)
'http' => new HTMLPurifier_ConfigDef_Namespace($d)
));
$this->expectError('Cannot redefine namespace');
@@ -68,7 +68,7 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase
$this->assertIdentical($this->our_copy->defaults['Car']['Seats'], 5);
$this->assertIdentical($this->our_copy->info['Car']['Seats'],
new HTMLPurifier_ConfigEntity_Directive('int',
new HTMLPurifier_ConfigDef_Directive('int',
array($this->file => array($l => $d))
)
);
@@ -77,7 +77,7 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase
$this->assertIdentical($this->our_copy->defaults['Car']['Age'], null);
$this->assertIdentical($this->our_copy->info['Car']['Age'],
new HTMLPurifier_ConfigEntity_Directive('int',
new HTMLPurifier_ConfigDef_Directive('int',
array($this->file => array($l => $d)), true
)
);
@@ -106,7 +106,7 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase
$this->assertIdentical($this->our_copy->defaults['Cat']['Dead'], false);
$this->assertIdentical($this->our_copy->info['Cat']['Dead'],
new HTMLPurifier_ConfigEntity_Directive('bool',
new HTMLPurifier_ConfigDef_Directive('bool',
array($this->file => array($l1 => $d1, $l2 => $d2))
)
);
@@ -132,7 +132,7 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase
$this->assertIdentical($this->our_copy->defaults['QuantumNumber']['Difficulty'], null);
$this->assertIdentical($this->our_copy->info['QuantumNumber']['Difficulty'],
new HTMLPurifier_ConfigEntity_Directive(
new HTMLPurifier_ConfigDef_Directive(
'string',
array($this->file => array($l => $d)),
true,
@@ -184,7 +184,7 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase
$this->assertIdentical($this->our_copy->defaults['Abbrev']['HTH'], 'Happy to Help');
$this->assertIdentical($this->our_copy->info['Abbrev']['HTH'],
new HTMLPurifier_ConfigEntity_Directive(
new HTMLPurifier_ConfigDef_Directive(
'string',
array($this->file => array($l => $d)),
false,
@@ -224,7 +224,7 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase
$this->assertTrue(!isset($this->our_copy->defaults['Home']['Carpet']));
$this->assertIdentical($this->our_copy->info['Home']['Carpet'],
new HTMLPurifier_ConfigEntity_DirectiveAlias('Home', 'Rug')
new HTMLPurifier_ConfigDef_DirectiveAlias('Home', 'Rug')
);
$this->expectError('Cannot define directive alias in undefined namespace');

View File

@@ -20,7 +20,7 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
function tearDown() {
HTMLPurifier_ConfigSchema::instance($this->old_copy);
tally_errors();
tally_errors($this);
}
// test functionality based on ConfigSchema
@@ -216,7 +216,7 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
}
function test_getDefinition() {
function test_getHTMLDefinition() {
// we actually want to use the old copy, because the definition
// generation routines have dependencies on configuration values
@@ -224,12 +224,41 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
$this->old_copy = HTMLPurifier_ConfigSchema::instance($this->old_copy);
$config = HTMLPurifier_Config::createDefault();
$def = $config->getHTMLDefinition();
$this->assertIsA($def, 'HTMLPurifier_HTMLDefinition');
$def = $config->getCSSDefinition();
$this->assertIsA($def, 'HTMLPurifier_CSSDefinition');
$def = $config->getHTMLDefinition();
$def2 = $config->getHTMLDefinition();
$this->assertIsA($def, 'HTMLPurifier_HTMLDefinition');
$this->assertEqual($def, $def2);
$this->assertTrue($def->setup);
// test re-calculation if HTML changes
$config->set('HTML', 'Strict', true);
$def = $config->getHTMLDefinition();
$this->assertIsA($def, 'HTMLPurifier_HTMLDefinition');
$this->assertNotEqual($def, $def2);
$this->assertTrue($def->setup);
// test retrieval of raw definition
$def =& $config->getHTMLDefinition(true);
$this->assertNotEqual($def, $def2);
$this->assertFalse($def->setup);
// auto initialization
$config->getHTMLDefinition();
$this->assertTrue($def->setup);
}
function test_getCSSDefinition() {
$this->old_copy = HTMLPurifier_ConfigSchema::instance($this->old_copy);
$config = HTMLPurifier_Config::createDefault();
$def = $config->getCSSDefinition();
$this->assertIsA($def, 'HTMLPurifier_CSSDefinition');
}
function test_loadArray() {

View File

@@ -0,0 +1,274 @@
<?php
require_once 'HTMLPurifier/HTMLModuleManager.php';
// stub classes for unit testing
class HTMLPurifier_HTMLModule_ManagerTestModule extends HTMLPurifier_HTMLModule {
var $name = 'ManagerTestModule';
}
class HTMLPurifier_HTMLModuleManagerTest_TestModule extends HTMLPurifier_HTMLModule {
var $name = 'TestModule';
}
class HTMLPurifier_HTMLModuleManagerTest extends UnitTestCase
{
/**
* System under test, instance of HTMLPurifier_HTMLModuleManager.
*/
var $manager;
function setup() {
$this->manager = new HTMLPurifier_HTMLModuleManager(true);
}
function teardown() {
tally_errors($this);
}
function createModule($name) {
$module = new HTMLPurifier_HTMLModule();
$module->name = $name;
return $module;
}
function test_addModule_withAutoload() {
$this->manager->autoDoctype = 'Generic Document 0.1';
$this->manager->autoCollection = 'Default';
$module = new HTMLPurifier_HTMLModule();
$module->name = 'Module';
$module2 = new HTMLPurifier_HTMLModule();
$module2->name = 'Module2';
// we need to grab the dynamically generated orders from
// the object since modules are not passed by reference
$this->manager->addModule($module);
$module_order = $this->manager->modules['Module']->order;
$module->order = $module_order;
$this->assertEqual($module, $this->manager->modules['Module']);
$this->manager->addModule($module2);
$module2_order = $this->manager->modules['Module2']->order;
$module2->order = $module2_order;
$this->assertEqual($module2, $this->manager->modules['Module2']);
$this->assertEqual($module_order + 1, $module2_order);
$this->assertEqual(
$this->manager->collections['Default']['Generic Document 0.1'],
array('Module', 'Module2')
);
$this->manager->setup(HTMLPurifier_Config::createDefault());
$modules = array(
'Module' => $this->manager->modules['Module'],
'Module2' => $this->manager->modules['Module2']
);
$this->assertIdentical(
$this->manager->collections['Default']['Generic Document 0.1'],
$modules
);
$this->assertIdentical($this->manager->activeModules, $modules);
$this->assertIdentical($this->manager->activeCollections, array('Default'));
}
function test_addModule_undefinedClass() {
$this->expectError('TotallyCannotBeDefined module does not exist');
$this->manager->addModule('TotallyCannotBeDefined');
}
function test_addModule_stringExpansion() {
$this->manager->addModule('ManagerTestModule');
$this->assertIsA($this->manager->modules['ManagerTestModule'],
'HTMLPurifier_HTMLModule_ManagerTestModule');
}
function test_addPrefix() {
$this->manager->addPrefix('HTMLPurifier_HTMLModuleManagerTest_');
$this->manager->addModule('TestModule');
$this->assertIsA($this->manager->modules['TestModule'],
'HTMLPurifier_HTMLModuleManagerTest_TestModule');
}
function assertProcessCollections($input, $expect = false) {
if ($expect === false) $expect = $input;
$this->manager->processCollections($input);
// substitute in modules for $expect
foreach ($expect as $col_i => $col) {
$disable = false;
foreach ($col as $mod_i => $mod) {
unset($expect[$col_i][$mod_i]);
if ($mod_i === '*') {
$disable = true;
continue;
}
$expect[$col_i][$mod] = $this->manager->modules[$mod];
}
if ($disable) $expect[$col_i]['*'] = false;
}
$this->assertIdentical($input, $expect);
}
function testImpl_processCollections() {
$this->manager->initialize();
$this->assertProcessCollections(
array()
);
$this->assertProcessCollections(
array('HTML' => array('Text'))
);
$this->assertProcessCollections(
array('HTML' => array('Text', 'Legacy'))
);
$this->assertProcessCollections( // order is important!
array('HTML' => array('Legacy', 'Text')),
array('HTML' => array('Text', 'Legacy'))
);
$this->assertProcessCollections( // privates removed after process
array('_Private' => array('Legacy', 'Text')),
array()
);
$this->assertProcessCollections( // inclusions come first
array(
'HTML' => array(array('XHTML'), 'Legacy'),
'XHTML' => array('Text', 'Hypertext')
),
array(
'HTML' => array('Text', 'Hypertext', 'Legacy'),
'XHTML' => array('Text', 'Hypertext')
)
);
$this->assertProcessCollections(
array(
'HTML' => array(array('_Common'), 'Legacy'),
'_Common' => array('Text', 'Hypertext')
),
array(
'HTML' => array('Text', 'Hypertext', 'Legacy')
)
);
$this->assertProcessCollections( // nested inclusions
array(
'Full' => array(array('Minimal'), 'Hypertext'),
'Minimal' => array(array('Bare'), 'List'),
'Bare' => array('Text')
),
array(
'Full' => array('Text', 'Hypertext', 'List'),
'Minimal' => array('Text', 'List'),
'Bare' => array('Text')
)
);
// strange but valid stuff that will be handled in assembleModules
$this->assertProcessCollections(
array(
'Linky' => array('Hypertext'),
'Listy' => array('List'),
'*' => array('Text')
)
);
$this->assertProcessCollections(
array(
'Linky' => array('Hypertext'),
'ListyOnly' => array('List', '*' => false),
'*' => array('Text')
)
);
}
function testImpl_processCollections_error() {
$this->manager->initialize();
$this->expectError( // active variables, watch out!
'Illegal inclusion array at index 1 found collection HTML, '.
'inclusion arrays must be at start of collection (index 0)');
$c = array(
'HTML' => array('Legacy', array('XHTML')),
'XHTML' => array('Text', 'Hypertext')
);
$this->manager->processCollections($c);
unset($c);
$this->expectError('Collection HTML references undefined '.
'module Foobar');
$c = array(
'HTML' => array('Foobar')
);
$this->manager->processCollections($c);
unset($c);
$this->expectError('Collection HTML tried to include undefined '.
'collection _Common');
$c = array(
'HTML' => array(array('_Common'), 'Legacy')
);
$this->manager->processCollections($c);
unset($c);
// reports the first circular inclusion it runs across
$this->expectError('Circular inclusion detected in HTML collection');
$c = array(
'HTML' => array(array('XHTML')),
'XHTML' => array(array('HTML'))
);
$this->manager->processCollections($c);
unset($c);
}
function test_makeCollection() {
$config = HTMLPurifier_Config::create(array(
'HTML.Doctype' => 'Custom Doctype'
));
$this->manager->addModule($this->createModule('ActiveModule'));
$this->manager->addModule($this->createModule('DudModule'));
$this->manager->addModule($this->createModule('ValidModule'));
$ActiveModule = $this->manager->modules['ActiveModule'];
$DudModule = $this->manager->modules['DudModule'];
$ValidModule = $this->manager->modules['ValidModule'];
$this->manager->collections['ToBeValid']['Custom Doctype'] = array('ValidModule');
$this->manager->collections['ToBeActive']['Custom Doctype'] = array('ActiveModule');
$this->manager->makeCollectionValid('ToBeValid');
$this->manager->makeCollectionActive('ToBeActive');
$this->manager->setup($config);
$this->assertIdentical($this->manager->validModules, array(
'ValidModule' => $ValidModule,
'ActiveModule' => $ActiveModule
));
$this->assertIdentical($this->manager->activeModules, array(
'ActiveModule' => $ActiveModule
));
}
function test_makeCollection_undefinedCollection() {
$config = HTMLPurifier_Config::create(array(
'HTML.Doctype' => 'Sweets Document 1.0'
));
$this->manager->addModule($this->createModule('DonutsModule'));
$this->manager->addModule($this->createModule('ChocolateModule'));
$this->manager->collections['CocoaBased']['Sweets Document 1.0'] = array('ChocolateModule');
// notice how BreadBased collection is missing
$this->manager->makeCollectionActive('CocoaBased'); // to prevent other errors
$this->manager->makeCollectionValid('BreadBased');
$this->expectError('BreadBased collection is undefined');
$this->manager->setup($config);
}
function untest_soupStuff() {
$config = HTMLPurifier_Config::create(array(
'HTML.Doctype' => 'The Soup Specification 8.0'
));
$this->manager->addModule($this->createModule('VegetablesModule'));
$this->manager->addModule($this->createModule('MeatModule'));
}
}
?>

View File

@@ -0,0 +1,47 @@
<?php
require_once 'HTMLPurifier/LanguageFactory.php';
class HTMLPurifier_LanguageFactoryTest extends UnitTestCase
{
function test() {
$factory = HTMLPurifier_LanguageFactory::instance();
$language = $factory->create('en');
$this->assertIsA($language, 'HTMLPurifier_Language');
$this->assertEqual($language->code, 'en');
// lazy loading test
$this->assertEqual(count($language->messages), 0);
$language->load();
$this->assertNotEqual(count($language->messages), 0);
// actual tests for content can be found in LanguageTest
}
function testFallback() {
$factory = HTMLPurifier_LanguageFactory::instance();
$language = $factory->create('en-x-test');
$this->assertIsA($language, 'HTMLPurifier_Language_en_x_test');
$this->assertEqual($language->code, 'en-x-test');
$language->load();
// test overloaded message
$this->assertEqual($language->getMessage('htmlpurifier'), 'HTML Purifier X');
// test inherited message
$this->assertEqual($language->getMessage('pizza'), 'Pizza');
}
}
?>

View File

@@ -0,0 +1,22 @@
<?php
require_once 'HTMLPurifier/Language.php';
class HTMLPurifier_LanguageTest extends UnitTestCase
{
var $lang;
function setup() {
$factory = HTMLPurifier_LanguageFactory::instance();
$this->lang = $factory->create('en');
}
function test_getMessage() {
$this->assertIdentical($this->lang->getMessage('htmlpurifier'), 'HTML Purifier');
$this->assertIdentical($this->lang->getMessage('totally-non-existent-key'), '');
}
}
?>

View File

@@ -70,19 +70,33 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
'<span><ins>Not allowed!</ins></span>'
);
// block in inline ins not allowed
$this->assertResult(
$this->assertResult( // alt config
'<span><ins><div>Not allowed!</div></ins></span>',
'<span><ins>&lt;div&gt;Not allowed!&lt;/div&gt;</ins></span>',
array('Core.EscapeInvalidChildren' => true)
);
// test block element that has inline content
$this->assertResult(
'<h1><ins><div>Not allowed!</div></ins></h1>',
'<h1><ins>Not allowed!</ins></h1>'
);
// test exclusions
$this->assertResult(
'<a><span><a>Not allowed</a></span></a>',
'<a><span></span></a>'
);
// stacked ins/del
$this->assertResult(
'<h1><ins><del><div>Not allowed!</div></del></ins></h1>',
'<h1><ins><del>Not allowed!</del></ins></h1>'
);
$this->assertResult(
'<div><ins><del><div>Allowed!</div></del></ins></div>'
);
// test inline parent
$this->assertResult(
'<b>Bold</b>', true, array('HTML.Parent' => 'span')

View File

@@ -100,7 +100,7 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
$this->assertResult(
'<table frame="above" rules="rows" summary="A test table" border="2" cellpadding="5%" cellspacing="3" width="100%">
<col align="right" width="4*" />
<col charoff="5" align="char" width="1*" />
<col charoff="5" align="char" width="*" />
<tr valign="top">
<th abbr="name">Fiddly name</th>
<th abbr="price">Super-duper-price</th>

View File

@@ -2,6 +2,11 @@
require_once 'HTMLPurifier/TagTransform.php';
// needs to be seperated into files
require_once 'HTMLPurifier/TagTransform/Center.php';
require_once 'HTMLPurifier/TagTransform/Font.php';
require_once 'HTMLPurifier/TagTransform/Simple.php';
class HTMLPurifier_TagTransformTest extends UnitTestCase
{

View File

@@ -83,6 +83,20 @@ class HTMLPurifier_Test extends UnitTestCase
}
function testEnableAttrID() {
$this->purifier = new HTMLPurifier();
$this->assertPurification(
'<span id="moon">foobar</span>',
'<span>foobar</span>'
);
$this->purifier = new HTMLPurifier(array('HTML.EnableAttrID' => true));
$this->assertPurification('<span id="moon">foobar</span>');
}
}
?>