diff --git a/library/Toplevelview/Tree/TLVIcingaNode.php b/library/Toplevelview/Tree/TLVIcingaNode.php index 7001447..5dab18d 100644 --- a/library/Toplevelview/Tree/TLVIcingaNode.php +++ b/library/Toplevelview/Tree/TLVIcingaNode.php @@ -5,6 +5,9 @@ use Icinga\Exception\NotImplementedError; +/** + * @codeCoverageIgnore + */ class TLVIcingaNode extends TLVTreeNode { protected static $canHaveChildren = false; diff --git a/library/Toplevelview/Web/Controller.php b/library/Toplevelview/Web/Controller.php index 580bf74..ce7d2b6 100644 --- a/library/Toplevelview/Web/Controller.php +++ b/library/Toplevelview/Web/Controller.php @@ -10,6 +10,7 @@ * Controller wraps around the Icinga\Web\Controller to * check for the PHP YAML extension * + * @codeCoverageIgnore * @throws ConfigurationError if the PHP yaml extension is not loaded */ class Controller extends CompatController diff --git a/test/php/library/Toplevelview/Tree/TLVHostGroupNodeTest.php b/test/php/library/Toplevelview/Tree/TLVHostGroupNodeTest.php index ced27c5..627260a 100644 --- a/test/php/library/Toplevelview/Tree/TLVHostGroupNodeTest.php +++ b/test/php/library/Toplevelview/Tree/TLVHostGroupNodeTest.php @@ -30,4 +30,48 @@ public function getFetched($type, $key) { $this->assertSame('unit', $n->getTitle()); } + + public function testGetStatus() + { + $n = new TLVHostGroupNode(); + $n->setProperties(['hostgroup'=>'unit']); + + $mockRoot = new class { + public function get($thing) { + return false; + } + public function getFetched($type, $key) { + $h = new stdClass; + $s = new stdClass; + $s->hard_state = 1; + $s->is_handled = true; + $s->in_downtime = true; + $h->display_name = 'hostgroup'; + + $h->hosts_total = 1; + $h->hosts_up = 1; + $h->hosts_total = 1; + $h->services_total = 1; + $h->hosts_up = 1; + $h->services_ok = 1; + $h->hosts_down_handled = 1; + $h->hosts_down_unhandled = 1; + $h->services_warning_handled = 1; + $h->services_warning_unhandled = 1; + $h->services_critical_handled = 1; + $h->services_critical_unhandled = 1; + $h->services_unknown_handled = 1; + $h->services_unknown_unhandled = 1; + + return $h; + } + }; + + $reflection = new ReflectionClass($n); + $reflection_root = $reflection->getProperty('root'); + $reflection_root->setAccessible(true); + $reflection_root->setValue($n, $mockRoot); + + $this->assertSame('critical unhandled', $n->getStatus()->getOverall()); + } } diff --git a/test/php/library/Toplevelview/Tree/TLVHostNodeTest.php b/test/php/library/Toplevelview/Tree/TLVHostNodeTest.php index d27a8aa..d4755cd 100644 --- a/test/php/library/Toplevelview/Tree/TLVHostNodeTest.php +++ b/test/php/library/Toplevelview/Tree/TLVHostNodeTest.php @@ -37,9 +37,19 @@ public function testGetStatus() $n->setProperties(['host'=>'unit']); $mockRoot = new class { + public function get($thing) { + return false; + } public function getFetched($type, $key) { $h = new stdClass; $h->display_name = 'host'; + $s = new stdClass; + $s->hard_state = 2; + $s->is_handled = false; + $s->in_downtime = false; + $h->notifications_enabled = false; + $h->state = $s; + return $h; } }; @@ -48,6 +58,6 @@ public function getFetched($type, $key) { $reflection_root->setAccessible(true); $reflection_root->setValue($n, $mockRoot); - $this->assertSame('missing', $n->getStatus()->getOverall()); + $this->assertSame('critical unhandled', $n->getStatus()->getOverall()); } } diff --git a/test/php/library/Toplevelview/Tree/TLVServiceGroupNodeTest.php b/test/php/library/Toplevelview/Tree/TLVServiceGroupNodeTest.php index 4fb16f1..78d9ce4 100644 --- a/test/php/library/Toplevelview/Tree/TLVServiceGroupNodeTest.php +++ b/test/php/library/Toplevelview/Tree/TLVServiceGroupNodeTest.php @@ -30,4 +30,42 @@ public function getFetched($type, $key) { $this->assertSame('unit', $n->getTitle()); } + + public function testGetStatus() + { + $n = new TLVServiceGroupNode(); + $n->setProperties(['servicegroup'=>'unit']); + + $mockRoot = new class { + public function get($thing) { + return false; + } + public function getFetched($type, $key) { + $h = new stdClass; + $s = new stdClass; + $s->hard_state = 1; + $s->is_handled = true; + $s->in_downtime = true; + $h->display_name = 'servicegroup'; + + $h->services_total = 1; + $h->services_ok = 1; + $h->services_warning_handled = 1; + $h->services_warning_unhandled = 1; + $h->services_critical_handled = 1; + $h->services_critical_unhandled = 1; + $h->services_unknown_handled = 1; + $h->services_unknown_unhandled = 1; + + return $h; + } + }; + + $reflection = new ReflectionClass($n); + $reflection_root = $reflection->getProperty('root'); + $reflection_root->setAccessible(true); + $reflection_root->setValue($n, $mockRoot); + + $this->assertSame('critical unhandled', $n->getStatus()->getOverall()); + } } diff --git a/test/php/library/Toplevelview/Tree/TLVServiceNodeTest.php b/test/php/library/Toplevelview/Tree/TLVServiceNodeTest.php index 56023af..ef1bec6 100644 --- a/test/php/library/Toplevelview/Tree/TLVServiceNodeTest.php +++ b/test/php/library/Toplevelview/Tree/TLVServiceNodeTest.php @@ -37,9 +37,19 @@ public function testGetStatus() $n->setProperties(['service'=>'unit', 'host'=>'test']); $mockRoot = new class { + public function get($thing) { + return false; + } public function getFetched($type, $key) { $h = new stdClass; + $s = new stdClass; + $s->hard_state = 1; + $s->is_handled = true; + $s->in_downtime = true; $h->display_name = 'service'; + $h->notifications_enabled = false; + $h->state = $s; + return $h; } }; @@ -48,6 +58,6 @@ public function getFetched($type, $key) { $reflection_root->setAccessible(true); $reflection_root->setValue($n, $mockRoot); - $this->assertSame('missing', $n->getStatus()->getOverall()); + $this->assertSame('downtime handled', $n->getStatus()->getOverall()); } } diff --git a/test/php/library/Toplevelview/Tree/TLVTreeNodeTest.php b/test/php/library/Toplevelview/Tree/TLVTreeNodeTest.php new file mode 100644 index 0000000..bd718c0 --- /dev/null +++ b/test/php/library/Toplevelview/Tree/TLVTreeNodeTest.php @@ -0,0 +1,29 @@ +setProperties(['name' => 'bar']); + $this->assertSame('bar', $n->getTitle()); + + $this->assertSame(['name' => 'bar'], $n->getProperties()); + + $n->set('name', 'foo'); + $this->assertSame('foo', $n->getTitle()); + } + + public function testGetBreadCrumb() + { + $n = new TLVTreeNode(); + $this->assertSame([$n], $n->getBreadCrumb()); + } +} diff --git a/test/php/library/Toplevelview/ViewConfigTest.php b/test/php/library/Toplevelview/ViewConfigTest.php index 30f28fa..25971ca 100644 --- a/test/php/library/Toplevelview/ViewConfigTest.php +++ b/test/php/library/Toplevelview/ViewConfigTest.php @@ -92,4 +92,16 @@ public function testViewConfigWithSession() $this->assertFalse($view->hasBeenLoadedFromSession()); $this->assertTrue($view2->hasBeenLoadedFromSession()); } + + public function testViewConfigTree() + { + $c = new ViewConfig('test/testdata'); + $view = $c->loadByName('example'); + + $t = $view->getTree(); + $this->assertSame('5fc0ad55066b871d376eee60c84300d32ac7cb1d', $t->getViewChecksum()); + $this->assertSame('example', $t->getViewName()); + $t->setCacheLifetime(120); + $this->assertSame(120, $t->getCacheLifetime()); + } }