From 682c2619d45e26b3c9b336e2bd3b8cf9aee16cc6 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 25 Feb 2016 19:21:10 +0100 Subject: [PATCH] IcingaHostTest: add Icinga Host object tests --- .../Director/Objects/IcingaHostTest.php | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 test/php/library/Director/Objects/IcingaHostTest.php diff --git a/test/php/library/Director/Objects/IcingaHostTest.php b/test/php/library/Director/Objects/IcingaHostTest.php new file mode 100644 index 00000000..80072c39 --- /dev/null +++ b/test/php/library/Director/Objects/IcingaHostTest.php @@ -0,0 +1,117 @@ +host(); + $host->display_name = 'Something else'; + $this->assertEquals( + $host->display_name, + 'Something else' + ); + } + + public function testWhetherHostsCanBeReplaced() + { + $host = $this->host(); + $newHost = IcingaHost::create( + array('display_name' => 'Replaced display') + ); + + $this->assertEquals( + count($host->vars()), + 3 + ); + $this->assertEquals( + $host->address, + '127.0.0.127' + ); + + $host->replaceWith($newHost); + $this->assertEquals( + $host->display_name, + 'Replaced display' + ); + $this->assertEquals( + $host->address, + null + ); + + $this->assertEquals( + count($host->vars()), + 0 + ); + } + + public function testWhetherHostsCanBeMerged() + { + $host = $this->host(); + $newHost = IcingaHost::create( + array('display_name' => 'Replaced display') + ); + + $this->assertEquals( + count($host->vars()), + 3 + ); + $this->assertEquals( + $host->address, + '127.0.0.127' + ); + + $host->merge($newHost); + $this->assertEquals( + $host->display_name, + 'Replaced display' + ); + $this->assertEquals( + $host->address, + '127.0.0.127' + ); + $this->assertEquals( + count($host->vars()), + 3 + ); + } + + public function testWhetherDistinctCustomVarsCanBeSetWithoutSideEffects() + { + $host = $this->host(); + $host->set('vars.test2', 18); + $this->assertEquals( + $host->vars()->test1->getValue(), + 'string' + ); + $this->assertEquals( + $host->vars()->test2->getValue(), + 18 + ); + $this->assertEquals( + $host->vars()->test3->getValue(), + false + ); + } + + protected function host() + { + return IcingaHost::create(array( + 'object_name' => $this->testHostName, + 'object_type' => 'object', + 'address' => '127.0.0.127', + 'display_name' => 'Whatever', + 'vars' => array( + 'test1' => 'string', + 'test2' => 17, + 'test3' => false, + ) + )); + } +}