-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test: Introduce basic dashboard test cases
- Loading branch information
Showing
4 changed files
with
415 additions
and
0 deletions.
There are no files selected for viewing
134 changes: 134 additions & 0 deletions
134
test/php/library/Icinga/Web/Dashboard/BaseDashboardTestCaseTest.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,134 @@ | ||
<?php | ||
|
||
/* Icinga Web 2 | (c) 2022 Icinga GmbH | GPLv2+ */ | ||
|
||
namespace Tests\Icinga\Web\Dashboard; | ||
|
||
use Icinga\Exception\ProgrammingError; | ||
use Icinga\Test\BaseDashboardTestCase; | ||
|
||
class BaseDashboardTestCaseTest extends BaseDashboardTestCase | ||
{ | ||
public function testWhetherAddEntryAddsAnEntry() | ||
{ | ||
$this->dashboard->addEntry($this->getTestHome()); | ||
|
||
$this->assertTrue( | ||
$this->dashboard->hasEntry(self::TEST_HOME), | ||
'DashboardEntries::addEntry() could not add a Dashboard entry' | ||
); | ||
} | ||
|
||
/** | ||
* @depends testWhetherAddEntryAddsAnEntry | ||
*/ | ||
public function testWhetherAddEntryAddsDifferentEntries() | ||
{ | ||
$this->dashboard->addEntry($this->getTestHome()); | ||
$this->dashboard->addEntry($this->getTestHome('Second Home')); | ||
$this->dashboard->addEntry($this->getTestHome('Third Home')); | ||
|
||
$this->assertCount( | ||
3, | ||
$this->dashboard->getEntries(), | ||
'DashboardEntries::addEntry() could not add different Dashboard entries' | ||
); | ||
} | ||
|
||
/** | ||
* @depends testWhetherAddEntryAddsDifferentEntries | ||
*/ | ||
public function testMergeEntryWithSameEntryName() | ||
{ | ||
$this->dashboard->addEntry($this->getTestHome()); | ||
$this->dashboard->addEntry($this->getTestHome('Second Home')); | ||
$this->dashboard->addEntry($this->getTestHome('Second Home')); | ||
|
||
$this->assertCount( | ||
2, | ||
$this->dashboard->getEntries(), | ||
'DashboardEntries::addEntry() could not merge same Dashboard entries' | ||
); | ||
} | ||
|
||
/** | ||
* @depends testMergeEntryWithSameEntryName | ||
*/ | ||
public function testWhetherGetEntriesReturnsExpectedEntries() | ||
{ | ||
$this->dashboard->addEntry($this->getTestHome()); | ||
|
||
$this->assertCount( | ||
1, | ||
$this->dashboard->getEntries(), | ||
'DashboardEntries::getEntries() returns unexpected dashboard entries' | ||
); | ||
} | ||
|
||
public function testeWhetherGetEntryThrowsAnExceptionOnNotExistentEntryName() | ||
{ | ||
$this->expectException(ProgrammingError::class); | ||
|
||
$this->dashboard->getEntry('test'); | ||
} | ||
|
||
/** | ||
* @depends testeWhetherGetEntryThrowsAnExceptionOnNotExistentEntryName | ||
*/ | ||
public function testWhetherGetEntryGetsAnEntryByName() | ||
{ | ||
$this->dashboard->addEntry($this->getTestHome()); | ||
|
||
$this->assertEquals( | ||
self::TEST_HOME, | ||
$this->dashboard->getEntry(self::TEST_HOME)->getName(), | ||
'DashboardEntries:getEntry() could not return Dashboard entry by name' | ||
); | ||
} | ||
|
||
/** | ||
* @depends testMergeEntryWithSameEntryName | ||
*/ | ||
public function testWhetherHasEntriesHasNoEntries() | ||
{ | ||
$this->assertFalse( | ||
$this->dashboard->hasEntries(), | ||
'DashboardEntries::hasEntries() has Dashboard entries but should not' | ||
); | ||
} | ||
|
||
/** | ||
* @depends testWhetherHasEntriesHasNoEntries | ||
*/ | ||
public function testWhetherHasEntriesHasEntries() | ||
{ | ||
$this->dashboard->addEntry($this->getTestHome()); | ||
|
||
$this->assertTrue( | ||
$this->dashboard->hasEntries(), | ||
'DashboardEntries::hasEntries() could not return valid expectation' | ||
); | ||
} | ||
|
||
/** | ||
* @depends testWhetherHasEntriesHasEntries | ||
*/ | ||
public function testWhetherGetEntryKeyTitleArrayReturnFormedArray() | ||
{ | ||
$this->dashboard->addEntry(($this->getTestHome())->setTitle('First Home')); | ||
$this->dashboard->addEntry(($this->getTestHome('Test2')->setTitle('Second Home'))); | ||
$this->dashboard->addEntry(($this->getTestHome('Test3')->setTitle('Third Home'))); | ||
|
||
$expected = [ | ||
self::TEST_HOME => 'First Home', | ||
'Test2' => 'Second Home', | ||
'Test3' => 'Third Home' | ||
]; | ||
|
||
$this->assertEquals( | ||
$expected, | ||
$this->dashboard->getEntryKeyTitleArr(), | ||
'DashboardEntries::getEntryKeyTitleArray() could not return valid expectation' | ||
); | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
/* Icinga Web 2 | (c) 2022 Icinga GmbH | GPLv2+ */ | ||
|
||
namespace Tests\Icinga\Web\Dashboard; | ||
|
||
use Icinga\Test\BaseDashboardTestCase; | ||
|
||
class DashletTest extends BaseDashboardTestCase | ||
{ | ||
|
||
} |
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,156 @@ | ||
<?php | ||
|
||
/* Icinga Web 2 | (c) 2022 Icinga GmbH | GPLv2+ */ | ||
|
||
namespace Tests\Icinga\Web\Dashboard; | ||
|
||
use Icinga\Exception\Http\HttpNotFoundException; | ||
use Icinga\Exception\ProgrammingError; | ||
use Icinga\Test\BaseDashboardTestCase; | ||
|
||
class HomeTest extends BaseDashboardTestCase | ||
{ | ||
public function testWhetherManageEntryManagesANewHomeEntry() | ||
{ | ||
$this->dashboard->manageEntry($this->getTestHome()); | ||
$this->dashboard->load(self::TEST_HOME); | ||
|
||
$this->assertCount( | ||
1, | ||
$this->dashboard->getEntries(), | ||
'Dashboard::manageEntry() could not manage a new Dashboard Home' | ||
); | ||
} | ||
|
||
/** | ||
* @depends testWhetherManageEntryManagesANewHomeEntry | ||
*/ | ||
public function testWhetherManageEntryUpdatesExistingHomeEntry() | ||
{ | ||
$this->dashboard->manageEntry($this->getTestHome()); | ||
$this->dashboard->load(self::TEST_HOME); | ||
|
||
$home = $this->dashboard->getEntry(self::TEST_HOME); | ||
$home->setTitle('Hello'); | ||
|
||
$this->dashboard->manageEntry($home); | ||
$this->dashboard->load(self::TEST_HOME); | ||
|
||
$home = $this->dashboard->getEntry(self::TEST_HOME); | ||
|
||
$this->assertEquals( | ||
'Hello', | ||
$home->getTitle(), | ||
'Dashboard::manageEntry() could not update existing Dashboard Home' | ||
); | ||
} | ||
|
||
/** | ||
* @depends testWhetherManageEntryUpdatesExistingHomeEntry | ||
*/ | ||
public function testWhetherRemoveEntryThrowsAnExceptionIfNotExists() | ||
{ | ||
$this->expectException(ProgrammingError::class); | ||
|
||
$this->dashboard->removeEntry('test'); | ||
} | ||
|
||
/** | ||
* @depends testWhetherRemoveEntryThrowsAnExceptionIfNotExists | ||
*/ | ||
public function testWhetherRemoveEntryRemovesExpectedHomeEntry() | ||
{ | ||
$this->dashboard->manageEntry($this->getTestHome('Second Home')); | ||
$this->dashboard->load(); | ||
|
||
$this->dashboard->removeEntry('Second Home'); | ||
$this->dashboard->load(); | ||
|
||
$this->assertFalse( | ||
$this->dashboard->hasEntry('Second Home'), | ||
'Dashboard::removeEntry() could not remove expected Dashboard Home entry' | ||
); | ||
} | ||
|
||
/** | ||
* @depends testWhetherRemoveEntryRemovesExpectedHomeEntry | ||
*/ | ||
public function testWhetherRemoveEntriesRemovesAllHomeEntries() | ||
{ | ||
$this->dashboard->manageEntry($this->getTestHome('Second Home')); | ||
$this->dashboard->load(); | ||
|
||
$this->dashboard->removeEntries(); | ||
$this->dashboard->load(); | ||
|
||
$this->assertTrue( | ||
$this->dashboard->hasEntries(), | ||
'Dashboard::removeEntries() could not remove all Dashboard Homes' | ||
); | ||
} | ||
|
||
/** | ||
* @depends testWhetherRemoveEntriesRemovesAllHomeEntries | ||
*/ | ||
public function testWhetherLoadHomesLoadsNullHomes() | ||
{ | ||
$this->dashboard->load(); | ||
|
||
$this->assertFalse( | ||
$this->dashboard->hasEntries(), | ||
'Dashboard::load() has loaded Dashboard Homes but should not' | ||
); | ||
} | ||
|
||
public function testWhetherLoadHomeByNameThrowsAnExceptionIfNotExists() | ||
{ | ||
$this->expectException(HttpNotFoundException::class); | ||
|
||
$this->dashboard->load('test'); | ||
} | ||
|
||
public function testWhetherLoadHomesActivatesFirstHome() | ||
{ | ||
$this->dashboard->manageEntry([$this->getTestHome(), $this->getTestHome('Second Home')]); | ||
|
||
$this->dashboard->load(); | ||
|
||
$this->assertEquals( | ||
self::TEST_HOME, | ||
$this->dashboard->getActiveHome()->getName(), | ||
'Dashboard::load() could not activate expected Dashboard Home' | ||
); | ||
} | ||
|
||
/** | ||
* @depends testWhetherLoadHomesActivatesFirstHome | ||
*/ | ||
public function testWhetherActivateHomeActivatesAHomeEntry() | ||
{ | ||
$this->dashboard->manageEntry([$this->getTestHome(), $this->getTestHome('Second Home')]); | ||
$this->dashboard->load(); | ||
|
||
$active = $this->dashboard->getEntry('Second Home'); | ||
$this->dashboard->activateHome($active); | ||
|
||
$this->assertTrue($active->getActive(), 'Dashboard::activateHome() could not activate expected Dashboard Home'); | ||
} | ||
|
||
/** | ||
* @depends testWhetherActivateHomeActivatesAHomeEntry | ||
*/ | ||
public function testWhetherGetActiveHomeGetsExpectedHome() | ||
{ | ||
$this->dashboard->addEntry($this->getTestHome()); | ||
$this->dashboard->addEntry($this->getTestHome('Second Home')); | ||
|
||
$active = $this->dashboard->getEntry(self::TEST_HOME); | ||
$this->dashboard->activateHome($active); | ||
|
||
$this->assertEquals( | ||
self::TEST_HOME, | ||
$this->dashboard->getActiveHome()->getName(), | ||
'Dashboard::getActiveHome() could not return expected Dashboard Home' | ||
); | ||
} | ||
} |
Oops, something went wrong.