2008-06-25 01:10:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class HTMLPurifier_Strategy_ValidateAttributes_IDTest extends HTMLPurifier_StrategyHarness
|
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-06-25 01:10:51 +00:00
|
|
|
function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
$this->obj = new HTMLPurifier_Strategy_ValidateAttributes();
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('Attr.EnableID', true);
|
2008-06-25 01:10:51 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
|
|
|
|
2008-06-25 01:10:51 +00:00
|
|
|
function testPreserveIDWhenEnabled() {
|
|
|
|
$this->assertResult('<div id="valid">Preserve the ID.</div>');
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-06-25 01:10:51 +00:00
|
|
|
function testRemoveInvalidID() {
|
|
|
|
$this->assertResult(
|
|
|
|
'<div id="0invalid">Kill the ID.</div>',
|
|
|
|
'<div>Kill the ID.</div>'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-06-25 01:10:51 +00:00
|
|
|
function testRemoveDuplicateID() {
|
|
|
|
$this->assertResult(
|
|
|
|
'<div id="valid">Valid</div><div id="valid">Invalid</div>',
|
|
|
|
'<div id="valid">Valid</div><div>Invalid</div>'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-06-25 01:10:51 +00:00
|
|
|
function testAttributeKeyCaseInsensitivity() {
|
|
|
|
$this->assertResult(
|
|
|
|
'<div ID="valid">Convert ID to lowercase.</div>',
|
|
|
|
'<div id="valid">Convert ID to lowercase.</div>'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-06-25 01:10:51 +00:00
|
|
|
function testTrimWhitespace() {
|
|
|
|
$this->assertResult(
|
|
|
|
'<div id=" valid ">Trim whitespace.</div>',
|
|
|
|
'<div id="valid">Trim whitespace.</div>'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-06-25 01:10:51 +00:00
|
|
|
function testIDBlacklist() {
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('Attr.IDBlacklist', array('invalid'));
|
2008-06-25 01:10:51 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<div id="invalid">Invalid</div>',
|
|
|
|
'<div>Invalid</div>'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-06-25 01:10:51 +00:00
|
|
|
function testNameConvertedToID() {
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('HTML.TidyLevel', 'heavy');
|
2008-06-25 01:10:51 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<a name="foobar" />',
|
|
|
|
'<a id="foobar" />'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-06-25 01:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|