0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-22 16:31:53 +00:00
htmlpurifier/tests/HTML_Generator.php
Edward Z. Yang 83f735ea7e Finish HTMLDTD_ChildDef_Required.
Fix bug in HTML_Generator that resulted in attribute-less empty elements to have extra spaces in them.

Add whitespace designation to MF_Text.

git-svn-id: http://htmlpurifier.org/svnroot/html_purifier/trunk@44 48356398-32a2-884e-a903-53898d9a118a
2006-04-17 00:49:15 +00:00

83 lines
2.4 KiB
PHP

<?php
class Test_HTML_Generator extends UnitTestCase
{
var $gen;
function Test_HTML_Generator() {
$this->UnitTestCase();
$this->gen = new HTML_Generator();
}
function test_generateFromToken() {
$inputs = array();
$expect = array();
$inputs[0] = new MF_Text('Foobar.<>');
$expect[0] = 'Foobar.&lt;&gt;';
$inputs[1] = new MF_StartTag('a', array('href' => 'dyn?a=foo&b=bar'));
$expect[1] = '<a href="dyn?a=foo&amp;b=bar">';
$inputs[2] = new MF_EndTag('b');
$expect[2] = '</b>';
$inputs[3] = new MF_EmptyTag('br', array('style' => 'font-family:"Courier New";'));
$expect[3] = '<br style="font-family:&quot;Courier New&quot;;" />';
$inputs[4] = new MF_StartTag('asdf');
$expect[4] = '<asdf>';
$inputs[5] = new MF_EmptyTag('br');
$expect[5] = '<br />';
foreach ($inputs as $i => $input) {
$result = $this->gen->generateFromToken($input);
$this->assertEqual($result, $expect[$i]);
paintIf($result, $result != $expect[$i]);
}
}
function test_generateAttributes() {
$inputs = array();
$expect = array();
$inputs[0] = array();
$expect[0] = '';
$inputs[1] = array('href' => 'dyn?a=foo&b=bar');
$expect[1] = 'href="dyn?a=foo&amp;b=bar"';
$inputs[2] = array('style' => 'font-family:"Courier New";');
$expect[2] = 'style="font-family:&quot;Courier New&quot;;"';
$inputs[3] = array('src' => 'picture.jpg', 'alt' => 'Short & interesting');
$expect[3] = 'src="picture.jpg" alt="Short &amp; interesting"';
foreach ($inputs as $i => $input) {
$result = $this->gen->generateAttributes($input);
$this->assertEqual($result, $expect[$i]);
paintIf($result, $result != $expect[$i]);
}
}
function test_generateFromTokens() {
$tokens = array(
new MF_StartTag('b'),
new MF_Text('Foobar!'),
new MF_EndTag('b')
);
$expect = '<b>Foobar!</b>';
$this->assertEqual($expect, $this->gen->generateFromTokens($tokens));
}
}
?>