1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-08-08 07:06:46 +02:00

Release 2.0.1, merged in 1181 to HEAD.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/branches/strict@1255 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2007-06-27 14:30:45 +00:00
parent 42858ad594
commit 495164e938
326 changed files with 3025 additions and 826 deletions

View File

@@ -18,7 +18,7 @@ class HTMLPurifier_AttrCollectionsTest extends UnitTestCase
$collections = new HTMLPurifier_AttrCollectionsTest_NoConstructor();
$types = new HTMLPurifier_AttrTypesMock($this);
$types = new HTMLPurifier_AttrTypesMock();
$modules = array();
@@ -68,7 +68,7 @@ class HTMLPurifier_AttrCollectionsTest extends UnitTestCase
generate_mock_once('HTMLPurifier_AttrTypes');
$types = new HTMLPurifier_AttrTypesMock($this);
$types = new HTMLPurifier_AttrTypesMock();
$collections = new HTMLPurifier_AttrCollections($types, array());
$collections->info = array(
'Core' => array(0 => array('Inclusion', 'Undefined'), 'attr-original' => 'Type'),
@@ -106,7 +106,7 @@ class HTMLPurifier_AttrCollectionsTest extends UnitTestCase
generate_mock_once('HTMLPurifier_AttrTypes');
$types = new HTMLPurifier_AttrTypesMock($this);
$types = new HTMLPurifier_AttrTypesMock();
$collections = new HTMLPurifier_AttrCollections($types, array());
$attr = array(
@@ -136,4 +136,3 @@ class HTMLPurifier_AttrCollectionsTest extends UnitTestCase
}
?>

View File

@@ -68,4 +68,3 @@ class HTMLPurifier_AttrDef_CSS_BackgroundPositionTest extends HTMLPurifier_AttrD
}
?>

View File

@@ -19,4 +19,3 @@ class HTMLPurifier_AttrDef_CSS_BackgroundTest extends HTMLPurifier_AttrDefHarnes
}
?>

View File

@@ -19,4 +19,3 @@ class HTMLPurifier_AttrDef_CSS_BorderTest extends HTMLPurifier_AttrDefHarness
}
?>

View File

@@ -34,4 +34,3 @@ class HTMLPurifier_AttrDef_CSS_ColorTest extends HTMLPurifier_AttrDefHarness
}
?>

View File

@@ -29,8 +29,8 @@ class HTMLPurifier_AttrDef_CSS_CompositeTest extends HTMLPurifier_AttrDefHarness
// first test: value properly validates on first definition
// so second def is never called
$def1 = new HTMLPurifier_AttrDefMock($this);
$def2 = new HTMLPurifier_AttrDefMock($this);
$def1 = new HTMLPurifier_AttrDefMock();
$def2 = new HTMLPurifier_AttrDefMock();
$defs = array(&$def1, &$def2);
$def = new HTMLPurifier_AttrDef_CSS_Composite_Testable($defs);
$input = 'FOOBAR';
@@ -48,8 +48,8 @@ class HTMLPurifier_AttrDef_CSS_CompositeTest extends HTMLPurifier_AttrDefHarness
// second test, first def fails, second def works
$def1 = new HTMLPurifier_AttrDefMock($this);
$def2 = new HTMLPurifier_AttrDefMock($this);
$def1 = new HTMLPurifier_AttrDefMock();
$def2 = new HTMLPurifier_AttrDefMock();
$defs = array(&$def1, &$def2);
$def = new HTMLPurifier_AttrDef_CSS_Composite_Testable($defs);
$input = 'BOOMA';
@@ -68,8 +68,8 @@ class HTMLPurifier_AttrDef_CSS_CompositeTest extends HTMLPurifier_AttrDefHarness
// third test, all fail, so composite faiils
$def1 = new HTMLPurifier_AttrDefMock($this);
$def2 = new HTMLPurifier_AttrDefMock($this);
$def1 = new HTMLPurifier_AttrDefMock();
$def2 = new HTMLPurifier_AttrDefMock();
$defs = array(&$def1, &$def2);
$def = new HTMLPurifier_AttrDef_CSS_Composite_Testable($defs);
$input = 'BOOMA';
@@ -90,4 +90,3 @@ class HTMLPurifier_AttrDef_CSS_CompositeTest extends HTMLPurifier_AttrDefHarness
}
?>

View File

@@ -21,4 +21,3 @@ class HTMLPurifier_AttrDef_CSS_FontFamilyTest extends HTMLPurifier_AttrDefHarnes
}
?>

View File

@@ -34,4 +34,3 @@ class HTMLPurifier_AttrDef_CSS_FontTest extends HTMLPurifier_AttrDefHarness
}
?>

View File

@@ -40,4 +40,3 @@ class HTMLPurifier_AttrDef_CSS_LengthTest extends HTMLPurifier_AttrDefHarness
}
?>

View File

@@ -35,4 +35,3 @@ class HTMLPurifier_AttrDef_CSS_ListStyleTest extends HTMLPurifier_AttrDefHarness
}
?>

View File

@@ -30,4 +30,3 @@ class HTMLPurifier_AttrDef_CSS_MultipleTest extends HTMLPurifier_AttrDefHarness
}
?>

View File

@@ -37,4 +37,3 @@ class HTMLPurifier_AttrDef_CSS_NumberTest extends HTMLPurifier_AttrDefHarness
}
?>

View File

@@ -24,4 +24,3 @@ class HTMLPurifier_AttrDef_CSS_PercentageTest extends HTMLPurifier_AttrDefHarnes
}
?>

View File

@@ -24,4 +24,3 @@ class HTMLPurifier_AttrDef_CSS_TextDecorationTest extends HTMLPurifier_AttrDefHa
}
?>

View File

@@ -34,4 +34,3 @@ class HTMLPurifier_AttrDef_CSS_URITest extends HTMLPurifier_AttrDefHarness
}
?>

View File

@@ -108,4 +108,3 @@ class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness
}
?>

View File

@@ -37,4 +37,3 @@ class HTMLPurifier_AttrDef_EnumTest extends HTMLPurifier_AttrDefHarness
}
?>

View File

@@ -22,4 +22,3 @@ class HTMLPurifier_AttrDef_HTML_BoolTest extends HTMLPurifier_AttrDefHarness
}
?>

View File

@@ -20,4 +20,3 @@ class HTMLPurifier_AttrDef_HTML_ColorTest extends HTMLPurifier_AttrDefHarness
}
}
?>

View File

@@ -28,4 +28,3 @@ class HTMLPurifier_AttrDef_HTML_FrameTargetTest extends HTMLPurifier_AttrDefHarn
}
?>

View File

@@ -109,4 +109,3 @@ class HTMLPurifier_AttrDef_HTML_IDTest extends HTMLPurifier_AttrDefHarness
}
?>

View File

@@ -32,4 +32,3 @@ class HTMLPurifier_AttrDef_HTML_LengthTest extends HTMLPurifier_AttrDef_HTML_Pix
}
?>

View File

@@ -21,4 +21,3 @@ class HTMLPurifier_AttrDef_HTML_LinkTypesTest extends HTMLPurifier_AttrDefHarnes
}
?>

View File

@@ -28,4 +28,3 @@ class HTMLPurifier_AttrDef_HTML_MultiLengthTest extends HTMLPurifier_AttrDef_HTM
}
?>

View File

@@ -32,4 +32,3 @@ class HTMLPurifier_AttrDef_HTML_NmtokensTest extends HTMLPurifier_AttrDefHarness
}
?>

View File

@@ -38,4 +38,3 @@ class HTMLPurifier_AttrDef_HTML_PixelsTest extends HTMLPurifier_AttrDefHarness
}
?>

View File

@@ -61,4 +61,3 @@ class HTMLPurifier_AttrDef_IntegerTest extends HTMLPurifier_AttrDefHarness
}
?>

View File

@@ -85,4 +85,3 @@ class HTMLPurifier_AttrDef_LangTest extends HTMLPurifier_AttrDefHarness
}
?>

View File

@@ -17,4 +17,3 @@ class HTMLPurifier_AttrDef_TextTest extends HTMLPurifier_AttrDefHarness
}
?>

View File

@@ -13,4 +13,3 @@ class HTMLPurifier_AttrDef_URI_Email_SimpleCheckTest
}
?>

View File

@@ -31,4 +31,3 @@ class HTMLPurifier_AttrDef_URI_EmailHarness extends HTMLPurifier_AttrDefHarness
}
?>

