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

74 lines
2.4 KiB
PHP
Raw Normal View History

2014-09-04 18:30:22 +02:00
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
2014-09-04 18:30:22 +02:00
namespace Tests\Icinga\Web;
use Mockery;
use Icinga\Test\BaseTestCase;
use Icinga\User;
use Icinga\Web\Widget\SearchDashboard;
2014-09-04 18:30:22 +02:00
class SearchDashboardTest extends BaseTestCase
{
public function setUp()
2014-09-04 18:30:22 +02:00
{
$moduleMock = Mockery::mock('Icinga\Application\Modules\Module');
$searchUrl = (object) array(
'title' => 'Hosts',
'url' => 'monitoring/list/hosts?sort=host_severity&limit=10'
);
$moduleMock->shouldReceive('getSearchUrls')->andReturn(array(
$searchUrl
));
$moduleMock->shouldReceive('getName')->andReturn('test');
2014-09-04 18:30:22 +02:00
$moduleManagerMock = Mockery::mock('Icinga\Application\Modules\Manager');
$moduleManagerMock->shouldReceive('getLoadedModules')->andReturn(array(
'test-module' => $moduleMock
));
$bootstrapMock = $this->setupIcingaMock();
2014-09-04 18:30:22 +02:00
$bootstrapMock->shouldReceive('getModuleManager')->andReturn($moduleManagerMock);
}
/**
* @expectedException Zend_Controller_Action_Exception
*/
2014-11-20 12:48:05 +01:00
public function testWhetherRenderThrowsAnExceptionWhenHasNoDashlets()
2014-09-04 18:30:22 +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();
}
public function testWhetherSearchLoadsSearchDashletsFromModules()
2014-09-04 18:30:22 +02:00
{
$user = new User('test');
$user->setPermissions(array('*' => '*'));
$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
$this->assertTrue($result, 'Dashboard::search() could not load search dashlets from modules');
2014-09-04 18:30:22 +02:00
}
public function testWhetherSearchProvidesHintWhenSearchStringIsEmpty()
2014-09-04 18:30:22 +02:00
{
$user = new User('test');
$user->setPermissions(array('*' => '*'));
$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
$this->assertTrue($result, 'Dashboard::search() could not get hint for search');
2014-09-04 18:30:22 +02:00
}
}