0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-24 09:11:52 +00:00
htmlpurifier/tests/HTMLPurifier/Strategy/MakeWellFormedTest.php
2006-07-24 02:49:37 +00:00

64 lines
2.0 KiB
PHP

<?php
require_once 'HTMLPurifier/StrategyAbstractTest.php';
require_once 'HTMLPurifier/Strategy/MakeWellFormed.php';
class HTMLPurifier_Strategy_MakeWellFormedTest
extends HTMLPurifier_StrategyAbstractTest
{
function test() {
$strategy = new HTMLPurifier_Strategy_MakeWellFormed();
$inputs = array();
$expect = array();
$inputs[0] = '';
$expect[0] = $inputs[0];
$inputs[1] = 'This is <b>bold text</b>.';
$expect[1] = $inputs[1];
$inputs[2] = '<b>Unclosed tag, gasp!';
$expect[2] = '<b>Unclosed tag, gasp!</b>';
$inputs[3] = '<b><i>Bold and italic?</b>';
$expect[3] = '<b><i>Bold and italic?</i></b>';
// CHANGE THIS BEHAVIOR!
$inputs[4] = 'Unused end tags... recycle!</b>';
$expect[4] = 'Unused end tags... recycle!&lt;/b&gt;';
$inputs[5] = '<br style="clear:both;">';
$expect[5] = '<br style="clear:both;" />';
$inputs[6] = '<div style="clear:both;" />';
$expect[6] = '<div style="clear:both;"></div>';
// test automatic paragraph closing
$inputs[7] = '<p>Paragraph 1<p>Paragraph 2';
$expect[7] = '<p>Paragraph 1</p><p>Paragraph 2</p>';
$inputs[8] = '<div><p>Paragraphs<p>In<p>A<p>Div</div>';
$expect[8] = '<div><p>Paragraphs</p><p>In</p><p>A</p><p>Div</p></div>';
// automatic list closing
$inputs[9] = '<ol><li>Item 1<li>Item 2</ol>';
$expect[9] = '<ol><li>Item 1</li><li>Item 2</li></ol>';
foreach ($inputs as $i => $input) {
$tokens = $this->lex->tokenizeHTML($input);
$result_tokens = $strategy->execute($tokens);
$result = $this->gen->generateFromTokens($result_tokens);
$this->assertEqual($expect[$i], $result, "Test $i: %s");
paintIf($result, $result != $expect[$i]);
}
}
}
?>