From 3b1c40b2fc500d532b6294f622e27354e9d06219 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 13 May 2007 20:43:38 +0000 Subject: [PATCH] [1.7.0] Add some module unit tests for Edit, Hypertext, Image and Legacy (incomplete). Remove redundant img scaffolding. git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1050 48356398-32a2-884e-a903-53898d9a118a --- library/HTMLPurifier/HTMLModule/Image.php | 2 - tests/HTMLPurifier/HTMLModule/BdoTest.php | 18 ++++++ tests/HTMLPurifier/HTMLModule/EditTest.php | 58 +++++++++++++++++++ .../HTMLPurifier/HTMLModule/HypertextTest.php | 52 +++++++++++++++++ tests/HTMLPurifier/HTMLModule/ImageTest.php | 50 ++++++++++++++++ tests/HTMLPurifier/HTMLModule/LegacyTest.php | 32 ++++++++++ tests/test_files.php | 4 ++ 7 files changed, 214 insertions(+), 2 deletions(-) create mode 100644 tests/HTMLPurifier/HTMLModule/EditTest.php create mode 100644 tests/HTMLPurifier/HTMLModule/HypertextTest.php create mode 100644 tests/HTMLPurifier/HTMLModule/ImageTest.php create mode 100644 tests/HTMLPurifier/HTMLModule/LegacyTest.php diff --git a/library/HTMLPurifier/HTMLModule/Image.php b/library/HTMLPurifier/HTMLModule/Image.php index 6608e9dc..dc9c732b 100644 --- a/library/HTMLPurifier/HTMLModule/Image.php +++ b/library/HTMLPurifier/HTMLModule/Image.php @@ -14,8 +14,6 @@ class HTMLPurifier_HTMLModule_Image extends HTMLPurifier_HTMLModule { var $name = 'Image'; - var $elements = array('img'); - var $content_sets = array('Inline' => 'img'); function HTMLPurifier_HTMLModule_Image() { $img =& $this->addElement( diff --git a/tests/HTMLPurifier/HTMLModule/BdoTest.php b/tests/HTMLPurifier/HTMLModule/BdoTest.php index c402fc29..b2fcc1c8 100644 --- a/tests/HTMLPurifier/HTMLModule/BdoTest.php +++ b/tests/HTMLPurifier/HTMLModule/BdoTest.php @@ -7,6 +7,7 @@ class HTMLPurifier_HTMLModule_BdoTest extends HTMLPurifier_HTMLModuleHarness function test() { + // max $this->assertResult( ' ', true, array('Attr.EnableID' => true) ); + // min + $this->assertResult( + '', '' + ); + + // children + $this->assertResult( + 'Text
', + 'Text' + ); + + // global attr + $this->assertResult( + '
', + '
' + ); + } } diff --git a/tests/HTMLPurifier/HTMLModule/EditTest.php b/tests/HTMLPurifier/HTMLModule/EditTest.php new file mode 100644 index 00000000..3acf7917 --- /dev/null +++ b/tests/HTMLPurifier/HTMLModule/EditTest.php @@ -0,0 +1,58 @@ +assertResult( + ' + + #PCDATA + + + #PCDATA + + +
+ + #PCDATA
+
+ + #PCDATA
+
+
' + ); + + // inline removal + $this->assertResult( + ' +
+
+
', + ' + + + ' + ); + + // unsupported attributes + $this->assertResult( + ' + ', + ' + ' + ); + + } + +} + +?> \ No newline at end of file diff --git a/tests/HTMLPurifier/HTMLModule/HypertextTest.php b/tests/HTMLPurifier/HTMLModule/HypertextTest.php new file mode 100644 index 00000000..41d364dc --- /dev/null +++ b/tests/HTMLPurifier/HTMLModule/HypertextTest.php @@ -0,0 +1,52 @@ +assertResult( + ' + + #PCDATA Inline + + ', true, array( + 'Attr.AllowedRel' => 'nofollow', + 'Attr.AllowedRev' => 'index' + ) + ); + + // invalid children + $this->assertResult( + 'Text
', + 'Text' + ); + + // unsupported attributes + $this->assertResult( + '', + '' + ); + + } + +} + +?> \ No newline at end of file diff --git a/tests/HTMLPurifier/HTMLModule/ImageTest.php b/tests/HTMLPurifier/HTMLModule/ImageTest.php new file mode 100644 index 00000000..3156af8a --- /dev/null +++ b/tests/HTMLPurifier/HTMLModule/ImageTest.php @@ -0,0 +1,50 @@ +assertResult( + ' + Example image + ' + ); + + // required attributes + $this->assertResult( + '', + 'foo.png' + ); + + // empty + $this->assertResult( + 'foo', + 'foo' + ); + + // unsupported attributes + $this->assertResult( + 'Example', + 'Example' + ); + + } + +} + +?> \ No newline at end of file diff --git a/tests/HTMLPurifier/HTMLModule/LegacyTest.php b/tests/HTMLPurifier/HTMLModule/LegacyTest.php new file mode 100644 index 00000000..8d345552 --- /dev/null +++ b/tests/HTMLPurifier/HTMLModule/LegacyTest.php @@ -0,0 +1,32 @@ +assertResult( + ' + Text + Text + Text + ' + ); + + // redefinitions + /*$this->assertResult( + '
    +
  1. Foo
  2. +
+
Text

+
Text
' + );*/ + + } + +} + +?> \ No newline at end of file diff --git a/tests/test_files.php b/tests/test_files.php index 0f989c75..d0ec5089 100644 --- a/tests/test_files.php +++ b/tests/test_files.php @@ -63,6 +63,10 @@ $test_files[] = 'GeneratorTest.php'; $test_files[] = 'HTMLModuleManagerTest.php'; $test_files[] = 'HTMLModuleTest.php'; $test_files[] = 'HTMLModule/BdoTest.php'; +$test_files[] = 'HTMLModule/EditTest.php'; +$test_files[] = 'HTMLModule/HypertextTest.php'; +$test_files[] = 'HTMLModule/ImageTest.php'; +$test_files[] = 'HTMLModule/LegacyTest.php'; $test_files[] = 'IDAccumulatorTest.php'; $test_files[] = 'LanguageFactoryTest.php'; $test_files[] = 'LanguageTest.php';