protected function assertConversion($input, $expect, $unit = null, $test_negative = true) { $length = HTMLPurifier_Length::make($input); if ($expect !== false) { $expectl = HTMLPurifier_Length::make($expect); } else { $expectl = false; } $to_unit = $unit !== null ? $unit : $expectl->getUnit(); $converter = new HTMLPurifier_UnitConverter(4, 10); $result = $converter->convert($length, $to_unit); if (!$result || !$expectl) { $this->assertIdentical($result, $expectl); } else { $this->assertIdentical($result->toString(), $expectl->toString()); } $converter = new HTMLPurifier_UnitConverter(4, 10, true); $result = $converter->convert($length, $to_unit); if (!$result || !$expectl) { $this->assertIdentical($result, $expectl); } else { $this->assertIdentical($result->toString(), $expectl->toString(), 'BCMath substitute: %s'); } if ($test_negative) { $this->assertConversion("-{$input}", $expect === false ? false : "-{$expect}", $unit, false); } }
/** * Compares two lengths, and returns 1 if greater, -1 if less and 0 if equal. * @param HTMLPurifier_Length $l * @return int * @warning If both values are too large or small, this calculation will * not work properly */ public function compareTo($l) { if ($l === false) { return false; } if ($l->unit !== $this->unit) { $converter = new HTMLPurifier_UnitConverter(); $l = $converter->convert($l, $this->unit); if ($l === false) { return false; } } return $this->n - $l->n; }