您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

81 行
2.5KB

  1. <?php
  2. class HTMLPurifier_LengthTest extends HTMLPurifier_Harness
  3. {
  4. public function testConstruct()
  5. {
  6. $l = new HTMLPurifier_Length('23', 'in');
  7. $this->assertIdentical($l->getN(), '23');
  8. $this->assertIdentical($l->getUnit(), 'in');
  9. }
  10. public function testMake()
  11. {
  12. $l = HTMLPurifier_Length::make('+23.4in');
  13. $this->assertIdentical($l->getN(), '+23.4');
  14. $this->assertIdentical($l->getUnit(), 'in');
  15. }
  16. public function testToString()
  17. {
  18. $l = new HTMLPurifier_Length('23', 'in');
  19. $this->assertIdentical($l->toString(), '23in');
  20. }
  21. protected function assertValidate($string, $expect = true)
  22. {
  23. if ($expect === true) $expect = $string;
  24. $l = HTMLPurifier_Length::make($string);
  25. $result = $l->isValid();
  26. if ($result === false) $this->assertIdentical($expect, false);
  27. else $this->assertIdentical($l->toString(), $expect);
  28. }
  29. public function testValidate()
  30. {
  31. $this->assertValidate('0');
  32. $this->assertValidate('+0', '0');
  33. $this->assertValidate('-0', '0');
  34. $this->assertValidate('0px');
  35. $this->assertValidate('4.5px');
  36. $this->assertValidate('-4.5px');
  37. $this->assertValidate('3ex');
  38. $this->assertValidate('3em');
  39. $this->assertValidate('3in');
  40. $this->assertValidate('3cm');
  41. $this->assertValidate('3mm');
  42. $this->assertValidate('3pt');
  43. $this->assertValidate('3pc');
  44. $this->assertValidate('3PX', '3px');
  45. $this->assertValidate('3', false);
  46. $this->assertValidate('3miles', false);
  47. }
  48. /**
  49. * @param $s1 First string to compare
  50. * @param $s2 Second string to compare
  51. * @param $expect 0 for $s1 == $s2, 1 for $s1 > $s2 and -1 for $s1 < $s2
  52. */
  53. protected function assertComparison($s1, $s2, $expect = 0)
  54. {
  55. $l1 = HTMLPurifier_Length::make($s1);
  56. $l2 = HTMLPurifier_Length::make($s2);
  57. $r1 = $l1->compareTo($l2);
  58. $r2 = $l2->compareTo($l1);
  59. $this->assertIdentical($r1 == 0 ? 0 : ($r1 > 0 ? 1 : -1), $expect);
  60. $this->assertIdentical($r2 == 0 ? 0 : ($r2 > 0 ? 1 : -1), - $expect);
  61. }
  62. public function testCompareTo()
  63. {
  64. $this->assertComparison('12in', '12in');
  65. $this->assertComparison('12in', '12mm', 1);
  66. $this->assertComparison('1px', '1mm', -1);
  67. $this->assertComparison(str_repeat('2', 38) . 'in', '100px', 1);
  68. }
  69. }
  70. // vim: et sw=4 sts=4