2006-07-30 16:35:05 +00:00
|
|
|
<?php
|
|
|
|
|
2006-08-05 00:30:31 +00:00
|
|
|
require_once 'HTMLPurifier/AttrDefHarness.php';
|
2006-07-30 16:35:05 +00:00
|
|
|
require_once 'HTMLPurifier/AttrDef/ID.php';
|
|
|
|
require_once 'HTMLPurifier/IDAccumulator.php';
|
|
|
|
|
2006-08-05 00:30:31 +00:00
|
|
|
class HTMLPurifier_AttrDef_IDTest extends HTMLPurifier_AttrDefHarness
|
2006-07-30 16:35:05 +00:00
|
|
|
{
|
|
|
|
|
2006-11-17 01:05:41 +00:00
|
|
|
function setUp() {
|
|
|
|
parent::setUp();
|
2006-07-30 16:35:05 +00:00
|
|
|
|
2006-10-01 21:55:13 +00:00
|
|
|
$id_accumulator = new HTMLPurifier_IDAccumulator();
|
|
|
|
$this->context->register('IDAccumulator', $id_accumulator);
|
2006-08-05 00:30:31 +00:00
|
|
|
$this->def = new HTMLPurifier_AttrDef_ID();
|
2006-08-04 01:52:54 +00:00
|
|
|
|
2006-11-17 01:05:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test() {
|
|
|
|
|
2006-07-30 16:35:05 +00:00
|
|
|
// valid ID names
|
2006-08-05 00:30:31 +00:00
|
|
|
$this->assertDef('alpha');
|
|
|
|
$this->assertDef('al_ha');
|
|
|
|
$this->assertDef('a0-:.');
|
|
|
|
$this->assertDef('a');
|
2006-07-30 16:35:05 +00:00
|
|
|
|
|
|
|
// invalid ID names
|
2006-08-05 00:30:31 +00:00
|
|
|
$this->assertDef('<asa', false);
|
|
|
|
$this->assertDef('0123', false);
|
|
|
|
$this->assertDef('.asa', false);
|
2006-07-30 16:35:05 +00:00
|
|
|
|
|
|
|
// test duplicate detection
|
2006-10-21 18:18:36 +00:00
|
|
|
$this->assertDef('once');
|
|
|
|
$this->assertDef('once', false);
|
2006-07-30 16:35:05 +00:00
|
|
|
|
2006-08-04 00:11:54 +00:00
|
|
|
// valid once whitespace stripped, but needs to be amended
|
2006-08-05 00:30:31 +00:00
|
|
|
$this->assertDef(' whee ', 'whee');
|
2006-08-04 00:11:54 +00:00
|
|
|
|
2006-07-30 16:35:05 +00:00
|
|
|
}
|
|
|
|
|
2006-11-17 01:05:41 +00:00
|
|
|
function testPrefix() {
|
|
|
|
|
|
|
|
$this->config->set('Attr', 'IDPrefix', 'user_');
|
|
|
|
|
|
|
|
$this->assertDef('alpha', 'user_alpha');
|
|
|
|
$this->assertDef('<asa', false);
|
|
|
|
$this->assertDef('once', 'user_once');
|
|
|
|
$this->assertDef('once', false);
|
|
|
|
|
|
|
|
// if already prefixed, leave alone
|
|
|
|
$this->assertDef('user_alas');
|
|
|
|
$this->assertDef('user_user_alas'); // how to bypass
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testTwoPrefixes() {
|
|
|
|
|
|
|
|
$this->config->set('Attr', 'IDPrefix', 'user_');
|
|
|
|
$this->config->set('Attr', 'IDPrefixLocal', 'story95_');
|
|
|
|
|
|
|
|
$this->assertDef('alpha', 'user_story95_alpha');
|
|
|
|
$this->assertDef('<asa', false);
|
|
|
|
$this->assertDef('once', 'user_story95_once');
|
|
|
|
$this->assertDef('once', false);
|
|
|
|
|
|
|
|
$this->assertDef('user_story95_alas');
|
|
|
|
$this->assertDef('user_alas', 'user_story95_user_alas'); // !
|
|
|
|
|
2007-01-20 19:22:55 +00:00
|
|
|
// no effect when IDPrefix isn't set
|
2006-11-17 01:05:41 +00:00
|
|
|
$this->config->set('Attr', 'IDPrefix', '');
|
2007-01-20 19:22:55 +00:00
|
|
|
$this->expectError('%Attr.IDPrefixLocal cannot be used unless '.
|
2006-11-17 01:05:41 +00:00
|
|
|
'%Attr.IDPrefix is set');
|
2007-01-20 19:22:55 +00:00
|
|
|
$this->assertDef('amherst');
|
2006-11-17 01:05:41 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-07-30 16:35:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|