icingaweb2-module-businessp.../test/php/library/Businessprocess/HostNodeTest.php
Eric Lippmann 0ce3381488 License source files as GPL-3.0-or-later
Add SPDX license headers and mark source files as GPL-3.0-or-later to
preserve the option to relicense under later GPL versions.
2026-03-11 20:44:42 +01:00

66 lines
1.7 KiB
PHP

<?php
// SPDX-FileCopyrightText: 2018 Icinga GmbH <https://icinga.com>
// SPDX-License-Identifier: GPL-3.0-or-later
namespace Tests\Icinga\Module\Businessprocess;
use Icinga\Module\Businessprocess\BpConfig;
use Icinga\Module\Businessprocess\HostNode;
use Icinga\Module\Businessprocess\Test\BaseTestCase;
class HostNodeTest extends BaseTestCase
{
public function testReturnsCorrectHostName()
{
$this->assertEquals(
'localhost',
$this->localhost()->getHostname()
);
}
public function testReturnsCorrectIdentifierWhenCastedToString()
{
$this->assertEquals(
'localhost;Hoststatus',
$this->localhost()->getName()
);
}
public function testReturnsCorrectAlias()
{
$this->assertEquals(
'localhost',
$this->localhost()->getAlias()
);
}
public function testRendersCorrectLink()
{
$this->assertEquals(
'<a href="/icingaweb2/businessprocess/host/show?host=localhost">'
. 'localhost</a>',
$this->localhost()->getLink()->render()
);
}
public function testSettingAnInvalidStateFails()
{
$this->expectException(\Icinga\Exception\ProgrammingError::class);
$bp = new BpConfig();
$host = $bp->createHost('localhost')->setState(98);
$bp->createBp('p')->addChild($host)->getState();
}
/**
* @return HostNode
*/
protected function localhost()
{
$bp = new BpConfig();
return (new HostNode((object) array(
'hostname' => 'localhost',
'state' => 0,
)))->setBpConfig($bp)->setAlias('localhost');
}
}