mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-08 07:06:46 +02:00
Release 1.6.1, merged in 931 to HEAD.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/branches/strict@1026 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
31
tests/HTMLPurifier/AttrDef/HTML/FrameTargetTest.php
Normal file
31
tests/HTMLPurifier/AttrDef/HTML/FrameTargetTest.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/AttrDefHarness.php';
|
||||
require_once 'HTMLPurifier/AttrDef/HTML/FrameTarget.php';
|
||||
|
||||
class HTMLPurifier_AttrDef_HTML_FrameTargetTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
function setup() {
|
||||
parent::setup();
|
||||
$this->def = new HTMLPurifier_AttrDef_HTML_FrameTarget();
|
||||
}
|
||||
|
||||
function testNoneAllowed() {
|
||||
$this->assertDef('', false);
|
||||
$this->assertDef('foo', false);
|
||||
$this->assertDef('_blank', false);
|
||||
$this->assertDef('baz', false);
|
||||
}
|
||||
|
||||
function test() {
|
||||
$this->config->set('Attr', 'AllowedFrameTargets', 'foo,_blank');
|
||||
$this->assertDef('', false);
|
||||
$this->assertDef('foo');
|
||||
$this->assertDef('_blank');
|
||||
$this->assertDef('baz', false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@@ -9,11 +9,11 @@ class HTMLPurifier_AttrDefTest extends UnitTestCase
|
||||
|
||||
$def = new HTMLPurifier_AttrDef();
|
||||
|
||||
$this->assertEqual('', $def->parseCDATA(''));
|
||||
$this->assertEqual('', $def->parseCDATA("\t\n\r \t\t"));
|
||||
$this->assertEqual('foo', $def->parseCDATA("\t\n\r foo\t\t"));
|
||||
$this->assertEqual('ignorelinefeeds', $def->parseCDATA("ignore\nline\nfeeds"));
|
||||
$this->assertEqual('translate to space', $def->parseCDATA("translate\rto\tspace"));
|
||||
$this->assertIdentical('', $def->parseCDATA(''));
|
||||
$this->assertIdentical('', $def->parseCDATA("\t\n\r \t\t"));
|
||||
$this->assertIdentical('foo', $def->parseCDATA("\t\n\r foo\t\t"));
|
||||
$this->assertIdentical('ignorelinefeeds', $def->parseCDATA("ignore\nline\nfeeds"));
|
||||
$this->assertIdentical('translate to space', $def->parseCDATA("translate\rto\tspace"));
|
||||
|
||||
}
|
||||
|
||||
|
39
tests/HTMLPurifier/AttrTransform/BoolToCSSTest.php
Normal file
39
tests/HTMLPurifier/AttrTransform/BoolToCSSTest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/AttrTransform/BoolToCSS.php';
|
||||
require_once 'HTMLPurifier/AttrTransformHarness.php';
|
||||
|
||||
class HTMLPurifier_AttrTransform_BoolToCSSTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_BoolToCSS('foo', 'bar:3in;');
|
||||
}
|
||||
|
||||
function test() {
|
||||
|
||||
$this->assertResult( array() );
|
||||
|
||||
$this->assertResult(
|
||||
array('foo' => 'foo'),
|
||||
array('style' => 'bar:3in;')
|
||||
);
|
||||
|
||||
// boolean attribute just has to be set: we don't care about
|
||||
// anything else
|
||||
$this->assertResult(
|
||||
array('foo' => 'no'),
|
||||
array('style' => 'bar:3in;')
|
||||
);
|
||||
|
||||
$this->assertResult(
|
||||
array('foo' => 'foo', 'style' => 'background-color:#F00;'),
|
||||
array('style' => 'bar:3in;background-color:#F00;')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@@ -1,17 +1,17 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/AttrTransform/TextAlign.php';
|
||||
require_once 'HTMLPurifier/AttrTransform/EnumToCSS.php';
|
||||
require_once 'HTMLPurifier/AttrTransformHarness.php';
|
||||
|
||||
class HTMLPurifier_AttrTransform_TextAlignTest extends HTMLPurifier_AttrTransformHarness
|
||||
class HTMLPurifier_AttrTransform_EnumToCSSTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_TextAlign();
|
||||
}
|
||||
|
||||
function test() {
|
||||
function testRegular() {
|
||||
|
||||
$this->obj = new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
|
||||
'left' => 'text-align:left;',
|
||||
'right' => 'text-align:right;'
|
||||
));
|
||||
|
||||
// leave empty arrays alone
|
||||
$this->assertResult( array() );
|
||||
@@ -31,16 +31,6 @@ class HTMLPurifier_AttrTransform_TextAlignTest extends HTMLPurifier_AttrTransfor
|
||||
array('style' => 'text-align:right;')
|
||||
);
|
||||
|
||||
$this->assertResult(
|
||||
array('align' => 'center'),
|
||||
array('style' => 'text-align:center;')
|
||||
);
|
||||
|
||||
$this->assertResult(
|
||||
array('align' => 'justify'),
|
||||
array('style' => 'text-align:justify;')
|
||||
);
|
||||
|
||||
// drop garbage value
|
||||
$this->assertResult(
|
||||
array('align' => 'invalid'),
|
||||
@@ -53,10 +43,32 @@ class HTMLPurifier_AttrTransform_TextAlignTest extends HTMLPurifier_AttrTransfor
|
||||
array('style' => 'text-align:left;font-weight:bold;')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testCaseInsensitive() {
|
||||
|
||||
$this->obj = new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
|
||||
'right' => 'text-align:right;'
|
||||
));
|
||||
|
||||
// test case insensitivity
|
||||
$this->assertResult(
|
||||
array('align' => 'CENTER'),
|
||||
array('style' => 'text-align:center;')
|
||||
array('align' => 'RIGHT'),
|
||||
array('style' => 'text-align:right;')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testCaseSensitive() {
|
||||
|
||||
$this->obj = new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
|
||||
'right' => 'text-align:right;'
|
||||
), true);
|
||||
|
||||
// test case insensitivity
|
||||
$this->assertResult(
|
||||
array('align' => 'RIGHT'),
|
||||
array()
|
||||
);
|
||||
|
||||
}
|
@@ -34,7 +34,7 @@ class HTMLPurifier_AttrTransform_ImgRequiredTest extends HTMLPurifier_AttrTransf
|
||||
|
||||
$this->assertResult(
|
||||
array('alt' => 'intrigue'),
|
||||
array('src' => '', 'alt' => 'intrigue')
|
||||
array('alt' => 'intrigue', 'src' => '')
|
||||
);
|
||||
|
||||
}
|
||||
|
57
tests/HTMLPurifier/AttrTransform/ImgSpaceTest.php
Normal file
57
tests/HTMLPurifier/AttrTransform/ImgSpaceTest.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/AttrTransform/ImgSpace.php';
|
||||
require_once 'HTMLPurifier/AttrTransformHarness.php';
|
||||
|
||||
|
||||
class HTMLPurifier_AttrTransform_ImgSpaceTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
function testVertical() {
|
||||
|
||||
$this->obj = new HTMLPurifier_AttrTransform_ImgSpace('vspace');
|
||||
|
||||
$this->assertResult( array() );
|
||||
|
||||
$this->assertResult(
|
||||
array('vspace' => '1'),
|
||||
array('style' => 'margin-top:1px;margin-bottom:1px;')
|
||||
);
|
||||
|
||||
// no validation done here, we expect CSS validator to catch it
|
||||
$this->assertResult(
|
||||
array('vspace' => '10%'),
|
||||
array('style' => 'margin-top:10%px;margin-bottom:10%px;')
|
||||
);
|
||||
|
||||
$this->assertResult(
|
||||
array('vspace' => '23', 'style' => 'font-weight:bold;'),
|
||||
array('style' => 'margin-top:23px;margin-bottom:23px;font-weight:bold;')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testHorizontal() {
|
||||
$this->obj = new HTMLPurifier_AttrTransform_ImgSpace('hspace');
|
||||
$this->assertResult(
|
||||
array('hspace' => '1'),
|
||||
array('style' => 'margin-left:1px;margin-right:1px;')
|
||||
);
|
||||
}
|
||||
|
||||
function testInvalid() {
|
||||
$this->expectError('ispace is not valid space attribute');
|
||||
$this->obj = new HTMLPurifier_AttrTransform_ImgSpace('ispace');
|
||||
$this->assertResult(
|
||||
array('ispace' => '1'),
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@@ -33,7 +33,7 @@ class HTMLPurifier_AttrTransform_LangTest
|
||||
// copy xml:lang to lang
|
||||
$this->assertResult(
|
||||
array('xml:lang' => 'en'),
|
||||
array('lang' => 'en', 'xml:lang' => 'en')
|
||||
array('xml:lang' => 'en', 'lang' => 'en')
|
||||
);
|
||||
|
||||
// both set, override lang with xml:lang
|
||||
|
42
tests/HTMLPurifier/AttrTransformTest.php
Normal file
42
tests/HTMLPurifier/AttrTransformTest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/AttrTransform.php';
|
||||
|
||||
class HTMLPurifier_AttrTransformTest extends UnitTestCase
|
||||
{
|
||||
|
||||
function test_prependCSS() {
|
||||
|
||||
$t = new HTMLPurifier_AttrTransform();
|
||||
|
||||
$attr = array();
|
||||
$t->prependCSS($attr, 'style:new;');
|
||||
$this->assertIdentical(array('style' => 'style:new;'), $attr);
|
||||
|
||||
$attr = array('style' => 'style:original;');
|
||||
$t->prependCSS($attr, 'style:new;');
|
||||
$this->assertIdentical(array('style' => 'style:new;style:original;'), $attr);
|
||||
|
||||
$attr = array('style' => 'style:original;', 'misc' => 'un-related');
|
||||
$t->prependCSS($attr, 'style:new;');
|
||||
$this->assertIdentical(array('style' => 'style:new;style:original;', 'misc' => 'un-related'), $attr);
|
||||
|
||||
}
|
||||
|
||||
function test_confiscateAttr() {
|
||||
|
||||
$t = new HTMLPurifier_AttrTransform();
|
||||
|
||||
$attr = array('flavor' => 'sweet');
|
||||
$this->assertIdentical('sweet', $t->confiscateAttr($attr, 'flavor'));
|
||||
$this->assertIdentical(array(), $attr);
|
||||
|
||||
$attr = array('flavor' => 'sweet');
|
||||
$this->assertIdentical(null, $t->confiscateAttr($attr, 'color'));
|
||||
$this->assertIdentical(array('flavor' => 'sweet'), $attr);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@@ -9,7 +9,7 @@ class HTMLPurifier_ChildDef_RequiredTest extends HTMLPurifier_ChildDefHarness
|
||||
function testParsing() {
|
||||
|
||||
$def = new HTMLPurifier_ChildDef_Required('foobar | bang |gizmo');
|
||||
$this->assertEqual($def->elements,
|
||||
$this->assertIdentical($def->elements,
|
||||
array(
|
||||
'foobar' => true
|
||||
,'bang' => true
|
||||
@@ -17,7 +17,7 @@ class HTMLPurifier_ChildDef_RequiredTest extends HTMLPurifier_ChildDefHarness
|
||||
));
|
||||
|
||||
$def = new HTMLPurifier_ChildDef_Required(array('href', 'src'));
|
||||
$this->assertEqual($def->elements,
|
||||
$this->assertIdentical($def->elements,
|
||||
array(
|
||||
'href' => true
|
||||
,'src' => true
|
||||
|
@@ -277,14 +277,17 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase
|
||||
|
||||
$this->assertValid(array('1', '2', '3'), 'list');
|
||||
$this->assertValid('foo,bar, cow', 'list', array('foo', 'bar', 'cow'));
|
||||
$this->assertValid('', 'list', array());
|
||||
|
||||
$this->assertValid(array('1' => true, '2' => true), 'lookup');
|
||||
$this->assertValid(array('1', '2'), 'lookup', array('1' => true, '2' => true));
|
||||
$this->assertValid('foo,bar', 'lookup', array('foo' => true, 'bar' => true));
|
||||
$this->assertValid('', 'lookup', array());
|
||||
|
||||
$this->assertValid(array('foo' => 'bar'), 'hash');
|
||||
$this->assertValid(array(1 => 'moo'), 'hash');
|
||||
$this->assertInvalid(array(0 => 'moo'), 'hash');
|
||||
$this->assertValid('', 'hash', array());
|
||||
|
||||
$this->assertValid(23, 'mixed');
|
||||
|
||||
|
@@ -164,13 +164,13 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
|
||||
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
|
||||
$this->assertEqual($config->get('Home', 'Rug'), 3);
|
||||
$this->assertIdentical($config->get('Home', 'Rug'), 3);
|
||||
|
||||
$this->expectError('Cannot get value from aliased directive, use real name');
|
||||
$config->get('Home', 'Carpet');
|
||||
|
||||
$config->set('Home', 'Carpet', 999);
|
||||
$this->assertEqual($config->get('Home', 'Rug'), 999);
|
||||
$this->assertIdentical($config->get('Home', 'Rug'), 999);
|
||||
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
|
||||
$def = $config->getHTMLDefinition();
|
||||
$def2 = $config->getHTMLDefinition();
|
||||
$this->assertIsA($def, 'HTMLPurifier_HTMLDefinition');
|
||||
$this->assertEqual($def, $def2);
|
||||
$this->assertIdentical($def, $def2);
|
||||
$this->assertTrue($def->setup);
|
||||
|
||||
// test re-calculation if HTML changes
|
||||
@@ -298,8 +298,8 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
|
||||
)
|
||||
));
|
||||
|
||||
$this->assertEqual($config_manual, $config_loadabbr);
|
||||
$this->assertEqual($config_manual, $config_loadfull);
|
||||
$this->assertIdentical($config_manual, $config_loadabbr);
|
||||
$this->assertIdentical($config_manual, $config_loadfull);
|
||||
|
||||
}
|
||||
|
||||
@@ -314,15 +314,15 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
|
||||
|
||||
// test flat pass-through
|
||||
$created_config = HTMLPurifier_Config::create($config);
|
||||
$this->assertEqual($config, $created_config);
|
||||
$this->assertIdentical($config, $created_config);
|
||||
|
||||
// test loadArray
|
||||
$created_config = HTMLPurifier_Config::create(array('Cake.Sprinkles' => 42));
|
||||
$this->assertEqual($config, $created_config);
|
||||
$this->assertIdentical($config, $created_config);
|
||||
|
||||
// test loadIni
|
||||
$created_config = HTMLPurifier_Config::create(dirname(__FILE__) . '/ConfigTest-create.ini');
|
||||
$this->assertEqual($config, $created_config);
|
||||
$this->assertIdentical($config, $created_config);
|
||||
|
||||
}
|
||||
|
||||
|
@@ -61,7 +61,7 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
|
||||
|
||||
foreach ($inputs as $i => $input) {
|
||||
$result = $this->obj->generateFromToken($input);
|
||||
$this->assertEqual($result, $expect[$i]);
|
||||
$this->assertIdentical($result, $expect[$i]);
|
||||
paintIf($result, $result != $expect[$i]);
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
|
||||
|
||||
foreach ($inputs as $i => $input) {
|
||||
$result = $this->obj->generateAttributes($input);
|
||||
$this->assertEqual($result, $expect[$i]);
|
||||
$this->assertIdentical($result, $expect[$i]);
|
||||
paintIf($result, $result != $expect[$i]);
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
|
||||
// normalized newlines, this probably should be put somewhere else
|
||||
$result = str_replace("\r\n", "\n", $result);
|
||||
$result = str_replace("\r", "\n", $result);
|
||||
$this->assertEqual($expect, $result);
|
||||
$this->assertIdentical($expect, $result);
|
||||
}
|
||||
|
||||
function test_generateFromTokens_XHTMLoff() {
|
||||
|
@@ -48,15 +48,15 @@ class HTMLPurifier_HTMLModuleManagerTest extends UnitTestCase
|
||||
$this->manager->addModule($module);
|
||||
$module_order = $this->manager->modules['Module']->order;
|
||||
$module->order = $module_order;
|
||||
$this->assertEqual($module, $this->manager->modules['Module']);
|
||||
$this->assertIdentical($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->assertIdentical($module2, $this->manager->modules['Module2']);
|
||||
$this->assertIdentical($module_order + 1, $module2_order);
|
||||
|
||||
$this->assertEqual(
|
||||
$this->assertIdentical(
|
||||
$this->manager->collections['Default']['Generic Document 0.1'],
|
||||
array('Module', 'Module2')
|
||||
);
|
||||
|
@@ -97,7 +97,7 @@ class HTMLPurifier_Harness extends UnitTestCase
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEqual($expect, $result);
|
||||
$this->assertIdentical($expect, $result);
|
||||
|
||||
}
|
||||
|
||||
|
@@ -12,10 +12,10 @@ class HTMLPurifier_LanguageFactoryTest extends UnitTestCase
|
||||
$language = $factory->create('en');
|
||||
|
||||
$this->assertIsA($language, 'HTMLPurifier_Language');
|
||||
$this->assertEqual($language->code, 'en');
|
||||
$this->assertIdentical($language->code, 'en');
|
||||
|
||||
// lazy loading test
|
||||
$this->assertEqual(count($language->messages), 0);
|
||||
$this->assertIdentical(count($language->messages), 0);
|
||||
$language->load();
|
||||
$this->assertNotEqual(count($language->messages), 0);
|
||||
|
||||
@@ -30,15 +30,15 @@ class HTMLPurifier_LanguageFactoryTest extends UnitTestCase
|
||||
$language = $factory->create('en-x-test');
|
||||
|
||||
$this->assertIsA($language, 'HTMLPurifier_Language_en_x_test');
|
||||
$this->assertEqual($language->code, 'en-x-test');
|
||||
$this->assertIdentical($language->code, 'en-x-test');
|
||||
|
||||
$language->load();
|
||||
|
||||
// test overloaded message
|
||||
$this->assertEqual($language->getMessage('htmlpurifier'), 'HTML Purifier X');
|
||||
$this->assertIdentical($language->getMessage('htmlpurifier'), 'HTML Purifier X');
|
||||
|
||||
// test inherited message
|
||||
$this->assertEqual($language->getMessage('pizza'), 'Pizza');
|
||||
$this->assertIdentical($language->getMessage('pizza'), 'Pizza');
|
||||
|
||||
}
|
||||
|
||||
|
@@ -58,7 +58,7 @@ class HTMLPurifier_Lexer_DirectLexTest extends UnitTestCase
|
||||
$size = count($input);
|
||||
for($i = 0; $i < $size; $i++) {
|
||||
$result = $this->DirectLex->parseAttributeString($input[$i], $config, $context);
|
||||
$this->assertEqual($expect[$i], $result, 'Test ' . $i . ': %s');
|
||||
$this->assertIdentical($expect[$i], $result, 'Test ' . $i . ': %s');
|
||||
paintIf($result, $expect[$i] != $result);
|
||||
}
|
||||
|
||||
|
@@ -280,13 +280,25 @@ class HTMLPurifier_LexerTest extends UnitTestCase
|
||||
$input[18] = '<br test="x < 6" />';
|
||||
$expect[18] = array( new HTMLPurifier_Token_Empty('br', array('test' => 'x < 6')) );
|
||||
|
||||
// test emoticon protection
|
||||
$input[19] = '<b>Whoa! >.< That\'s not good >.></b>';
|
||||
$expect[19] = array(
|
||||
new HTMLPurifier_Token_Start('b'),
|
||||
new HTMLPurifier_Token_Text('Whoa! >.'),
|
||||
new HTMLPurifier_Token_Text('< That\'s not good >'),
|
||||
new HTMLPurifier_Token_Text('.>'),
|
||||
new HTMLPurifier_Token_End('b'),
|
||||
);
|
||||
$sax_expect[19] = false; // SAX drops the < character
|
||||
$dom_expect[19] = false; // DOM drops the entire pseudo-tag
|
||||
|
||||
$default_config = HTMLPurifier_Config::createDefault();
|
||||
$default_context = new HTMLPurifier_Context();
|
||||
foreach($input as $i => $discard) {
|
||||
if (!isset($config[$i])) $config[$i] = $default_config;
|
||||
|
||||
$result = $this->DirectLex->tokenizeHTML($input[$i], $config[$i], $default_context);
|
||||
$this->assertEqual($expect[$i], $result, 'DirectLexTest '.$i.': %s');
|
||||
$this->assertIdentical($expect[$i], $result, 'DirectLexTest '.$i.': %s');
|
||||
paintIf($result, $expect[$i] != $result);
|
||||
|
||||
if ($this->_has_pear) {
|
||||
@@ -294,14 +306,14 @@ class HTMLPurifier_LexerTest extends UnitTestCase
|
||||
$sax_result = $this->PEARSax3->tokenizeHTML($input[$i], $config[$i], $default_context);
|
||||
if (!isset($sax_expect[$i])) {
|
||||
// by default, assert with normal result
|
||||
$this->assertEqual($expect[$i], $sax_result, 'PEARSax3Test '.$i.': %s');
|
||||
$this->assertIdentical($expect[$i], $sax_result, 'PEARSax3Test '.$i.': %s');
|
||||
paintIf($sax_result, $expect[$i] != $sax_result);
|
||||
} elseif ($sax_expect[$i] === false) {
|
||||
// assertions were turned off, optionally dump
|
||||
// paintIf($sax_expect, $i == NUMBER);
|
||||
} else {
|
||||
// match with a custom SAX result array
|
||||
$this->assertEqual($sax_expect[$i], $sax_result, 'PEARSax3Test (custom) '.$i.': %s');
|
||||
$this->assertIdentical($sax_expect[$i], $sax_result, 'PEARSax3Test (custom) '.$i.': %s');
|
||||
paintIf($sax_result, $sax_expect[$i] != $sax_result);
|
||||
}
|
||||
}
|
||||
@@ -310,12 +322,12 @@ class HTMLPurifier_LexerTest extends UnitTestCase
|
||||
$dom_result = $this->DOMLex->tokenizeHTML($input[$i], $config[$i], $default_context);
|
||||
// same structure as SAX
|
||||
if (!isset($dom_expect[$i])) {
|
||||
$this->assertEqual($expect[$i], $dom_result, 'DOMLexTest '.$i.': %s');
|
||||
$this->assertIdentical($expect[$i], $dom_result, 'DOMLexTest '.$i.': %s');
|
||||
paintIf($dom_result, $expect[$i] != $dom_result);
|
||||
} elseif ($dom_expect[$i] === false) {
|
||||
// paintIf($dom_result, $i == NUMBER);
|
||||
} else {
|
||||
$this->assertEqual($dom_expect[$i], $dom_result, 'DOMLexTest (custom) '.$i.': %s');
|
||||
$this->assertIdentical($dom_expect[$i], $dom_result, 'DOMLexTest (custom) '.$i.': %s');
|
||||
paintIf($dom_result, $dom_expect[$i] != $dom_result);
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ class HTMLPurifier_PercentEncoderTest extends UnitTestCase
|
||||
|
||||
function assertDecode($string, $expect = true) {
|
||||
if ($expect === true) $expect = $string;
|
||||
$this->assertEqual($this->PercentEncoder->{$this->func}($string), $expect);
|
||||
$this->assertIdentical($this->PercentEncoder->{$this->func}($string), $expect);
|
||||
}
|
||||
|
||||
function test_normalize() {
|
||||
|
@@ -51,6 +51,15 @@ class HTMLPurifier_Strategy_RemoveForeignElementsTest
|
||||
// test preservation of valid img tag
|
||||
$this->assertResult('<img src="foobar.gif" />');
|
||||
|
||||
// test preservation of invalid img tag when removal is disabled
|
||||
$this->assertResult(
|
||||
'<img />',
|
||||
true,
|
||||
array(
|
||||
'Core.RemoveInvalidImg' => false
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -13,14 +13,11 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
|
||||
$this->obj = new HTMLPurifier_Strategy_ValidateAttributes();
|
||||
}
|
||||
|
||||
function test() {
|
||||
|
||||
// attribute order is VERY fragile, perhaps we should define
|
||||
// an ordering scheme!
|
||||
|
||||
function testEmpty() {
|
||||
$this->assertResult('');
|
||||
|
||||
// test ids
|
||||
}
|
||||
|
||||
function testIDs() {
|
||||
$this->assertResult(
|
||||
'<div id="valid">Kill the ID.</div>',
|
||||
'<div>Kill the ID.</div>'
|
||||
@@ -71,32 +68,68 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
|
||||
)
|
||||
);
|
||||
|
||||
// test classes
|
||||
// name rewritten as id
|
||||
$this->assertResult(
|
||||
'<a name="foobar" />',
|
||||
'<a id="foobar" />',
|
||||
array('HTML.EnableAttrID' => true)
|
||||
);
|
||||
}
|
||||
|
||||
function testClasses() {
|
||||
$this->assertResult('<div class="valid">Valid</div>');
|
||||
|
||||
$this->assertResult(
|
||||
'<div class="valid 0invalid">Keep valid.</div>',
|
||||
'<div class="valid">Keep valid.</div>'
|
||||
);
|
||||
|
||||
// test title
|
||||
}
|
||||
|
||||
function testTitle() {
|
||||
$this->assertResult(
|
||||
'<acronym title="PHP: Hypertext Preprocessor">PHP</acronym>'
|
||||
);
|
||||
|
||||
// test lang
|
||||
}
|
||||
|
||||
function testLang() {
|
||||
$this->assertResult(
|
||||
'<span lang="fr">La soupe.</span>',
|
||||
'<span lang="fr" xml:lang="fr">La soupe.</span>'
|
||||
);
|
||||
|
||||
// test align
|
||||
// test only xml:lang for XHTML 1.1
|
||||
$this->assertResult(
|
||||
'<b lang="en">asdf</b>',
|
||||
'<b xml:lang="en">asdf</b>', array('HTML.Doctype' => 'XHTML 1.1')
|
||||
);
|
||||
}
|
||||
|
||||
function testAlign() {
|
||||
|
||||
$this->assertResult(
|
||||
'<h1 align="center">Centered Headline</h1>',
|
||||
'<h1 style="text-align:center;">Centered Headline</h1>'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<h1 align="right">Right-aligned Headline</h1>',
|
||||
'<h1 style="text-align:right;">Right-aligned Headline</h1>'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<h1 align="left">Left-aligned Headline</h1>',
|
||||
'<h1 style="text-align:left;">Left-aligned Headline</h1>'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<p align="justify">Justified Paragraph</p>',
|
||||
'<p style="text-align:justify;">Justified Paragraph</p>'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<h1 align="invalid">Invalid Headline</h1>',
|
||||
'<h1>Invalid Headline</h1>'
|
||||
);
|
||||
|
||||
// test table
|
||||
}
|
||||
|
||||
function testTable() {
|
||||
$this->assertResult(
|
||||
'<table frame="above" rules="rows" summary="A test table" border="2" cellpadding="5%" cellspacing="3" width="100%">
|
||||
<col align="right" width="4*" />
|
||||
@@ -115,7 +148,64 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
|
||||
</table>'
|
||||
);
|
||||
|
||||
// test URI
|
||||
// test col.span is non-zero
|
||||
$this->assertResult(
|
||||
'<col span="0" />',
|
||||
'<col />'
|
||||
);
|
||||
// lengths
|
||||
$this->assertResult(
|
||||
'<td height="10" width="5%" /><th height="5%" width="10" /><hr width="10" height="10" />',
|
||||
'<td style="height:10px;width:5%;" /><th style="height:5%;width:10px;" /><hr style="width:10px;" />'
|
||||
);
|
||||
// td boolean transformation
|
||||
$this->assertResult(
|
||||
'<td nowrap />',
|
||||
'<td style="white-space:nowrap;" />'
|
||||
);
|
||||
|
||||
// caption align transformation
|
||||
$this->assertResult(
|
||||
'<caption align="left" />',
|
||||
'<caption style="text-align:left;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<caption align="right" />',
|
||||
'<caption style="text-align:right;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<caption align="top" />',
|
||||
'<caption style="caption-side:top;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<caption align="bottom" />',
|
||||
'<caption style="caption-side:bottom;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<caption align="nonsense" />',
|
||||
'<caption />'
|
||||
);
|
||||
|
||||
// align transformation
|
||||
$this->assertResult(
|
||||
'<table align="left" />',
|
||||
'<table style="float:left;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<table align="center" />',
|
||||
'<table style="margin-left:auto;margin-right:auto;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<table align="right" />',
|
||||
'<table style="float:right;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<table align="top" />',
|
||||
'<table />'
|
||||
);
|
||||
}
|
||||
|
||||
function testURI() {
|
||||
$this->assertResult('<a href="http://www.google.com/">Google</a>');
|
||||
|
||||
// test invalid URI
|
||||
@@ -123,9 +213,9 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
|
||||
'<a href="javascript:badstuff();">Google</a>',
|
||||
'<a>Google</a>'
|
||||
);
|
||||
|
||||
// test required attributes for img
|
||||
|
||||
}
|
||||
|
||||
function testImg() {
|
||||
// (this should never happen, as RemoveForeignElements
|
||||
// should have removed the offending image tag)
|
||||
$this->assertResult(
|
||||
@@ -142,7 +232,40 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
|
||||
'<img alt="pretty picture" />',
|
||||
'<img alt="pretty picture" src="" />'
|
||||
);
|
||||
// mailto in image is not allowed
|
||||
$this->assertResult(
|
||||
'<img src="mailto:foo@example.com" />',
|
||||
'<img src="" alt="Invalid image" />'
|
||||
);
|
||||
// align transformation
|
||||
$this->assertResult(
|
||||
'<img src="foobar.jpg" alt="foobar" align="left" />',
|
||||
'<img src="foobar.jpg" alt="foobar" style="float:left;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<img src="foobar.jpg" alt="foobar" align="right" />',
|
||||
'<img src="foobar.jpg" alt="foobar" style="float:right;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<img src="foobar.jpg" alt="foobar" align="bottom" />',
|
||||
'<img src="foobar.jpg" alt="foobar" style="vertical-align:baseline;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<img src="foobar.jpg" alt="foobar" align="middle" />',
|
||||
'<img src="foobar.jpg" alt="foobar" style="vertical-align:middle;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<img src="foobar.jpg" alt="foobar" align="top" />',
|
||||
'<img src="foobar.jpg" alt="foobar" style="vertical-align:top;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<img src="foobar.jpg" alt="foobar" align="outerspace" />',
|
||||
'<img src="foobar.jpg" alt="foobar" />'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testBdo() {
|
||||
// test required attributes for bdo
|
||||
$this->assertResult(
|
||||
'<bdo>Go left.</bdo>',
|
||||
@@ -153,44 +276,161 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
|
||||
'<bdo dir="blahblah">Invalid value!</bdo>',
|
||||
'<bdo dir="ltr">Invalid value!</bdo>'
|
||||
);
|
||||
|
||||
// see above, behavior is subtly different
|
||||
}
|
||||
|
||||
function testDir() {
|
||||
// see testBdo, behavior is subtly different
|
||||
$this->assertResult(
|
||||
'<span dir="blahblah">Invalid value!</span>',
|
||||
'<span>Invalid value!</span>'
|
||||
);
|
||||
}
|
||||
|
||||
// test col.span is non-zero
|
||||
$this->assertResult(
|
||||
'<col span="0" />',
|
||||
'<col />'
|
||||
);
|
||||
|
||||
// mailto in image is not allowed
|
||||
$this->assertResult(
|
||||
'<img src="mailto:foo@example.com" />',
|
||||
'<img src="" alt="Invalid image" />'
|
||||
);
|
||||
|
||||
// name rewritten as id
|
||||
$this->assertResult(
|
||||
'<a name="foobar" />',
|
||||
'<a id="foobar" />',
|
||||
array('HTML.EnableAttrID' => true)
|
||||
);
|
||||
|
||||
// lengths
|
||||
$this->assertResult(
|
||||
'<td height="10" width="5%" /><th height="5%" width="10" /><hr width="10" height="10" />',
|
||||
'<td style="height:10px;width:5%;" /><th style="height:5%;width:10px;" /><hr style="width:10px;" />'
|
||||
);
|
||||
|
||||
function testLinks() {
|
||||
// link types
|
||||
$this->assertResult(
|
||||
'<a href="foo" rel="nofollow" />',
|
||||
true,
|
||||
array('Attr.AllowedRel' => 'nofollow')
|
||||
);
|
||||
// link targets
|
||||
$this->assertResult(
|
||||
'<a href="foo" target="_top" />',
|
||||
true,
|
||||
array('Attr.AllowedFrameTargets' => '_top')
|
||||
);
|
||||
$this->assertResult(
|
||||
'<a href="foo" target="_top" />',
|
||||
'<a href="foo" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<a href="foo" target="_top" />',
|
||||
'<a href="foo" />',
|
||||
array('Attr.AllowedFrameTargets' => '_top', 'HTML.Strict' => true)
|
||||
);
|
||||
}
|
||||
|
||||
function testBorder() {
|
||||
// border
|
||||
$this->assertResult(
|
||||
'<img src="foo" alt="foo" hspace="1" vspace="3" />',
|
||||
'<img src="foo" alt="foo" style="margin-top:3px;margin-bottom:3px;margin-left:1px;margin-right:1px;" />',
|
||||
array('Attr.AllowedRel' => 'nofollow')
|
||||
);
|
||||
}
|
||||
|
||||
function testHr() {
|
||||
$this->assertResult(
|
||||
'<hr size="3" />',
|
||||
'<hr style="height:3px;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<hr noshade />',
|
||||
'<hr style="color:#808080;background-color:#808080;border:0;" />'
|
||||
);
|
||||
// align transformation
|
||||
$this->assertResult(
|
||||
'<hr align="left" />',
|
||||
'<hr style="margin-left:0;margin-right:auto;text-align:left;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<hr align="center" />',
|
||||
'<hr style="margin-left:auto;margin-right:auto;text-align:center;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<hr align="right" />',
|
||||
'<hr style="margin-left:auto;margin-right:0;text-align:right;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<hr align="bottom" />',
|
||||
'<hr />'
|
||||
);
|
||||
}
|
||||
|
||||
function testBr() {
|
||||
// br clear transformation
|
||||
$this->assertResult(
|
||||
'<br clear="left" />',
|
||||
'<br style="clear:left;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<br clear="right" />',
|
||||
'<br style="clear:right;" />'
|
||||
);
|
||||
$this->assertResult( // test both?
|
||||
'<br clear="all" />',
|
||||
'<br style="clear:both;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<br clear="none" />',
|
||||
'<br style="clear:none;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<br clear="foo" />',
|
||||
'<br />'
|
||||
);
|
||||
}
|
||||
|
||||
function testListTypeTransform() {
|
||||
// ul
|
||||
$this->assertResult(
|
||||
'<ul type="disc" />',
|
||||
'<ul style="list-style-type:disc;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<ul type="square" />',
|
||||
'<ul style="list-style-type:square;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<ul type="circle" />',
|
||||
'<ul style="list-style-type:circle;" />'
|
||||
);
|
||||
$this->assertResult( // case insensitive
|
||||
'<ul type="CIRCLE" />',
|
||||
'<ul style="list-style-type:circle;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<ul type="a" />',
|
||||
'<ul />'
|
||||
);
|
||||
// ol
|
||||
$this->assertResult(
|
||||
'<ol type="1" />',
|
||||
'<ol style="list-style-type:decimal;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<ol type="i" />',
|
||||
'<ol style="list-style-type:lower-roman;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<ol type="I" />',
|
||||
'<ol style="list-style-type:upper-roman;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<ol type="a" />',
|
||||
'<ol style="list-style-type:lower-alpha;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<ol type="A" />',
|
||||
'<ol style="list-style-type:upper-alpha;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<ol type="disc" />',
|
||||
'<ol />'
|
||||
);
|
||||
// li
|
||||
$this->assertResult(
|
||||
'<li type="circle" />',
|
||||
'<li style="list-style-type:circle;" />'
|
||||
);
|
||||
$this->assertResult(
|
||||
'<li type="A" />',
|
||||
'<li style="list-style-type:upper-alpha;" />'
|
||||
);
|
||||
$this->assertResult( // case sensitive
|
||||
'<li type="CIRCLE" />',
|
||||
'<li />'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
@@ -49,14 +49,14 @@ class HTMLPurifier_TagTransformTest extends UnitTestCase
|
||||
$context->loadArray($context_array);
|
||||
|
||||
// start tag transform
|
||||
$this->assertEqual(
|
||||
$this->assertIdentical(
|
||||
new HTMLPurifier_Token_Start($expect_name, $expect_added_attributes),
|
||||
$transformer->transform(
|
||||
new HTMLPurifier_Token_Start($name), $config, $context)
|
||||
);
|
||||
|
||||
// start tag transform with attributes
|
||||
$this->assertEqual(
|
||||
$this->assertIdentical(
|
||||
new HTMLPurifier_Token_Start($expect_name, $expect_attributes),
|
||||
$transformer->transform(
|
||||
new HTMLPurifier_Token_Start($name, $attributes),
|
||||
@@ -65,7 +65,7 @@ class HTMLPurifier_TagTransformTest extends UnitTestCase
|
||||
);
|
||||
|
||||
// end tag transform
|
||||
$this->assertEqual(
|
||||
$this->assertIdentical(
|
||||
new HTMLPurifier_Token_End($expect_name),
|
||||
$transformer->transform(
|
||||
new HTMLPurifier_Token_End($name), $config, $context
|
||||
@@ -73,7 +73,7 @@ class HTMLPurifier_TagTransformTest extends UnitTestCase
|
||||
);
|
||||
|
||||
// empty tag transform
|
||||
$this->assertEqual(
|
||||
$this->assertIdentical(
|
||||
new HTMLPurifier_Token_Empty($expect_name, $expect_added_attributes),
|
||||
$transformer->transform(
|
||||
new HTMLPurifier_Token_Empty($name), $config, $context
|
||||
@@ -81,7 +81,7 @@ class HTMLPurifier_TagTransformTest extends UnitTestCase
|
||||
);
|
||||
|
||||
// empty tag transform with attributes
|
||||
$this->assertEqual(
|
||||
$this->assertIdentical(
|
||||
new HTMLPurifier_Token_Empty($expect_name, $expect_attributes),
|
||||
$transformer->transform(
|
||||
new HTMLPurifier_Token_Empty($name, $attributes),
|
||||
@@ -152,6 +152,7 @@ class HTMLPurifier_TagTransformTest extends UnitTestCase
|
||||
);
|
||||
|
||||
// test the size transforms
|
||||
$this->assertSizeToStyle($transformer, '0', 'xx-small');
|
||||
$this->assertSizeToStyle($transformer, '1', 'xx-small');
|
||||
$this->assertSizeToStyle($transformer, '2', 'small');
|
||||
$this->assertSizeToStyle($transformer, '3', 'medium');
|
||||
@@ -160,10 +161,13 @@ class HTMLPurifier_TagTransformTest extends UnitTestCase
|
||||
$this->assertSizeToStyle($transformer, '6', 'xx-large');
|
||||
$this->assertSizeToStyle($transformer, '7', '300%');
|
||||
$this->assertSizeToStyle($transformer, '-1', 'smaller');
|
||||
$this->assertSizeToStyle($transformer, '+1', 'larger');
|
||||
$this->assertSizeToStyle($transformer, '-2', '60%');
|
||||
$this->assertSizeToStyle($transformer, '-3', '60%');
|
||||
$this->assertSizeToStyle($transformer, '+1', 'larger');
|
||||
$this->assertSizeToStyle($transformer, '+2', '150%');
|
||||
$this->assertSizeToStyle($transformer, '+3', '200%');
|
||||
$this->assertSizeToStyle($transformer, '+4', '300%');
|
||||
$this->assertSizeToStyle($transformer, '+5', '300%');
|
||||
|
||||
// test multiple transforms, the alphabetical ordering is important
|
||||
$this->assertTransformation(
|
||||
|
@@ -72,7 +72,7 @@ class HTMLPurifier_Test extends UnitTestCase
|
||||
|
||||
$this->purifier = new HTMLPurifier();
|
||||
|
||||
$this->assertEqual(
|
||||
$this->assertIdentical(
|
||||
$this->purifier->purifyArray(
|
||||
array('Good', '<b>Sketchy', 'foo' => '<script>bad</script>')
|
||||
),
|
||||
|
@@ -11,7 +11,7 @@ class HTMLPurifier_TokenFactoryTest extends UnitTestCase
|
||||
$regular = new HTMLPurifier_Token_Start('a', array('href' => 'about:blank'));
|
||||
$generated = $factory->createStart('a', array('href' => 'about:blank'));
|
||||
|
||||
$this->assertEqual($regular, $generated);
|
||||
$this->assertIdentical($regular, $generated);
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -12,8 +12,8 @@ class HTMLPurifier_TokenTest extends UnitTestCase
|
||||
if ($expect_attr === null) $expect_attr = $attr;
|
||||
$token = new HTMLPurifier_Token_Start($name, $attr);
|
||||
|
||||
$this->assertEqual($expect_name, $token->name);
|
||||
$this->assertEqual($expect_attr, $token->attr);
|
||||
$this->assertIdentical($expect_name, $token->name);
|
||||
$this->assertIdentical($expect_attr, $token->attr);
|
||||
}
|
||||
|
||||
function testConstruct() {
|
||||
|
Reference in New Issue
Block a user