0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-01-03 05:11:52 +00:00

More unit test refactoring; remove unnecessary periods from HTMLDefinition error messages

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1374 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2007-08-07 05:38:22 +00:00
parent 3af6457801
commit f922285383
4 changed files with 57 additions and 42 deletions

View File

@ -330,7 +330,7 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
if (isset($this->info_content_sets['Block'][$block_wrapper])) { if (isset($this->info_content_sets['Block'][$block_wrapper])) {
$this->info_block_wrapper = $block_wrapper; $this->info_block_wrapper = $block_wrapper;
} else { } else {
trigger_error('Cannot use non-block element as block wrapper.', trigger_error('Cannot use non-block element as block wrapper',
E_USER_ERROR); E_USER_ERROR);
} }
@ -340,7 +340,7 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
$this->info_parent = $parent; $this->info_parent = $parent;
$this->info_parent_def = $def; $this->info_parent_def = $def;
} else { } else {
trigger_error('Cannot use unrecognized element as parent.', trigger_error('Cannot use unrecognized element as parent',
E_USER_ERROR); E_USER_ERROR);
$this->info_parent_def = $this->manager->getElement($this->info_parent, true); $this->info_parent_def = $this->manager->getElement($this->info_parent, true);
} }

View File

@ -74,6 +74,7 @@ extends HTMLPurifier_ChildDefHarness
} }
function testError() { function testError() {
$this->expectError('Cannot use non-block element as block wrapper');
$this->obj = new HTMLPurifier_ChildDef_StrictBlockquote('div | p'); $this->obj = new HTMLPurifier_ChildDef_StrictBlockquote('div | p');
$this->config->set('HTML', 'BlockWrapper', 'dav'); $this->config->set('HTML', 'BlockWrapper', 'dav');
$this->assertResult('Needs wrap', '<p>Needs wrap</p>'); $this->assertResult('Needs wrap', '<p>Needs wrap</p>');

View File

@ -3,6 +3,9 @@
require_once 'HTMLPurifier/ChildDefHarness.php'; require_once 'HTMLPurifier/ChildDefHarness.php';
require_once 'HTMLPurifier/ChildDef/Table.php'; require_once 'HTMLPurifier/ChildDef/Table.php';
// we're using empty tags to compact the tests: under real circumstances
// there would be contents in them
class HTMLPurifier_ChildDef_TableTest extends HTMLPurifier_ChildDefHarness class HTMLPurifier_ChildDef_TableTest extends HTMLPurifier_ChildDefHarness
{ {
@ -11,40 +14,47 @@ class HTMLPurifier_ChildDef_TableTest extends HTMLPurifier_ChildDefHarness
$this->obj = new HTMLPurifier_ChildDef_Table(); $this->obj = new HTMLPurifier_ChildDef_Table();
} }
function test() { function testEmptyInput() {
$this->assertResult('', false); $this->assertResult('', false);
}
// we're using empty tags to compact the tests: under real circumstances
// there would be contents in them function testSingleRow() {
$this->assertResult('<tr />'); $this->assertResult('<tr />');
}
function testComplexContents() {
$this->assertResult('<caption /><col /><thead /><tfoot /><tbody>'. $this->assertResult('<caption /><col /><thead /><tfoot /><tbody>'.
'<tr><td>asdf</td></tr></tbody>'); '<tr><td>asdf</td></tr></tbody>');
$this->assertResult('<col /><col /><col /><tr />'); $this->assertResult('<col /><col /><col /><tr />');
}
// mixed up order
function testReorderContents() {
$this->assertResult( $this->assertResult(
'<col /><colgroup /><tbody /><tfoot /><thead /><tr>1</tr><caption /><tr />', '<col /><colgroup /><tbody /><tfoot /><thead /><tr>1</tr><caption /><tr />',
'<caption /><col /><colgroup /><thead /><tfoot /><tbody /><tr>1</tr><tr />'); '<caption /><col /><colgroup /><thead /><tfoot /><tbody /><tr>1</tr><tr />');
}
// duplicates of singles
// - first caption serves function testDuplicateProcessing() {
// - trailing tfoots/theads get turned into tbodys
$this->assertResult( $this->assertResult(
'<caption>1</caption><caption /><tbody /><tbody /><tfoot>1</tfoot><tfoot />', '<caption>1</caption><caption /><tbody /><tbody /><tfoot>1</tfoot><tfoot />',
'<caption>1</caption><tfoot>1</tfoot><tbody /><tbody /><tbody />' '<caption>1</caption><tfoot>1</tfoot><tbody /><tbody /><tbody />'
); );
}
// errant text dropped (until bubbling is implemented)
function testRemoveText() {
$this->assertResult('foo', false); $this->assertResult('foo', false);
}
// whitespace sticks to the previous element, last whitespace is
// stationary function testStickyWhitespaceOnTr() {
$this->assertResult("\n <tr />\n <tr />\n ", true, array('Output.Newline' => "\n")); $this->config->set('Output', 'Newline', "\n");
$this->assertResult("\n <tr />\n <tr />\n ");
}
function testStickyWhitespaceOnTSection() {
$this->config->set('Output', 'Newline', "\n");
$this->assertResult( $this->assertResult(
"\n\t<tbody />\n\t\t<tfoot />\n\t\t\t", "\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

@ -5,47 +5,51 @@ require_once 'HTMLPurifier/HTMLModuleHarness.php';
class HTMLPurifier_HTMLModule_ScriptingTest extends HTMLPurifier_HTMLModuleHarness class HTMLPurifier_HTMLModule_ScriptingTest extends HTMLPurifier_HTMLModuleHarness
{ {
function test() { function setUp() {
parent::setUp();
// default (remove everything) $this->config->set('HTML', 'Trusted', true);
$this->config->set('Core', 'CommentScriptContents', false);
}
function testDefaultRemoval() {
$this->config->set('HTML', 'Trusted', false);
$this->assertResult( $this->assertResult(
'<script type="text/javascript">foo();</script>', '' '<script type="text/javascript">foo();</script>', ''
); );
}
// enabled
function testPreserve() {
$this->assertResult( $this->assertResult(
'<script type="text/javascript">foo();</script>', true, '<script type="text/javascript">foo();</script>'
array('HTML.Trusted' => true)
); );
}
// CDATA
function testCDATAEnclosure() {
$this->assertResult( $this->assertResult(
'//<![CDATA[ '<script type="text/javascript">//<![CDATA[
alert("<This is compatible with XHTML>"); alert("<This is compatible with XHTML>");
//]]> ', true, //]]></script>'
array('HTML.Trusted' => true)
); );
}
// max
function testAllAttributes() {
$this->assertResult( $this->assertResult(
'<script '<script
defer="defer" defer="defer"
src="test.js" src="test.js"
type="text/javascript" type="text/javascript"
>PCDATA</script>', true, >PCDATA</script>'
array('HTML.Trusted' => true, 'Core.CommentScriptContents' => false)
); );
}
// unsupported
function testUnsupportedAttributes() {
$this->assertResult( $this->assertResult(
'<script '<script
type="text/javascript" type="text/javascript"
charset="utf-8" charset="utf-8"
>PCDATA</script>', >PCDATA</script>',
'<script type="text/javascript">PCDATA</script>', '<script type="text/javascript">PCDATA</script>'
array('HTML.Trusted' => true, 'Core.CommentScriptContents' => false)
); );
} }
} }