-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from Icinga/tlvnodetests
Add some basic node tests
- Loading branch information
Showing
4 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
test/php/library/Toplevelview/Tree/TLVHostGroupNodeTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
33
test/php/library/Toplevelview/Tree/TLVServiceGroupNodeTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |