PSR-2 reformatting PHPDoc corrections
[htmlpurifier.git] / tests / HTMLPurifier / AttrDef / HTML / IDTest.php
blob31870d22839d58eaef831e16ea678dac39929a0a
1 <?php
3 class HTMLPurifier_AttrDef_HTML_IDTest extends HTMLPurifier_AttrDefHarness
6 public function setUp()
8 parent::setUp();
10 $id_accumulator = new HTMLPurifier_IDAccumulator();
11 $this->context->register('IDAccumulator', $id_accumulator);
12 $this->config->set('Attr.EnableID', true);
13 $this->def = new HTMLPurifier_AttrDef_HTML_ID();
17 public function test()
19 // valid ID names
20 $this->assertDef('alpha');
21 $this->assertDef('al_ha');
22 $this->assertDef('a0-:.');
23 $this->assertDef('a');
25 // invalid ID names
26 $this->assertDef('<asa', false);
27 $this->assertDef('0123', false);
28 $this->assertDef('.asa', false);
30 // test duplicate detection
31 $this->assertDef('once');
32 $this->assertDef('once', false);
34 // valid once whitespace stripped, but needs to be amended
35 $this->assertDef(' whee ', 'whee');
39 public function testPrefix()
41 $this->config->set('Attr.IDPrefix', 'user_');
43 $this->assertDef('alpha', 'user_alpha');
44 $this->assertDef('<asa', false);
45 $this->assertDef('once', 'user_once');
46 $this->assertDef('once', false);
48 // if already prefixed, leave alone
49 $this->assertDef('user_alas');
50 $this->assertDef('user_user_alas'); // how to bypass
54 public function testTwoPrefixes()
56 $this->config->set('Attr.IDPrefix', 'user_');
57 $this->config->set('Attr.IDPrefixLocal', 'story95_');
59 $this->assertDef('alpha', 'user_story95_alpha');
60 $this->assertDef('<asa', false);
61 $this->assertDef('once', 'user_story95_once');
62 $this->assertDef('once', false);
64 $this->assertDef('user_story95_alas');
65 $this->assertDef('user_alas', 'user_story95_user_alas'); // !
68 public function testLocalPrefixWithoutMainPrefix()
70 // no effect when IDPrefix isn't set
71 $this->config->set('Attr.IDPrefix', '');
72 $this->config->set('Attr.IDPrefixLocal', 'story95_');
73 $this->expectError('%Attr.IDPrefixLocal cannot be used unless '.
74 '%Attr.IDPrefix is set');
75 $this->assertDef('amherst');
79 // reference functionality is disabled for now
80 public function disabled_testIDReference()
82 $this->def = new HTMLPurifier_AttrDef_HTML_ID(true);
84 $this->assertDef('good_id');
85 $this->assertDef('good_id'); // duplicates okay
86 $this->assertDef('<b>', false);
88 $this->def = new HTMLPurifier_AttrDef_HTML_ID();
90 $this->assertDef('good_id');
91 $this->assertDef('good_id', false); // duplicate now not okay
93 $this->def = new HTMLPurifier_AttrDef_HTML_ID(true);
95 $this->assertDef('good_id'); // reference still okay
99 public function testRegexp()
101 $this->config->set('Attr.IDBlacklistRegexp', '/^g_/');
103 $this->assertDef('good_id');
104 $this->assertDef('g_bad_id', false);
110 // vim: et sw=4 sts=4