Skip to content

Commit d32cbe3

Browse files
committed
SearchDashboardTest: Adjust unit tests according to the new dashboards
1 parent 6f0b3fb commit d32cbe3

File tree

1 file changed

+19
-52
lines changed

1 file changed

+19
-52
lines changed

test/php/library/Icinga/Web/Widget/SearchDashboardTest.php

Lines changed: 19 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,79 +3,46 @@
33

44
namespace Tests\Icinga\Web;
55

6-
use Icinga\Authentication\Role;
7-
use Mockery;
8-
use Icinga\Test\BaseTestCase;
9-
use Icinga\User;
6+
use Icinga\Exception\Http\HttpNotFoundException;
7+
use Icinga\Test\BaseDashboardTestCase;
108
use Icinga\Web\Widget\SearchDashboard;
119

12-
class SearchDashboardTest extends BaseTestCase
10+
class SearchDashboardTest extends BaseDashboardTestCase
1311
{
14-
public function setUp(): void
15-
{
16-
$moduleMock = Mockery::mock('Icinga\Application\Modules\Module');
17-
$searchUrl = (object) array(
18-
'title' => 'Hosts',
19-
'url' => 'monitoring/list/hosts?sort=host_severity&limit=10'
20-
);
21-
$moduleMock->shouldReceive('getSearchUrls')->andReturn(array(
22-
$searchUrl
23-
));
24-
$moduleMock->shouldReceive('getName')->andReturn('test');
25-
26-
$moduleManagerMock = Mockery::mock('Icinga\Application\Modules\Manager');
27-
$moduleManagerMock->shouldReceive('getLoadedModules')->andReturn(array(
28-
'test-module' => $moduleMock
29-
));
30-
31-
$bootstrapMock = $this->setupIcingaMock();
32-
$bootstrapMock->shouldReceive('getModuleManager')->andReturn($moduleManagerMock);
33-
}
34-
3512
public function testWhetherRenderThrowsAnExceptionWhenHasNoDashlets()
3613
{
37-
$this->expectException(\Zend_Controller_Action_Exception::class);
14+
$this->expectException(HttpNotFoundException::class);
3815

39-
$user = new User('test');
40-
$user->setPermissions(array('*' => '*'));
4116
$dashboard = new SearchDashboard();
42-
$dashboard->setUser($user);
43-
$dashboard = $dashboard->search('pending');
44-
$dashboard->getPane('search')->removeDashlets();
17+
$dashboard->setUser($this->getUser());
18+
$dashboard->search('pending');
19+
20+
$searchHome = $dashboard->getActiveHome();
21+
$searchHome->getEntry(SearchDashboard::SEARCH_PANE)->setEntries([]);
4522
$dashboard->render();
4623
}
4724

4825
public function testWhetherSearchLoadsSearchDashletsFromModules()
4926
{
50-
$role = new Role();
51-
$role->setPermissions(['*']);
52-
53-
$user = new User('test');
54-
$user->setRoles([$role]);
55-
5627
$dashboard = new SearchDashboard();
57-
$dashboard->setUser($user);
58-
$dashboard = $dashboard->search('pending');
28+
$dashboard->setUser($this->getUser());
29+
$dashboard->search('pending');
5930

60-
$result = $dashboard->getPane('search')->hasDashlet('Hosts: pending');
31+
$searchHome = $dashboard->getActiveHome();
32+
$result = $searchHome->getEntry(SearchDashboard::SEARCH_PANE)->hasEntry('Hosts: pending');
6133

62-
$this->assertTrue($result, 'Dashboard::search() could not load search dashlets from modules');
34+
$this->assertTrue($result, 'SearchDashboard::search() could not load search dashlets from modules');
6335
}
6436

6537
public function testWhetherSearchProvidesHintWhenSearchStringIsEmpty()
6638
{
67-
$role = new Role();
68-
$role->setPermissions(['*']);
69-
70-
$user = new User('test');
71-
$user->setRoles([$role]);
72-
7339
$dashboard = new SearchDashboard();
74-
$dashboard->setUser($user);
75-
$dashboard = $dashboard->search();
40+
$dashboard->setUser($this->getUser());
41+
$dashboard->search();
7642

77-
$result = $dashboard->getPane('search')->hasDashlet('Ready to search');
43+
$searchHome = $dashboard->getActiveHome();
44+
$result = $searchHome->getEntry(SearchDashboard::SEARCH_PANE)->hasEntry('Ready to search');
7845

79-
$this->assertTrue($result, 'Dashboard::search() could not get hint for search');
46+
$this->assertTrue($result, 'SearchDashboard::search() could not get hint for search');
8047
}
8148
}

0 commit comments

Comments
 (0)