Skip to content

Commit f29673b

Browse files
committed
Test: Introduce basic dashboard test cases
1 parent d32cbe3 commit f29673b

File tree

4 files changed

+415
-0
lines changed

4 files changed

+415
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?php
2+
3+
/* Icinga Web 2 | (c) 2022 Icinga GmbH | GPLv2+ */
4+
5+
namespace Tests\Icinga\Web\Dashboard;
6+
7+
use Icinga\Exception\ProgrammingError;
8+
use Icinga\Test\BaseDashboardTestCase;
9+
10+
class BaseDashboardTestCaseTest extends BaseDashboardTestCase
11+
{
12+
public function testWhetherAddEntryAddsAnEntry()
13+
{
14+
$this->dashboard->addEntry($this->getTestHome());
15+
16+
$this->assertTrue(
17+
$this->dashboard->hasEntry(self::TEST_HOME),
18+
'DashboardEntries::addEntry() could not add a Dashboard entry'
19+
);
20+
}
21+
22+
/**
23+
* @depends testWhetherAddEntryAddsAnEntry
24+
*/
25+
public function testWhetherAddEntryAddsDifferentEntries()
26+
{
27+
$this->dashboard->addEntry($this->getTestHome());
28+
$this->dashboard->addEntry($this->getTestHome('Second Home'));
29+
$this->dashboard->addEntry($this->getTestHome('Third Home'));
30+
31+
$this->assertCount(
32+
3,
33+
$this->dashboard->getEntries(),
34+
'DashboardEntries::addEntry() could not add different Dashboard entries'
35+
);
36+
}
37+
38+
/**
39+
* @depends testWhetherAddEntryAddsDifferentEntries
40+
*/
41+
public function testMergeEntryWithSameEntryName()
42+
{
43+
$this->dashboard->addEntry($this->getTestHome());
44+
$this->dashboard->addEntry($this->getTestHome('Second Home'));
45+
$this->dashboard->addEntry($this->getTestHome('Second Home'));
46+
47+
$this->assertCount(
48+
2,
49+
$this->dashboard->getEntries(),
50+
'DashboardEntries::addEntry() could not merge same Dashboard entries'
51+
);
52+
}
53+
54+
/**
55+
* @depends testMergeEntryWithSameEntryName
56+
*/
57+
public function testWhetherGetEntriesReturnsExpectedEntries()
58+
{
59+
$this->dashboard->addEntry($this->getTestHome());
60+
61+
$this->assertCount(
62+
1,
63+
$this->dashboard->getEntries(),
64+
'DashboardEntries::getEntries() returns unexpected dashboard entries'
65+
);
66+
}
67+
68+
public function testeWhetherGetEntryThrowsAnExceptionOnNotExistentEntryName()
69+
{
70+
$this->expectException(ProgrammingError::class);
71+
72+
$this->dashboard->getEntry('test');
73+
}
74+
75+
/**
76+
* @depends testeWhetherGetEntryThrowsAnExceptionOnNotExistentEntryName
77+
*/
78+
public function testWhetherGetEntryGetsAnEntryByName()
79+
{
80+
$this->dashboard->addEntry($this->getTestHome());
81+
82+
$this->assertEquals(
83+
self::TEST_HOME,
84+
$this->dashboard->getEntry(self::TEST_HOME)->getName(),
85+
'DashboardEntries:getEntry() could not return Dashboard entry by name'
86+
);
87+
}
88+
89+
/**
90+
* @depends testMergeEntryWithSameEntryName
91+
*/
92+
public function testWhetherHasEntriesHasNoEntries()
93+
{
94+
$this->assertFalse(
95+
$this->dashboard->hasEntries(),
96+
'DashboardEntries::hasEntries() has Dashboard entries but should not'
97+
);
98+
}
99+
100+
/**
101+
* @depends testWhetherHasEntriesHasNoEntries
102+
*/
103+
public function testWhetherHasEntriesHasEntries()
104+
{
105+
$this->dashboard->addEntry($this->getTestHome());
106+
107+
$this->assertTrue(
108+
$this->dashboard->hasEntries(),
109+
'DashboardEntries::hasEntries() could not return valid expectation'
110+
);
111+
}
112+
113+
/**
114+
* @depends testWhetherHasEntriesHasEntries
115+
*/
116+
public function testWhetherGetEntryKeyTitleArrayReturnFormedArray()
117+
{
118+
$this->dashboard->addEntry(($this->getTestHome())->setTitle('First Home'));
119+
$this->dashboard->addEntry(($this->getTestHome('Test2')->setTitle('Second Home')));
120+
$this->dashboard->addEntry(($this->getTestHome('Test3')->setTitle('Third Home')));
121+
122+
$expected = [
123+
self::TEST_HOME => 'First Home',
124+
'Test2' => 'Second Home',
125+
'Test3' => 'Third Home'
126+
];
127+
128+
$this->assertEquals(
129+
$expected,
130+
$this->dashboard->getEntryKeyTitleArr(),
131+
'DashboardEntries::getEntryKeyTitleArray() could not return valid expectation'
132+
);
133+
}
134+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
/* Icinga Web 2 | (c) 2022 Icinga GmbH | GPLv2+ */
4+
5+
namespace Tests\Icinga\Web\Dashboard;
6+
7+
use Icinga\Test\BaseDashboardTestCase;
8+
9+
class DashletTest extends BaseDashboardTestCase
10+
{
11+
12+
}
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?php
2+
3+
/* Icinga Web 2 | (c) 2022 Icinga GmbH | GPLv2+ */
4+
5+
namespace Tests\Icinga\Web\Dashboard;
6+
7+
use Icinga\Exception\Http\HttpNotFoundException;
8+
use Icinga\Exception\ProgrammingError;
9+
use Icinga\Test\BaseDashboardTestCase;
10+
11+
class HomeTest extends BaseDashboardTestCase
12+
{
13+
public function testWhetherManageEntryManagesANewHomeEntry()
14+
{
15+
$this->dashboard->manageEntry($this->getTestHome());
16+
$this->dashboard->load(self::TEST_HOME);
17+
18+
$this->assertCount(
19+
1,
20+
$this->dashboard->getEntries(),
21+
'Dashboard::manageEntry() could not manage a new Dashboard Home'
22+
);
23+
}
24+
25+
/**
26+
* @depends testWhetherManageEntryManagesANewHomeEntry
27+
*/
28+
public function testWhetherManageEntryUpdatesExistingHomeEntry()
29+
{
30+
$this->dashboard->manageEntry($this->getTestHome());
31+
$this->dashboard->load(self::TEST_HOME);
32+
33+
$home = $this->dashboard->getEntry(self::TEST_HOME);
34+
$home->setTitle('Hello');
35+
36+
$this->dashboard->manageEntry($home);
37+
$this->dashboard->load(self::TEST_HOME);
38+
39+
$home = $this->dashboard->getEntry(self::TEST_HOME);
40+
41+
$this->assertEquals(
42+
'Hello',
43+
$home->getTitle(),
44+
'Dashboard::manageEntry() could not update existing Dashboard Home'
45+
);
46+
}
47+
48+
/**
49+
* @depends testWhetherManageEntryUpdatesExistingHomeEntry
50+
*/
51+
public function testWhetherRemoveEntryThrowsAnExceptionIfNotExists()
52+
{
53+
$this->expectException(ProgrammingError::class);
54+
55+
$this->dashboard->removeEntry('test');
56+
}
57+
58+
/**
59+
* @depends testWhetherRemoveEntryThrowsAnExceptionIfNotExists
60+
*/
61+
public function testWhetherRemoveEntryRemovesExpectedHomeEntry()
62+
{
63+
$this->dashboard->manageEntry($this->getTestHome('Second Home'));
64+
$this->dashboard->load();
65+
66+
$this->dashboard->removeEntry('Second Home');
67+
$this->dashboard->load();
68+
69+
$this->assertFalse(
70+
$this->dashboard->hasEntry('Second Home'),
71+
'Dashboard::removeEntry() could not remove expected Dashboard Home entry'
72+
);
73+
}
74+
75+
/**
76+
* @depends testWhetherRemoveEntryRemovesExpectedHomeEntry
77+
*/
78+
public function testWhetherRemoveEntriesRemovesAllHomeEntries()
79+
{
80+
$this->dashboard->manageEntry($this->getTestHome('Second Home'));
81+
$this->dashboard->load();
82+
83+
$this->dashboard->removeEntries();
84+
$this->dashboard->load();
85+
86+
$this->assertTrue(
87+
$this->dashboard->hasEntries(),
88+
'Dashboard::removeEntries() could not remove all Dashboard Homes'
89+
);
90+
}
91+
92+
/**
93+
* @depends testWhetherRemoveEntriesRemovesAllHomeEntries
94+
*/
95+
public function testWhetherLoadHomesLoadsNullHomes()
96+
{
97+
$this->dashboard->load();
98+
99+
$this->assertFalse(
100+
$this->dashboard->hasEntries(),
101+
'Dashboard::load() has loaded Dashboard Homes but should not'
102+
);
103+
}
104+
105+
public function testWhetherLoadHomeByNameThrowsAnExceptionIfNotExists()
106+
{
107+
$this->expectException(HttpNotFoundException::class);
108+
109+
$this->dashboard->load('test');
110+
}
111+
112+
public function testWhetherLoadHomesActivatesFirstHome()
113+
{
114+
$this->dashboard->manageEntry([$this->getTestHome(), $this->getTestHome('Second Home')]);
115+
116+
$this->dashboard->load();
117+
118+
$this->assertEquals(
119+
self::TEST_HOME,
120+
$this->dashboard->getActiveHome()->getName(),
121+
'Dashboard::load() could not activate expected Dashboard Home'
122+
);
123+
}
124+
125+
/**
126+
* @depends testWhetherLoadHomesActivatesFirstHome
127+
*/
128+
public function testWhetherActivateHomeActivatesAHomeEntry()
129+
{
130+
$this->dashboard->manageEntry([$this->getTestHome(), $this->getTestHome('Second Home')]);
131+
$this->dashboard->load();
132+
133+
$active = $this->dashboard->getEntry('Second Home');
134+
$this->dashboard->activateHome($active);
135+
136+
$this->assertTrue($active->getActive(), 'Dashboard::activateHome() could not activate expected Dashboard Home');
137+
}
138+
139+
/**
140+
* @depends testWhetherActivateHomeActivatesAHomeEntry
141+
*/
142+
public function testWhetherGetActiveHomeGetsExpectedHome()
143+
{
144+
$this->dashboard->addEntry($this->getTestHome());
145+
$this->dashboard->addEntry($this->getTestHome('Second Home'));
146+
147+
$active = $this->dashboard->getEntry(self::TEST_HOME);
148+
$this->dashboard->activateHome($active);
149+
150+
$this->assertEquals(
151+
self::TEST_HOME,
152+
$this->dashboard->getActiveHome()->getName(),
153+
'Dashboard::getActiveHome() could not return expected Dashboard Home'
154+
);
155+
}
156+
}

0 commit comments

Comments
 (0)