View File

@@ -21,4 +21,3 @@ class HTMLPurifier_AttrDef_URI_HostTest extends HTMLPurifier_AttrDefHarness
}
?>

View File

@@ -43,4 +43,3 @@ class HTMLPurifier_AttrDef_URI_IPv6Test extends HTMLPurifier_AttrDefHarness
}
?>

View File

@@ -202,11 +202,11 @@ class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness
// $fake_registry isn't the real mock, because due to PHP 4 weirdness
// I cannot set a default value to function parameters that are passed
// by reference. So we use the value instance() returns.
$fake_registry = new HTMLPurifier_URISchemeRegistryMock($this);
$fake_registry = new HTMLPurifier_URISchemeRegistryMock();
$registry =& HTMLPurifier_URISchemeRegistry::instance($fake_registry);
// now, let's add a pseudo-scheme to the registry
$this->scheme = new HTMLPurifier_URISchemeMock($this);
$this->scheme = new HTMLPurifier_URISchemeMock();
// here are the schemes we will support with overloaded mocks
$registry->setReturnReference('getScheme', $this->scheme, array('http', '*', '*'));
@@ -325,4 +325,4 @@ class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness
}
?>

View File

@@ -30,4 +30,3 @@ class HTMLPurifier_AttrDefHarness extends UnitTestCase
}
?>

View File

@@ -27,4 +27,3 @@ class HTMLPurifier_AttrDefTest extends UnitTestCase
}
?>

View File

@@ -29,4 +29,3 @@ class HTMLPurifier_AttrTransform_BdoDirTest extends HTMLPurifier_AttrTransformHa
}
?>

View File

@@ -40,4 +40,3 @@ class HTMLPurifier_AttrTransform_BgColorTest extends HTMLPurifier_AttrTransformH
}
?>

View File

@@ -36,4 +36,3 @@ class HTMLPurifier_AttrTransform_BoolToCSSTest extends HTMLPurifier_AttrTransfor
}
?>

View File

@@ -37,4 +37,3 @@ class HTMLPurifier_AttrTransform_BorderTest extends HTMLPurifier_AttrTransformHa
}
?>

View File

@@ -75,4 +75,3 @@ class HTMLPurifier_AttrTransform_EnumToCSSTest extends HTMLPurifier_AttrTransfor
}
?>

View File

@@ -48,4 +48,3 @@ class HTMLPurifier_AttrTransform_ImgRequiredTest extends HTMLPurifier_AttrTransf
}
?>

View File

@@ -54,4 +54,3 @@ class HTMLPurifier_AttrTransform_ImgSpaceTest extends HTMLPurifier_AttrTransform
}
?>

View File

@@ -46,4 +46,3 @@ class HTMLPurifier_AttrTransform_LangTest
}
?>

View File

@@ -34,4 +34,3 @@ class HTMLPurifier_AttrTransform_LengthTest extends HTMLPurifier_AttrTransformHa
}
?>

View File

@@ -25,4 +25,3 @@ class HTMLPurifier_AttrTransform_NameTest extends HTMLPurifier_AttrTransformHarn
}
?>

View File

@@ -11,4 +11,3 @@ class HTMLPurifier_AttrTransformHarness extends HTMLPurifier_Harness
}
?>

View File

@@ -39,4 +39,3 @@ class HTMLPurifier_AttrTransformTest extends UnitTestCase
}
?>

View File

@@ -25,4 +25,3 @@ class HTMLPurifier_AttrTypesTest extends UnitTestCase
}
?>

View File

@@ -0,0 +1,49 @@
<?php
require_once 'HTMLPurifier/ErrorsHarness.php';
require_once 'HTMLPurifier/AttrValidator.php';
class HTMLPurifier_AttrValidator_ErrorsTest extends HTMLPurifier_ErrorsHarness
{
function invoke($input) {
$validator = new HTMLPurifier_AttrValidator();
$validator->validateToken($input, $this->config, $this->context);
}
function testAttributesTransformedGlobalPre() {
$this->config->set('HTML', 'DefinitionID',
'HTMLPurifier_AttrValidator_ErrorsTest::testAttributesTransformedGlobalPre');
$def =& $this->config->getHTMLDefinition(true);
generate_mock_once('HTMLPurifier_AttrTransform');
$transform = new HTMLPurifier_AttrTransformMock();
$input = array('original' => 'value');
$output = array('class' => 'value'); // must be valid
$transform->setReturnValue('transform', $output, array($input, new AnythingExpectation(), new AnythingExpectation()));
$def->info_attr_transform_pre[] = $transform;
$this->expectErrorCollection(E_NOTICE, 'AttrValidator: Attributes transformed', $input, $output);
$token = new HTMLPurifier_Token_Start('span', $input, 1);
$this->invoke($token);
}
function testAttributesTransformedLocalPre() {
$this->config->set('HTML', 'TidyLevel', 'heavy');
$input = array('align' => 'right');
$output = array('style' => 'text-align:right;');
$this->expectErrorCollection(E_NOTICE, 'AttrValidator: Attributes transformed', $input, $output);
$token = new HTMLPurifier_Token_Start('p', $input, 1);
$this->invoke($token);
}
// to lazy to check for global post and global pre
function testAttributeRemoved() {
$this->expectErrorCollection(E_ERROR, 'AttrValidator: Attribute removed');
$this->expectContext('CurrentAttr', 'foobar');
$token = new HTMLPurifier_Token_Start('p', array('foobar' => 'right'), 1);
$this->expectContext('CurrentToken', $token);
$this->invoke($token);
}
}

View File

@@ -32,4 +32,3 @@ class HTMLPurifier_ChildDef_ChameleonTest extends HTMLPurifier_ChildDefHarness
}
?>

View File

@@ -10,6 +10,9 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness
$this->obj = new HTMLPurifier_ChildDef_Custom('(a,b?,c*,d+,(a,b)*)');
$this->assertEqual($this->obj->elements, array('a' => true,
'b' => true, 'c' => true, 'd' => true));
$this->assertResult('', false);
$this->assertResult('<a /><a />', false);
@@ -21,6 +24,8 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness
function testNesting() {
$this->obj = new HTMLPurifier_ChildDef_Custom('(a,b,(c|d))+');
$this->assertEqual($this->obj->elements, array('a' => true,
'b' => true, 'c' => true, 'd' => true));
$this->assertResult('', false);
$this->assertResult('<a /><b /><c /><a /><b /><d />');
$this->assertResult('<a /><b /><c /><d />', false);
@@ -28,6 +33,8 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness
function testNestedEitherOr() {
$this->obj = new HTMLPurifier_ChildDef_Custom('b,(a|(c|d))+');
$this->assertEqual($this->obj->elements, array('a' => true,
'b' => true, 'c' => true, 'd' => true));
$this->assertResult('', false);
$this->assertResult('<b /><a /><c /><d />');
$this->assertResult('<b /><d /><a /><a />');
@@ -37,6 +44,7 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness
function testNestedQuantifier() {
$this->obj = new HTMLPurifier_ChildDef_Custom('(b,c+)*');
$this->assertEqual($this->obj->elements, array('b' => true, 'c' => true));
$this->assertResult('');
$this->assertResult('<b /><c />');
$this->assertResult('<b /><c /><c /><c />');
@@ -47,6 +55,7 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness
function testEitherOr() {
$this->obj = new HTMLPurifier_ChildDef_Custom('a|b');
$this->assertEqual($this->obj->elements, array('a' => true, 'b' => true));
$this->assertResult('', false);
$this->assertResult('<a />');
$this->assertResult('<b />');
@@ -57,6 +66,7 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness
function testCommafication() {
$this->obj = new HTMLPurifier_ChildDef_Custom('a,b');
$this->assertEqual($this->obj->elements, array('a' => true, 'b' => true));
$this->assertResult('<a /><b />');
$this->assertResult('<ab />', false);
@@ -64,4 +74,3 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness
}
?>

View File

@@ -17,4 +17,3 @@ class HTMLPurifier_ChildDef_OptionalTest extends HTMLPurifier_ChildDefHarness
}
?>

View File

@@ -66,4 +66,3 @@ class HTMLPurifier_ChildDef_RequiredTest extends HTMLPurifier_ChildDefHarness
}
?>

View File

@@ -42,12 +42,14 @@ extends HTMLPurifier_ChildDefHarness
$this->assertResult('Needs wrap', '<div>Needs wrap</div>',
array('HTML.BlockWrapper' => 'div'));
$this->expectError('Cannot use non-block element as block wrapper.');
}
function testError() {
$this->obj = new HTMLPurifier_ChildDef_StrictBlockquote('div | p');
$this->assertResult('Needs wrap', '<p>Needs wrap</p>',
array('HTML.BlockWrapper' => 'dav'));
$this->swallowErrors();
}
}
?>

