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
|
|
|
{
|
|
|
|
|
2006-10-01 21:55:13 +00:00
|
|
|
function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
$this->obj = new HTMLPurifier_Strategy_ValidateAttributes();
|
|
|
|
}
|
|
|
|
|
2006-07-30 18:37:42 +00:00
|
|
|
function test() {
|
|
|
|
|
2006-08-14 23:11:28 +00:00
|
|
|
// attribute order is VERY fragile, perhaps we should define
|
|
|
|
// an ordering scheme!
|
|
|
|
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult('');
|
2006-07-30 18:37:42 +00:00
|
|
|
|
2006-08-04 02:48:20 +00:00
|
|
|
// test ids
|
2006-11-17 01:05:41 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<div id="valid">Kill the ID.</div>',
|
|
|
|
'<div>Kill the ID.</div>'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertResult('<div id="valid">Preserve the ID.</div>', true,
|
|
|
|
array('HTML.EnableAttrID' => true));
|
2006-08-04 02:48:20 +00:00
|
|
|
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<div id="0invalid">Kill the ID.</div>',
|
2006-11-17 01:05:41 +00:00
|
|
|
'<div>Kill the ID.</div>',
|
|
|
|
array('HTML.EnableAttrID' => true)
|
2006-10-01 21:55:13 +00:00
|
|
|
);
|
2006-07-30 18:37:42 +00:00
|
|
|
|
2006-08-04 02:48:20 +00:00
|
|
|
// test id accumulator
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<div id="valid">Valid</div><div id="valid">Invalid</div>',
|
2006-11-17 01:05:41 +00:00
|
|
|
'<div id="valid">Valid</div><div>Invalid</div>',
|
|
|
|
array('HTML.EnableAttrID' => true)
|
2006-10-01 21:55:13 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertResult(
|
|
|
|
'<span dir="up-to-down">Bad dir.</span>',
|
|
|
|
'<span>Bad dir.</span>'
|
|
|
|
);
|
|
|
|
|
|
|
|
// test attribute key case sensitivity
|
|
|
|
$this->assertResult(
|
|
|
|
'<div ID="valid">Convert ID to lowercase.</div>',
|
2006-11-17 01:05:41 +00:00
|
|
|
'<div id="valid">Convert ID to lowercase.</div>',
|
|
|
|
array('HTML.EnableAttrID' => true)
|
2006-10-01 21:55:13 +00:00
|
|
|
);
|
2006-08-02 02:43:52 +00:00
|
|
|
|
2006-08-04 00:11:54 +00:00
|
|
|
// test simple attribute substitution
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<div id=" valid ">Trim whitespace.</div>',
|
2006-11-17 01:05:41 +00:00
|
|
|
'<div id="valid">Trim whitespace.</div>',
|
|
|
|
array('HTML.EnableAttrID' => true)
|
2006-10-01 21:55:13 +00:00
|
|
|
);
|
2006-08-04 00:11:54 +00:00
|
|
|
|
2006-08-04 01:47:48 +00:00
|
|
|
// test configuration id blacklist
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<div id="invalid">Invalid</div>',
|
|
|
|
'<div>Invalid</div>',
|
2006-11-17 01:05:41 +00:00
|
|
|
array(
|
|
|
|
'Attr.IDBlacklist' => array('invalid'),
|
|
|
|
'HTML.EnableAttrID' => true
|
|
|
|
)
|
2006-10-01 21:55:13 +00:00
|
|
|
);
|
2006-08-04 01:47:48 +00:00
|
|
|
|
2006-08-04 02:48:20 +00:00
|
|
|
// test classes
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult('<div class="valid">Valid</div>');
|
2006-08-04 02:48:20 +00:00
|
|
|
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<div class="valid 0invalid">Keep valid.</div>',
|
|
|
|
'<div class="valid">Keep valid.</div>'
|
|
|
|
);
|
2006-08-04 03:13:04 +00:00
|
|
|
|
|
|
|
// test title
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<acronym title="PHP: Hypertext Preprocessor">PHP</acronym>'
|
|
|
|
);
|
2006-08-04 03:13:04 +00:00
|
|
|
|
2006-08-05 02:56:57 +00:00
|
|
|
// test lang
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<span lang="fr">La soupe.</span>',
|
|
|
|
'<span lang="fr" xml:lang="fr">La soupe.</span>'
|
|
|
|
);
|
2006-08-05 01:50:13 +00:00
|
|
|
|
2006-10-01 21:55:13 +00:00
|
|
|
// test align
|
|
|
|
$this->assertResult(
|
|
|
|
'<h1 align="center">Centered Headline</h1>',
|
|
|
|
'<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
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
2006-08-14 23:11:28 +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-10-01 21:55:13 +00:00
|
|
|
</table>'
|
|
|
|
);
|
2006-08-05 22:14:19 +00:00
|
|
|
|
2006-08-12 19:22:57 +00:00
|
|
|
// test URI
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult('<a href="http://www.google.com/">Google</a>');
|
2006-08-12 19:22:57 +00:00
|
|
|
|
|
|
|
// test invalid URI
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<a href="javascript:badstuff();">Google</a>',
|
|
|
|
'<a>Google</a>'
|
|
|
|
);
|
2006-08-12 19:22:57 +00:00
|
|
|
|
2006-08-14 23:11:28 +00:00
|
|
|
// test required attributes for img
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<img />',
|
|
|
|
'<img src="" alt="Invalid image" />'
|
|
|
|
);
|
2006-08-14 23:11:28 +00:00
|
|
|
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<img src="foobar.jpg" />',
|
|
|
|
'<img src="foobar.jpg" alt="foobar.jpg" />'
|
|
|
|
);
|
2006-08-14 23:11:28 +00:00
|
|
|
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<img alt="pretty picture" />',
|
|
|
|
'<img alt="pretty picture" src="" />'
|
|
|
|
);
|
2006-08-14 23:11:28 +00:00
|
|
|
|
|
|
|
// test required attributes for bdo
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<bdo>Go left.</bdo>',
|
|
|
|
'<bdo dir="ltr">Go left.</bdo>'
|
|
|
|
);
|
2006-08-14 23:11:28 +00:00
|
|
|
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<bdo dir="blahblah">Invalid value!</bdo>',
|
|
|
|
'<bdo dir="ltr">Invalid value!</bdo>'
|
|
|
|
);
|
2006-08-14 23:11:28 +00:00
|
|
|
|
|
|
|
// comparison check for test 20
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<span dir="blahblah">Invalid value!</span>',
|
|
|
|
'<span>Invalid value!</span>'
|
|
|
|
);
|
2006-08-14 23:11:28 +00:00
|
|
|
|
2006-08-25 02:48:49 +00:00
|
|
|
// test col.span is non-zero
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<col span="0" />',
|
|
|
|
'<col />'
|
|
|
|
);
|
2006-07-30 18:37:42 +00:00
|
|
|
|
2006-11-17 23:09:10 +00:00
|
|
|
// mailto in image is not allowed
|
|
|
|
$this->assertResult(
|
|
|
|
'<img src="mailto:foo@example.com" />',
|
|
|
|
'<img src="" alt="Invalid image" />'
|
|
|
|
);
|
|
|
|
|
2006-07-30 18:37:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|