IntegerTest.php 1.8 KB

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