View File

@@ -38,14 +38,14 @@ class HTMLPurifier_ChildDef_TableTest extends HTMLPurifier_ChildDefHarness
// whitespace sticks to the previous element, last whitespace is
// stationary
$this->assertResult("\n <tr />\n <tr />\n ");
$this->assertResult("\n <tr />\n <tr />\n ", true, array('Output.Newline' => "\n"));
$this->assertResult(
"\n\t<tbody />\n\t\t<tfoot />\n\t\t\t",
"\n\t\t<tfoot />\n\t<tbody />\n\t\t\t"
"\n\t\t<tfoot />\n\t<tbody />\n\t\t\t",
array('Output.Newline' => "\n")
);
}
}
?>

View File

@@ -15,4 +15,4 @@ class HTMLPurifier_ChildDefHarness extends HTMLPurifier_Harness
}
?>

View File

@@ -336,4 +336,3 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase
}
?>

View File

@@ -252,9 +252,10 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
// test retrieval of raw definition
$config->set('HTML', 'DefinitionID', 'HTMLPurifier_ConfigTest->test_getHTMLDefinition()');
$config->set('HTML', 'DefinitionRev', 3);
$def =& $config->getHTMLDefinition(true);
$this->assertNotEqual($def, $def2);
$this->assertFalse($def->setup);
$this->assertEqual(false, $def->setup);
// auto initialization
$config->getHTMLDefinition();
@@ -277,8 +278,8 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
}
function test_getDefinition() {
CS::defineNamespace('Core', 'Core stuff');
CS::define('Core', 'DefinitionCache', null, 'string/null', 'Cache?');
CS::defineNamespace('Cache', 'Cache stuff');
CS::define('Cache', 'DefinitionImpl', null, 'string/null', 'Cache?');
CS::defineNamespace('Crust', 'Krusty Krabs');
$config = HTMLPurifier_Config::createDefault();
$this->expectError("Definition of Crust type not supported");
@@ -375,6 +376,85 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
}
function test_loadArrayFromForm() {
CS::defineNamespace('Pancake', 'This should not be user customizable');
CS::define('Pancake', 'Mix', 'buttermilk', 'string', 'Type of pancake mix to use.');
CS::define('Pancake', 'Served', true, 'bool', 'But this is customizable by user.');
CS::defineNamespace('Toppings', 'This is user customizable');
CS::define('Toppings', 'Syrup', true, 'bool', 'Absolutely standard!');
CS::define('Toppings', 'Flavor', 'maple', 'string', 'What flavor is the syrup?');
CS::define('Toppings', 'Strawberries', 3, 'int', 'Quite delightful fruit.');
CS::define('Toppings', 'Calories', 2000, 'int/null', 'Some things are best left unknown.');
CS::define('Toppings', 'DefinitionID', null, 'string/null', 'Do not let this be set');
CS::define('Toppings', 'DefinitionRev', 1, 'int', 'Do not let this be set');
CS::define('Toppings', 'Protected', 1, 'int', 'Do not let this be set');
$get = array(
'breakfast' => array(
'Pancake.Mix' => 'nasty',
'Pancake.Served' => '0',
'Toppings.Syrup' => '0',
'Toppings.Flavor' => "juice",
'Toppings.Strawberries' => '999',
'Toppings.Calories' => '',
'Null_Toppings.Calories' => '1',
'Toppings.DefinitionID' => '<argh>',
'Toppings.DefinitionRev' => '65',
'Toppings.Protected' => '4',
)
);
$config_expect = HTMLPurifier_Config::create(array(
'Pancake.Served' => false,
'Toppings.Syrup' => false,
'Toppings.Flavor' => "juice",
'Toppings.Strawberries' => 999,
'Toppings.Calories' => null
));
$config_result = HTMLPurifier_Config::loadArrayFromForm($get, 'breakfast', array('Pancake.Served', 'Toppings', '-Toppings.Protected'));
$this->assertEqual($config_expect, $config_result);
/*
MAGIC QUOTES NOT TESTED!!!
$get = array(
'breakfast' => array(
'Pancake.Mix' => 'n\\asty'
)
);
$config_expect = HTMLPurifier_Config::create(array(
'Pancake.Mix' => 'n\\asty'
));
$config_result = HTMLPurifier_Config::loadArrayFromForm($get, 'breakfast', true, false);
$this->assertEqual($config_expect, $config_result);
*/
}
function test_getAllowedDirectivesForForm() {
CS::defineNamespace('Unused', 'Not mentioned, so deny');
CS::define('Unused', 'Unused', 'Foobar', 'string', 'Not mentioned, do not allow');
CS::defineNamespace('Partial', 'Some are mentioned, allow only those');
CS::define('Partial', 'Allowed', true, 'bool', 'Mentioned, allowed');
CS::define('Partial', 'Unused', 'Foobar', 'string', 'Not mentioned, do not allow');
CS::defineNamespace('All', 'Entire namespace allowed, allow all unless...');
CS::define('All', 'Allowed', true, 'bool', 'Not mentioned, allowed');
CS::define('All', 'Blacklisted', 'Foobar', 'string', 'Specifically blacklisted');
CS::define('All', 'DefinitionID', 'Foobar', 'string/null', 'Special case, auto-blacklisted');
CS::define('All', 'DefinitionRev', 2, 'int', 'Special case, auto-blacklisted');
$input = array('Partial.Allowed', 'All', '-All.Blacklisted');
$output = HTMLPurifier_Config::getAllowedDirectivesForForm($input);
$expect = array(
array('Partial', 'Allowed'),
array('All', 'Allowed')
);
$this->assertEqual($output, $expect);
}
}
?>

View File

@@ -20,7 +20,7 @@ class HTMLPurifier_ContextTest extends UnitTestCase
$this->assertFalse($this->context->exists('IDAccumulator'));
$accumulator = new HTMLPurifier_IDAccumulatorMock($this);
$accumulator = new HTMLPurifier_IDAccumulatorMock();
$this->context->register('IDAccumulator', $accumulator);
$this->assertTrue($this->context->exists('IDAccumulator'));
@@ -30,11 +30,11 @@ class HTMLPurifier_ContextTest extends UnitTestCase
$this->context->destroy('IDAccumulator');
$this->assertFalse($this->context->exists('IDAccumulator'));
$this->expectError('Attempted to retrieve non-existent variable');
$this->expectError('Attempted to retrieve non-existent variable IDAccumulator');
$accumulator_3 =& $this->context->get('IDAccumulator');
$this->assertNull($accumulator_3);
$this->expectError('Attempted to destroy non-existent variable');
$this->expectError('Attempted to destroy non-existent variable IDAccumulator');
$this->context->destroy('IDAccumulator');
}
@@ -44,7 +44,7 @@ class HTMLPurifier_ContextTest extends UnitTestCase
$var = true;
$this->context->register('OnceOnly', $var);
$this->expectError('Name collision, cannot re-register');
$this->expectError('Name OnceOnly produces collision, cannot re-register');
$this->context->register('OnceOnly', $var);
// destroy it, now registration is okay
@@ -85,4 +85,3 @@ class HTMLPurifier_ContextTest extends UnitTestCase
}
?>

View File

@@ -56,4 +56,3 @@ class HTMLPurifier_DefinitionCache_Decorator_CleanupTest extends HTMLPurifier_De
}
?>

View File

@@ -70,4 +70,3 @@ class HTMLPurifier_DefinitionCache_Decorator_MemoryTest extends HTMLPurifier_Def
}
?>

View File

