2006-07-30 18:37:42 +00:00
|
|
|
<?php
|
|
|
|
|
2006-08-04 01:47:48 +00:00
|
|
|
require_once('HTMLPurifier/Config.php');
|
2006-08-05 00:30:31 +00:00
|
|
|
require_once('HTMLPurifier/StrategyHarness.php');
|
2006-07-30 18:37:42 +00:00
|
|
|
require_once('HTMLPurifier/Strategy/ValidateAttributes.php');
|
|
|
|
|
|
|
|
class HTMLPurifier_Strategy_ValidateAttributesTest extends
|
2006-08-05 00:30:31 +00:00
|
|
|
HTMLPurifier_StrategyHarness
|
2006-07-30 18:37:42 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
function test() {
|
|
|
|
|
|
|
|
$strategy = new HTMLPurifier_Strategy_ValidateAttributes();
|
|
|
|
|
|
|
|
$inputs = array();
|
|
|
|
$expect = array();
|
2006-08-04 01:47:48 +00:00
|
|
|
$config = array();
|
2006-07-30 18:37:42 +00:00
|
|
|
|
|
|
|
$inputs[0] = '';
|
|
|
|
$expect[0] = '';
|
|
|
|
|
2006-08-04 02:48:20 +00:00
|
|
|
// test ids
|
|
|
|
|
2006-07-30 18:37:42 +00:00
|
|
|
$inputs[1] = '<div id="valid">Preserve the ID.</div>';
|
|
|
|
$expect[1] = $inputs[1];
|
|
|
|
|
|
|
|
$inputs[2] = '<div id="0invalid">Kill the ID.</div>';
|
|
|
|
$expect[2] = '<div>Kill the ID.</div>';
|
|
|
|
|
2006-08-04 02:48:20 +00:00
|
|
|
// test id accumulator
|
2006-07-30 18:37:42 +00:00
|
|
|
$inputs[3] = '<div id="valid">Valid</div><div id="valid">Invalid</div>';
|
|
|
|
$expect[3] = '<div id="valid">Valid</div><div>Invalid</div>';
|
|
|
|
|
|
|
|
$inputs[4] = '<span dir="up-to-down">Bad dir.</span>';
|
|
|
|
$expect[4] = '<span>Bad dir.</span>';
|
|
|
|
|
2006-08-04 02:48:20 +00:00
|
|
|
// test attribute case sensitivity
|
2006-08-02 02:43:52 +00:00
|
|
|
$inputs[5] = '<div ID="valid">Convert ID to lowercase.</div>';
|
|
|
|
$expect[5] = '<div id="valid">Convert ID to lowercase.</div>';
|
|
|
|
|
2006-08-04 00:11:54 +00:00
|
|
|
// test simple attribute substitution
|
|
|
|
$inputs[6] = '<div id=" valid ">Trim whitespace.</div>';
|
|
|
|
$expect[6] = '<div id="valid">Trim whitespace.</div>';
|
|
|
|
|
2006-08-04 01:47:48 +00:00
|
|
|
// test configuration id blacklist
|
|
|
|
$inputs[7] = '<div id="invalid">Invalid</div>';
|
|
|
|
$expect[7] = '<div>Invalid</div>';
|
|
|
|
$config[7] = HTMLPurifier_Config::createDefault();
|
2006-08-11 20:23:41 +00:00
|
|
|
$config[7]->set('Attr', 'IDBlacklist', array('invalid'));
|
2006-08-04 01:47:48 +00:00
|
|
|
|
2006-08-04 02:48:20 +00:00
|
|
|
// test classes
|
|
|
|
$inputs[8] = '<div class="valid">Valid</div>';
|
|
|
|
$expect[8] = $inputs[8];
|
|
|
|
|
2006-08-04 03:13:04 +00:00
|
|
|
$inputs[9] = '<div class="valid 0invalid">Keep valid.</div>';
|
|
|
|
$expect[9] = '<div class="valid">Keep valid.</div>';
|
|
|
|
|
|
|
|
// test title
|
|
|
|
$inputs[10] = '<acronym title="PHP: Hypertext Preprocessor">PHP</acronym>';
|
|
|
|
$expect[10] = $inputs[10];
|
|
|
|
|
2006-08-05 02:56:57 +00:00
|
|
|
// test lang
|
2006-08-05 01:50:13 +00:00
|
|
|
$inputs[11] = '<span lang="fr">La soupe.</span>';
|
|
|
|
$expect[11] = '<span lang="fr" xml:lang="fr">La soupe.</span>';
|
|
|
|
|
2006-08-05 22:14:19 +00:00
|
|
|
// test align (won't work till CSS validation is implemented)
|
2006-08-12 20:22:09 +00:00
|
|
|
$inputs[12] = '<h1 align="center">Centered Headline</h1>';
|
|
|
|
$expect[12] = '<h1 style="text-align:center;">Centered Headline</h1>';
|
2006-08-05 02:56:57 +00:00
|
|
|
|
2006-08-05 22:14:19 +00:00
|
|
|
// test table
|
|
|
|
$inputs[13] = <<<HTML
|
2006-08-06 01:30:54 +00:00
|
|
|
<table frame="above" rules="rows" summary="A test table" border="2" cellpadding="5%" cellspacing="3" width="100%">
|
2006-08-06 01:41:18 +00:00
|
|
|
<col align="right" width="4*" />
|
|
|
|
<col charoff="5" align="char" width="1*" />
|
2006-08-05 22:14:19 +00:00
|
|
|
<tr valign="top">
|
2006-08-06 01:30:54 +00:00
|
|
|
<th abbr="name">Fiddly name</th>
|
|
|
|
<th abbr="price">Super-duper-price</th>
|
2006-08-05 22:14:19 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2006-08-06 01:30:54 +00:00
|
|
|
<td abbr="carrot">Carrot Humungous</td>
|
|
|
|
<td>$500.23</td>
|
2006-08-05 22:14:19 +00:00
|
|
|
</tr>
|
2006-08-06 03:58:48 +00:00
|
|
|
<tr>
|
|
|
|
<td colspan="2">Taken off the market</td>
|
|
|
|
</tr>
|
2006-08-05 22:14:19 +00:00
|
|
|
</table>
|
|
|
|
HTML;
|
|
|
|
$expect[13] = $inputs[13];
|
|
|
|
|
2006-08-12 19:22:57 +00:00
|
|
|
// test URI
|
|
|
|
$inputs[14] = '<a href="http://www.google.com/">Google</a>';
|
|
|
|
$expect[14] = $inputs[14];
|
|
|
|
|
|
|
|
// test invalid URI
|
|
|
|
$inputs[15] = '<a href="javascript:badstuff();">Google</a>';
|
|
|
|
$expect[15] = '<a>Google</a>';
|
|
|
|
|
2006-08-04 01:47:48 +00:00
|
|
|
$this->assertStrategyWorks($strategy, $inputs, $expect, $config);
|
2006-07-30 18:37:42 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|