SearchDashboardTest: Adjust unit tests according to the new dashboards

This commit is contained in:
Yonas Habteab 2022-06-01 14:56:52 +02:00
parent af4d9c8257
commit c773ad3ac7
3 changed files with 21 additions and 32 deletions

View File

@ -43,7 +43,7 @@ class DashletManager
{
$query = Model\ModuleDashlet::on(DBUtils::getConn())
->disableDefaultSort()
->setColumns([new Expression('1')])
->columns([new Expression('1')])
->filter(Filter::equal('id', $dashlet->getUuid()));
return $query->execute()->hasResult();

View File

@ -71,7 +71,7 @@ trait DashboardUserManager
public static function userExist(): bool
{
$query = DashboardOwner::on(DBUtils::getConn())
->setColumns(['id'])
->columns(['id'])
->filter(Filter::equal('username', self::getUser()->getUsername()));
$found = false;

View File

@ -4,12 +4,11 @@
namespace Tests\Icinga\Web;
use Icinga\Application\Icinga;
use Icinga\Authentication\Role;
use Icinga\Test\BaseTestCase;
use Icinga\User;
use Icinga\Exception\Http\HttpNotFoundException;
use Icinga\Test\BaseDashboardTestCase;
use Icinga\Web\Widget\SearchDashboard;
class SearchDashboardTest extends BaseTestCase
class SearchDashboardTest extends BaseDashboardTestCase
{
public function setUp(): void
{
@ -23,48 +22,38 @@ class SearchDashboardTest extends BaseTestCase
public function testWhetherRenderThrowsAnExceptionWhenHasNoDashlets()
{
$this->expectException(\Zend_Controller_Action_Exception::class);
$this->expectException(HttpNotFoundException::class);
$user = new User('test');
$user->setPermissions(array('*' => '*'));
$dashboard = new SearchDashboard();
$dashboard->setUser($user);
$dashboard = $dashboard->search('pending');
$dashboard->getPane('search')->removeDashlets();
$dashboard->setUser($this->getUser());
$dashboard->search('pending');
$searchHome = $dashboard->getActiveHome();
$searchHome->getEntry(SearchDashboard::SEARCH_PANE)->setEntries([]);
$dashboard->render();
}
public function testWhetherSearchLoadsSearchDashletsFromModules()
{
$role = new Role();
$role->setPermissions(['*']);
$user = new User('test');
$user->setRoles([$role]);
$dashboard = new SearchDashboard();
$dashboard->setUser($user);
$dashboard = $dashboard->search('pending');
$dashboard->setUser($this->getUser());
$dashboard->search('pending');
$result = $dashboard->getPane('search')->hasDashlet('Hosts: pending');
$searchHome = $dashboard->getActiveHome();
$result = $searchHome->getEntry(SearchDashboard::SEARCH_PANE)->hasEntry('Hosts: pending');
$this->assertTrue($result, 'Dashboard::search() could not load search dashlets from modules');
$this->assertTrue($result, 'SearchDashboard::search() could not load search dashlets from modules');
}
public function testWhetherSearchProvidesHintWhenSearchStringIsEmpty()
{
$role = new Role();
$role->setPermissions(['*']);
$user = new User('test');
$user->setRoles([$role]);
$dashboard = new SearchDashboard();
$dashboard->setUser($user);
$dashboard = $dashboard->search();
$dashboard->setUser($this->getUser());
$dashboard->search();
$result = $dashboard->getPane('search')->hasDashlet('Ready to search');
$searchHome = $dashboard->getActiveHome();
$result = $searchHome->getEntry(SearchDashboard::SEARCH_PANE)->hasEntry('Ready to search');
$this->assertTrue($result, 'Dashboard::search() could not get hint for search');
$this->assertTrue($result, 'SearchDashboard::search() could not get hint for search');
}
}