@@ -9,7 +9,7 @@ class HTMLPurifier_DefinitionCache_DecoratorHarness extends HTMLPurifier_Definit
{
function setup() {
$this->mock = new HTMLPurifier_DefinitionCacheMock($this);
$this->mock = new HTMLPurifier_DefinitionCacheMock();
$this->mock->type = 'Test';
$this->cache = $this->cache->decorate($this->mock);
$this->def = $this->generateDefinition();
@@ -23,4 +23,3 @@ class HTMLPurifier_DefinitionCache_DecoratorHarness extends HTMLPurifier_Definit
}
?>

View File

@@ -9,7 +9,7 @@ class HTMLPurifier_DefinitionCache_DecoratorTest extends HTMLPurifier_Definition
function test() {
generate_mock_once('HTMLPurifier_DefinitionCache');
$mock = new HTMLPurifier_DefinitionCacheMock($this);
$mock = new HTMLPurifier_DefinitionCacheMock();
$mock->type = 'Test';
$cache = new HTMLPurifier_DefinitionCache_Decorator();
@@ -42,4 +42,3 @@ class HTMLPurifier_DefinitionCache_DecoratorTest extends HTMLPurifier_Definition
}
?>

View File

@@ -14,7 +14,7 @@ class HTMLPurifier_DefinitionCache_SerializerTest extends HTMLPurifier_Definitio
$config->setReturnValue('get', 2, array('Test', 'DefinitionRev'));
$config->version = '1.0.0';
$config_md5 = '1.0.0-2-serial';
$config_md5 = '1.0.0-serial-2';
$file = realpath(
$rel_file = dirname(__FILE__) .
@@ -138,6 +138,32 @@ class HTMLPurifier_DefinitionCache_SerializerTest extends HTMLPurifier_Definitio
}
function testCleanupOnlySameID() {
$cache = new HTMLPurifier_DefinitionCache_Serializer('Test');
$config1 = $this->generateConfigMock('serial1');
$config1->version = '1.0.0';
$config1->setReturnValue('get', 1, array('Test', 'DefinitionRev'));
$def1 = $this->generateDefinition(array('info' => 1));
$config2 = $this->generateConfigMock('serial2');
$config2->version = '1.0.0';
$config2->setReturnValue('get', 34, array('Test', 'DefinitionRev'));
$def2 = $this->generateDefinition(array('info' => 3));
$cache->set($def1, $config1);
$cache->cleanup($config1);
$this->assertEqual($def1, $cache->get($config1)); // no change
$cache->set($def2, $config2);
$cache->cleanup($config2);
$this->assertEqual($def1, $cache->get($config1));
$this->assertEqual($def2, $cache->get($config2));
$cache->flush($config1);
}
/**
* Asserts that a file exists, ignoring the stat cache
*/
@@ -164,13 +190,12 @@ class HTMLPurifier_DefinitionCache_SerializerTest extends HTMLPurifier_Definitio
$def_original = $this->generateDefinition();
$cache->add($def_original, $config);
$this->assertFileExist($dir . '/Test/1.0.0-1-serial.ser');
$this->assertFileExist($dir . '/Test/1.0.0-serial-1.ser');
unlink($dir . '/Test/1.0.0-1-serial.ser');
unlink($dir . '/Test/1.0.0-serial-1.ser');
rmdir( $dir . '/Test');
}
}
?>

View File

@@ -62,4 +62,3 @@ class HTMLPurifier_DefinitionCacheFactoryTest extends UnitTestCase
}
?>

View File

@@ -10,7 +10,7 @@ class HTMLPurifier_DefinitionCacheHarness extends UnitTestCase
*/
function generateConfigMock($serial = 'defaultserial') {
generate_mock_once('HTMLPurifier_Config');
$config = new HTMLPurifier_ConfigMock($this);
$config = new HTMLPurifier_ConfigMock();
$config->setReturnValue('getBatchSerial', $serial, array('Test'));
$config->version = '1.0.0';
return $config;
@@ -31,4 +31,3 @@ class HTMLPurifier_DefinitionCacheHarness extends UnitTestCase
}
?>

View File

@@ -15,16 +15,22 @@ class HTMLPurifier_DefinitionCacheTest extends UnitTestCase
HTMLPurifier_ConfigSchema::defineNamespace('Test', 'Test namespace');
HTMLPurifier_ConfigSchema::define('Test', 'DefinitionRev', 1, 'int', 'Definition revision.');
$config = HTMLPurifier_Config::createDefault();
$config->version = '1.0.0';
$config->set('Test', 'DefinitionRev', 10);
generate_mock_once('HTMLPurifier_Config');
$config = new HTMLPurifier_ConfigMock();
$config->version = '1.0.0'; // hopefully no conflicts
$config->setReturnValue('get', 10, array('Test', 'DefinitionRev'));
$config->setReturnValue('getBatchSerial', 'hash', array('Test'));
$this->assertIdentical($cache->isOld('1.0.0-10-hashstuffhere', $config), false);
$this->assertIdentical($cache->isOld('1.5.0-1-hashstuffhere', $config), false);
$this->assertIdentical($cache->isOld('1.0.0-hash-10', $config), false);
$this->assertIdentical($cache->isOld('1.5.0-hash-1', $config), true);
$this->assertIdentical($cache->isOld('0.9.0-1-hashstuffhere', $config), true);
$this->assertIdentical($cache->isOld('1.0.0-1-hashstuffhere', $config), true);
$this->assertIdentical($cache->isOld('1.0.0beta-11-hashstuffhere', $config), true);
$this->assertIdentical($cache->isOld('0.9.0-hash-1', $config), true);
$this->assertIdentical($cache->isOld('1.0.0-hash-1', $config), true);
$this->assertIdentical($cache->isOld('1.0.0beta-hash-11', $config), true);
$this->assertIdentical($cache->isOld('0.9.0-hash2-1', $config), true);
$this->assertIdentical($cache->isOld('1.0.0-hash2-1', $config), false); // if hash is different, don't touch!
$this->assertIdentical($cache->isOld('1.0.0beta-hash2-11', $config), true);
HTMLPurifier_ConfigSchema::instance($old_copy);
@@ -32,4 +38,3 @@ class HTMLPurifier_DefinitionCacheTest extends UnitTestCase
}
?>

View File

@@ -30,4 +30,3 @@ class HTMLPurifier_DefinitionTest extends UnitTestCase
}
}
?>

View File

@@ -76,4 +76,3 @@ class HTMLPurifier_DoctypeRegistryTest extends UnitTestCase
}
?>

View File

@@ -33,10 +33,6 @@ class HTMLPurifier_ElementDefTest extends UnitTestCase
$def1->child = $overloaded_old;
$def1->content_model = 'old';
$def1->content_model_type = $overloaded_old;
$def1->auto_close = array(
'old' => true,
'removed-old' => true
);
$def1->descendants_are_inline = false;
$def1->excludes = array(
'old' => true,
@@ -60,10 +56,6 @@ class HTMLPurifier_ElementDefTest extends UnitTestCase
$def2->child = $new;
$def2->content_model = 'new';
$def2->content_model_type = $overloaded_new;
$def2->auto_close = array(
'new' => true,
'removed-old' => false
);
$def2->descendants_are_inline = true;
$def2->excludes = array(
'new' => true,
@@ -90,10 +82,6 @@ class HTMLPurifier_ElementDefTest extends UnitTestCase
$this->assertIdentical($def1->child, $new);
$this->assertIdentical($def1->content_model, 'old | new');
$this->assertIdentical($def1->content_model_type, $overloaded_new);
$this->assertIdentical($def1->auto_close, array(
'old' => true,
'new' => true
));
$this->assertIdentical($def1->descendants_are_inline, true);
$this->assertIdentical($def1->excludes, array(
'old' => true,
@@ -105,4 +93,3 @@ class HTMLPurifier_ElementDefTest extends UnitTestCase
}
?>

View File

@@ -141,4 +141,3 @@ class HTMLPurifier_EncoderTest extends UnitTestCase
}
?>

View File

@@ -26,4 +26,3 @@ class HTMLPurifier_EntityLookupTest extends UnitTestCase
}
?>

View File

@@ -82,4 +82,3 @@ class HTMLPurifier_EntityParserTest extends UnitTestCase
}
?>

View File

