1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-07-30 19:00:10 +02:00

Merged r1746: Length and UnitConverter implementation.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/branches/php4@1783 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2008-06-11 01:21:36 +00:00
parent 864cb9e136
commit 245b5bdb27
6 changed files with 337 additions and 1 deletions

View File

@@ -0,0 +1,51 @@
<?php
require_once 'HTMLPurifier/Length.php';
class HTMLPurifier_LengthTest extends HTMLPurifier_Harness
{
function testConstruct() {
$l = new HTMLPurifier_Length('23', 'in');
$this->assertIdentical($l->n, '23');
$this->assertIdentical($l->unit, 'in');
}
function testMake() {
$l = HTMLPurifier_Length::make('+23.4in');
$this->assertIdentical($l->n, '+23.4');
$this->assertIdentical($l->unit, 'in');
}
function testToString() {
$l = new HTMLPurifier_Length('23', 'in');
$this->assertIdentical($l->toString(), '23in');
}
function assertValidate($string, $expect = true, $disable_negative = false) {
if ($expect === true) $expect = $string;
$l = HTMLPurifier_Length::make($string);
$result = $l->validate($disable_negative, $this->config, $this->context);
if ($result === false) $this->assertIdentical($expect, false);
else $this->assertIdentical($l->toString(), $expect);
}
function testValidate() {
$this->assertValidate('0');
$this->assertValidate('0px');
$this->assertValidate('4.5px');
$this->assertValidate('-4.5px');
$this->assertValidate('3ex');
$this->assertValidate('3em');
$this->assertValidate('3in');
$this->assertValidate('3cm');
$this->assertValidate('3mm');
$this->assertValidate('3pt');
$this->assertValidate('3pc');
$this->assertValidate('3PX', '3px');
$this->assertValidate('3', false);
$this->assertValidate('3miles', false);
$this->assertValidate('-3mm', false, true); // no-negatives
}
}