From d9c8effc9b43b3e888f211cf1888043d62a0dc44 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 11 Jun 2006 22:53:40 +0000 Subject: [PATCH] Begin fleshing out test_fixNesting(). Still needs more test-cases. git-svn-id: http://htmlpurifier.org/svnroot/html_purifier/trunk@52 48356398-32a2-884e-a903-53898d9a118a --- tests/PureHTMLDefinition.php | 51 +++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/tests/PureHTMLDefinition.php b/tests/PureHTMLDefinition.php index aaffe26c..b7fbeac6 100644 --- a/tests/PureHTMLDefinition.php +++ b/tests/PureHTMLDefinition.php @@ -3,12 +3,13 @@ class Test_PureHTMLDefinition extends UnitTestCase { - var $def; + var $def, $lexer; function Test_PureHTMLDefinition() { $this->UnitTestCase(); $this->def = new PureHTMLDefinition(); $this->def->loadData(); + $this->lexer = new HTML_Lexer(); } function test_removeForeignElements() { @@ -185,6 +186,54 @@ class Test_PureHTMLDefinition extends UnitTestCase } + function test_fixNesting() { + $inputs = array(); + $expect = array(); + + // some legal nestings + + $inputs[0] = array( + new MF_StartTag('b'), + new MF_Text('Bold text'), + new MF_EndTag('b'), + ); + $expect[0] = $inputs[0]; + + // test acceptance of inline and block + // as the parent element is considered FLOW + $inputs[1] = array( + new MF_StartTag('a', array('href' => 'http://www.example.com/')), + new MF_Text('Linky'), + new MF_EndTag('a'), + new MF_StartTag('div'), + new MF_Text('Block element'), + new MF_EndTag('div'), + ); + $expect[1] = $inputs[1]; + + // test illegal block element -> text + $inputs[2] = array( + new MF_StartTag('b'), + new MF_StartTag('div'), + new MF_Text('Illegal Div'), + new MF_EndTag('div'), + new MF_EndTag('b'), + ); + $expect[2] = array( + new MF_StartTag('b'), + new MF_Text('
'), + new MF_Text('Illegal Div'), + new MF_Text('
'), + new MF_EndTag('b'), + ); + + foreach ($inputs as $i => $input) { + $result = $this->def->fixNesting($input); + $this->assertEqual($expect[$i], $result); + paintIf($result, $result != $expect[$i]); + } + } + } class Test_HTMLDTD_ChildDef extends UnitTestCase