aboutsummaryrefslogtreecommitdiffstats
path: root/lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed
diff options
context:
space:
mode:
Diffstat (limited to 'lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed')
-rw-r--r--lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/EndInsertInjector.php18
-rw-r--r--lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/EndInsertInjectorTest.php38
-rw-r--r--lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/EndRewindInjector.php29
-rw-r--r--lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/EndRewindInjectorTest.php33
-rw-r--r--lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/SkipInjector.php12
-rw-r--r--lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/SkipInjectorTest.php27
6 files changed, 157 insertions, 0 deletions
diff --git a/lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/EndInsertInjector.php b/lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/EndInsertInjector.php
new file mode 100644
index 000000000..d1724bcb3
--- /dev/null
+++ b/lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/EndInsertInjector.php
@@ -0,0 +1,18 @@
+<?php
+
+class HTMLPurifier_Strategy_MakeWellFormed_EndInsertInjector extends HTMLPurifier_Injector
+{
+ public $name = 'EndInsertInjector';
+ public $needed = array('span');
+ public function handleEnd(&$token) {
+ if ($token->name == 'div') return;
+ $token = array(
+ new HTMLPurifier_Token_Start('b'),
+ new HTMLPurifier_Token_Text('Comment'),
+ new HTMLPurifier_Token_End('b'),
+ $token
+ );
+ }
+}
+
+// vim: et sw=4 sts=4
diff --git a/lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/EndInsertInjectorTest.php b/lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/EndInsertInjectorTest.php
new file mode 100644
index 000000000..72e833b71
--- /dev/null
+++ b/lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/EndInsertInjectorTest.php
@@ -0,0 +1,38 @@
+<?php
+
+class HTMLPurifier_Strategy_MakeWellFormed_EndInsertInjectorTest extends HTMLPurifier_StrategyHarness
+{
+ function setUp() {
+ parent::setUp();
+ $this->obj = new HTMLPurifier_Strategy_MakeWellFormed();
+ $this->config->set('AutoFormat.Custom', array(
+ new HTMLPurifier_Strategy_MakeWellFormed_EndInsertInjector()
+ ));
+ }
+ function testEmpty() {
+ $this->assertResult('');
+ }
+ function testNormal() {
+ $this->assertResult('<i>Foo</i>', '<i>Foo<b>Comment</b></i>');
+ }
+ function testEndOfDocumentProcessing() {
+ $this->assertResult('<i>Foo', '<i>Foo<b>Comment</b></i>');
+ }
+ function testDoubleEndOfDocumentProcessing() {
+ $this->assertResult('<i><i>Foo', '<i><i>Foo<b>Comment</b></i><b>Comment</b></i>');
+ }
+ function testEndOfNodeProcessing() {
+ $this->assertResult('<div><i>Foo</div>asdf', '<div><i>Foo<b>Comment</b></i></div><i>asdf<b>Comment</b></i>');
+ }
+ function testEmptyToStartEndProcessing() {
+ $this->assertResult('<i />', '<i><b>Comment</b></i>');
+ }
+ function testSpuriousEndTag() {
+ $this->assertResult('</i>', '');
+ }
+ function testLessButStillSpuriousEndTag() {
+ $this->assertResult('<div></i></div>', '<div></div>');
+ }
+}
+
+// vim: et sw=4 sts=4
diff --git a/lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/EndRewindInjector.php b/lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/EndRewindInjector.php
new file mode 100644
index 000000000..21c491436
--- /dev/null
+++ b/lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/EndRewindInjector.php
@@ -0,0 +1,29 @@
+<?php
+
+class HTMLPurifier_Strategy_MakeWellFormed_EndRewindInjector extends HTMLPurifier_Injector
+{
+ public $name = 'EndRewindInjector';
+ public $needed = array('span');
+ public function handleElement(&$token) {
+ if (isset($token->_InjectorTest_EndRewindInjector_delete)) {
+ $token = false;
+ }
+ }
+ public function handleText(&$token) {
+ $token = false;
+ }
+ public function handleEnd(&$token) {
+ $i = null;
+ if (
+ $this->backward($i, $prev) &&
+ $prev instanceof HTMLPurifier_Token_Start &&
+ $prev->name == 'span'
+ ) {
+ $token = false;
+ $prev->_InjectorTest_EndRewindInjector_delete = true;
+ $this->rewind($i);
+ }
+ }
+}
+
+// vim: et sw=4 sts=4
diff --git a/lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/EndRewindInjectorTest.php b/lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/EndRewindInjectorTest.php
new file mode 100644
index 000000000..96c88748d
--- /dev/null
+++ b/lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/EndRewindInjectorTest.php
@@ -0,0 +1,33 @@
+<?php
+
+class HTMLPurifier_Strategy_MakeWellFormed_EndRewindInjectorTest extends HTMLPurifier_StrategyHarness
+{
+ function setUp() {
+ parent::setUp();
+ $this->obj = new HTMLPurifier_Strategy_MakeWellFormed();
+ $this->config->set('AutoFormat.Custom', array(
+ new HTMLPurifier_Strategy_MakeWellFormed_EndRewindInjector()
+ ));
+ }
+ function testBasic() {
+ $this->assertResult('');
+ }
+ function testFunction() {
+ $this->assertResult('<span>asdf</span>','');
+ }
+ function testFailedFunction() {
+ $this->assertResult('<span>asd<b>asdf</b>asdf</span>','<span><b></b></span>');
+ }
+ function testPadded() {
+ $this->assertResult('<b></b><span>asdf</span><b></b>','<b></b><b></b>');
+ }
+ function testDoubled() {
+ $this->config->set('AutoFormat.Custom', array(
+ new HTMLPurifier_Strategy_MakeWellFormed_EndRewindInjector(),
+ new HTMLPurifier_Strategy_MakeWellFormed_EndRewindInjector(),
+ ));
+ $this->assertResult('<b></b><span>asdf</span>', '<b></b>');
+ }
+}
+
+// vim: et sw=4 sts=4
diff --git a/lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/SkipInjector.php b/lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/SkipInjector.php
new file mode 100644
index 000000000..258346b8d
--- /dev/null
+++ b/lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/SkipInjector.php
@@ -0,0 +1,12 @@
+<?php
+
+class HTMLPurifier_Strategy_MakeWellFormed_SkipInjector extends HTMLPurifier_Injector
+{
+ public $name = 'EndRewindInjector';
+ public $needed = array('span');
+ public function handleElement(&$token) {
+ $token = array(clone $token, clone $token);
+ }
+}
+
+// vim: et sw=4 sts=4
diff --git a/lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/SkipInjectorTest.php b/lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/SkipInjectorTest.php
new file mode 100644
index 000000000..770b3d84e
--- /dev/null
+++ b/lib/htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormed/SkipInjectorTest.php
@@ -0,0 +1,27 @@
+<?php
+
+class HTMLPurifier_Strategy_MakeWellFormed_SkipInjectorTest extends HTMLPurifier_StrategyHarness
+{
+ function setUp() {
+ parent::setUp();
+ $this->obj = new HTMLPurifier_Strategy_MakeWellFormed();
+ $this->config->set('AutoFormat.Custom', array(
+ new HTMLPurifier_Strategy_MakeWellFormed_SkipInjector()
+ ));
+ }
+ function testEmpty() {
+ $this->assertResult('');
+ }
+ function testMultiply() {
+ $this->assertResult('<br />', '<br /><br />');
+ }
+ function testMultiplyMultiply() {
+ $this->config->set('AutoFormat.Custom', array(
+ new HTMLPurifier_Strategy_MakeWellFormed_SkipInjector(),
+ new HTMLPurifier_Strategy_MakeWellFormed_SkipInjector()
+ ));
+ $this->assertResult('<br />', '<br /><br /><br /><br />');
+ }
+}
+
+// vim: et sw=4 sts=4