From bf564b1b7a1d3e2dd16b496e8846c8af3897b9f2 Mon Sep 17 00:00:00 2001 From: Markus Opolka Date: Mon, 30 Sep 2024 16:34:07 +0200 Subject: [PATCH] Add some basic node tests --- .../Tree/TLVHostGroupNodeTest.php | 33 ++++++++++++ .../Toplevelview/Tree/TLVHostNodeTest.php | 53 +++++++++++++++++++ .../Tree/TLVServiceGroupNodeTest.php | 33 ++++++++++++ .../Toplevelview/Tree/TLVServiceNodeTest.php | 53 +++++++++++++++++++ 4 files changed, 172 insertions(+) create mode 100644 test/php/library/Toplevelview/Tree/TLVHostGroupNodeTest.php create mode 100644 test/php/library/Toplevelview/Tree/TLVHostNodeTest.php create mode 100644 test/php/library/Toplevelview/Tree/TLVServiceGroupNodeTest.php create mode 100644 test/php/library/Toplevelview/Tree/TLVServiceNodeTest.php diff --git a/test/php/library/Toplevelview/Tree/TLVHostGroupNodeTest.php b/test/php/library/Toplevelview/Tree/TLVHostGroupNodeTest.php new file mode 100644 index 0000000..ced27c5 --- /dev/null +++ b/test/php/library/Toplevelview/Tree/TLVHostGroupNodeTest.php @@ -0,0 +1,33 @@ +setProperties(['hostgroup'=>'unit']); + $this->assertSame('unit', $n->getKey()); + + $mockRoot = new class { + public function getFetched($type, $key) { + $h = new stdClass; + $h->display_name = 'host'; + } + }; + + $reflection = new ReflectionClass($n); + $reflection_root = $reflection->getProperty('root'); + $reflection_root->setAccessible(true); + $reflection_root->setValue($n, $mockRoot); + + $this->assertSame('unit', $n->getTitle()); + } +} diff --git a/test/php/library/Toplevelview/Tree/TLVHostNodeTest.php b/test/php/library/Toplevelview/Tree/TLVHostNodeTest.php new file mode 100644 index 0000000..d27a8aa --- /dev/null +++ b/test/php/library/Toplevelview/Tree/TLVHostNodeTest.php @@ -0,0 +1,53 @@ +setProperties(['host'=>'unit']); + $this->assertSame('unit', $n->getKey()); + + $mockRoot = new class { + public function getFetched($type, $key) { + $h = new stdClass; + $h->display_name = 'host'; + } + }; + + $reflection = new ReflectionClass($n); + $reflection_root = $reflection->getProperty('root'); + $reflection_root->setAccessible(true); + $reflection_root->setValue($n, $mockRoot); + + $this->assertSame('unit', $n->getTitle()); + } + + public function testGetStatus() + { + $n = new TLVHostNode(); + $n->setProperties(['host'=>'unit']); + + $mockRoot = new class { + public function getFetched($type, $key) { + $h = new stdClass; + $h->display_name = 'host'; + } + }; + + $reflection = new ReflectionClass($n); + $reflection_root = $reflection->getProperty('root'); + $reflection_root->setAccessible(true); + $reflection_root->setValue($n, $mockRoot); + + $this->assertSame('missing', $n->getStatus()->getOverall()); + } +} diff --git a/test/php/library/Toplevelview/Tree/TLVServiceGroupNodeTest.php b/test/php/library/Toplevelview/Tree/TLVServiceGroupNodeTest.php new file mode 100644 index 0000000..4fb16f1 --- /dev/null +++ b/test/php/library/Toplevelview/Tree/TLVServiceGroupNodeTest.php @@ -0,0 +1,33 @@ +setProperties(['servicegroup'=>'unit']); + $this->assertSame('unit', $n->getKey()); + + $mockRoot = new class { + public function getFetched($type, $key) { + $h = new stdClass; + $h->display_name = 'service'; + } + }; + + $reflection = new ReflectionClass($n); + $reflection_root = $reflection->getProperty('root'); + $reflection_root->setAccessible(true); + $reflection_root->setValue($n, $mockRoot); + + $this->assertSame('unit', $n->getTitle()); + } +} diff --git a/test/php/library/Toplevelview/Tree/TLVServiceNodeTest.php b/test/php/library/Toplevelview/Tree/TLVServiceNodeTest.php new file mode 100644 index 0000000..56023af --- /dev/null +++ b/test/php/library/Toplevelview/Tree/TLVServiceNodeTest.php @@ -0,0 +1,53 @@ +setProperties(['service'=>'unit', 'host'=>'test']); + $this->assertSame('test!unit', $n->getKey()); + + $mockRoot = new class { + public function getFetched($type, $key) { + $h = new stdClass; + $h->display_name = 'service'; + } + }; + + $reflection = new ReflectionClass($n); + $reflection_root = $reflection->getProperty('root'); + $reflection_root->setAccessible(true); + $reflection_root->setValue($n, $mockRoot); + + $this->assertSame('test: unit', $n->getTitle()); + } + + public function testGetStatus() + { + $n = new TLVServiceNode(); + $n->setProperties(['service'=>'unit', 'host'=>'test']); + + $mockRoot = new class { + public function getFetched($type, $key) { + $h = new stdClass; + $h->display_name = 'service'; + } + }; + + $reflection = new ReflectionClass($n); + $reflection_root = $reflection->getProperty('root'); + $reflection_root->setAccessible(true); + $reflection_root->setValue($n, $mockRoot); + + $this->assertSame('missing', $n->getStatus()->getOverall()); + } +}