All three.
';
- $expect[4] = 'All three.';
-
- $this->assertStrategyWorks($strategy, $inputs, $expect, $config);
}
}
diff --git a/tests/HTMLPurifier/Strategy/FixNestingTest.php b/tests/HTMLPurifier/Strategy/FixNestingTest.php
index 182b11e8..ff88cc09 100644
--- a/tests/HTMLPurifier/Strategy/FixNestingTest.php
+++ b/tests/HTMLPurifier/Strategy/FixNestingTest.php
@@ -3,89 +3,86 @@
require_once 'HTMLPurifier/StrategyHarness.php';
require_once 'HTMLPurifier/Strategy/FixNesting.php';
-class HTMLPurifier_Strategy_FixNestingTest
- extends HTMLPurifier_StrategyHarness
+class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
{
+ function setUp() {
+ parent::setUp();
+ $this->obj = new HTMLPurifier_Strategy_FixNesting();
+ }
+
function test() {
- $strategy = new HTMLPurifier_Strategy_FixNesting();
-
- $inputs = array();
- $expect = array();
- $config = array();
-
- $config_escape = HTMLPurifier_Config::createDefault();
- $config_escape->set('Core', 'EscapeInvalidChildren', true);
-
- // next id = 4
-
- // legal inline nesting
- $inputs[0] = 'Bold text';
- $expect[0] = $inputs[0];
+ // legal inline
+ $this->assertResult('Bold text');
// legal inline and block
// as the parent element is considered FLOW
- $inputs[1] = 'BlankBlock
';
- $expect[1] = $inputs[1];
+ $this->assertResult('BlankBlock
');
// illegal block in inline
- $inputs[2] = 'Illegal div.
';
- $expect[2] = 'Illegal div.';
+ $this->assertResult(
+ 'Illegal div.
',
+ 'Illegal div.'
+ );
// same test with different configuration (fragile)
- $inputs[13] = 'Illegal div.
';
- $expect[13] = '<div>Illegal div.</div>';
- $config[13] = $config_escape;
+ $this->assertResult(
+ 'Illegal div.
',
+ '<div>Illegal div.</div>',
+ array('Core.EscapeInvalidChildren' => true)
+ );
// test of empty set that's required, resulting in removal of node
- $inputs[3] = '';
- $expect[3] = '';
+ $this->assertResult('', '');
// test illegal text which gets removed
- $inputs[4] = '';
- $expect[4] = '';
+ $this->assertResult(
+ '',
+ ''
+ );
// test custom table definition
-
- $inputs[5] = '';
- $expect[5] = '';
-
- $inputs[6] = '';
- $expect[6] = '';
+ $this->assertResult(
+ '',
+ ''
+ );
+ $this->assertResult('', '');
// breaks without the redundant checking code
- $inputs[7] = '';
- $expect[7] = '';
+ $this->assertResult('', '');
// special case, prevents scrolling one back to find parent
- $inputs[8] = '';
- $expect[8] = '';
+ $this->assertResult('', '');
// cascading rollbacks
- $inputs[9] = '';
- $expect[9] = '';
+ $this->assertResult(
+ '',
+ ''
+ );
// rollbacks twice
- $inputs[10] = '';
- $expect[10] = '';
+ $this->assertResult('', '');
// block in inline ins not allowed
- $inputs[11] = 'Not allowed!
';
- $expect[11] = 'Not allowed!';
+ $this->assertResult(
+ 'Not allowed!
',
+ 'Not allowed!'
+ );
// block in inline ins not allowed
- $inputs[14] = 'Not allowed!
';
- $expect[14] = '<div>Not allowed!</div>';
- $config[14] = $config_escape;
+ $this->assertResult(
+ 'Not allowed!
',
+ '<div>Not allowed!</div>',
+ array('Core.EscapeInvalidChildren' => true)
+ );
// test exclusions
- $inputs[12] = 'Not allowed';
- $expect[12] = '';
+ $this->assertResult(
+ 'Not allowed',
+ ''
+ );
- // next test is *15*
-
- $this->assertStrategyWorks($strategy, $inputs, $expect, $config);
}
}
diff --git a/tests/HTMLPurifier/Strategy/MakeWellFormedTest.php b/tests/HTMLPurifier/Strategy/MakeWellFormedTest.php
index 526b22a0..07e9202d 100644
--- a/tests/HTMLPurifier/Strategy/MakeWellFormedTest.php
+++ b/tests/HTMLPurifier/Strategy/MakeWellFormedTest.php
@@ -3,53 +3,62 @@
require_once 'HTMLPurifier/StrategyHarness.php';
require_once 'HTMLPurifier/Strategy/MakeWellFormed.php';
-class HTMLPurifier_Strategy_MakeWellFormedTest
- extends HTMLPurifier_StrategyHarness
+class HTMLPurifier_Strategy_MakeWellFormedTest extends HTMLPurifier_StrategyHarness
{
+ function setUp() {
+ parent::setUp();
+ $this->obj = new HTMLPurifier_Strategy_MakeWellFormed();
+ }
+
function test() {
- $strategy = new HTMLPurifier_Strategy_MakeWellFormed();
+ $this->assertResult('');
+ $this->assertResult('This is bold text.');
- $inputs = array();
- $expect = array();
+ $this->assertResult(
+ 'Unclosed tag, gasp!',
+ 'Unclosed tag, gasp!'
+ );
- $inputs[0] = '';
- $expect[0] = $inputs[0];
+ $this->assertResult(
+ 'Bold and italic?',
+ 'Bold and italic?'
+ );
- $inputs[1] = 'This is bold text.';
- $expect[1] = $inputs[1];
+ $this->assertResult(
+ 'Unused end tags... recycle!',
+ 'Unused end tags... recycle!'
+ );
- $inputs[2] = 'Unclosed tag, gasp!';
- $expect[2] = 'Unclosed tag, gasp!';
+ $this->assertResult(
+ '
',
+ '
'
+ );
- $inputs[3] = 'Bold and italic?';
- $expect[3] = 'Bold and italic?';
-
- // CHANGE THIS BEHAVIOR!
- $inputs[4] = 'Unused end tags... recycle!';
- $expect[4] = 'Unused end tags... recycle!';
-
- $inputs[5] = '
';
- $expect[5] = '
';
-
- $inputs[6] = '';
- $expect[6] = '';
+ $this->assertResult(
+ '',
+ ''
+ );
// test automatic paragraph closing
- $inputs[7] = 'Paragraph 1
Paragraph 2';
- $expect[7] = '
Paragraph 1
Paragraph 2
';
+ $this->assertResult(
+ 'Paragraph 1
Paragraph 2',
+ '
Paragraph 1
Paragraph 2
'
+ );
- $inputs[8] = '';
- $expect[8] = '';
+ $this->assertResult(
+ '',
+ ''
+ );
// automatic list closing
- $inputs[9] = '- Item 1
- Item 2
';
- $expect[9] = '- Item 1
- Item 2
';
-
- $this->assertStrategyWorks($strategy, $inputs, $expect);
+ $this->assertResult(
+ '- Item 1
- Item 2
',
+ '- Item 1
- Item 2
'
+ );
}
}
diff --git a/tests/HTMLPurifier/Strategy/RemoveForeignElementsTest.php b/tests/HTMLPurifier/Strategy/RemoveForeignElementsTest.php
index 894e1a6a..1f212bf6 100644
--- a/tests/HTMLPurifier/Strategy/RemoveForeignElementsTest.php
+++ b/tests/HTMLPurifier/Strategy/RemoveForeignElementsTest.php
@@ -4,39 +4,44 @@ require_once 'HTMLPurifier/StrategyHarness.php';
require_once 'HTMLPurifier/Strategy/RemoveForeignElements.php';
class HTMLPurifier_Strategy_RemoveForeignElementsTest
- extends HTMLPurifier_StrategyHarness
+ extends HTMLPurifier_StrategyHarness
{
+ function setUp() {
+ parent::setUp();
+ $this->obj = new HTMLPurifier_Strategy_RemoveForeignElements();
+ }
+
function test() {
- $strategy = new HTMLPurifier_Strategy_RemoveForeignElements();
- $inputs = array();
- $expect = array();
+ $this->assertResult('');
- $inputs[0] = '';
- $expect[0] = $inputs[0];
+ $this->assertResult('This is bold text.');
- $inputs[1] = 'This is bold text.';
- $expect[1] = $inputs[1];
+ $this->assertResult(
+ 'BlingBong',
+ 'BlingBong'
+ );
- // [INVALID]
- $inputs[2] = 'BlingBong';
- $expect[2] = 'BlingBong';
-
- // test simple transform
- $inputs[3] = '';
- $expect[3] = '';
+ $this->assertResult(
+ '',
+ ''
+ );
// test center transform
- $inputs[4] = 'Look I am Centered!';
- $expect[4] = 'Look I am Centered!
';
+ $this->assertResult(
+ 'Look I am Centered!',
+ 'Look I am Centered!
'
+ );
// test font transform
- $inputs[5] = 'Big Warning!';
- $expect[5] = 'Big Warning!';
+ $this->assertResult(
+ 'Big Warning!',
+ 'Big'.
+ ' Warning!'
+ );
- $this->assertStrategyWorks($strategy, $inputs, $expect);
}
}
diff --git a/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php b/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php
index 82f87607..60183558 100644
--- a/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php
+++ b/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php
@@ -8,71 +8,83 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
HTMLPurifier_StrategyHarness
{
+ function setUp() {
+ parent::setUp();
+ $this->obj = new HTMLPurifier_Strategy_ValidateAttributes();
+ }
+
function test() {
- $strategy = new HTMLPurifier_Strategy_ValidateAttributes();
-
// attribute order is VERY fragile, perhaps we should define
// an ordering scheme!
- $inputs = array();
- $expect = array();
- $config = array();
-
- $inputs[0] = '';
- $expect[0] = '';
+ $this->assertResult('');
// test ids
+ $this->assertResult('Preserve the ID.
');
- $inputs[1] = 'Preserve the ID.
';
- $expect[1] = $inputs[1];
-
- $inputs[2] = 'Kill the ID.
';
- $expect[2] = 'Kill the ID.
';
+ $this->assertResult(
+ 'Kill the ID.
',
+ 'Kill the ID.
'
+ );
// test id accumulator
- $inputs[3] = 'Valid
Invalid
';
- $expect[3] = 'Valid
Invalid
';
+ $this->assertResult(
+ 'Valid
Invalid
',
+ 'Valid
Invalid
'
+ );
- $inputs[4] = 'Bad dir.';
- $expect[4] = 'Bad dir.';
+ $this->assertResult(
+ 'Bad dir.',
+ 'Bad dir.'
+ );
- // test attribute case sensitivity
- $inputs[5] = 'Convert ID to lowercase.
';
- $expect[5] = 'Convert ID to lowercase.
';
+ // test attribute key case sensitivity
+ $this->assertResult(
+ 'Convert ID to lowercase.
',
+ 'Convert ID to lowercase.
'
+ );
// test simple attribute substitution
- $inputs[6] = 'Trim whitespace.
';
- $expect[6] = 'Trim whitespace.
';
+ $this->assertResult(
+ 'Trim whitespace.
',
+ 'Trim whitespace.
'
+ );
// test configuration id blacklist
- $inputs[7] = 'Invalid
';
- $expect[7] = 'Invalid
';
- $config[7] = HTMLPurifier_Config::createDefault();
- $config[7]->set('Attr', 'IDBlacklist', array('invalid'));
+ $this->assertResult(
+ 'Invalid
',
+ 'Invalid
',
+ array('Attr.IDBlacklist' => array('invalid'))
+ );
// test classes
- $inputs[8] = 'Valid
';
- $expect[8] = $inputs[8];
+ $this->assertResult('Valid
');
- $inputs[9] = 'Keep valid.
';
- $expect[9] = 'Keep valid.
';
+ $this->assertResult(
+ 'Keep valid.
',
+ 'Keep valid.
'
+ );
// test title
- $inputs[10] = 'PHP';
- $expect[10] = $inputs[10];
+ $this->assertResult(
+ 'PHP'
+ );
// test lang
- $inputs[11] = 'La soupe.';
- $expect[11] = 'La soupe.';
+ $this->assertResult(
+ 'La soupe.',
+ 'La soupe.'
+ );
- // test align (won't work till CSS validation is implemented)
- $inputs[12] = 'Centered Headline
';
- $expect[12] = 'Centered Headline
';
+ // test align
+ $this->assertResult(
+ 'Centered Headline
',
+ 'Centered Headline
'
+ );
// test table
- $inputs[13] =
-
+ $this->assertResult(
'
@@ -87,44 +99,56 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
Taken off the market |
-
';
-
- $expect[13] = $inputs[13];
+'
+ );
// test URI
- $inputs[14] = 'Google';
- $expect[14] = $inputs[14];
+ $this->assertResult('Google');
// test invalid URI
- $inputs[15] = 'Google';
- $expect[15] = 'Google';
+ $this->assertResult(
+ 'Google',
+ 'Google'
+ );
// test required attributes for img
- $inputs[16] = '';
- $expect[16] = '';
+ $this->assertResult(
+ '',
+ ''
+ );
- $inputs[17] = '';
- $expect[17] = '';
+ $this->assertResult(
+ '',
+ ''
+ );
- $inputs[18] = '';
- $expect[18] = '';
+ $this->assertResult(
+ '',
+ ''
+ );
// test required attributes for bdo
- $inputs[19] = 'Go left.';
- $expect[19] = 'Go left.';
+ $this->assertResult(
+ 'Go left.',
+ 'Go left.'
+ );
- $inputs[20] = 'Invalid value!';
- $expect[20] = 'Invalid value!';
+ $this->assertResult(
+ 'Invalid value!',
+ 'Invalid value!'
+ );
// comparison check for test 20
- $inputs[21] = 'Invalid value!';
- $expect[21] = 'Invalid value!';
+ $this->assertResult(
+ 'Invalid value!',
+ 'Invalid value!'
+ );
// test col.span is non-zero
- $inputs[22] = '';
- $expect[22] = '';
-
- $this->assertStrategyWorks($strategy, $inputs, $expect, $config);
+ $this->assertResult(
+ '',
+ ''
+ );
}
diff --git a/tests/HTMLPurifier/StrategyHarness.php b/tests/HTMLPurifier/StrategyHarness.php
index 3ca07753..9b452a8b 100644
--- a/tests/HTMLPurifier/StrategyHarness.php
+++ b/tests/HTMLPurifier/StrategyHarness.php
@@ -1,41 +1,14 @@
UnitTestCase();
-
- // we can't use the DOM lexer since it does too much stuff
- // automatically, however, we should be able to use it
- // interchangeably if we wanted to...
-
- if (true) {
- $this->lex = new HTMLPurifier_Lexer_DirectLex();
- } else {
- require_once 'HTMLPurifier/Lexer/DOMLex.php';
- $this->lex = new HTMLPurifier_Lexer_DOMLex();
- }
-
- $this->gen = new HTMLPurifier_Generator();
- }
-
- function assertStrategyWorks($strategy, $inputs, $expect, $config = array()) {
- $context = new HTMLPurifier_Context();
- foreach ($inputs as $i => $input) {
- if (!isset($config[$i])) {
- $config[$i] = HTMLPurifier_Config::createDefault();
- }
- $tokens = $this->lex->tokenizeHTML($input, $config[$i], $context);
- $result_tokens = $strategy->execute($tokens, $config[$i], $context);
- $result = $this->gen->generateFromTokens($result_tokens, $config[$i]);
- $this->assertEqual($expect[$i], $result, "Test $i: %s");
- paintIf($result, $result != $expect[$i]);
- }
+ function setUp() {
+ $this->func = 'execute';
+ $this->to_tokens = true;
+ $this->to_html = true;
}
}