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

[3.1.1] Added HTMLPurifier_UnitConverter and HTMLPurifier_Length for convenient handling of CSS-style lengths.

- Fixed another de-underscoring in the SimpleTest library

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1746 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2008-05-20 01:19:00 +00:00
parent 32a6afa27c
commit 16fa73afa0
6 changed files with 332 additions and 2 deletions

View File

@@ -76,7 +76,7 @@ class HTMLPurifier_Harness extends UnitTestCase
// __onlytest makes only one test get triggered
foreach (get_class_methods(get_class($this)) as $method) {
if (strtolower(substr($method, 0, 10)) == '__onlytest') {
$this->_reporter->paintSkip('All test methods in ' . $this->_label . ' besides ' . $method);
$this->reporter->paintSkip('All test methods besides ' . $method);
return array($method);
}
}

View File

@@ -0,0 +1,49 @@
<?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');
}
protected 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
}
}

View File

@@ -0,0 +1,42 @@
<?php
class HTMLPurifier_UnitConverterTest extends HTMLPurifier_Harness
{
protected function assertConversion($input, $expect) {
$input = HTMLPurifier_Length::make($input);
$expect = HTMLPurifier_Length::make($expect);
$converter = new HTMLPurifier_UnitConverter();
$result = $converter->convert($input, $expect->unit);
$this->assertIdentical($result, $expect);
}
function testEnglish() {
$this->assertConversion('1in', '6pc');
$this->assertConversion('6pc', '1in');
$this->assertConversion('1in', '72pt');
$this->assertConversion('72pt', '1in');
$this->assertConversion('1pc', '12pt');
$this->assertConversion('12pt', '1pc');
$this->assertConversion('1pt', '0.01389in');
$this->assertConversion('1.000pt', '0.01389in');
$this->assertConversion('100000pt', '1389in');
}
function testMetric() {
$this->assertConversion('1cm', '10mm');
$this->assertConversion('10mm', '1cm');
$this->assertConversion('1mm', '0.1cm');
$this->assertConversion('100mm', '10cm');
}
function testEnglishMetric() {
$this->assertConversion('2.835pt', '1mm');
$this->assertConversion('1mm', '2.835pt');
$this->assertConversion('0.3937in', '1cm');
}
}