2014-09-04 18:30:22 +02:00
|
|
|
<?php
|
2016-02-08 15:41:00 +01:00
|
|
|
/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
|
2014-09-04 18:30:22 +02:00
|
|
|
|
|
|
|
namespace Tests\Icinga\Web;
|
|
|
|
|
2023-07-04 16:26:36 +02:00
|
|
|
use Icinga\Application\Icinga;
|
2021-01-22 15:59:01 +01:00
|
|
|
use Icinga\Authentication\Role;
|
2014-09-04 18:30:22 +02:00
|
|
|
use Icinga\Test\BaseTestCase;
|
2015-07-23 13:01:05 +02:00
|
|
|
use Icinga\User;
|
2014-09-09 10:21:37 +02:00
|
|
|
use Icinga\Web\Widget\SearchDashboard;
|
2014-09-04 18:30:22 +02:00
|
|
|
|
|
|
|
class SearchDashboardTest extends BaseTestCase
|
|
|
|
{
|
2021-04-09 09:39:10 +02:00
|
|
|
public function setUp(): void
|
2014-09-04 18:30:22 +02:00
|
|
|
{
|
2023-07-04 16:26:36 +02:00
|
|
|
parent::setUp();
|
2014-09-04 18:30:22 +02:00
|
|
|
|
2023-07-04 16:26:36 +02:00
|
|
|
Icinga::app()->getModuleManager()
|
|
|
|
->loadModule('test-module', '/tmp')
|
|
|
|
->getModule('test-module')
|
|
|
|
->provideSearchUrl('Hosts', 'monitoring/list/hosts?sort=host_severity&limit=10');
|
2014-09-04 18:30:22 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 12:48:05 +01:00
|
|
|
public function testWhetherRenderThrowsAnExceptionWhenHasNoDashlets()
|
2014-09-04 18:30:22 +02:00
|
|
|
{
|
2021-04-09 10:49:17 +02:00
|
|
|
$this->expectException(\Zend_Controller_Action_Exception::class);
|
|
|
|
|
2015-07-23 13:01:05 +02:00
|
|
|
$user = new User('test');
|
|
|
|
$user->setPermissions(array('*' => '*'));
|
|
|
|
$dashboard = new SearchDashboard();
|
|
|
|
$dashboard->setUser($user);
|
|
|
|
$dashboard = $dashboard->search('pending');
|
2014-11-20 12:48:05 +01:00
|
|
|
$dashboard->getPane('search')->removeDashlets();
|
2014-09-04 18:30:22 +02:00
|
|
|
$dashboard->render();
|
|
|
|
}
|
|
|
|
|
2014-09-04 22:54:41 +02:00
|
|
|
public function testWhetherSearchLoadsSearchDashletsFromModules()
|
2014-09-04 18:30:22 +02:00
|
|
|
{
|
2021-01-22 15:59:01 +01:00
|
|
|
$role = new Role();
|
|
|
|
$role->setPermissions(['*']);
|
|
|
|
|
2015-07-23 13:01:05 +02:00
|
|
|
$user = new User('test');
|
2021-01-22 15:59:01 +01:00
|
|
|
$user->setRoles([$role]);
|
|
|
|
|
2015-07-23 13:01:05 +02:00
|
|
|
$dashboard = new SearchDashboard();
|
|
|
|
$dashboard->setUser($user);
|
|
|
|
$dashboard = $dashboard->search('pending');
|
2014-09-04 18:30:22 +02:00
|
|
|
|
2014-11-20 12:48:05 +01:00
|
|
|
$result = $dashboard->getPane('search')->hasDashlet('Hosts: pending');
|
2014-09-04 18:30:22 +02:00
|
|
|
|
2014-09-04 19:35:31 +02:00
|
|
|
$this->assertTrue($result, 'Dashboard::search() could not load search dashlets from modules');
|
2014-09-04 18:30:22 +02:00
|
|
|
}
|
|
|
|
|
2014-09-04 22:54:41 +02:00
|
|
|
public function testWhetherSearchProvidesHintWhenSearchStringIsEmpty()
|
2014-09-04 18:30:22 +02:00
|
|
|
{
|
2021-01-22 15:59:01 +01:00
|
|
|
$role = new Role();
|
|
|
|
$role->setPermissions(['*']);
|
|
|
|
|
2015-07-23 13:01:05 +02:00
|
|
|
$user = new User('test');
|
2021-01-22 15:59:01 +01:00
|
|
|
$user->setRoles([$role]);
|
|
|
|
|
2015-07-23 13:01:05 +02:00
|
|
|
$dashboard = new SearchDashboard();
|
|
|
|
$dashboard->setUser($user);
|
|
|
|
$dashboard = $dashboard->search();
|
2014-09-04 18:30:22 +02:00
|
|
|
|
2014-11-20 12:48:05 +01:00
|
|
|
$result = $dashboard->getPane('search')->hasDashlet('Ready to search');
|
2014-09-04 18:30:22 +02:00
|
|
|
|
2014-09-04 19:35:31 +02:00
|
|
|
$this->assertTrue($result, 'Dashboard::search() could not get hint for search');
|
2014-09-04 18:30:22 +02:00
|
|
|
}
|
|
|
|
}
|