Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some basic node tests #87

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}