| 1 |
<?php |
| 2 |
|
| 3 |
namespace Tests\Icinga\Module\Toplevelview; |
| 4 |
|
| 5 |
use Icinga\Module\Toplevelview\Tree\TLVHostGroupNode; |
| 6 |
|
| 7 |
use PHPUnit\Framework\TestCase; |
| 8 |
use stdClass; |
| 9 |
use ReflectionClass; |
| 10 |
|
| 11 |
final class TLVHostGroupNodeTest extends TestCase |
| 12 |
{ |
| 13 |
public function testGetTitle() |
| 14 |
{ |
| 15 |
$n = new TLVHostGroupNode(); |
| 16 |
$n->setProperties(['hostgroup'=>'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 TLVHostGroupNode(); |
| 36 |
$n->setProperties(['hostgroup'=>'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 = 'hostgroup'; |
| 49 |
|
| 50 |
$h->hosts_total = 1; |
| 51 |
$h->hosts_up = 1; |
| 52 |
$h->hosts_total = 1; |
| 53 |
$h->services_total = 1; |
| 54 |
$h->hosts_up = 1; |
| 55 |
$h->services_ok = 1; |
| 56 |
$h->hosts_down_handled = 1; |
| 57 |
$h->hosts_down_unhandled = 1; |
| 58 |
$h->services_warning_handled = 1; |
| 59 |
$h->services_warning_unhandled = 1; |
| 60 |
$h->services_critical_handled = 1; |
| 61 |
$h->services_critical_unhandled = 1; |
| 62 |
$h->services_unknown_handled = 1; |
| 63 |
$h->services_unknown_unhandled = 1; |
| 64 |
$h->hosts_downtime_handled = 1; |
| 65 |
$h->hosts_downtime_active = 1; |
| 66 |
$h->services_downtime_handled = 1; |
| 67 |
$h->services_downtime_active = 1; |
| 68 |
|
| 69 |
return $h; |
| 70 |
} |
| 71 |
}; |
| 72 |
|
| 73 |
$reflection = new ReflectionClass($n); |
| 74 |
$reflection_root = $reflection->getProperty('root'); |
| 75 |
$reflection_root->setValue($n, $mockRoot); |
| 76 |
|
| 77 |
$this->assertSame('critical unhandled', $n->getStatus()->getOverall()); |
| 78 |
} |
| 79 |
} |