diff --git a/test/php/library/Icingadb/Util/PerfdataTest.php b/test/php/library/Icingadb/Util/PerfdataTest.php index e31c86d00..d3e63d14f 100644 --- a/test/php/library/Icingadb/Util/PerfdataTest.php +++ b/test/php/library/Icingadb/Util/PerfdataTest.php @@ -259,6 +259,17 @@ public function testWhetherGetMinimumValueReturnsCorrectValues() Perfdata::fromString('test=1;;;1337.5')->getMinimumValue(), 'Perfdata::getMinimumValue does not return correct values' ); + + $this->assertSame( + '10,00', + Perfdata::fromString('test=1;;;;10,00')->getMinimumValue(), + 'Perfdata::getMinimumValue does not return correct values' + ); + $this->assertSame( + 'foo', + Perfdata::fromString('test=1;;;;foo')->getMinimumValue(), + 'Perfdata::getMinimumValue does not return correct values' + ); } /** @@ -276,6 +287,16 @@ public function testWhetherGetMaximumValueReturnsCorrectValues() Perfdata::fromString('test=1;;;;1337.5')->getMaximumValue(), 'Perfdata::getMaximumValue does not return correct values' ); + $this->assertSame( + '10,00', + Perfdata::fromString('test=1;;;;10,00')->getMaximumValue(), + 'Perfdata::getMaximumValue does not return correct values' + ); + $this->assertSame( + 'foo', + Perfdata::fromString('test=1;;;;foo')->getMaximumValue(), + 'Perfdata::getMaximumValue does not return correct values' + ); } /** @@ -399,4 +420,16 @@ public function testWhetherPercentagesAreHandledCorrectly() 'Perfdata objects do not ignore impossible min/max combinations when returning percentages' ); } + + /** + * @depends testWhetherFromStringParsesAGivenStringCorrectly + */ + public function testInvalidPerfDataHandling() + { + $this->assertFalse(Perfdata::fromString('test=1;;;2,00;10,00')); + $this->assertFalse(Perfdata::fromString('test=1;;;foo;1000')); + $this->assertFalse(Perfdata::fromString('test=1;10@:')); + $this->assertFalse(Perfdata::fromString('test=1;foo:')); + $this->assertFalse(Perfdata::fromString('test=1;2,2:4,4')); + } } diff --git a/test/php/library/Icingadb/Util/ThresholdRangeTest.php b/test/php/library/Icingadb/Util/ThresholdRangeTest.php index c0d757371..b191e8804 100644 --- a/test/php/library/Icingadb/Util/ThresholdRangeTest.php +++ b/test/php/library/Icingadb/Util/ThresholdRangeTest.php @@ -319,5 +319,25 @@ public function testInvalidThresholdNotationsAreRenderedAsIs() 'foo', (string) ThresholdRange::fromString('foo') ); + $this->assertSame( + '4,4:2,2', + (string) ThresholdRange::fromString('4,4:2,2') + ); + } + + public function testInvalidThresholdNotationsConsideredInValid() + { + $this->assertFalse( + ThresholdRange::fromString('10@')->isValid(), + 'Invalid threshold notation 10@ considered as valid' + ); + $this->assertFalse( + ThresholdRange::fromString('foo')->isValid(), + 'Invalid threshold notation foo considered as valid' + ); + $this->assertFalse( + ThresholdRange::fromString('4,4:2,2')->isValid(), + 'Invalid threshold notation 4,4:2,2 considered as valid' + ); } }