@@ -0,0 +1,46 @@
<?php
require_once 'HTMLPurifier/ErrorCollector.php';
generate_mock_once('HTMLPurifier_ErrorCollector');
/**
* Extended error collector mock that has the ability to expect context
*/
class HTMLPurifier_ErrorCollectorEMock extends HTMLPurifier_ErrorCollectorMock
{
var $_context;
var $_expected_context = array();
var $_expected_context_at = array();
function prepare(&$context) {
$this->_context =& $context;
}
function expectContext($key, $value) {
$this->_expected_context[$key] = $value;
}
function expectContextAt($step, $key, $value) {
$this->_expected_context_at[$step][$key] = $value;
}
function send($severity, $msg) {
// test for context
$test = &$this->_getCurrentTestCase();
foreach ($this->_expected_context as $key => $value) {
$test->assertEqual($value, $this->_context->get($key));
}
$step = $this->getCallCount('send');
if (isset($this->_expected_context_at[$step])) {
foreach ($this->_expected_context_at[$step] as $key => $value) {
$test->assertEqual($value, $this->_context->get($key));
}
}
// boilerplate mock code, does not have return value or references
$args = func_get_args();
$this->_invoke('send', $args);
}
}

View File

@@ -5,38 +5,137 @@ require_once 'HTMLPurifier/ErrorCollector.php';
class HTMLPurifier_ErrorCollectorTest extends UnitTestCase
{
function setup() {
generate_mock_once('HTMLPurifier_Language');
generate_mock_once('HTMLPurifier_Generator');
}
function test() {
$tok1 = new HTMLPurifier_Token_Text('Token that caused error');
$tok1->line = 23;
$tok2 = new HTMLPurifier_Token_Start('a'); // also caused error
$tok2->line = 3;
$tok3 = new HTMLPurifier_Token_Text('Context before'); // before $tok2
$tok3->line = 3;
$tok4 = new HTMLPurifier_Token_Text('Context after'); // after $tok2
$tok4->line = 3;
$language = new HTMLPurifier_LanguageMock();
$language->setReturnValue('getErrorName', 'Error', array(E_ERROR));
$language->setReturnValue('getErrorName', 'Warning', array(E_WARNING));
$language->setReturnValue('getMessage', 'Message 1', array('message-1'));
$language->setReturnValue('formatMessage', 'Message 2', array('message-2', array(1 => 'param')));
$language->setReturnValue('formatMessage', ' at line 23', array('ErrorCollector: At line', array('line' => 23)));
$language->setReturnValue('formatMessage', ' at line 3', array('ErrorCollector: At line', array('line' => 3)));
$collector = new HTMLPurifier_ErrorCollector();
$collector->send('Big fat error', $tok1);
$collector->send('Another <error>', $tok2, array($tok3, true, $tok4));
$line = false;
$context = new HTMLPurifier_Context();
$context->register('Locale', $language);
$context->register('CurrentLine', $line);
$generator = new HTMLPurifier_Generator();
$context->register('Generator', $generator);
$collector = new HTMLPurifier_ErrorCollector($context);
$line = 23;
$collector->send(E_ERROR, 'message-1');
$line = 3;
$collector->send(E_WARNING, 'message-2', 'param');
$result = array(
0 => array('Big fat error', $tok1, array(true)),
1 => array('Another <error>', $tok2, array($tok3, true, $tok4))
0 => array(23, E_ERROR, 'Message 1'),
1 => array(3, E_WARNING, 'Message 2')
);
$this->assertIdentical($collector->getRaw(), $result);
$formatted_result = array(
0 => 'Another &lt;error&gt; at line 3 (<code>Context before<strong>&lt;a&gt;</strong>Context after</code>)',
1 => 'Big fat error at line 23 (<code><strong>Token that caused error</strong></code>)'
);
$formatted_result =
'<ul><li><strong>Warning</strong>: Message 2 at line 3</li>'.
'<li><strong>Error</strong>: Message 1 at line 23</li></ul>';
$config = HTMLPurifier_Config::create(array('Core.MaintainLineNumbers' => true));
$this->assertIdentical($collector->getHTMLFormatted($config), $formatted_result);
}
function testNoErrors() {
$language = new HTMLPurifier_LanguageMock();
$language->setReturnValue('getMessage', 'No errors', array('ErrorCollector: No errors'));
$context = new HTMLPurifier_Context();
$context->register('Locale', $language);
$generator = new HTMLPurifier_Generator();
$context->register('Generator', $generator);
$collector = new HTMLPurifier_ErrorCollector($context);
$formatted_result = '<p>No errors</p>';
$config = HTMLPurifier_Config::createDefault();
$this->assertIdentical($collector->getHTMLFormatted($config), $formatted_result);
}
function testNoLineNumbers() {
$language = new HTMLPurifier_LanguageMock();
$language->setReturnValue('getMessage', 'Message 1', array('message-1'));
$language->setReturnValue('getMessage', 'Message 2', array('message-2'));
$language->setReturnValue('getErrorName', 'Error', array(E_ERROR));
$context = new HTMLPurifier_Context();
$context->register('Locale', $language);
$generator = new HTMLPurifier_Generator();
$context->register('Generator', $generator);
$collector = new HTMLPurifier_ErrorCollector($context);
$collector->send(E_ERROR, 'message-1');
$collector->send(E_ERROR, 'message-2');
$result = array(
0 => array(null, E_ERROR, 'Message 1'),
1 => array(null, E_ERROR, 'Message 2')
);
$this->assertIdentical($collector->getRaw(), $result);
$formatted_result =
'<ul><li><strong>Error</strong>: Message 1</li>'.
'<li><strong>Error</strong>: Message 2</li></ul>';
$config = HTMLPurifier_Config::createDefault();
$this->assertIdentical($collector->getHTMLFormatted($config), $formatted_result);
}
function testContextSubstitutions() {
$language = new HTMLPurifier_LanguageMock();
$context = new HTMLPurifier_Context();
$context->register('Locale', $language);
$generator = new HTMLPurifier_Generator();
$context->register('Generator', $generator);
$current_token = false;
$context->register('CurrentToken', $current_token);
$collector = new HTMLPurifier_ErrorCollector($context);
// 0
$current_token = new HTMLPurifier_Token_Start('a', array('href' => 'http://example.com'), 32);
$language->setReturnValue('formatMessage', 'Token message',
array('message-data-token', array('CurrentToken' => $current_token)));
$collector->send(E_NOTICE, 'message-data-token');
$current_attr = 'href';
$language->setReturnValue('formatMessage', '$CurrentAttr.Name => $CurrentAttr.Value',
array('message-attr', array('CurrentToken' => $current_token)));
// 1
$collector->send(E_NOTICE, 'message-attr'); // test when context isn't available
// 2
$context->register('CurrentAttr', $current_attr);
$collector->send(E_NOTICE, 'message-attr');
$result = array(
0 => array(32, E_NOTICE, 'Token message'),
1 => array(32, E_NOTICE, '$CurrentAttr.Name => $CurrentAttr.Value'),
2 => array(32, E_NOTICE, 'href => http://example.com')
);
$this->assertIdentical($collector->getRaw(), $result);
}
}
?>

View File

@@ -0,0 +1,31 @@
<?php
require_once 'HTMLPurifier/ErrorCollectorEMock.php';
require_once 'HTMLPurifier/Lexer/DirectLex.php';
class HTMLPurifier_ErrorsHarness extends UnitTestCase
{
var $config, $context;
var $collector, $generator;
function setup() {
$this->config = HTMLPurifier_Config::create(array('Core.CollectErrors' => true));
$this->context = new HTMLPurifier_Context();
generate_mock_once('HTMLPurifier_ErrorCollector');
$this->collector = new HTMLPurifier_ErrorCollectorEMock();
$this->collector->prepare($this->context);
$this->context->register('ErrorCollector', $this->collector);
}
function expectErrorCollection() {
$args = func_get_args();
$this->collector->expectOnce('send', $args);
}
function expectContext($key, $value) {
$this->collector->expectContext($key, $value);
}
}

View File

@@ -141,9 +141,31 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
new HTMLPurifier_Token_Text('alert(3 < 5);'),
new HTMLPurifier_Token_End('script')
),
"<script><!--\nalert(3 < 5);\n// --></script>"
"<script><!--//--><![CDATA[//><!--\nalert(3 < 5);\n//--><!]]></script>"
);
// if missing close tag, don't do anything
$this->assertGeneration(
array(
new HTMLPurifier_Token_Start('script'),
new HTMLPurifier_Token_Text('alert(3 < 5);'),
),
"<script>alert(3 &lt; 5);"
);
// if two script blocks, don't do anything
$this->assertGeneration(
array(
new HTMLPurifier_Token_Start('script'),
new HTMLPurifier_Token_Text('alert(3 < 5);'),
new HTMLPurifier_Token_Text('foo();'),
new HTMLPurifier_Token_End('script')
),
"<script>alert(3 &lt; 5);foo();</script>"
);
$this->config = HTMLPurifier_Config::createDefault();
$this->config->set('Core', 'CommentScriptContents', false);
@@ -185,6 +207,7 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
$this->config = HTMLPurifier_Config::createDefault();
$this->config->set('Core', 'TidyFormat', true);
$this->config->set('Output', 'Newline', "\n");
// nice wrapping please
$this->assertGeneration(
@@ -200,4 +223,3 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
}
?>

