PSR-2 reformatting PHPDoc corrections
[htmlpurifier.git] / tests / HTMLPurifier / LengthTest.php
blobb7bf25e021dd0617fa10148869b6b4f02b2ae573
1 <?php
3 class HTMLPurifier_LengthTest extends HTMLPurifier_Harness
6 public function testConstruct()
8 $l = new HTMLPurifier_Length('23', 'in');
9 $this->assertIdentical($l->getN(), '23');
10 $this->assertIdentical($l->getUnit(), 'in');
13 public function testMake()
15 $l = HTMLPurifier_Length::make('+23.4in');
16 $this->assertIdentical($l->getN(), '+23.4');
17 $this->assertIdentical($l->getUnit(), 'in');
20 public function testToString()
22 $l = new HTMLPurifier_Length('23', 'in');
23 $this->assertIdentical($l->toString(), '23in');
26 protected function assertValidate($string, $expect = true)
28 if ($expect === true) $expect = $string;
29 $l = HTMLPurifier_Length::make($string);
30 $result = $l->isValid();
31 if ($result === false) $this->assertIdentical($expect, false);
32 else $this->assertIdentical($l->toString(), $expect);
35 public function testValidate()
37 $this->assertValidate('0');
38 $this->assertValidate('+0', '0');
39 $this->assertValidate('-0', '0');
40 $this->assertValidate('0px');
41 $this->assertValidate('4.5px');
42 $this->assertValidate('-4.5px');
43 $this->assertValidate('3ex');
44 $this->assertValidate('3em');
45 $this->assertValidate('3in');
46 $this->assertValidate('3cm');
47 $this->assertValidate('3mm');
48 $this->assertValidate('3pt');
49 $this->assertValidate('3pc');
50 $this->assertValidate('3PX', '3px');
51 $this->assertValidate('3', false);
52 $this->assertValidate('3miles', false);
55 /**
56 * @param $s1 First string to compare
57 * @param $s2 Second string to compare
58 * @param $expect 0 for $s1 == $s2, 1 for $s1 > $s2 and -1 for $s1 < $s2
60 protected function assertComparison($s1, $s2, $expect = 0)
62 $l1 = HTMLPurifier_Length::make($s1);
63 $l2 = HTMLPurifier_Length::make($s2);
64 $r1 = $l1->compareTo($l2);
65 $r2 = $l2->compareTo($l1);
66 $this->assertIdentical($r1 == 0 ? 0 : ($r1 > 0 ? 1 : -1), $expect);
67 $this->assertIdentical($r2 == 0 ? 0 : ($r2 > 0 ? 1 : -1), - $expect);
70 public function testCompareTo()
72 $this->assertComparison('12in', '12in');
73 $this->assertComparison('12in', '12mm', 1);
74 $this->assertComparison('1px', '1mm', -1);
75 $this->assertComparison(str_repeat('2', 38) . 'in', '100px', 1);
80 // vim: et sw=4 sts=4