You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IntegerTest.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. class HTMLPurifier_AttrDef_IntegerTest extends HTMLPurifier_AttrDefHarness
  3. {
  4. public function test()
  5. {
  6. $this->def = new HTMLPurifier_AttrDef_Integer();
  7. $this->assertDef('0');
  8. $this->assertDef('1');
  9. $this->assertDef('-1');
  10. $this->assertDef('-10');
  11. $this->assertDef('14');
  12. $this->assertDef('+24', '24');
  13. $this->assertDef(' 14 ', '14');
  14. $this->assertDef('-0', '0');
  15. $this->assertDef('-1.4', false);
  16. $this->assertDef('3.4', false);
  17. $this->assertDef('asdf', false); // must not return zero
  18. $this->assertDef('2in', false); // must not return zero
  19. }
  20. public function assertRange($negative, $zero, $positive)
  21. {
  22. $this->assertDef('-100', $negative);
  23. $this->assertDef('-1', $negative);
  24. $this->assertDef('0', $zero);
  25. $this->assertDef('1', $positive);
  26. $this->assertDef('42', $positive);
  27. }
  28. public function testRange()
  29. {
  30. $this->def = new HTMLPurifier_AttrDef_Integer(false);
  31. $this->assertRange(false, true, true); // non-negative
  32. $this->def = new HTMLPurifier_AttrDef_Integer(false, false);
  33. $this->assertRange(false, false, true); // positive
  34. // fringe cases
  35. $this->def = new HTMLPurifier_AttrDef_Integer(false, false, false);
  36. $this->assertRange(false, false, false); // allow none
  37. $this->def = new HTMLPurifier_AttrDef_Integer(true, false, false);
  38. $this->assertRange(true, false, false); // negative
  39. $this->def = new HTMLPurifier_AttrDef_Integer(false, true, false);
  40. $this->assertRange(false, true, false); // zero
  41. $this->def = new HTMLPurifier_AttrDef_Integer(true, true, false);
  42. $this->assertRange(true, true, false); // non-positive
  43. }
  44. }
  45. // vim: et sw=4 sts=4