From ec17efe3282944adca5be16d1a703bf5a4bcd409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannis=20Mo=C3=9Fhammer?= Date: Tue, 6 Aug 2013 18:03:51 +0200 Subject: [PATCH] Add test for Dimension refs #4192 --- .../php/library/Icinga/Util/DimensionTest.php | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test/php/library/Icinga/Util/DimensionTest.php diff --git a/test/php/library/Icinga/Util/DimensionTest.php b/test/php/library/Icinga/Util/DimensionTest.php new file mode 100644 index 000000000..b4e721d35 --- /dev/null +++ b/test/php/library/Icinga/Util/DimensionTest.php @@ -0,0 +1,58 @@ +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"); + } +} \ No newline at end of file