View File

@@ -84,4 +84,3 @@ class HTMLPurifier_HTMLDefinitionTest extends UnitTestCase
}
?>

View File

@@ -18,6 +18,14 @@ class HTMLPurifier_HTMLModule_ScriptingTest extends HTMLPurifier_HTMLModuleHarne
array('HTML.Trusted' => true)
);
// CDATA
$this->assertResult(
'//<![CDATA[
alert("<This is compatible with XHTML>");
//]]> ', true,
array('HTML.Trusted' => true)
);
// max
$this->assertResult(
'<script
@@ -38,15 +46,7 @@ class HTMLPurifier_HTMLModule_ScriptingTest extends HTMLPurifier_HTMLModuleHarne
array('HTML.Trusted' => true, 'Core.CommentScriptContents' => false)
);
// invalid children
$this->assertResult(
'<script type="text/javascript">PCDATA<span</script>',
'<script type="text/javascript">PCDATA</script>',
array('HTML.Trusted' => true, 'Core.CommentScriptContents' => false)
);
}
}
?>

View File

@@ -45,7 +45,7 @@ class HTMLPurifier_HTMLModule_TidyTest extends UnitTestCase
$i = 0; // counter, helps us isolate expectations
// initialize partial mock
$module = new HTMLPurifier_HTMLModule_Tidy_TestForConstruct($this);
$module = new HTMLPurifier_HTMLModule_Tidy_TestForConstruct();
$module->fixesForLevel['light'] = array('light-fix-1', 'light-fix-2');
$module->fixesForLevel['medium'] = array('medium-fix-1', 'medium-fix-2');
$module->fixesForLevel['heavy'] = array('heavy-fix-1', 'heavy-fix-2');
@@ -227,4 +227,3 @@ class HTMLPurifier_HTMLModule_TidyTest extends UnitTestCase
}
?>

View File

@@ -11,4 +11,3 @@ class HTMLPurifier_HTMLModuleHarness extends HTMLPurifier_StrategyHarness
}
}
?>

View File

@@ -13,7 +13,7 @@ class HTMLPurifier_HTMLModuleManagerTest extends UnitTestCase
$attrdef_nmtokens->_name = 'nmtokens'; // for testing only
generate_mock_once('HTMLPurifier_AttrDef');
$attrdef = new HTMLPurifier_AttrDefMock($this);
$attrdef = new HTMLPurifier_AttrDefMock();
$attrdef->setReturnValue('make', $attrdef_nmtokens);
$manager->attrTypes->info['NMTOKENS'] =& $attrdef;
@@ -38,7 +38,7 @@ class HTMLPurifier_HTMLModuleManagerTest extends UnitTestCase
$config = HTMLPurifier_Config::createDefault();
$config->set('HTML', 'Trusted', false);
$config->set('HTML', 'Doctype', 'Blank');
$config->set('HTML', 'CustomDoctype', 'Blank');
$manager->setup($config);
@@ -94,7 +94,7 @@ class HTMLPurifier_HTMLModuleManagerTest extends UnitTestCase
$manager->registerModule($magic_module);
$config = HTMLPurifier_Config::create(array(
'HTML.Doctype' => 'Fantasy Inventory 1.0',
'HTML.CustomDoctype' => 'Fantasy Inventory 1.0',
'HTML.AllowedModules' => 'Weapons'
));
$manager->setup($config);
@@ -106,4 +106,3 @@ class HTMLPurifier_HTMLModuleManagerTest extends UnitTestCase
}
?>

View File

@@ -147,4 +147,3 @@ class HTMLPurifier_HTMLModuleTest extends UnitTestCase
}
?>

View File

@@ -47,6 +47,11 @@ class HTMLPurifier_Harness extends UnitTestCase
*/
var $config;
/**
* Default context to fall back on if no context is available
*/
var $context;
function HTMLPurifier_Harness() {
$this->lexer = new HTMLPurifier_Lexer_DirectLex();
$this->generator = new HTMLPurifier_Generator();
@@ -77,8 +82,12 @@ class HTMLPurifier_Harness extends UnitTestCase
// setup context object. Note that we are operating on a copy of it!
// When necessary, extend the test harness to allow post-tests
// on the context object
$context = new HTMLPurifier_Context();
$context->loadArray($context_array);
if (empty($this->context)) {
$context = new HTMLPurifier_Context();
$context->loadArray($context_array);
} else {
$context =& $this->context;
}
if ($this->to_tokens && is_string($input)) {
// $func may cause $input to change, so "clone" another copy
@@ -116,4 +125,4 @@ class HTMLPurifier_Harness extends UnitTestCase
}
?>

View File

@@ -32,4 +32,3 @@ class HTMLPurifier_IDAccumulatorTest extends UnitTestCase
}
?>

View File

@@ -0,0 +1,253 @@
<?php
require_once 'HTMLPurifier/InjectorHarness.php';
require_once 'HTMLPurifier/Injector/AutoParagraph.php';
class HTMLPurifier_Injector_AutoParagraphTest extends HTMLPurifier_InjectorHarness
{
function setup() {
parent::setup();
$this->config = array('AutoFormat.AutoParagraph' => true);
}
function test() {
$this->assertResult(
'Foobar',
'<p>Foobar</p>'
);
$this->assertResult(
'Par 1
Par 1 still',
'<p>Par 1
Par 1 still</p>'
);
$this->assertResult(
'Par1
Par2',
'<p>Par1</p><p>Par2</p>'
);
$this->assertResult(
'Par1
Par2',
'<p>Par1</p><p>Par2</p>'
);
$this->assertResult(
'<b>Par1</b>
<i>Par2</i>',
'<p><b>Par1</b></p><p><i>Par2</i></p>'
);
$this->assertResult(
'<b>Par1
Par2</b>',
'<p><b>Par1
Par2</b></p>'
);
$this->assertResult(
'Par1<p>Par2</p>',
'<p>Par1</p><p>Par2</p>'
);
$this->assertResult(
'<b>Par1',
'<p><b>Par1</b></p>'
);
$this->assertResult(
'<pre>Par1
Par1</pre>'
);
$this->assertResult(
'Par1
',
'<p>Par1</p>'
);
$this->assertResult(
'Par1
<div>Par2</div>
Par3',
'<p>Par1</p><div>Par2</div><p>Par3</p>'
);
$this->assertResult(
'Par<b>1</b>',
'<p>Par<b>1</b></p>'
);
$this->assertResult(
'
Par',
'<p>Par</p>'
);
$this->assertResult(
'
Par
',
'<p>Par</p>'
);
$this->assertResult(
'<div>Par1
Par2</div>',
'<div><p>Par1</p><p>Par2</p></div>'
);
$this->assertResult(
'<div><b>Par1</b>
Par2</div>',
'<div><p><b>Par1</b></p><p>Par2</p></div>'
);
$this->assertResult('<div>Par1</div>');
$this->assertResult(
'<div><b>Par1</b>
<i>Par2</i></div>',
'<div><p><b>Par1</b></p><p><i>Par2</i></p></div>'
);
$this->assertResult(
'<pre><b>Par1</b>
<i>Par2</i></pre>',
true
);
$this->assertResult(
'<div><p>Foo
Bar</p></div>',
'<div><p>Foo</p><p>Bar</p></div>'
);
$this->assertResult(
'<div><p><b>Foo</b>
<i>Bar</i></p></div>',
'<div><p><b>Foo</b></p><p><i>Bar</i></p></div>'
);
$this->assertResult(
'<div><b>Foo</b></div>',
'<div><b>Foo</b></div>'
);
$this->assertResult(
'<blockquote>Par1
Par2</blockquote>',
'<blockquote><p>Par1</p><p>Par2</p></blockquote>'
);
$this->assertResult(
'<ul><li>Foo</li>
<li>Bar</li></ul>', true
);
$this->assertResult(
'<div>
Bar
</div>',
'<div><p>Bar</p></div>'
);
$this->assertResult(
'<b>Par1</b>a
Par2',
'<p><b>Par1</b>a</p><p>Par2</p>'
);
$this->assertResult(
'Par1
Par2</p>',
'<p>Par1</p><p>Par2</p>'
);
$this->assertResult(
'Par1
Par2</div>',
'<p>Par1</p><p>Par2</p>'
);
$this->assertResult(
'<div>
Par1
</div>', true
);
$this->assertResult(
'<div>Par1
<div>Par2</div></div>',
'<div><p>Par1</p><div>Par2</div></div>'
);
$this->assertResult(
'<div>Par1
<div>Par2</div></div>',
'<div><p>Par1
</p><div>Par2</div></div>'
);
$this->assertResult(
'Par1
<div>Par2</div>',
'<p>Par1
</p><div>Par2</div>'
);
$this->assertResult(
'Par1
<b>Par2</b>',
'<p>Par1</p><p><b>Par2</b></p>'
);
}
function testInlineRootNode() {
$this->assertResult(
'Par
Par2',
true,
array('AutoFormat.AutoParagraph' => true, 'HTML.Parent' => 'span')
);
}
}

View File

@@ -0,0 +1,38 @@
<?php
require_once 'HTMLPurifier/InjectorHarness.php';
require_once 'HTMLPurifier/Injector/Linkify.php';
class HTMLPurifier_Injector_LinkifyTest extends HTMLPurifier_InjectorHarness
{
function setup() {
parent::setup();
$this->config = array('AutoFormat.Linkify' => true);
}
function testLinkify() {
$this->assertResult(
'http://example.com',
'<a href="http://example.com">http://example.com</a>'
);
$this->assertResult(
'<b>http://example.com</b>',
'<b><a href="http://example.com">http://example.com</a></b>'
);
$this->assertResult(
'This URL http://example.com is what you need',
'This URL <a href="http://example.com">http://example.com</a> is what you need'
);
$this->assertResult(
'<a>http://example.com/</a>'
);
}
}

View File

@@ -0,0 +1,42 @@
<?php
require_once 'HTMLPurifier/InjectorHarness.php';
require_once 'HTMLPurifier/Injector/PurifierLinkify.php';
class HTMLPurifier_Injector_PurifierLinkifyTest extends HTMLPurifier_InjectorHarness
{
function setup() {
parent::setup();
$this->config = array(
'AutoFormat.PurifierLinkify' => true,
'AutoFormatParam.PurifierLinkifyDocURL' => '#%s'
);
}
function testLinkify() {
$this->assertResult('Foobar');
$this->assertResult('20% off!');
$this->assertResult('%Core namespace (not recognized)');
$this->assertResult(
'%Namespace.Directive',
'<a href="#Namespace.Directive">%Namespace.Directive</a>'
);
$this->assertResult(
'This %Namespace.Directive thing',
'This <a href="#Namespace.Directive">%Namespace.Directive</a> thing'
);
$this->assertResult(
'<div>This %Namespace.Directive thing</div>',
'<div>This <a href="#Namespace.Directive">%Namespace.Directive</a> thing</div>'
);
$this->assertResult(
'<a>%Namespace.Directive</a>'
);
}
}

View File

@@ -0,0 +1,15 @@
<?php
require_once 'HTMLPurifier/StrategyHarness.php';
require_once 'HTMLPurifier/Strategy/MakeWellFormed.php';
class HTMLPurifier_InjectorHarness extends HTMLPurifier_StrategyHarness
{
function setUp() {
parent::setUp();
$this->obj = new HTMLPurifier_Strategy_MakeWellFormed();
}
}

View File

@@ -9,7 +9,9 @@ class HTMLPurifier_LanguageFactoryTest extends UnitTestCase
$factory = HTMLPurifier_LanguageFactory::instance();
$language = $factory->create('en');
$config = HTMLPurifier_Config::create(array('Core.Language' => 'en'));
$context = new HTMLPurifier_Context();
$language = $factory->create($config, $context);
$this->assertIsA($language, 'HTMLPurifier_Language');
$this->assertIdentical($language->code, 'en');
@@ -27,7 +29,10 @@ class HTMLPurifier_LanguageFactoryTest extends UnitTestCase
$factory = HTMLPurifier_LanguageFactory::instance();
$language = $factory->create('en-x-test');
$config = HTMLPurifier_Config::create(array('Core.Language' => 'en-x-test'));
$context = new HTMLPurifier_Context();
$language = $factory->create($config, $context);
$this->assertIsA($language, 'HTMLPurifier_Language_en_x_test');
$this->assertIdentical($language->code, 'en-x-test');
@@ -35,13 +40,12 @@ class HTMLPurifier_LanguageFactoryTest extends UnitTestCase
$language->load();
// test overloaded message
$this->assertIdentical($language->getMessage('htmlpurifier'), 'HTML Purifier X');
$this->assertIdentical($language->getMessage('HTMLPurifier'), 'HTML Purifier X');
// test inherited message
$this->assertIdentical($language->getMessage('pizza'), 'Pizza');
$this->assertIdentical($language->getMessage('LanguageFactoryTest: Pizza'), 'Pizza');
}
}
?>

View File

@@ -7,21 +7,71 @@ class HTMLPurifier_LanguageTest extends UnitTestCase
var $lang;
function generateEnLanguage() {
$factory = HTMLPurifier_LanguageFactory::instance();
$config = HTMLPurifier_Config::create(array('Core.Language' => 'en'));
$context = new HTMLPurifier_Context();
return $factory->create($config, $context);
}
function test_getMessage() {
$lang = new HTMLPurifier_Language();
$config = HTMLPurifier_Config::createDefault();
$context = new HTMLPurifier_Context();
$lang = new HTMLPurifier_Language($config, $context);
$lang->_loaded = true;
$lang->messages['htmlpurifier'] = 'HTML Purifier';
$this->assertIdentical($lang->getMessage('htmlpurifier'), 'HTML Purifier');
$this->assertIdentical($lang->getMessage('totally-non-existent-key'), '[totally-non-existent-key]');
$lang->messages['HTMLPurifier'] = 'HTML Purifier';
$this->assertIdentical($lang->getMessage('HTMLPurifier'), 'HTML Purifier');
$this->assertIdentical($lang->getMessage('LanguageTest: Totally non-existent key'), '[LanguageTest: Totally non-existent key]');
}
function test_formatMessage() {
$lang = new HTMLPurifier_Language();
$config = HTMLPurifier_Config::createDefault();
$context = new HTMLPurifier_Context();
$lang = new HTMLPurifier_Language($config, $context);
$lang->_loaded = true;
$lang->messages['error'] = 'Error is $1 on line $2';
$this->assertIdentical($lang->formatMessage('error', 'fatal', 32), 'Error is fatal on line 32');
$lang->messages['LanguageTest: Error'] = 'Error is $1 on line $2';
$this->assertIdentical($lang->formatMessage('LanguageTest: Error', array(1=>'fatal', 32)), 'Error is fatal on line 32');
}
function test_formatMessage_tokenParameter() {
$config = HTMLPurifier_Config::createDefault();
$context = new HTMLPurifier_Context();
$generator = new HTMLPurifier_Generator(); // replace with mock if this gets icky
$context->register('Generator', $generator);
$lang = new HTMLPurifier_Language($config, $context);
$lang->_loaded = true;
$lang->messages['LanguageTest: Element info'] = 'Element Token: $1.Name, $1.Serialized, $1.Compact, $1.Line';
$lang->messages['LanguageTest: Data info'] = 'Data Token: $1.Data, $1.Serialized, $1.Compact, $1.Line';
$this->assertIdentical($lang->formatMessage('LanguageTest: Element info',
array(1=>new HTMLPurifier_Token_Start('a', array('href'=>'http://example.com'), 18))),
'Element Token: a, <a href="http://example.com">, <a>, 18');
$this->assertIdentical($lang->formatMessage('LanguageTest: Data info',
array(1=>new HTMLPurifier_Token_Text('data>', 23))),
'Data Token: data>, data&gt;, data&gt;, 23');
}
function test_listify() {
$lang = $this->generateEnLanguage();
$this->assertEqual($lang->listify(array('Item')), 'Item');
$this->assertEqual($lang->listify(array('Item', 'Item2')), 'Item and Item2');
$this->assertEqual($lang->listify(array('Item', 'Item2', 'Item3')), 'Item, Item2 and Item3');
}
function test_formatMessage_arrayParameter() {
$lang = $this->generateEnLanguage();
$array = array('Item1', 'Item2', 'Item3');
$this->assertIdentical(
$lang->formatMessage('LanguageTest: List', array(1=>$array)),
'Item1, Item2 and Item3'
);
$array = array('Key1' => 'Value1', 'Key2' => 'Value2');
$this->assertIdentical(
$lang->formatMessage('LanguageTest: Hash', array(1=>$array)),
'Key1 and Key2; Value1 and Value2'
);
}
}
?>

