From c774d686a0202518bf47784f1f3ce2a6f93f9f85 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 23 Nov 2016 20:55:57 +0100 Subject: [PATCH] NotOperatorTest: test NOT operator, parser and... ...state evaluation fixes #10315 --- .../Operators/NotOperatorTest.php | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 test/php/library/Businessprocess/Operators/NotOperatorTest.php diff --git a/test/php/library/Businessprocess/Operators/NotOperatorTest.php b/test/php/library/Businessprocess/Operators/NotOperatorTest.php new file mode 100644 index 0000000..d1fcbe9 --- /dev/null +++ b/test/php/library/Businessprocess/Operators/NotOperatorTest.php @@ -0,0 +1,85 @@ +emptyConfigSection()); + $expressions = array( + 'a = !b', + 'a = ! b', + 'a = b ! c ! d', + 'a = ! b ! c ! d !', + ); + + foreach ($expressions as $expression) { + $this->assertInstanceOf( + 'Icinga\\Module\\Businessprocess\\Businessprocess', + $storage->loadFromString('dummy', $expression) + ); + } + } + + public function testWhetherNegationsMatch() + { + $storage = new LegacyStorage($this->emptyConfigSection()); + $expression = 'a = !b'; + $bp = $storage->loadFromString('dummy', $expression); + $a = $bp->getNode('a'); + $b = $bp->createBp('b')->setState(3); + $this->assertEquals( + 'OK', + $a->getStateName() + ); + + $a->clearState(); + $b->setState(0); + $this->assertEquals( + 'CRITICAL', + $a->getStateName() + ); + } + + public function testWhetherNegatingMultipleValuesBehavesLikeNotAnd() + { + $storage = new LegacyStorage($this->emptyConfigSection()); + $expression = 'a = ! b ! c ! d'; + $bp = $storage->loadFromString('dummy', $expression); + $a = $bp->getNode('a'); + $b = $bp->createBp('b')->setState(3); + $c = $bp->createBp('c')->setState(3); + $d = $bp->createBp('d')->setState(3); + $this->assertEquals( + 'OK', + $a->getStateName() + ); + + $a->clearState(); + $b->setState(0); + $this->assertEquals( + 'OK', + $a->getStateName() + ); + + $a->clearState(); + $c->setState(0); + $this->assertEquals( + 'OK', + $a->getStateName() + ); + + $a->clearState(); + $d->setState(0); + $this->assertEquals( + 'CRITICAL', + $a->getStateName() + ); + } +} +