Debian Codegraph @

test/php/library/Toplevelview/Tree/TLVHostNodeTest.php

raw
1 <?php
2
3 namespace Tests\Icinga\Module\Toplevelview;
4
5 use Icinga\Module\Toplevelview\Tree\TLVHostNode;
6
7 use PHPUnit\Framework\TestCase;
8 use stdClass;
9 use ReflectionClass;
10
11 final class TLVHostNodeTest extends TestCase
12 {
13 public function testGetTitle()
14 {
15 $n = new TLVHostNode();
16 $n->setProperties(['host'=>'unit']);
17 $this->assertSame('unit', $n->getKey());
18
19 $mockRoot = new class {
20 public function getFetched($type, $key) {
21 $h = new stdClass;
22 $h->display_name = 'host';
23 }
24 };
25
26 $reflection = new ReflectionClass($n);
27 $reflection_root = $reflection->getProperty('root');
28 $reflection_root->setValue($n, $mockRoot);
29
30 $this->assertSame('unit', $n->getTitle());
31 }
32
33 public function testGetStatus()
34 {
35 $n = new TLVHostNode();
36 $n->setProperties(['host'=>'unit']);
37
38 $mockRoot = new class {
39 public function get($thing) {
40 return false;
41 }
42 public function getFetched($type, $key) {
43 $h = new stdClass;
44 $h->display_name = 'host';
45 $s = new stdClass;
46 $s->hard_state = 2;
47 $s->is_handled = false;
48 $s->in_downtime = false;
49 $h->notifications_enabled = false;
50 $h->state = $s;
51 return $h;
52 }
53 };
54
55 $reflection = new ReflectionClass($n);
56 $reflection_root = $reflection->getProperty('root');
57 $reflection_root->setValue($n, $mockRoot);
58
59 $this->assertSame('critical unhandled', $n->getStatus()->getOverall());
60 }
61 }