From e4d1143870da509ec04280f521e3bd70b973257c Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Thu, 4 Sep 2014 18:30:22 +0200 Subject: [PATCH] Add SearchDashboardTest --- library/Icinga/Web/Widget/SearchDashboard.php | 4 +- .../Icinga/Web/Widget/SearchDashboardTest.php | 74 +++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 test/php/library/Icinga/Web/Widget/SearchDashboardTest.php diff --git a/library/Icinga/Web/Widget/SearchDashboard.php b/library/Icinga/Web/Widget/SearchDashboard.php index a97de06e5..0c5aaee8e 100644 --- a/library/Icinga/Web/Widget/SearchDashboard.php +++ b/library/Icinga/Web/Widget/SearchDashboard.php @@ -32,7 +32,7 @@ class SearchDashboard extends Dashboard * @param $searchQuery * @return Dashboard|SearchDashboard */ - public static function load($searchQuery) + public static function load($searchQuery = '') { /** @var $dashboard SearchDashboard */ $dashboard = new static('searchDashboard'); @@ -48,7 +48,7 @@ class SearchDashboard extends Dashboard */ public function render() { - if (!$this->getPane(self::SEARCH_PANE)->hasComponents()) { + if (! $this->getPane(self::SEARCH_PANE)->hasComponents()) { throw new ActionError('Site not found', 404); } return parent::render(); diff --git a/test/php/library/Icinga/Web/Widget/SearchDashboardTest.php b/test/php/library/Icinga/Web/Widget/SearchDashboardTest.php new file mode 100644 index 000000000..d78fc041a --- /dev/null +++ b/test/php/library/Icinga/Web/Widget/SearchDashboardTest.php @@ -0,0 +1,74 @@ + 'Hosts', + 'url' => 'monitoring/list/hosts?sort=host_severity&limit=10' + ); + $moduleMock->shouldReceive('getSearchUrls')->andReturn(array( + $searchUrl + )); + + $moduleManagerMock = Mockery::mock('Icinga\Application\Modules\Manager'); + $moduleManagerMock->shouldReceive('getLoadedModules')->andReturn(array( + 'test-module' => $moduleMock + )); + + $bootstrapMock = Mockery::mock('Icinga\Application\ApplicationBootstrap')->shouldDeferMissing(); + $bootstrapMock->shouldReceive('getFrontController->getRequest')->andReturnUsing( + function () use ($request) { return $request; } + )->shouldReceive('getApplicationDir')->andReturn(self::$appDir); + + $bootstrapMock->shouldReceive('getModuleManager')->andReturn($moduleManagerMock); + + Icinga::setApp($bootstrapMock, true); + } + + /** + * @expectedException Zend_Controller_Action_Exception + */ + public function testFoo() + { + $dashboard = SearchDashboard::load('pending'); + $dashboard->getPane('search')->removeComponents(); + $dashboard->render(); + } + + public function testWhetherLoadLoadsSearchDashletsFromModules() + { + $dashboard = SearchDashboard::load('pending'); + + $result = $dashboard->getPane('search')->hasComponent('Hosts: pending'); + + $this->assertTrue($result, 'Dashboard::load() could not load search dashlets from modules'); + } + + + public function testWhetherLoadProvidesHint() + { + $dashboard = SearchDashboard::load(''); + + $result = $dashboard->getPane('search')->hasComponent('Ready to search'); + + $this->assertTrue($result, 'Dashboard::load() could not get hint for search'); + } +}