Skip to content

Commit

Permalink
Merge pull request #87 from Icinga/tlvnodetests
Browse files Browse the repository at this point in the history
Add some basic node tests
  • Loading branch information
martialblog authored Sep 30, 2024
2 parents 16d91d5 + bf564b1 commit 7bc23c1
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/php/library/Toplevelview/Tree/TLVHostGroupNodeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Tests\Icinga\Module\Toplevelview;

use Icinga\Module\Toplevelview\Tree\TLVHostGroupNode;

use PHPUnit\Framework\TestCase;
use stdClass;
use ReflectionClass;

final class TLVHostGroupNodeTest extends TestCase
{
public function testGetTitle()
{
$n = new TLVHostGroupNode();
$n->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());
}
}
53 changes: 53 additions & 0 deletions test/php/library/Toplevelview/Tree/TLVHostNodeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Tests\Icinga\Module\Toplevelview;

use Icinga\Module\Toplevelview\Tree\TLVHostNode;

use PHPUnit\Framework\TestCase;
use stdClass;
use ReflectionClass;

final class TLVHostNodeTest extends TestCase
{
public function testGetTitle()
{
$n = new TLVHostNode();
$n->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());
}
}
33 changes: 33 additions & 0 deletions test/php/library/Toplevelview/Tree/TLVServiceGroupNodeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Tests\Icinga\Module\Toplevelview;

use Icinga\Module\Toplevelview\Tree\TLVServiceGroupNode;

use PHPUnit\Framework\TestCase;
use stdClass;
use ReflectionClass;

final class TLVServiceGroupNodeTest extends TestCase
{
public function testGetTitle()
{
$n = new TLVServiceGroupNode();
$n->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());
}
}
53 changes: 53 additions & 0 deletions test/php/library/Toplevelview/Tree/TLVServiceNodeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Tests\Icinga\Module\Toplevelview;

use Icinga\Module\Toplevelview\Tree\TLVServiceNode;

use PHPUnit\Framework\TestCase;
use stdClass;
use ReflectionClass;

final class TLVServiceNodeTest extends TestCase
{
public function testGetTitle()
{
$n = new TLVServiceNode();
$n->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());
}
}

0 comments on commit 7bc23c1

Please sign in to comment.