Debian Codegraph @

test/php/library/Toplevelview/Tree/TLVServiceGroupNodeTest.php

raw
1 <?php
2
3 namespace Tests\Icinga\Module\Toplevelview;
4
5 use Icinga\Module\Toplevelview\Tree\TLVServiceGroupNode;
6
7 use PHPUnit\Framework\TestCase;
8 use stdClass;
9 use ReflectionClass;
10
11 final class TLVServiceGroupNodeTest extends TestCase
12 {
13 public function testGetTitle()
14 {
15 $n = new TLVServiceGroupNode();
16 $n->setProperties(['servicegroup'=>'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 = 'service';
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 TLVServiceGroupNode();
36 $n->setProperties(['servicegroup'=>'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 $s = new stdClass;
45 $s->hard_state = 1;
46 $s->is_handled = true;
47 $s->in_downtime = true;
48 $h->display_name = 'servicegroup';
49
50 $h->services_total = 1;
51 $h->services_ok = 1;
52 $h->services_warning_handled = 1;
53 $h->services_warning_unhandled = 1;
54 $h->services_critical_handled = 1;
55 $h->services_critical_unhandled = 1;
56 $h->services_unknown_handled = 1;
57 $h->services_unknown_unhandled = 1;
58 $h->services_downtime_handled = 1;
59 $h->services_downtime_active = 1;
60
61 return $h;
62 }
63 };
64
65 $reflection = new ReflectionClass($n);
66 $reflection_root = $reflection->getProperty('root');
67 $reflection_root->setValue($n, $mockRoot);
68
69 $this->assertSame('critical unhandled', $n->getStatus()->getOverall());
70 }
71 }