diff --git a/tests/HTMLPurifier/HTMLT.php b/tests/HTMLPurifier/HTMLT.php new file mode 100644 index 00000000..628640b3 --- /dev/null +++ b/tests/HTMLPurifier/HTMLT.php @@ -0,0 +1,31 @@ +path = $path; + parent::__construct($path); + } + + public function testHtmlt() { + $parser = new HTMLPurifier_StringHashParser(); + $hash = $parser->parseFile($this->path); // assume parser normalizes to "\n" + if (isset($hash['SKIPIF'])) { + if (eval($hash['SKIPIF'])) return; + } + $this->config->set('Output', 'Newline', "\n"); + if (isset($hash['INI'])) { + // there should be a more efficient way than writing another + // ini file every time... probably means building a parser for + // ini (check out the yaml implementation we saw somewhere else) + $ini_file = $this->path . '.ini'; + file_put_contents($ini_file, $hash['INI']); + $this->config->loadIni($ini_file); + } + $expect = isset($hash['EXPECT']) ? $hash['EXPECT'] : $hash['HTML']; + $this->assertPurification(rtrim($hash['HTML']), rtrim($expect)); + if (isset($hash['INI'])) unlink($ini_file); + } +} diff --git a/tests/HTMLPurifier/HTMLT/allowed-preserve.htmlt b/tests/HTMLPurifier/HTMLT/allowed-preserve.htmlt new file mode 100644 index 00000000..8d658c6c --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/allowed-preserve.htmlt @@ -0,0 +1,7 @@ +--INI-- +HTML.AllowedElements = b,i,p,a +HTML.AllowedAttributes = a.href,*.id +--HTML-- +

Par.

+

Paragraph

+TextBold diff --git a/tests/HTMLPurifier/HTMLT/allowed-remove.htmlt b/tests/HTMLPurifier/HTMLT/allowed-remove.htmlt new file mode 100644 index 00000000..6588a80e --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/allowed-remove.htmlt @@ -0,0 +1,7 @@ +--INI-- +HTML.AllowedElements = b,i,p,a +HTML.AllowedAttributes = a.href,*.id +--HTML-- +Not allowedRemove id too! +--EXPECT-- +Not allowedRemove id too! diff --git a/tests/HTMLPurifier/HTMLT/basic.htmlt b/tests/HTMLPurifier/HTMLT/basic.htmlt new file mode 100644 index 00000000..2471dfd6 --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/basic.htmlt @@ -0,0 +1,4 @@ +--HTML-- +basic +--EXPECT-- +basic diff --git a/tests/HTMLPurifier/HTMLT/blacklist-preserve.htmlt b/tests/HTMLPurifier/HTMLT/blacklist-preserve.htmlt new file mode 100644 index 00000000..89b6ca4c --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/blacklist-preserve.htmlt @@ -0,0 +1,5 @@ +--INI-- +HTML.ForbiddenElements = b +HTML.ForbiddenAttributes = a@href +--HTML-- +

foo

diff --git a/tests/HTMLPurifier/HTMLT/blacklist-remove.htmlt b/tests/HTMLPurifier/HTMLT/blacklist-remove.htmlt new file mode 100644 index 00000000..fcc815cf --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/blacklist-remove.htmlt @@ -0,0 +1,7 @@ +--INI-- +HTML.ForbiddenElements = b +HTML.ForbiddenAttributes = a@href +--HTML-- +Foobar +--EXPECT-- +Foobar diff --git a/tests/HTMLPurifier/HTMLT/css-allowed-preserve.htmlt b/tests/HTMLPurifier/HTMLT/css-allowed-preserve.htmlt new file mode 100644 index 00000000..d74b7d38 --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/css-allowed-preserve.htmlt @@ -0,0 +1,4 @@ +--INI-- +CSS.AllowedProperties = color,background-color +--HTML-- +
red
diff --git a/tests/HTMLPurifier/HTMLT/css-allowed-remove.htmlt b/tests/HTMLPurifier/HTMLT/css-allowed-remove.htmlt new file mode 100644 index 00000000..dfacc007 --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/css-allowed-remove.htmlt @@ -0,0 +1,6 @@ +--INI-- +CSS.AllowedProperties = color,background-color +--HTML-- +
red
+--EXPECT-- +
red
diff --git a/tests/HTMLPurifier/HTMLT/disable-uri.htmlt b/tests/HTMLPurifier/HTMLT/disable-uri.htmlt new file mode 100644 index 00000000..054b0ef5 --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/disable-uri.htmlt @@ -0,0 +1,5 @@ +--INI-- +URI.Disable = true +--HTML-- + +--EXPECT-- diff --git a/tests/HTMLPurifier/HTMLT/empty.htmlt b/tests/HTMLPurifier/HTMLT/empty.htmlt new file mode 100644 index 00000000..dee931f0 --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/empty.htmlt @@ -0,0 +1,6 @@ +--INI-- + +--HTML-- + +--EXPECT-- + diff --git a/tests/HTMLPurifier/HTMLT/id-default.htmlt b/tests/HTMLPurifier/HTMLT/id-default.htmlt new file mode 100644 index 00000000..26c78fc7 --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/id-default.htmlt @@ -0,0 +1,4 @@ +--HTML-- +foobar +--EXPECT-- +foobar diff --git a/tests/HTMLPurifier/HTMLT/id-enabled.htmlt b/tests/HTMLPurifier/HTMLT/id-enabled.htmlt new file mode 100644 index 00000000..0b43afae --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/id-enabled.htmlt @@ -0,0 +1,5 @@ +--INI-- +Attr.EnableID = true +--HTML-- +foobar +Omigosh! diff --git a/tests/HTMLPurifier/HTMLT/munge-extra.htmlt b/tests/HTMLPurifier/HTMLT/munge-extra.htmlt new file mode 100644 index 00000000..ba4e2373 --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/munge-extra.htmlt @@ -0,0 +1,10 @@ +--INI-- +URI.Munge = "/redirect?s=%s&t=%t&r=%r&n=%n&m=%m&p=%p" +URI.MungeSecretKey = "foo" +URI.MungeResources = true +--HTML-- +Link +example.com +--EXPECT-- +Link +example.com diff --git a/tests/HTMLPurifier/HTMLT/name.htmlt b/tests/HTMLPurifier/HTMLT/name.htmlt new file mode 100644 index 00000000..d853e81a --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/name.htmlt @@ -0,0 +1,5 @@ +--INI-- +Attr.EnableID = true +HTML.Doctype = "XHTML 1.0 Strict" +--HTML-- + diff --git a/tests/HTMLPurifier/HTMLT/safe-object-embed-munge.htmlt b/tests/HTMLPurifier/HTMLT/safe-object-embed-munge.htmlt new file mode 100644 index 00000000..16bbf322 --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/safe-object-embed-munge.htmlt @@ -0,0 +1,9 @@ +--INI-- +HTML.SafeObject = true +HTML.SafeEmbed = true +URI.Munge = "/redirect.php?url=%s&check=%t" +URI.MungeSecretKey = "foo" +--HTML-- + +--EXPECT-- + diff --git a/tests/HTMLPurifier/HTMLT/safe-object-embed.htmlt b/tests/HTMLPurifier/HTMLT/safe-object-embed.htmlt new file mode 100644 index 00000000..99c75903 --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/safe-object-embed.htmlt @@ -0,0 +1,7 @@ +--INI-- +HTML.SafeObject = true +HTML.SafeEmbed = true +--HTML-- + +--EXPECT-- + diff --git a/tests/HTMLPurifier/HTMLT/script-bare.htmlt b/tests/HTMLPurifier/HTMLT/script-bare.htmlt new file mode 100644 index 00000000..37a6042f --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/script-bare.htmlt @@ -0,0 +1,8 @@ +--INI-- +HTML.Trusted = true +--HTML-- + +--EXPECT-- + diff --git a/tests/HTMLPurifier/HTMLT/script-cdata.htmlt b/tests/HTMLPurifier/HTMLT/script-cdata.htmlt new file mode 100644 index 00000000..01e21700 --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/script-cdata.htmlt @@ -0,0 +1,10 @@ +--INI-- +HTML.Trusted = true +--HTML-- + +--EXPECT-- + diff --git a/tests/HTMLPurifier/HTMLT/script-comment.htmlt b/tests/HTMLPurifier/HTMLT/script-comment.htmlt new file mode 100644 index 00000000..fc877386 --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/script-comment.htmlt @@ -0,0 +1,10 @@ +--INI-- +HTML.Trusted = true +--HTML-- + +--EXPECT-- + diff --git a/tests/HTMLPurifier/HTMLT/script-dbl-comment.htmlt b/tests/HTMLPurifier/HTMLT/script-dbl-comment.htmlt new file mode 100644 index 00000000..c538c89e --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/script-dbl-comment.htmlt @@ -0,0 +1,10 @@ +--INI-- +HTML.Trusted = true +--HTML-- + +--EXPECT-- + diff --git a/tests/HTMLPurifier/HTMLT/script-ideal.htmlt b/tests/HTMLPurifier/HTMLT/script-ideal.htmlt new file mode 100644 index 00000000..15560d04 --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/script-ideal.htmlt @@ -0,0 +1,10 @@ +--INI-- +HTML.Trusted = true +--HTML-- + +--EXPECT-- + diff --git a/tests/HTMLPurifier/HTMLT/secure-munge.htmlt b/tests/HTMLPurifier/HTMLT/secure-munge.htmlt new file mode 100644 index 00000000..9fda1df4 --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/secure-munge.htmlt @@ -0,0 +1,9 @@ +--INI-- +URI.Munge = "/redirect.php?url=%s&check=%t" +URI.MungeSecretKey = "foo" +--HTML-- +foo +local +--EXPECT-- +foo +local diff --git a/tests/HTMLPurifier/HTMLT/shift-jis-preserve-yen.htmlt b/tests/HTMLPurifier/HTMLT/shift-jis-preserve-yen.htmlt new file mode 100644 index 00000000..a7abb785 --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/shift-jis-preserve-yen.htmlt @@ -0,0 +1,7 @@ +--SKIPIF-- +if (!function_exists('iconv')) return true; +--INI-- +Core.Encoding = "Shift_JIS" +Core.EscapeNonASCIICharacters = true +--HTML-- +111 diff --git a/tests/HTMLPurifier/HTMLT/shift-jis-remove-yen.htmlt b/tests/HTMLPurifier/HTMLT/shift-jis-remove-yen.htmlt new file mode 100644 index 00000000..2013554d --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/shift-jis-remove-yen.htmlt @@ -0,0 +1,8 @@ +--SKIPIF-- +if (!function_exists('iconv')) return true; +--INI-- +Core.Encoding = Shift_JIS +--HTML-- +111 +--EXPECT-- +111 diff --git a/tests/HTMLPurifier/HTMLT/strict-blockquote.htmlt b/tests/HTMLPurifier/HTMLT/strict-blockquote.htmlt new file mode 100644 index 00000000..333b6f92 --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/strict-blockquote.htmlt @@ -0,0 +1,6 @@ +--INI-- +HTML.Strict = true +--HTML-- +
Illegal contents
+--EXPECT-- +

Illegal contents

diff --git a/tests/HTMLPurifier/HTMLT/strict-underline.htmlt b/tests/HTMLPurifier/HTMLT/strict-underline.htmlt new file mode 100644 index 00000000..9c37b530 --- /dev/null +++ b/tests/HTMLPurifier/HTMLT/strict-underline.htmlt @@ -0,0 +1,6 @@ +--INI-- +HTML.Strict = true +--HTML-- +Illegal underline +--EXPECT-- +Illegal underline diff --git a/tests/HTMLPurifierTest.php b/tests/HTMLPurifierTest.php index b1ef5e94..e8d195fe 100644 --- a/tests/HTMLPurifierTest.php +++ b/tests/HTMLPurifierTest.php @@ -7,78 +7,7 @@ class HTMLPurifierTest extends HTMLPurifier_Harness function testNull() { $this->assertPurification("Null byte\0", "Null byte"); } - - function testStrict() { - $this->config->set('HTML', 'Strict', true); - $this->assertPurification( - 'Illegal underline', - 'Illegal underline' - ); - - $this->assertPurification( - '
Illegal contents
', - '

Illegal contents

' - ); - - } - - function testDifferentAllowedElements() { - - $this->config->set('HTML', 'AllowedElements', array('b', 'i', 'p', 'a')); - $this->config->set('HTML', 'AllowedAttributes', array('a.href', '*.id')); - - $this->assertPurification( - '

Par.

Paragraph

TextBold' - ); - - $this->assertPurification( - 'Not allowedFoobar', - 'Not allowedFoobar' // no ID!!! - ); - - } - - function testBlacklistElements() { - $this->config->set('HTML', 'ForbiddenElements', array('b')); - $this->config->set('HTML', 'ForbiddenAttributes', array('a@href')); - - $this->assertPurification( - '

Par.

' - ); - $this->assertPurification( - 'Par.', - 'Par.' - ); - - } - - function testDifferentAllowedCSSProperties() { - - $this->config->set('CSS', 'AllowedProperties', array('color', 'background-color')); - - $this->assertPurification( - '
red
' - ); - - $this->assertPurification( - '
red
', - '
red
' - ); - - } - - function testDisableURI() { - - $this->config->set('URI', 'Disable', true); - - $this->assertPurification( - '', - '' - ); - - } - function test_purifyArray() { $this->assertIdentical( @@ -92,57 +21,6 @@ class HTMLPurifierTest extends HTMLPurifier_Harness } - function testAttrIDDisabledByDefault() { - - $this->assertPurification( - 'foobar', - 'foobar' - ); - - } - - function testEnableAttrID() { - $this->config->set('Attr', 'EnableID', true); - $this->assertPurification('foobar'); - $this->assertPurification('Omigosh!'); - } - - function testScript() { - $this->config->set('HTML', 'Trusted', true); - - $ideal = ''; - - $this->assertPurification($ideal); - - $this->assertPurification( - '', - $ideal - ); - - $this->assertPurification( - '', - $ideal - ); - - $this->assertPurification( - '', - $ideal - ); - - $this->assertPurification( - '', - $ideal - ); - } - function testGetInstance() { $purifier = HTMLPurifier::getInstance(); $purifier2 = HTMLPurifier::getInstance(); @@ -167,70 +45,5 @@ alert(""); $this->purifier->purify('foo'); } - function test_shiftJis() { - if (!function_exists('iconv')) return; - $this->config->set('Core', 'Encoding', 'Shift_JIS'); - $this->config->set('Core', 'EscapeNonASCIICharacters', true); - $this->assertPurification( - "111" - ); - } - - function test_shiftJisWorstCase() { - if (!function_exists('iconv')) return; - $this->config->set('Core', 'Encoding', 'Shift_JIS'); - $this->assertPurification( // Notice how Yen disappears - "111", - "111" - ); - } - - function test_secureMunge() { - $this->config->set('URI', 'Munge', '/redirect.php?url=%s&check=%t'); - $this->config->set('URI', 'MungeSecretKey', 'foo'); - $this->assertPurification( - 'foolocal', - 'foolocal' - ); - } - - function test_safeObjectAndEmbed() { - $this->config->set('HTML', 'SafeObject', true); - $this->config->set('HTML', 'SafeEmbed', true); - $this->assertPurification( - '', - '' - ); - } - - function test_safeObjectAndEmbedWithSecureMunge() { - $this->config->set('HTML', 'SafeObject', true); - $this->config->set('HTML', 'SafeEmbed', true); - $this->config->set('URI', 'Munge', '/redirect.php?url=%s&check=%t'); - $this->config->set('URI', 'MungeSecretKey', 'foo'); - $this->assertPurification( - '', - '' - ); - } - - function test_mungeWithExtraParams() { - $this->config->set('URI', 'Munge', '/redirect?s=%s&t=%t&r=%r&n=%n&m=%m&p=%p'); - $this->config->set('URI', 'MungeSecretKey', 'foo'); - $this->config->set('URI', 'MungeResources', true); - $this->assertPurification( - 'Linkexample.com', - 'Link'. - 'example.com' - ); - } - - function test_name() { - $this->config->set('Attr', 'EnableID', true); - $this->config->set('HTML', 'Doctype', 'XHTML 1.0 Strict'); - $this->assertPurification(''); - } - } diff --git a/tests/common.php b/tests/common.php index 1e6890d4..de7cb966 100644 --- a/tests/common.php +++ b/tests/common.php @@ -161,6 +161,8 @@ function htmlpurifier_add_test($test, $test_file, $only_phpt = false) { return $test->add(path2class($test_file)); case '.vtest': return $test->add(new HTMLPurifier_ConfigSchema_ValidatorTestCase($test_file)); + case '.htmlt': + return $test->add(new HTMLPurifier_HTMLT($test_file)); default: trigger_error("$test_file is an invalid file for testing", E_USER_ERROR); }