Blame view

vendor/ezyang/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/IDTest.php 2.99 KB
70f4f18b   Administrator   first_commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
  <?php
  
  class HTMLPurifier_AttrDef_HTML_IDTest extends HTMLPurifier_AttrDefHarness
  {
  
      public function setUp()
      {
          parent::setUp();
  
          $id_accumulator = new HTMLPurifier_IDAccumulator();
          $this->context->register('IDAccumulator', $id_accumulator);
          $this->config->set('Attr.EnableID', true);
          $this->def = new HTMLPurifier_AttrDef_HTML_ID();
  
      }
  
      public function test()
      {
          // valid ID names
          $this->assertDef('alpha');
          $this->assertDef('al_ha');
          $this->assertDef('a0-:.');
          $this->assertDef('a');
  
          // invalid ID names
          $this->assertDef('<asa', false);
          $this->assertDef('0123', false);
          $this->assertDef('.asa', false);
  
          // test duplicate detection
          $this->assertDef('once');
          $this->assertDef('once', false);
  
          // valid once whitespace stripped, but needs to be amended
          $this->assertDef(' whee ', 'whee');
  
      }
  
      public 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
  
      }
  
      public 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'); // !
      }
  
      public function testLocalPrefixWithoutMainPrefix()
      {
          // no effect when IDPrefix isn't set
          $this->config->set('Attr.IDPrefix', '');
          $this->config->set('Attr.IDPrefixLocal', 'story95_');
          $this->expectError('%Attr.IDPrefixLocal cannot be used unless '.
              '%Attr.IDPrefix is set');
          $this->assertDef('amherst');
  
      }
  
      // reference functionality is disabled for now
      public function disabled_testIDReference()
      {
          $this->def = new HTMLPurifier_AttrDef_HTML_ID(true);
  
          $this->assertDef('good_id');
          $this->assertDef('good_id'); // duplicates okay
          $this->assertDef('<b>', false);
  
          $this->def = new HTMLPurifier_AttrDef_HTML_ID();
  
          $this->assertDef('good_id');
          $this->assertDef('good_id', false); // duplicate now not okay
  
          $this->def = new HTMLPurifier_AttrDef_HTML_ID(true);
  
          $this->assertDef('good_id'); // reference still okay
  
      }
  
      public function testRegexp()
      {
          $this->config->set('Attr.IDBlacklistRegexp', '/^g_/');
  
          $this->assertDef('good_id');
          $this->assertDef('g_bad_id', false);
  
      }
  
  }
  
  // vim: et sw=4 sts=4