2006-07-30 16:35:05 +00:00
|
|
|
<?php
|
|
|
|
|
2007-02-14 20:38:51 +00:00
|
|
|
class HTMLPurifier_AttrDef_HTML_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);
|
2007-02-14 02:54:41 +00:00
|
|
|
$this->config->set('Attr', 'EnableID', true);
|
2007-02-14 20:38:51 +00:00
|
|
|
$this->def = new HTMLPurifier_AttrDef_HTML_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-05-20 18:06:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testLocalPrefixWithoutMainPrefix() {
|
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-05-20 18:06:51 +00:00
|
|
|
$this->config->set('Attr', 'IDPrefixLocal', 'story95_');
|
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
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-02-14 02:54:41 +00:00
|
|
|
// reference functionality is disabled for now
|
|
|
|
function disabled_testIDReference() {
|
2007-02-02 22:03:09 +00:00
|
|
|
|
2007-02-14 20:38:51 +00:00
|
|
|
$this->def = new HTMLPurifier_AttrDef_HTML_ID(true);
|
2007-02-02 22:03:09 +00:00
|
|
|
|
|
|
|
$this->assertDef('good_id');
|
|
|
|
$this->assertDef('good_id'); // duplicates okay
|
|
|
|
$this->assertDef('<b>', false);
|
|
|
|
|
2007-02-14 20:38:51 +00:00
|
|
|
$this->def = new HTMLPurifier_AttrDef_HTML_ID();
|
2007-02-02 22:03:09 +00:00
|
|
|
|
|
|
|
$this->assertDef('good_id');
|
|
|
|
$this->assertDef('good_id', false); // duplicate now not okay
|
|
|
|
|
2007-02-14 20:38:51 +00:00
|
|
|
$this->def = new HTMLPurifier_AttrDef_HTML_ID(true);
|
2007-02-02 22:03:09 +00:00
|
|
|
|
|
|
|
$this->assertDef('good_id'); // reference still okay
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-03-31 03:25:10 +00:00
|
|
|
function testRegexp() {
|
|
|
|
|
|
|
|
$this->config->set('Attr', 'IDBlacklistRegexp', '/^g_/');
|
|
|
|
|
|
|
|
$this->assertDef('good_id');
|
|
|
|
$this->assertDef('g_bad_id', false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-07-30 16:35:05 +00:00
|
|
|
}
|
|
|
|
|