View File

@@ -53,6 +53,12 @@ class HTMLPurifier_Lexer_DirectLexTest extends UnitTestCase
$input[10] = 'name="input" selected';
$expect[10] = array('name' => 'input', 'selected' => 'selected');
$input[11] = '=""';
$expect[11] = array();
$input[12] = '="" =""';
$expect[12] = array('"' => ''); // tough to say, just don't throw a loop
$config = HTMLPurifier_Config::createDefault();
$context = new HTMLPurifier_Context();
$size = count($input);
@@ -66,32 +72,23 @@ class HTMLPurifier_Lexer_DirectLexTest extends UnitTestCase
function testLineNumbers() {
$html = '<b>Line 1</b>
<i>Line 2</i>
Still Line 2<br
/>Now Line 4
<br />';
$html = "<b>Line 1</b>\n<i>Line 2</i>\nStill Line 2<br\n/>Now Line 4\n\n<br />";
$expect = array(
// line 1
0 => new HTMLPurifier_Token_Start('b')
,1 => new HTMLPurifier_Token_Text('Line 1')
,2 => new HTMLPurifier_Token_End('b')
,3 => new HTMLPurifier_Token_Text('
')
,3 => new HTMLPurifier_Token_Text("\n")
// line 2
,4 => new HTMLPurifier_Token_Start('i')
,5 => new HTMLPurifier_Token_Text('Line 2')
,6 => new HTMLPurifier_Token_End('i')
,7 => new HTMLPurifier_Token_Text('
Still Line 2')
,7 => new HTMLPurifier_Token_Text("\nStill Line 2")
// line 3
,8 => new HTMLPurifier_Token_Empty('br')
// line 4
,9 => new HTMLPurifier_Token_Text('Now Line 4
')
,9 => new HTMLPurifier_Token_Text("Now Line 4\n\n")
// line SIX
,10 => new HTMLPurifier_Token_Empty('br')
);
@@ -123,7 +120,5 @@ class HTMLPurifier_Lexer_DirectLexTest extends UnitTestCase
}
}
?>

View File

@@ -0,0 +1,55 @@
<?php
require_once 'HTMLPurifier/ErrorsHarness.php';
require_once 'HTMLPurifier/Lexer/DirectLex.php';
class HTMLPurifier_Lexer_DirectLex_ErrorsTest extends HTMLPurifier_ErrorsHarness
{
function invoke($input) {
$lexer = new HTMLPurifier_Lexer_DirectLex();
$lexer->tokenizeHTML($input, $this->config, $this->context);
}
function invokeAttr($input) {
$lexer = new HTMLPurifier_Lexer_DirectLex();
$lexer->parseAttributeString($input, $this->config, $this->context);
}
function testUnclosedComment() {
$this->expectErrorCollection(E_WARNING, 'Lexer: Unclosed comment');
$this->expectContext('CurrentLine', 1);
$this->invoke('<!-- >');
}
function testUnescapedLt() {
$this->expectErrorCollection(E_NOTICE, 'Lexer: Unescaped lt');
$this->expectContext('CurrentLine', 1);
$this->invoke('< foo>');
}
function testMissingGt() {
$this->expectErrorCollection(E_WARNING, 'Lexer: Missing gt');
$this->expectContext('CurrentLine', 1);
$this->invoke('<a href=""');
}
// these are sub-errors, will only be thrown in context of collector
function testMissingAttributeKey1() {
$this->expectErrorCollection(E_ERROR, 'Lexer: Missing attribute key');
$this->invokeAttr('=""');
}
function testMissingAttributeKey2() {
$this->expectErrorCollection(E_ERROR, 'Lexer: Missing attribute key');
$this->invokeAttr('foo="bar" =""');
}
function testMissingEndQuote() {
$this->expectErrorCollection(E_ERROR, 'Lexer: Missing end quote');
$this->invokeAttr('src="foo');
}
}

View File

@@ -70,7 +70,7 @@ class HTMLPurifier_LexerTest extends UnitTestCase
$this->assertExtractBody('<html><body><b>Bold</b></body></html>', '<b>Bold</b>');
$this->assertExtractBody('<HTML><BODY><B>Bold</B></BODY></HTML>', '<B>Bold</B>');
$this->assertExtractBody(
'<?xml version="1.0"?>
'<?xml version="1.0"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
@@ -298,6 +298,33 @@ class HTMLPurifier_LexerTest extends UnitTestCase
$sax_expect[19] = false; // SAX drops the < character
$dom_expect[19] = false; // DOM drops the entire pseudo-tag
// test comment parsing with funky characters inside
$input[20] = '<!-- This >< comment --><br />';
$expect[20] = array(
new HTMLPurifier_Token_Comment(' This >< comment '),
new HTMLPurifier_Token_Empty('br')
);
$sax_expect[20] = false;
// test comment parsing of missing end
$input[21] = '<!-- This >< comment';
$expect[21] = array(
new HTMLPurifier_Token_Comment(' This >< comment')
);
$sax_expect[21] = false;
$dom_expect[21] = false;
// test CDATA tags
$input[22] = '<script>alert("<foo>");</script>';
$expect[22] = array(
new HTMLPurifier_Token_Start('script')
,new HTMLPurifier_Token_Text('alert("<foo>");')
,new HTMLPurifier_Token_End('script')
);
$config[22] = HTMLPurifier_Config::create(array('HTML.Trusted' => true));
$sax_expect[22] = false;
//$dom_expect[22] = false;
$default_config = HTMLPurifier_Config::createDefault();
$default_context = new HTMLPurifier_Context();
foreach($input as $i => $discard) {
@@ -344,4 +371,3 @@ class HTMLPurifier_LexerTest extends UnitTestCase
}
?>

View File

@@ -39,4 +39,3 @@ class HTMLPurifier_PercentEncoderTest extends UnitTestCase
}
?>

View File

@@ -32,4 +32,3 @@ class HTMLPurifier_SimpleTest_Reporter extends HTMLReporter
}
?>

View File

@@ -26,9 +26,9 @@ class HTMLPurifier_Strategy_CompositeTest extends UnitTestCase
// setup a bunch of mock strategies to inject into our composite test
$mock_1 = new HTMLPurifier_StrategyMock($this);
$mock_2 = new HTMLPurifier_StrategyMock($this);
$mock_3 = new HTMLPurifier_StrategyMock($this);
$mock_1 = new HTMLPurifier_StrategyMock();
$mock_2 = new HTMLPurifier_StrategyMock();
$mock_3 = new HTMLPurifier_StrategyMock();
// setup the object
@@ -73,4 +73,3 @@ class HTMLPurifier_Strategy_CompositeTest extends UnitTestCase
}
?>

View File

@@ -20,7 +20,7 @@ class HTMLPurifier_Strategy_CoreTest extends HTMLPurifier_StrategyHarness
);
$this->assertResult(
'<b><div>Fix nesting.</div></b>',
'<b>Fix nesting.</b>'
'<b></b><div>Fix nesting.</div>'
);
$this->assertResult(
'<asdf>Foreign element removal.</asdf>',
@@ -28,11 +28,10 @@ class HTMLPurifier_Strategy_CoreTest extends HTMLPurifier_StrategyHarness
);
$this->assertResult(
'<foo><b><div>All three.</div></b>',
'<b>All three.</b>'
'<b></b><div>All three.</div>'
);
}
}
?>

View File

@@ -0,0 +1,19 @@
<?php
require_once 'HTMLPurifier/ErrorsHarness.php';
class HTMLPurifier_Strategy_ErrorsHarness extends HTMLPurifier_ErrorsHarness
{
// needs to be defined
function getStrategy() {}
function invoke($input) {
$strategy = $this->getStrategy();
$lexer = new HTMLPurifier_Lexer_DirectLex();
$tokens = $lexer->tokenizeHTML($input, $this->config, $this->context);
$strategy->execute($tokens, $this->config, $this->context);
}
}

Some files were not shown because too many files have changed in this diff Show More