|
3 | 3 |
|
4 | 4 | namespace Tests\Icinga\Web; |
5 | 5 |
|
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; |
10 | 8 | use Icinga\Web\Widget\SearchDashboard; |
11 | 9 |
|
12 | | -class SearchDashboardTest extends BaseTestCase |
| 10 | +class SearchDashboardTest extends BaseDashboardTestCase |
13 | 11 | { |
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 | | - |
35 | 12 | public function testWhetherRenderThrowsAnExceptionWhenHasNoDashlets() |
36 | 13 | { |
37 | | - $this->expectException(\Zend_Controller_Action_Exception::class); |
| 14 | + $this->expectException(HttpNotFoundException::class); |
38 | 15 |
|
39 | | - $user = new User('test'); |
40 | | - $user->setPermissions(array('*' => '*')); |
41 | 16 | $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([]); |
45 | 22 | $dashboard->render(); |
46 | 23 | } |
47 | 24 |
|
48 | 25 | public function testWhetherSearchLoadsSearchDashletsFromModules() |
49 | 26 | { |
50 | | - $role = new Role(); |
51 | | - $role->setPermissions(['*']); |
52 | | - |
53 | | - $user = new User('test'); |
54 | | - $user->setRoles([$role]); |
55 | | - |
56 | 27 | $dashboard = new SearchDashboard(); |
57 | | - $dashboard->setUser($user); |
58 | | - $dashboard = $dashboard->search('pending'); |
| 28 | + $dashboard->setUser($this->getUser()); |
| 29 | + $dashboard->search('pending'); |
59 | 30 |
|
60 | | - $result = $dashboard->getPane('search')->hasDashlet('Hosts: pending'); |
| 31 | + $searchHome = $dashboard->getActiveHome(); |
| 32 | + $result = $searchHome->getEntry(SearchDashboard::SEARCH_PANE)->hasEntry('Hosts: pending'); |
61 | 33 |
|
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'); |
63 | 35 | } |
64 | 36 |
|
65 | 37 | public function testWhetherSearchProvidesHintWhenSearchStringIsEmpty() |
66 | 38 | { |
67 | | - $role = new Role(); |
68 | | - $role->setPermissions(['*']); |
69 | | - |
70 | | - $user = new User('test'); |
71 | | - $user->setRoles([$role]); |
72 | | - |
73 | 39 | $dashboard = new SearchDashboard(); |
74 | | - $dashboard->setUser($user); |
75 | | - $dashboard = $dashboard->search(); |
| 40 | + $dashboard->setUser($this->getUser()); |
| 41 | + $dashboard->search(); |
76 | 42 |
|
77 | | - $result = $dashboard->getPane('search')->hasDashlet('Ready to search'); |
| 43 | + $searchHome = $dashboard->getActiveHome(); |
| 44 | + $result = $searchHome->getEntry(SearchDashboard::SEARCH_PANE)->hasEntry('Ready to search'); |
78 | 45 |
|
79 | | - $this->assertTrue($result, 'Dashboard::search() could not get hint for search'); |
| 46 | + $this->assertTrue($result, 'SearchDashboard::search() could not get hint for search'); |
80 | 47 | } |
81 | 48 | } |
0 commit comments