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
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function setUp()
|
|
|
|
{
|
2006-11-17 01:05:41 +00:00
|
|
|
parent::setUp();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-10-01 21:55:13 +00:00
|
|
|
$id_accumulator = new HTMLPurifier_IDAccumulator();
|
|
|
|
$this->context->register('IDAccumulator', $id_accumulator);
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('Attr.EnableID', true);
|
2007-02-14 20:38:51 +00:00
|
|
|
$this->def = new HTMLPurifier_AttrDef_HTML_ID();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-11-17 01:05:41 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public 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');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
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);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
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);
|
2008-12-06 07:28:20 +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');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-07-30 16:35:05 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testPrefix()
|
|
|
|
{
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('Attr.IDPrefix', 'user_');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-11-17 01:05:41 +00:00
|
|
|
$this->assertDef('alpha', 'user_alpha');
|
|
|
|
$this->assertDef('<asa', false);
|
|
|
|
$this->assertDef('once', 'user_once');
|
|
|
|
$this->assertDef('once', false);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-11-17 01:05:41 +00:00
|
|
|
// if already prefixed, leave alone
|
|
|
|
$this->assertDef('user_alas');
|
|
|
|
$this->assertDef('user_user_alas'); // how to bypass
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-11-17 01:05:41 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testTwoPrefixes()
|
|
|
|
{
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('Attr.IDPrefix', 'user_');
|
|
|
|
$this->config->set('Attr.IDPrefixLocal', 'story95_');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-11-17 01:05:41 +00:00
|
|
|
$this->assertDef('alpha', 'user_story95_alpha');
|
|
|
|
$this->assertDef('<asa', false);
|
|
|
|
$this->assertDef('once', 'user_story95_once');
|
|
|
|
$this->assertDef('once', false);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-11-17 01:05:41 +00:00
|
|
|
$this->assertDef('user_story95_alas');
|
|
|
|
$this->assertDef('user_alas', 'user_story95_user_alas'); // !
|
2007-05-20 18:06:51 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testLocalPrefixWithoutMainPrefix()
|
|
|
|
{
|
2007-01-20 19:22:55 +00:00
|
|
|
// no effect when IDPrefix isn't set
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('Attr.IDPrefix', '');
|
|
|
|
$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');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-11-17 01:05:41 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-14 02:54:41 +00:00
|
|
|
// reference functionality is disabled for now
|
2013-07-16 11:56:14 +00:00
|
|
|
public function disabled_testIDReference()
|
|
|
|
{
|
2007-02-14 20:38:51 +00:00
|
|
|
$this->def = new HTMLPurifier_AttrDef_HTML_ID(true);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-02 22:03:09 +00:00
|
|
|
$this->assertDef('good_id');
|
|
|
|
$this->assertDef('good_id'); // duplicates okay
|
|
|
|
$this->assertDef('<b>', false);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-14 20:38:51 +00:00
|
|
|
$this->def = new HTMLPurifier_AttrDef_HTML_ID();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-02 22:03:09 +00:00
|
|
|
$this->assertDef('good_id');
|
|
|
|
$this->assertDef('good_id', false); // duplicate now not okay
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-14 20:38:51 +00:00
|
|
|
$this->def = new HTMLPurifier_AttrDef_HTML_ID(true);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-02 22:03:09 +00:00
|
|
|
$this->assertDef('good_id'); // reference still okay
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-02 22:03:09 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testRegexp()
|
|
|
|
{
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('Attr.IDBlacklistRegexp', '/^g_/');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-03-31 03:25:10 +00:00
|
|
|
$this->assertDef('good_id');
|
|
|
|
$this->assertDef('g_bad_id', false);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-03-31 03:25:10 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-07-30 16:35:05 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|