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