parent
2b25757e20
commit
ec17efe328
test/php/library/Icinga/Util
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Util;
|
||||
|
||||
require_once("../../library/Icinga/Util/Dimension.php");
|
||||
use Icinga\Util\Dimension;
|
||||
|
||||
/**
|
||||
* Tests for the dimension class
|
||||
*
|
||||
*/
|
||||
class DimensionTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* Test Dimension creation from string
|
||||
*
|
||||
*/
|
||||
public function testStringFactoryWithValidInput()
|
||||
{
|
||||
$d = Dimension::fromString("200px");
|
||||
$this->assertEquals(200, $d->getValue(), "Asserting the numeric value of px input to be correctly parsed");
|
||||
$this->assertEquals(Dimension::UNIT_PX, $d->getUnit(), "Asserting the unit of px input to be correctly parsed");
|
||||
|
||||
$d = Dimension::fromString("40%");
|
||||
$this->assertEquals(40, $d->getValue(), "Asserting the numeric value of % input to be correctly parsed");
|
||||
$this->assertEquals(Dimension::UNIT_PERCENT, $d->getUnit(), "Asserting the unit of % input to be correctly parsed");
|
||||
|
||||
$d = Dimension::fromString("4044em");
|
||||
$this->assertEquals(4044, $d->getValue(), "Asserting the numeric value of em input to be correctly parsed");
|
||||
$this->assertEquals(Dimension::UNIT_EM, $d->getUnit(), "Asserting the unit of em input to be correctly parsed");
|
||||
|
||||
$d = Dimension::fromString("010pt");
|
||||
$this->assertEquals(10, $d->getValue(), "Asserting the numeric value of pt input to be correctly parsed");
|
||||
$this->assertEquals(Dimension::UNIT_PT, $d->getUnit(), "Asserting the unit of pt input to be correctly parsed");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test string creation from Dimension
|
||||
*
|
||||
*/
|
||||
public function testStringCreation()
|
||||
{
|
||||
$d = new Dimension(1000, Dimension::UNIT_PX);
|
||||
$this->assertEquals("1000px", (string) $d, "Asserting value-unit string creation to be correct");
|
||||
|
||||
$d = new Dimension(40.5, Dimension::UNIT_PT);
|
||||
$this->assertEquals("40pt", (string) $d, "Asserting float values being truncated by now");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testInvalidDimensions()
|
||||
{
|
||||
$d = new Dimension(-20, Dimension::UNIT_PX);
|
||||
$this->assertFalse($d->isDefined(), "Asserting a negative dimension to be considered invalid");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue