File: HostNodeTest.php

package info (click to toggle)
icingaweb2-module-businessprocess 2.5.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,720 kB
  • sloc: php: 10,971; javascript: 2,019; sh: 115; xml: 49; makefile: 18
file content (63 lines) | stat: -rw-r--r-- 1,612 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php

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');
    }
}