Blame view

vendor/ezyang/htmlpurifier/tests/HTMLPurifier/AttrDef/IntegerTest.php 1.81 KB
abf1649b   andryeyev   Чистая установка ...
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
  <?php
  
  class HTMLPurifier_AttrDef_IntegerTest extends HTMLPurifier_AttrDefHarness
  {
  
      public function test()
      {
          $this->def = new HTMLPurifier_AttrDef_Integer();
  
          $this->assertDef('0');
          $this->assertDef('1');
          $this->assertDef('-1');
          $this->assertDef('-10');
          $this->assertDef('14');
          $this->assertDef('+24', '24');
          $this->assertDef(' 14 ', '14');
          $this->assertDef('-0', '0');
  
          $this->assertDef('-1.4', false);
          $this->assertDef('3.4', false);
          $this->assertDef('asdf', false); // must not return zero
          $this->assertDef('2in', false); // must not return zero
  
      }
  
      public function assertRange($negative, $zero, $positive)
      {
          $this->assertDef('-100', $negative);
          $this->assertDef('-1', $negative);
          $this->assertDef('0', $zero);
          $this->assertDef('1', $positive);
          $this->assertDef('42', $positive);
      }
  
      public function testRange()
      {
          $this->def = new HTMLPurifier_AttrDef_Integer(false);
          $this->assertRange(false, true, true); // non-negative
  
          $this->def = new HTMLPurifier_AttrDef_Integer(false, false);
          $this->assertRange(false, false, true); // positive
  
  
          // fringe cases
  
          $this->def = new HTMLPurifier_AttrDef_Integer(false, false, false);
          $this->assertRange(false, false, false); // allow none
  
          $this->def = new HTMLPurifier_AttrDef_Integer(true, false, false);
          $this->assertRange(true, false, false); // negative
  
          $this->def = new HTMLPurifier_AttrDef_Integer(false, true, false);
          $this->assertRange(false, true, false); // zero
  
          $this->def = new HTMLPurifier_AttrDef_Integer(true, true, false);
          $this->assertRange(true, true, false); // non-positive
  
      }
  
  }
  
  // vim: et sw=4 sts=4