From b28c7f2f4c6555087a048ed2457d3ad192299792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannis=20Mo=C3=9Fhammer?= Date: Thu, 8 Aug 2013 16:22:22 +0200 Subject: [PATCH 1/6] Refactor test, tabs and controller - Remove unused methods, - Code style - Documentation for widgets - Tabextensions instead of hardcoded tab actions - Add tests for tabs - Add missing phpdoc for touched files - Fix tests refs #4512 refs #4541 refs #4540 --- application/controllers/IndexController.php | 1 - application/forms/Dashboard/AddUrlForm.php | 29 +++ doc/widgets.md | 97 ++++++++ .../Web/Controller/ActionController.php | 209 ++++++------------ .../Web/Controller/ModuleActionController.php | 83 +------ library/Icinga/Web/Url.php | 28 ++- .../Icinga/Web/Widget/Dashboard/Component.php | 2 +- library/Icinga/Web/Widget/Tab.php | 31 ++- .../Web/Widget/Tabextension/BasketAction.php | 55 +++++ .../Widget/Tabextension/DashboardAction.php | 60 +++++ .../Web/Widget/Tabextension/OutputFormat.php | 128 +++++++++++ .../Web/Widget/Tabextension/Tabextension.php | 49 ++++ library/Icinga/Web/Widget/Tabs.php | 195 ++++++++-------- .../controllers/ListController.php | 21 +- .../controllers/ShowController.php | 27 ++- .../controllers/SoapController.php | 54 ----- .../controllers/SummaryController.php | 8 +- modules/monitoring/bin/soaptest.php | 21 -- .../test/php/library/Backend/ComboTest.php | 31 --- .../test/php/library/Backend/IdoTest.php | 40 ---- .../php/library/Backend/LivestatusTest.php | 40 ---- .../Backend/MonitoringObjectListTest.php | 67 ------ .../Statusdat/ServicelistQueryTest.php | 22 -- .../php/library/Backend/StatusdatTest.php | 31 --- .../views/helpers/PerfdataTest.php | 21 -- .../application/views/helpers/QUrlTest.php | 21 -- .../application/views/helpers/QlinkTest.php | 71 ------ .../helpers/RenderServicePerfdataTest.php | 31 --- .../views/helpers/TimeSinceTest.php | 31 --- .../application/views/helpers/UtilTest.php | 82 ------- .../Icinga/Application/BootstrapTest.php | 135 ----------- .../Icinga/Application/SessionTest.php | 23 -- .../Icinga/Authentication/CredentialsTest.php | 67 ------ .../Icinga/Authentication/UserBackendTest.php | 31 --- test/php/library/Icinga/BackendTest.php | 23 -- test/php/library/Icinga/BenchmarkTest.php | 73 ------ test/php/library/Icinga/FormatTest.php | 23 -- test/php/library/Icinga/Ido/DbTest.php | 40 ---- .../Icinga/Protocol/Ldap/ConnectionTest.php | 67 ------ .../Icinga/Protocol/Ldap/LdapUtilsTest.php | 53 ----- .../library/Icinga/Protocol/Ldap/NodeTest.php | 50 ----- .../library/Icinga/Protocol/Ldap/RootTest.php | 77 ------- .../Protocol/Livestatus/ConnectionTest.php | 36 --- .../Icinga/Protocol/Livestatus/QueryTest.php | 148 ------------- .../Icinga/Web/ActionControllerTest.php | 6 - .../ConfigurationTabBuilderTest.php | 11 + test/php/library/Icinga/Web/RequestMock.php | 89 ++++++++ test/php/library/Icinga/Web/UrlTest.php | 63 +----- test/php/library/Icinga/Web/ViewMock.php | 47 ++++ .../php/library/Icinga/Web/Widget/TabTest.php | 164 ++++++++++++++ .../Widget/Tabextension/OutputFormatTest.php | 88 ++++++++ .../library/Icinga/Web/Widget/TabsTest.php | 111 ++++++++++ 52 files changed, 1170 insertions(+), 1841 deletions(-) create mode 100644 doc/widgets.md create mode 100644 library/Icinga/Web/Widget/Tabextension/BasketAction.php create mode 100644 library/Icinga/Web/Widget/Tabextension/DashboardAction.php create mode 100644 library/Icinga/Web/Widget/Tabextension/OutputFormat.php create mode 100644 library/Icinga/Web/Widget/Tabextension/Tabextension.php delete mode 100644 modules/monitoring/application/controllers/SoapController.php delete mode 100644 modules/monitoring/bin/soaptest.php delete mode 100755 modules/monitoring/test/php/library/Backend/ComboTest.php delete mode 100755 modules/monitoring/test/php/library/Backend/IdoTest.php delete mode 100755 modules/monitoring/test/php/library/Backend/LivestatusTest.php delete mode 100755 modules/monitoring/test/php/library/Backend/MonitoringObjectListTest.php delete mode 100644 modules/monitoring/test/php/library/Backend/Statusdat/ServicelistQueryTest.php delete mode 100755 modules/monitoring/test/php/library/Backend/StatusdatTest.php delete mode 100755 test/php/application/views/helpers/PerfdataTest.php delete mode 100755 test/php/application/views/helpers/QUrlTest.php delete mode 100755 test/php/application/views/helpers/QlinkTest.php delete mode 100755 test/php/application/views/helpers/RenderServicePerfdataTest.php delete mode 100755 test/php/application/views/helpers/TimeSinceTest.php delete mode 100755 test/php/application/views/helpers/UtilTest.php delete mode 100644 test/php/library/Icinga/Application/BootstrapTest.php delete mode 100644 test/php/library/Icinga/Application/SessionTest.php delete mode 100644 test/php/library/Icinga/Authentication/CredentialsTest.php delete mode 100644 test/php/library/Icinga/Authentication/UserBackendTest.php delete mode 100755 test/php/library/Icinga/BackendTest.php delete mode 100755 test/php/library/Icinga/BenchmarkTest.php delete mode 100755 test/php/library/Icinga/FormatTest.php delete mode 100755 test/php/library/Icinga/Ido/DbTest.php delete mode 100644 test/php/library/Icinga/Protocol/Ldap/ConnectionTest.php delete mode 100644 test/php/library/Icinga/Protocol/Ldap/LdapUtilsTest.php delete mode 100644 test/php/library/Icinga/Protocol/Ldap/NodeTest.php delete mode 100644 test/php/library/Icinga/Protocol/Ldap/RootTest.php delete mode 100755 test/php/library/Icinga/Protocol/Livestatus/QueryTest.php delete mode 100755 test/php/library/Icinga/Web/ActionControllerTest.php create mode 100644 test/php/library/Icinga/Web/RequestMock.php create mode 100644 test/php/library/Icinga/Web/ViewMock.php create mode 100644 test/php/library/Icinga/Web/Widget/TabTest.php create mode 100644 test/php/library/Icinga/Web/Widget/Tabextension/OutputFormatTest.php create mode 100644 test/php/library/Icinga/Web/Widget/TabsTest.php diff --git a/application/controllers/IndexController.php b/application/controllers/IndexController.php index 9863efd09..ea33553e8 100644 --- a/application/controllers/IndexController.php +++ b/application/controllers/IndexController.php @@ -34,7 +34,6 @@ use Icinga\Application\Icinga; /** * Class IndexController - * @package Icinga\Application\Controllers */ class IndexController extends ActionController { diff --git a/application/forms/Dashboard/AddUrlForm.php b/application/forms/Dashboard/AddUrlForm.php index 4e245d58e..dcc1dbc3a 100644 --- a/application/forms/Dashboard/AddUrlForm.php +++ b/application/forms/Dashboard/AddUrlForm.php @@ -1,4 +1,30 @@ + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} namespace Icinga\Form\Dashboard; @@ -103,6 +129,7 @@ class AddUrlForm extends Form protected function create() { $dashboard = new Dashboard(); + $dashboard->readConfig(IcingaConfig::app('dashboard/dashboard')); $this->addElement( 'text', @@ -110,6 +137,7 @@ class AddUrlForm extends Form array( 'label' => 'Url', 'required' => true, + 'value' => $this->getRequest()->getParam('url', null) ) ); $elems = $dashboard->getPaneKeyTitleArray(); @@ -132,5 +160,6 @@ class AddUrlForm extends Form ) ); $this->setSubmitLabel("Add to dashboard"); + } } diff --git a/doc/widgets.md b/doc/widgets.md new file mode 100644 index 000000000..8a8710f20 --- /dev/null +++ b/doc/widgets.md @@ -0,0 +1,97 @@ +# Widgets + +Widgets are reusable UI components that are able to render themselves and return HTML to be included in your template. + +## Basic interface + +The interface needed for implementing widgets can be found under library/Icinga/Web/Widget/Widget.php. This is a rather +simple interface, only providing a 'render' method that takes a view and returns HTML: + + interface Widget + { + public function render(Zend_View_Abstract $view); + } + +When implementing own Widgets you just have to make sure that your provide this render method. + +## Using widgets + +Widgets are normally created in the controller and added to the view: + + // in your Controller + public function myControllerAction() + { + $this->view->myWidget = new MyWidget(); + } + + The HTML is then rendered in the template using the *render()* method described above. As the '$this' scope in a view is your + a reference to your current view, you can just pass it to the *render()* method: + + // in your template + +
+

Look at my beautiful widget

+ myWidget->render($this); ?> +
+ +## The 'Tabs' widget + +The Tabs (Icinga\Web\Widgets\Tabs) widget handles creation of Tab bars and allows you to create and add single tabs to this view. To create an empty +Tab bar, you just have to call: + + $tabbar = new Tabs(); + +**Note** : When using an ActionController, there's already an empty tabs object created unter $this->view->tabs. This is + done in the preDispatch function + +### Adding tabs + +Afterwards you can add tabs by calling the add($name, $tab) function, whereas $name is the name of your tab and $tab +is either an array with tab parameters or an existing Tab object. + + // Adding tabs: + $tabbar->add("myTab", array( + "title" => "My hosts", // displayed as the tab text + "iconCls" => "myicon", // icon-myicon will be used as an icon in a tag + "url" => "/my/url", // the url to use + "urlParams" => array("host" => "localhost") // will be used as GET parameter + )); + +### Adding tabs to the dropdown list + +Sometimes you want additional actions to be displayed in your tabbar. This can be accomplished with the 'addAsDropdown' +method. This one is similar to the *add* method, but displays your tab in a dropdown list on the right side of the tabbar. + +## Using tabextensions + +Often you find yourself adding the same tabs over and over again. You can write a Tabextension that does this for you +and just apply them on your tabs. Tabextensions are locate the Icinga/Web/Widgets/Tabextension/ and use the simple +Tabextension interface that just defines *apply(Tabs $tab)*. A simple example is the DashboardAction Tabextender which +just adds a new field to the dropdown list: + + class DashboardAction implements Tabextension + { + /** + * @see Tabextension::apply() + */ + public function apply(Tabs $tabs) + { + $tabs->addAsDropdown( + 'dashboard', + array( + 'title' => 'Add to Dashboard', + 'iconCls' => 'dashboard', + 'url' => Url::fromPath('dashboard/addurl'), + 'urlParams' => array( + 'url' => Url::fromRequest()->getRelativeUrl() + ) + ) + ); + } + } + +You can now either extend your Tabs object using the DashboardAction's *apply()* method or by calling the Tabs *extend* +method (which is more fluent): + + $tabs->extend(new DashboardAction()) + diff --git a/library/Icinga/Web/Controller/ActionController.php b/library/Icinga/Web/Controller/ActionController.php index 8ade9e2e9..f60fa340e 100755 --- a/library/Icinga/Web/Controller/ActionController.php +++ b/library/Icinga/Web/Controller/ActionController.php @@ -32,17 +32,13 @@ use \Icinga\Application\Benchmark; use \Icinga\Exception; use \Icinga\Application\Config; use \Icinga\Web\Notification; +use \Icinga\Web\Widget\Tabs; use \Zend_Layout as ZfLayout; use \Zend_Controller_Action as ZfController; use \Zend_Controller_Request_Abstract as ZfRequest; use \Zend_Controller_Response_Abstract as ZfResponse; use \Zend_Controller_Action_HelperBroker as ZfActionHelper; -/* - * @TODO(el): There was a note from tg that the following line is temporary. Ask him why. - */ -use Icinga\File\Pdf; - /** * Base class for all core action controllers * @@ -54,15 +50,41 @@ use Icinga\File\Pdf; */ class ActionController extends ZfController { - /** - * The Icinga Config object is available in all controllers. This is the - * modules config for module action controllers. - * @var Config - */ - protected $config; + /** + * True to mark this layout to not render the full layout + * + * @var bool + */ protected $replaceLayout = false; + /** + * If true, this controller will be shown even when no authentication is available + * Needed mainly for the authentication controller + * + * @var bool + */ + protected $handlesAuthentication = false; + + /** + * Set true when this controller modifies the session. + * + * otherwise the session will be written back to disk and closed before the controller + * action is executed, leading to every modification in the session to be lost after + * the response is submitted + * + * @var bool + */ + protected $modifiesSession = false; + + /** + * True if authentication suceeded, otherwise false + * + * @var bool + **/ + protected $allowAccess = false; + + /** * The current module name. TODO: Find out whether this shall be null for * non-module actions @@ -85,12 +107,7 @@ class ActionController extends ZfController */ protected $action_name; - // @TODO(el): Should be true, is/was disabled for testing purpose - protected $handlesAuthentication = false; - protected $modifiesSession = false; - - private $allowAccess = false; /** * The constructor starts benchmarking, loads the configuration and sets @@ -111,13 +128,12 @@ class ActionController extends ZfController $this->controller_name = $request->getControllerName(); $this->action_name = $request->getActionName(); - $this->loadConfig(); $this->setRequest($request) ->setResponse($response) ->_setInvokeArgs($invokeArgs); $this->_helper = new ZfActionHelper($this); - if ($this->handlesAuthentication() || + if ($this->handlesAuthentication || AuthManager::getInstance( null, array( @@ -126,24 +142,26 @@ class ActionController extends ZfController )->isAuthenticated() ) { $this->allowAccess = true; + $this->view->tabs = new Tabs(); $this->init(); } } /** - * This is where the configuration is going to be loaded - * - * @return void - */ - protected function loadConfig() + * Return the @see \Icinga\Widget\Web\Tabs of this view + * + * @return Tabs + **/ + public function getTabs() { - $this->config = Config::app(); + return $this->view->tabs; } + /** - * Translates the given string with the global translation catalog + * Translate the given string with the global translation catalog * - * @param string $string The string that should be translated + * @param string $string The string that should be translated * * @return string */ @@ -155,14 +173,11 @@ class ActionController extends ZfController /** * Whether the current user has the given permission * - * TODO: This has not been implemented yet - * - * @param string $permission Permission name - * @param string $object No idea what this should have been :-) + * TODO: This has not been implemented yet (Feature #4111) * * @return bool */ - final protected function hasPermission($uri, $permission = 'read') + final protected function hasPermission($uri) { return true; } @@ -170,38 +185,25 @@ class ActionController extends ZfController /** * Assert the current user has the given permission * - * TODO: This has not been implemented yet - * - * @param string $permission Permission name - * @param string $object No idea what this should have been :-) - * + * TODO: This has not been implemented yet (Feature #4111) + * * @return self */ - final protected function assertPermission($permission, $object = null) + final protected function assertPermission() { - if (! $this->hasPermission($permission, $object)) { - // TODO: Log violation, create dedicated Exception class - throw new \Exception('Permission denied'); - } return $this; } - protected function preserve($key, $value = null) + private function redirectToLogin() { - if ($value === null) { - $value = $this->_getParam($key); - } - if ($value !== null) { - if (! isset($this->view->preserve)) { - $this->view->preserve = array(); - } - $this->view->preserve[$key] = $value; - } - return $this; + $this->_request->setModuleName('default') + ->setControllerName('authentication') + ->setActionName('login') + ->setDispatched(false); } /** - * Our benchmark wants to know when we started our dispatch loop + * Prepare action execution by testing for correct permissions and setting shortcuts * * @return void */ @@ -209,20 +211,13 @@ class ActionController extends ZfController { Benchmark::measure('Action::preDispatch()'); if (! $this->allowAccess) { - $this->_request->setModuleName('default') - ->setControllerName('authentication') - ->setActionName('login') - ->setDispatched(false); - return; + return $this->redirectToLogin(); } $this->view->action_name = $this->action_name; $this->view->controller_name = $this->controller_name; $this->view->module_name = $this->module_name; - // TODO(el): What is this, why do we need that here? - $this->view->compact = $this->_request->getParam('view') === 'compact'; - Benchmark::measure( sprintf( 'Action::preDispatched(): %s / %s / %s', @@ -231,11 +226,14 @@ class ActionController extends ZfController $this->action_name ) ); - - //$this->quickRedirect('/authentication/login?a=e'); } - public function redirectNow($url, array $params = array()) + /** + * Redirect to a specific url, updating the browsers URL field + * + * @param Url|string $url The target to redirect to + **/ + public function redirectNow($url) { if ($url instanceof Url) { $url = $url->getRelativeUrl(); @@ -243,77 +241,15 @@ class ActionController extends ZfController $this->_helper->Redirector->gotoUrlAndExit($url); } - public function handlesAuthentication() - { - return $this->handlesAuthentication; - } - /** - * Render our benchmark + * Detect whether the current request requires changes in the layout and apply them before rendering * - * @return string - */ - protected function renderBenchmark() - { - return '
'
-             . Benchmark::renderToHtml()
-             . '
'; - } - - /** - * After dispatch happend we are going to do some automagic stuff - * - * - Benchmark is completed and rendered - * - Notifications will be collected here - * - Layout is disabled for XHR requests - * - TODO: Headers with required JS and other things will be created - * for XHR requests - * - * @return void + * @see Zend_Controller_Action::postDispatch() */ public function postDispatch() { Benchmark::measure('Action::postDispatch()'); - // TODO: Move this elsewhere, this is just an ugly test: - if ($this->_request->getParam('filetype') === 'pdf') { - - // Snippet stolen from less compiler in public/css.php: - - require_once 'vendor/lessphp/lessc.inc.php'; - $less = new \lessc; - $cssdir = dirname(ICINGA_LIBDIR) . '/public/css'; - // TODO: We need a way to retrieve public dir, even if located elsewhere - - $css = $less->compileFile($cssdir . '/pdfprint.less'); - $this->render( - null, - $this->_helper->viewRenderer->getResponseSegment(), - $this->_helper->viewRenderer->getNoController() - ); - $html = (string) $this->getResponse(); - if ($this->module_name !== null) { - $html = '
' - . "\n" - . $html - . '
'; - } - - $html = '' . $html; - - $pdf = new Pdf(); - $pdf->AddPage(); - $pdf->setFontSubsetting(false); - $pdf->writeHTML($html); //0, 0, '', '', $html, 0, 1, 0, true, '', true); - - $pdf->Output('docs.pdf', 'I'); - exit; - } - // END of PDF test - - if ($this->_request->isXmlHttpRequest()) { if ($this->replaceLayout || $this->_getParam('_render') === 'body') { $this->_helper->layout()->setLayout('just-the-body'); @@ -322,22 +258,5 @@ class ActionController extends ZfController $this->_helper->layout()->setLayout('inline'); } } - $notification = Notification::getInstance(); - if ($notification->hasMessages()) { - $nhtml = '
    '; - foreach ($notification->getMessages() as $msg) { - $nhtml .= '
  • [' - . $msg->type - . '] ' - . htmlspecialchars($msg->message); - } - $nhtml .= '
'; - $this->getResponse()->append('notification', $nhtml); - } - - if (AuthManager::getInstance()->getSession()->get('show_benchmark')) { - Benchmark::measure('Response ready'); - $this->_helper->layout()->benchmark = $this->renderBenchmark(); - } } } diff --git a/library/Icinga/Web/Controller/ModuleActionController.php b/library/Icinga/Web/Controller/ModuleActionController.php index a2fdf6c68..fccf700b9 100644 --- a/library/Icinga/Web/Controller/ModuleActionController.php +++ b/library/Icinga/Web/Controller/ModuleActionController.php @@ -1,7 +1,9 @@ - * @author Icinga Development Team + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team */ // {{{ICINGA_LICENSE_HEADER}}} @@ -27,84 +30,12 @@ * Module action controller */ namespace Icinga\Web\Controller; - -use \Icinga\Application\Config as IcingaConfig; -use Icinga\Application\Icinga; - /** * Base class for all module action controllers * - * All Icinga Web module controllers should extend this class + * @TODO: Only here for compatibility and testing reasons, make ActionController testable and remove this (Bug #4540) * - * @copyright Copyright (c) 2013 Icinga-Web Team - * @author Icinga-Web Team - * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License - */ +*/ class ModuleActionController extends ActionController { - protected $module; - protected $module_dir; - - /** - * Gives you this modules base directory - * - * @return string - */ - public function getModuleDir() - { - if ($this->module_dir === null) { - $this->module_dir = $this->getModule()->getBaseDir(); - } - return $this->module_dir; - } - - public function getModule() - { - if ($this->module === null) { - $this->module = Icinga::app()->getModule( - $this->module_name - ); - } - return $this->module; - } - - /** - * Translates the given string with the modules translation catalog - * - * @param string $string The string that should be translated - * - * @return string - */ - public function translate($string) - { - return mt($this->module_name, $string); - } - - /** - * This is where the module configuration is going to be loaded - * - * @return void - */ - protected function loadConfig() - { - $this->config = IcingaConfig::module($this->module_name); - } - - /** - * Once dispatched we are going to place each modules output in a div - * container having the icinga-module and the icinga-$module-name classes - * - * @return void - */ - public function postDispatch() - { - parent::postDispatch(); - $this->_helper->layout()->moduleStart = - '
' - . "\n" - ; - $this->_helper->layout()->moduleEnd = "
\n"; - } } diff --git a/library/Icinga/Web/Url.php b/library/Icinga/Web/Url.php index 253bde3a7..6c99fbbdb 100644 --- a/library/Icinga/Web/Url.php +++ b/library/Icinga/Web/Url.php @@ -16,6 +16,14 @@ use Icinga\Application\Icinga; */ class Url { + /** + * Rather dirty hack as the ApplicationBootstrap isn't an interface right now and can't be mocked + * overwrite this to use a specific request for all Urls (so only in tests) + * + * @var null + */ + public static $overwrittenRequest = null; + /** * An array of all parameters stored in this Url * @@ -59,7 +67,7 @@ class Url public static function fromRequest(array $params = array(), $request = null) { if ($request === null) { - $request = Icinga::app()->getFrontController()->getRequest(); + $request = self::getRequest(); } $urlObject = new Url(); @@ -69,6 +77,19 @@ class Url return $urlObject; } + /** + * Return a request object that should be used for determining the URL + * + * @return Zend_Abstract_Request + */ + private static function getRequest() + { + if (self::$overwrittenRequest) { + return self::$overwrittenRequest; + } + return Icinga::app()->getFrontController()->getRequest(); + } + /** * Create a new Url class representing the given url * @@ -85,7 +106,7 @@ class Url { $urlObject = new Url(); if ($request === null) { - $request = Icinga::app()->getFrontController()->getRequest(); + $request = self::getRequest(); } $urlObject->setBaseUrl($request->getBaseUrl()); @@ -174,8 +195,7 @@ class Url public function getAbsoluteUrl() { $url = $this->getRelativeUrl(); - $baseUrl = '/'.ltrim($this->baseUrl, '/'); - return $baseUrl.'/'.$url; + return preg_replace('/\/{2,}/', '/', '/'.$this->baseUrl.'/'.$url); } /** diff --git a/library/Icinga/Web/Widget/Dashboard/Component.php b/library/Icinga/Web/Widget/Dashboard/Component.php index e47c3e90b..8c138e593 100644 --- a/library/Icinga/Web/Widget/Dashboard/Component.php +++ b/library/Icinga/Web/Widget/Dashboard/Component.php @@ -207,7 +207,7 @@ EOD; $html = str_replace('{URL}', $url->getAbsoluteUrl(), $this->template); $html = str_replace('{REMOVE_URL}', $removeUrl, $html); $html = str_replace('{DIMENSION}', $this->getBoxSizeAsCSS(), $html); - $html = str_replace('{TITLE}', $view->escape($this->getTitle()), $html); + $html = str_replace('{TITLE}', htmlentities($this->getTitle()), $html); return $html; } diff --git a/library/Icinga/Web/Widget/Tab.php b/library/Icinga/Web/Widget/Tab.php index 7393ea2ff..fd923ad72 100644 --- a/library/Icinga/Web/Widget/Tab.php +++ b/library/Icinga/Web/Widget/Tab.php @@ -29,6 +29,7 @@ namespace Icinga\Web\Widget; use Icinga\Exception\ProgrammingError; +use Icinga\Web\Url; use Zend_View_Abstract; /** @@ -99,7 +100,6 @@ class Tab implements Widget */ private $iconCls = null; - /** * Sets an icon image for this tab * @@ -107,6 +107,9 @@ class Tab implements Widget */ public function setIcon($icon) { + if (is_string($icon)) { + $icon = Url::fromPath($icon); + } $this->icon = $icon; } @@ -152,10 +155,12 @@ class Tab implements Widget */ public function setUrl($url) { + if (is_string($url)) { + $url = Url::fromPath($url); + } $this->url = $url; } - /** * Set the parameters to be set for this tabs Url * @@ -181,9 +186,6 @@ class Tab implements Widget $this->$setter($value); } } - if ($this->name === null) { - throw new ProgrammingError('Cannot create a nameless tab'); - } } /** @@ -203,6 +205,7 @@ class Tab implements Widget } + /** * @see Widget::render() */ @@ -210,24 +213,16 @@ class Tab implements Widget { $class = $this->active ? ' class="active"' : ''; $caption = $this->title; + if ($this->icon !== null) { - $caption = $view->img( - $this->icon, - array( - 'width' => 16, - 'height' => 16 - ) - ) . ' ' . $caption; + $caption = ' ' . $caption; } elseif ($this->iconCls !== null) { $caption = ' ' . $caption; } if ($this->url !== null) { - $tab = $view->qlink( - $caption, - $this->url, - $this->urlParams, - array('quote' => false) - ); + $this->url->addParams($this->urlParams); + $tab = '' . $caption . ''; } else { $tab = $caption; } diff --git a/library/Icinga/Web/Widget/Tabextension/BasketAction.php b/library/Icinga/Web/Widget/Tabextension/BasketAction.php new file mode 100644 index 000000000..8e5fdcd9b --- /dev/null +++ b/library/Icinga/Web/Widget/Tabextension/BasketAction.php @@ -0,0 +1,55 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Icinga\Web\Widget\Tabextension; + +use Icinga\Web\Widget\Tabs; +use Icinga\Web\Url; + +/** + * Tabextension that adds the basket command + * + * @TODO: Baskets are not supported in the codebase yet (Feature #4537) + */ +class BasketAction implements Tabextension +{ + /** + * @see Tabextension::apply() + */ + public function apply(Tabs $tabs) + { + $tabs->addAsDropdown('basket', array( + 'title' => 'URL Basket', + 'icon' => 'img/classic/basket.png', + 'url' => Url::fromPath('basket/add'), + 'urlParams' => array( + 'url' => Url::fromRequest()->getRelativeUrl() + ) + )); + } +} \ No newline at end of file diff --git a/library/Icinga/Web/Widget/Tabextension/DashboardAction.php b/library/Icinga/Web/Widget/Tabextension/DashboardAction.php new file mode 100644 index 000000000..cd5227628 --- /dev/null +++ b/library/Icinga/Web/Widget/Tabextension/DashboardAction.php @@ -0,0 +1,60 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Icinga\Web\Widget\Tabextension; + +use Icinga\Web\Url; +use Icinga\Config\Config as IcingaConfig; +use Icinga\Web\Widget\Tabs; +use Icinga\Web\Widget\Dashboard; + +/** + * Tabextension that allows to add the current URL to a dashboard + * + * Displayed as a dropdown field in the tabs + */ +class DashboardAction implements Tabextension +{ + /** + * @see Tabextension::apply() + */ + public function apply(Tabs $tabs) + { + $tabs->addAsDropdown( + 'dashboard', + array( + 'title' => 'Add to Dashboard', + 'iconCls' => 'dashboard', + 'url' => Url::fromPath('dashboard/addurl'), + 'urlParams' => array( + 'url' => Url::fromRequest()->getRelativeUrl() + ) + ) + ); + } +} diff --git a/library/Icinga/Web/Widget/Tabextension/OutputFormat.php b/library/Icinga/Web/Widget/Tabextension/OutputFormat.php new file mode 100644 index 000000000..d84f0d7e8 --- /dev/null +++ b/library/Icinga/Web/Widget/Tabextension/OutputFormat.php @@ -0,0 +1,128 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Icinga\Web\Widget\Tabextension; + +use Icinga\Application\Logger; +use Icinga\Web\Widget\Tab; +use Icinga\Web\Widget\Tabs; +use Icinga\Web\Url; + +/** + * Tabextension that offers different output formats for the user in the dropdown area + * + * + */ +class OutputFormat implements Tabextension +{ + /** + * PDF output type + */ + const TYPE_PDF = 'pdf'; + + /** + * JSON output type + */ + const TYPE_JSON = 'json'; + + /** + * CSV output type + */ + const TYPE_CSV = 'csv'; + + /** + * An array containing the tab definitions for all supported types + * + * Using array_keys on this array or isset allows to check whether a + * requested type is supported + * + * @var array + */ + private $supportedTypes = array( + self::TYPE_PDF => array( + 'name' => 'pdf', + 'title' => 'PDF', + 'icon' => 'img/classic/application-pdf.png', + 'urlParams' => array('filetype' => 'pdf') + ), + self::TYPE_CSV => array( + 'name' => 'csv', + 'title' => 'CSV', + 'icon' => 'img/classic/application-csv.png', + 'urlParams' => array('filetype' => 'csv') + ), + self::TYPE_JSON => array( + 'name' => 'json', + 'title' => 'JSON', + 'icon' => 'img/classic/application-json.png', + 'urlParams' => array('filetype' => 'json') + ) + ); + + /** + * An array of tabs to be added to the dropdown area + * + * @var array + */ + private $tabs = array(); + + /** + * Create a new OutputFormat extender + * + * In general, it's assumed that all types are supported when an outputFormat extension + * is added, so this class offers to remove specific types instead of adding ones + * + * @param array $disabled An array of output types to not show. + * + */ + public function __construct(array $disabled = array()) + { + foreach ($this->supportedTypes as $type => $values) { + if (in_array($type, $disabled)) { + continue; + } + if (!isset($this->supportedTypes[$type])) { + Logger::error('Tried to add an unsupported output type: %s', $type); + continue; + } + $tabConfig = $this->supportedTypes[$type]; + $tabConfig["url"] = Url::fromRequest(); + $this->tabs[] = new Tab($tabConfig); + } + } + + /** + * @see Tabextension::apply() + */ + public function apply(Tabs $tabs) + { + foreach ($this->tabs as $tab) { + $tabs->addAsDropdown($tab->getName(), $tab); + } + } +} \ No newline at end of file diff --git a/library/Icinga/Web/Widget/Tabextension/Tabextension.php b/library/Icinga/Web/Widget/Tabextension/Tabextension.php new file mode 100644 index 000000000..b301039a8 --- /dev/null +++ b/library/Icinga/Web/Widget/Tabextension/Tabextension.php @@ -0,0 +1,49 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Icinga\Web\Widget\Tabextension; + +use Icinga\Web\Widget\Tabs; + +/** +* Tabextension interface that allows to extend a tabbar with reusable components. +* +* Tabs can be either extended by creating a tabextension and calling the apply method +* or by calling the tabs @see \Icinga\Web\Widget\Tabs::extend() method and providing +* a tab extension. +* +**/ +interface Tabextension +{ + /** + * Apply this tabextension to the provided tabs + * + * @param Tabs $tabs The tabbar to modify + **/ + public function apply(Tabs $tabs); +} diff --git a/library/Icinga/Web/Widget/Tabs.php b/library/Icinga/Web/Widget/Tabs.php index 9ddc6cd13..0ffe3e273 100644 --- a/library/Icinga/Web/Widget/Tabs.php +++ b/library/Icinga/Web/Widget/Tabs.php @@ -29,7 +29,8 @@ namespace Icinga\Web\Widget; use Icinga\Exception\ProgrammingError; -use Icinga\Web\Url; +use Icinga\Web\Widget\Tabextension\Tabextension; +use Zend_View_Abstract; use Countable; @@ -39,6 +40,33 @@ use Countable; */ class Tabs implements Countable, Widget { + /** + * Template used for the base tabs + * + * @var string + */ + private $baseTpl =<<<'EOT' + +EOT; + + /** + * Template used for the tabs dropdown + * + * @var string + */ + private $dropdownTpl =<<<'EOT' + +EOT; + + /** * This is where single tabs added to this container will be stored * @@ -54,19 +82,11 @@ class Tabs implements Countable, Widget private $active; /** - * Class name(s) going to be assigned to the <ul> element + * Array of tab names which should be displayed in a dropdown * - * @var string + * @var array */ - private $tab_class = 'nav-tabs'; - - /** - * Array when special actions (dropdown) are enabled - * @TODO: Remove special part from tabs (Bug #4512) - * - * @var bool|array - */ - private $specialActions = false; + private $dropdownTabs = array(); /** * Activate the tab with the given name @@ -87,18 +107,8 @@ class Tabs implements Countable, Widget } $this->get($name)->setActive(); $this->active = $name; - return $this; } - - throw new ProgrammingError( - sprintf( - "Cannot activate a tab that doesn't exist: %s. Available: %s", - $name, - empty($this->tabs) - ? 'none' - : implode(', ', array_keys($this->tabs)) - ) - ); + return $this; } /** @@ -148,12 +158,7 @@ class Tabs implements Countable, Widget public function get($name) { if (!$this->has($name)) { - throw new ProgrammingError( - sprintf( - 'There is no such tab: %s', - $name - ) - ); + return null; } return $this->tabs[$name]; } @@ -207,84 +212,73 @@ class Tabs implements Countable, Widget } /** - * Enable special actions (dropdown with format, basket and dashboard) + * Add a tab to the dropdown on the right side of the tab-bar. * - * @TODO: Remove special part from tabs (Bug #4512) - * - * @return $this + * @param $name + * @param $tab */ - public function enableSpecialActions() + public function addAsDropdown($name, $tab) { - $this->specialActions = true; - return $this; + $this->set($name, $tab); + $this->dropdownTabs[] = $name; + $this->dropdownTabs = array_unique($this->dropdownTabs); + } + + /** + * Render the dropdown area with it's tabs and return the resulting HTML + * + * @param Zend_View_Abstract $view The view used for rendering + * + * @return mixed|string + */ + private function renderDropdownTabs(Zend_View_Abstract $view) + { + if (empty($this->dropdownTabs)) { + return ''; + } + $tabs = ''; + foreach ($this->dropdownTabs as $tabname) { + $tab = $this->get($tabname); + if ($tab === null) { + continue; + } + $tabs .= $tab->render($view); + } + return str_replace("{TABS}", $tabs, $this->dropdownTpl); + } + + /** + * Render all tabs, except the ones in dropdown area and return the resulting HTML + * + * @param Zend_View_Abstract $view The view used for rendering + * + * @return string + */ + private function renderTabs(Zend_View_Abstract $view) + { + $tabs = ''; + foreach ($this->tabs as $name => $tab) { + // ignore tabs added to dropdown + if (in_array($name, $this->dropdownTabs)) { + continue; + } + $tabs .= $tab->render($view); + } + return $tabs; } /** * @see Widget::render */ - public function render(\Zend_View_Abstract $view) + public function render(Zend_View_Abstract $view) { if (empty($this->tabs)) { return ''; } - $html = '\n"; + $html = $this->baseTpl; + $html = str_replace("{TABS}", $this->renderTabs($view), $html); + $html = str_replace("{DROPDOWN}", $this->renderDropdownTabs($view), $html); return $html; } @@ -309,4 +303,17 @@ class Tabs implements Countable, Widget { return $this->tabs; } + + /** + * Apply a Tabextension on this tabs object + * + * @param Tabextension $tabextension + * + * @return self + */ + public function extend(Tabextension $tabextension) + { + $tabextension->apply($this); + return $this; + } } diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 9fcb3638f..044ae6bcf 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -31,7 +31,9 @@ use Icinga\Web\Hook; use Icinga\File\Csv; use Monitoring\Backend; use Icinga\Application\Benchmark; -use Icinga\Web\Widget\Tabs; +use Icinga\Web\Widget\Tabextension\OutputFormat; +use Icinga\Web\Widget\Tabextension\DashboardAction; +use Icinga\Web\Widget\Tabextension\BasketAction; class Monitoring_ListController extends ModuleActionController { @@ -57,11 +59,9 @@ class Monitoring_ListController extends ModuleActionController */ public function init() { - $this->view->tabs = $this->getTabs() - ->activate($this->action_name) - ->enableSpecialActions(); $this->backend = Backend::getInstance($this->_getParam('backend')); $this->view->grapher = Hook::get('grapher'); + $this->createTabs(); } /** @@ -275,9 +275,14 @@ class Monitoring_ListController extends ModuleActionController * * @return Tabs */ - protected function getTabs() + protected function createTabs() { - $tabs = new Tabs(); + + $tabs = $this->getTabs(); + $tabs->extend(new OutputFormat()) + ->extend(new DashboardAction()) + ->extend(new BasketAction()); + $tabs->add('services', array( 'title' => 'All services', 'icon' => 'img/classic/service.png', @@ -290,9 +295,12 @@ class Monitoring_ListController extends ModuleActionController )); $tabs->add('downtimes', array( 'title' => 'Downtimes', + 'usePost' => true, 'icon' => 'img/classic/downtime.gif', 'url' => 'monitoring/list/downtimes', )); + + /* $tabs->add('hostgroups', array( 'title' => 'Hostgroups', @@ -315,7 +323,6 @@ class Monitoring_ListController extends ModuleActionController 'url' => 'monitoring/list/contactgroups', )); */ - return $tabs; } diff --git a/modules/monitoring/application/controllers/ShowController.php b/modules/monitoring/application/controllers/ShowController.php index f5f95a23a..231760ddd 100644 --- a/modules/monitoring/application/controllers/ShowController.php +++ b/modules/monitoring/application/controllers/ShowController.php @@ -33,14 +33,16 @@ use Icinga\Web\Hook; use Monitoring\Object\Host; use Monitoring\Object\Service; use Icinga\Application\Benchmark; -use Icinga\Web\Widget\Tabs; + +use Icinga\Web\Widget\Tabextension\OutputFormat; +use Icinga\Web\Widget\Tabextension\DashboardAction; +use Icinga\Web\Widget\Tabextension\BasketAction; + /** * Class Monitoring_ShowController * * Actions for show context */ - - class Monitoring_ShowController extends ModuleActionController { /** @@ -82,7 +84,7 @@ class Monitoring_ShowController extends ModuleActionController return; } $this->view->object = $object; - $this->view->tabs = $this->createTabs(); + $this->createTabs(); $this->prepareTicketHook(); } @@ -93,7 +95,6 @@ class Monitoring_ShowController extends ModuleActionController { Benchmark::measure('Entered service action'); $this->view->active = 'service'; - $this->view->tabs->activate('service')->enableSpecialActions(); if ($grapher = Hook::get('grapher')) { if ($grapher->hasGraph( @@ -209,7 +210,6 @@ class Monitoring_ShowController extends ModuleActionController public function hostAction() { $this->view->active = 'host'; - $this->view->tabs->activate('host')->enableSpecialActions(); if ($grapher = Hook::get('grapher')) { if ($grapher->hasGraph($this->view->host->host_name)) { @@ -302,6 +302,7 @@ class Monitoring_ShowController extends ModuleActionController ->where('object_type', 'host') ->fetchPairs(); $this->view->object->prefetch(); + $this->prepareTicketHook(); $this->prepareGrapherHook(); } @@ -426,7 +427,7 @@ class Monitoring_ShowController extends ModuleActionController protected function createTabs() { $object = $this->view->object; - $tabs = new Tabs(); + $tabs = $this->getTabs(); if (!$this->view->host) { return $tabs; } @@ -493,7 +494,9 @@ class Monitoring_ShowController extends ModuleActionController ); } - $tabs->activate($this->action_name)->enableSpecialActions(); + $tabs->extend(new OutputFormat()) + ->extend(new DashboardAction()) + ->extend(new BasketAction); /** $tabs->add('contacts', array( @@ -501,12 +504,8 @@ class Monitoring_ShowController extends ModuleActionController 'icon' => 'img/classic/customer.png', 'url' => 'monitoring/detail/contacts', 'urlParams' => $params, - )); - */ - // TODO: Inventory 'img/classic/facts.gif' - // Ticket 'img/classic/ticket.gif' - // Customer 'img/classic/customer.png' - return $tabs; + ));**/ + } } diff --git a/modules/monitoring/application/controllers/SoapController.php b/modules/monitoring/application/controllers/SoapController.php deleted file mode 100644 index cec6372bc..000000000 --- a/modules/monitoring/application/controllers/SoapController.php +++ /dev/null @@ -1,54 +0,0 @@ -select()->from('status', array( - 'host', 'service', 'host_state', 'service_state', 'service_output' -))->where('problems', 1)->fetchAll(); -} catch (Exception $e) { - return array('error' => $e->getMessage()); -} - return $result; - } -} - - -class Monitoring_SoapController extends ModuleActionController -{ - protected $handlesAuthentication = true; - - public function indexAction() - { - $wsdl = new ZfSoapAutoDiscover(); - $wsdl->setClass('Api'); - if (isset($_GET['wsdl'])) { - $wsdl->handle(); - } else { - $wsdl->dump('/tmp/test.wsdl'); - $uri = 'http://itenos-devel.tom.local/' . Url::fromPath('monitoring/soap'); - $server = new Zend_Soap_Server('/tmp/test.wsdl'); - $server->setClass('Api'); - $server->handle(); - } - exit; - } -} -// @codingStandardsIgnoreEnd diff --git a/modules/monitoring/application/controllers/SummaryController.php b/modules/monitoring/application/controllers/SummaryController.php index ba15eb2ca..23c1d6422 100644 --- a/modules/monitoring/application/controllers/SummaryController.php +++ b/modules/monitoring/application/controllers/SummaryController.php @@ -28,7 +28,6 @@ // {{{ICINGA_LICENSE_HEADER}}} use Icinga\Web\Controller\ModuleActionController; use Icinga\Backend; -use Icinga\Web\Widget\Tabs; class Monitoring_SummaryController extends ModuleActionController { @@ -39,13 +38,12 @@ class Monitoring_SummaryController extends ModuleActionController public function init() { $this->backend = Backend::getInstance($this->_getParam('backend')); - $this->view->compact = $this->_getParam('view') === 'compact'; $this->view->tabs = $this->getTabs(); } - protected function getTabs() + protected function createTabs() { - $tabs = new Tabs(); + $tabs = $this->getTabs(); $tabs->add('hostgroup', array( 'title' => 'Hostgroups', 'url' => 'monitoring/summary/group', @@ -94,4 +92,4 @@ class Monitoring_SummaryController extends ModuleActionController } } -// @codingStandardsIgnoreEnd \ No newline at end of file +// @codingStandardsIgnoreEnd diff --git a/modules/monitoring/bin/soaptest.php b/modules/monitoring/bin/soaptest.php deleted file mode 100644 index 2b0fada80..000000000 --- a/modules/monitoring/bin/soaptest.php +++ /dev/null @@ -1,21 +0,0 @@ - 'icingaadmin', - 'password' => 'tomtom', - 'trace' => true, - 'exceptions' => true, - 'cache_wsdl' => WSDL_CACHE_NONE, - 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, -// 'authentication' => SOAP_AUTHENTICATION_BASIC - -)); - -// print_r($client->__getFunctions()); -try { -print_r($client->problems()); -} catch (Exception $e) { - echo $e->getMessage() . "\n\n"; - echo $client->__getLastRequest() . "\n\n"; - echo $client->__getLastResponse() . "\n\n"; -} diff --git a/modules/monitoring/test/php/library/Backend/ComboTest.php b/modules/monitoring/test/php/library/Backend/ComboTest.php deleted file mode 100755 index dbee9cccf..000000000 --- a/modules/monitoring/test/php/library/Backend/ComboTest.php +++ /dev/null @@ -1,31 +0,0 @@ -markTestIncomplete('testInit is not implemented yet'); - } - - /** - * Test for Combo::ListServices() - * - **/ - public function testListServices() - { - $this->markTestIncomplete('testListServices is not implemented yet'); - } - -} diff --git a/modules/monitoring/test/php/library/Backend/IdoTest.php b/modules/monitoring/test/php/library/Backend/IdoTest.php deleted file mode 100755 index 9465d6b8d..000000000 --- a/modules/monitoring/test/php/library/Backend/IdoTest.php +++ /dev/null @@ -1,40 +0,0 @@ -markTestIncomplete('testInit is not implemented yet'); - } - - /** - * Test for Ido::GetSummary() - * - **/ - public function testGetSummary() - { - $this->markTestIncomplete('testGetSummary is not implemented yet'); - } - - /** - * Test for Ido::ListServices() - * - **/ - public function testListServices() - { - $this->markTestIncomplete('testListServices is not implemented yet'); - } - -} diff --git a/modules/monitoring/test/php/library/Backend/LivestatusTest.php b/modules/monitoring/test/php/library/Backend/LivestatusTest.php deleted file mode 100755 index aa45e5459..000000000 --- a/modules/monitoring/test/php/library/Backend/LivestatusTest.php +++ /dev/null @@ -1,40 +0,0 @@ -markTestIncomplete('testInit is not implemented yet'); - } - - /** - * Test for Livestatus::Summary() - * - **/ - public function testSummary() - { - $this->markTestIncomplete('testSummary is not implemented yet'); - } - - /** - * Test for Livestatus::ListServices() - * - **/ - public function testListServices() - { - $this->markTestIncomplete('testListServices is not implemented yet'); - } - -} diff --git a/modules/monitoring/test/php/library/Backend/MonitoringObjectListTest.php b/modules/monitoring/test/php/library/Backend/MonitoringObjectListTest.php deleted file mode 100755 index 426887f68..000000000 --- a/modules/monitoring/test/php/library/Backend/MonitoringObjectListTest.php +++ /dev/null @@ -1,67 +0,0 @@ -markTestIncomplete('testCurrent is not implemented yet'); - } - - /** - * Test for MonitoringObjectList::Next() - * - **/ - public function testNext() - { - $this->markTestIncomplete('testNext is not implemented yet'); - } - - /** - * Test for MonitoringObjectList::Key() - * - **/ - public function testKey() - { - $this->markTestIncomplete('testKey is not implemented yet'); - } - - /** - * Test for MonitoringObjectList::Valid() - * - **/ - public function testValid() - { - $this->markTestIncomplete('testValid is not implemented yet'); - } - - /** - * Test for MonitoringObjectList::Rewind() - * - **/ - public function testRewind() - { - $this->markTestIncomplete('testRewind is not implemented yet'); - } - - /** - * Test for MonitoringObjectList::__isset() - * - **/ - public function test__isset() - { - $this->markTestIncomplete('test__isset is not implemented yet'); - } - -} diff --git a/modules/monitoring/test/php/library/Backend/Statusdat/ServicelistQueryTest.php b/modules/monitoring/test/php/library/Backend/Statusdat/ServicelistQueryTest.php deleted file mode 100644 index b17ea5985..000000000 --- a/modules/monitoring/test/php/library/Backend/Statusdat/ServicelistQueryTest.php +++ /dev/null @@ -1,22 +0,0 @@ -markTestIncomplete('testInit is not implemented yet'); - } - -} diff --git a/modules/monitoring/test/php/library/Backend/StatusdatTest.php b/modules/monitoring/test/php/library/Backend/StatusdatTest.php deleted file mode 100755 index 673aa58d2..000000000 --- a/modules/monitoring/test/php/library/Backend/StatusdatTest.php +++ /dev/null @@ -1,31 +0,0 @@ -markTestIncomplete('testInit is not implemented yet'); - } - - /** - * Test for Statusdat::ListServices() - * - **/ - public function testListServices() - { - $this->markTestIncomplete('testListServices is not implemented yet'); - } - -} diff --git a/test/php/application/views/helpers/PerfdataTest.php b/test/php/application/views/helpers/PerfdataTest.php deleted file mode 100755 index 7085fb348..000000000 --- a/test/php/application/views/helpers/PerfdataTest.php +++ /dev/null @@ -1,21 +0,0 @@ -markTestIncomplete('testPerfdata is not implemented yet'); - } - -} diff --git a/test/php/application/views/helpers/QUrlTest.php b/test/php/application/views/helpers/QUrlTest.php deleted file mode 100755 index 923c93ec9..000000000 --- a/test/php/application/views/helpers/QUrlTest.php +++ /dev/null @@ -1,21 +0,0 @@ -markTestIncomplete('testQUrl is not implemented yet'); - } - -} diff --git a/test/php/application/views/helpers/QlinkTest.php b/test/php/application/views/helpers/QlinkTest.php deleted file mode 100755 index 5c447d850..000000000 --- a/test/php/application/views/helpers/QlinkTest.php +++ /dev/null @@ -1,71 +0,0 @@ -markTestIncomplete('testQlink is not implemented yet'); - } - - /* - * TODO: Url handling has benn moved to `library\Icinga\Web\Url`. Replace following tests. - */ -// public function testURLPathParameter() -// { -// $view = new Zend_View(); -// -// $helper = new Zend_View_Helper_Qlink(); -// $helper->setView($view); -// $pathTpl = "/path/%s/to/%s"; -// $this->assertEquals( -// "/path/param1/to/param2", -// $helper->getFormattedURL($pathTpl,array('param1','param2')) -// ); -// } -// -// public function testUrlGETParameter() -// { -// $view = new Zend_View(); -// $helper = new Zend_View_Helper_Qlink(); -// $helper->setView($view); -// $pathTpl = 'path'; -// $this->assertEquals( -// '/path?param1=value1&param2=value2', -// $helper->getFormattedURL($pathTpl,array('param1'=>'value1','param2'=>'value2')) -// ); -// } -// -// public function testMixedParameters() -// { -// $view = new Zend_View(); -// $helper = new Zend_View_Helper_Qlink(); -// $helper->setView($view); -// $pathTpl = 'path/%s/to/%s'; -// $this->assertEquals( -// '/path/path1/to/path2?param1=value1&param2=value2', -// $helper->getFormattedURL($pathTpl,array( -// 'path1','path2', -// 'param1'=>'value1', -// 'param2'=>'value2')) -// ); -// } -// -// // TODO: Test error case -// public function testWrongUrl() { -// -// } - -} diff --git a/test/php/application/views/helpers/RenderServicePerfdataTest.php b/test/php/application/views/helpers/RenderServicePerfdataTest.php deleted file mode 100755 index fd123ab4d..000000000 --- a/test/php/application/views/helpers/RenderServicePerfdataTest.php +++ /dev/null @@ -1,31 +0,0 @@ -markTestIncomplete('testRenderServicePerfdata is not implemented yet'); - } - - /** - * Test for Zend_View_Helper_RenderServicePerfdata::RenderDiskPie() - * Note: This method is static! - * - **/ - public function testRenderDiskPie() - { - $this->markTestIncomplete('testRenderDiskPie is not implemented yet'); - } - -} diff --git a/test/php/application/views/helpers/TimeSinceTest.php b/test/php/application/views/helpers/TimeSinceTest.php deleted file mode 100755 index 0d306e591..000000000 --- a/test/php/application/views/helpers/TimeSinceTest.php +++ /dev/null @@ -1,31 +0,0 @@ -markTestIncomplete('testTimeSince is not implemented yet'); - } - - /** - * Test for Zend_View_Helper_TimeSince::ShowHourMin() - * Note: This method is static! - * - **/ - public function testShowHourMin() - { - $this->markTestIncomplete('testShowHourMin is not implemented yet'); - } - -} diff --git a/test/php/application/views/helpers/UtilTest.php b/test/php/application/views/helpers/UtilTest.php deleted file mode 100755 index e2406853f..000000000 --- a/test/php/application/views/helpers/UtilTest.php +++ /dev/null @@ -1,82 +0,0 @@ -markTestIncomplete('testShowTimeSince is not implemented yet'); - } - - /** - * Test for Monlib_Gui_Util::ShowHourMin() - * Note: This method is static! - * - **/ - public function testShowHourMin() - { - $this->markTestIncomplete('testShowHourMin is not implemented yet'); - } - - /** - * Test for Monlib_Gui_Util::ShowSeconds() - * Note: This method is static! - * - **/ - public function testShowSeconds() - { - $this->markTestIncomplete('testShowSeconds is not implemented yet'); - } - - /** - * Test for Monlib_Gui_Util::ShowTime() - * Note: This method is static! - * - **/ - public function testShowTime() - { - $this->markTestIncomplete('testShowTime is not implemented yet'); - } - - /** - * Test for Monlib_Gui_Util::GetHostStateClassName() - * Note: This method is static! - * - **/ - public function testGetHostStateClassName() - { - $this->markTestIncomplete('testGetHostStateClassName is not implemented yet'); - } - - /** - * Test for Monlib_Gui_Util::GetHostStateName() - * Note: This method is static! - * - **/ - public function testGetHostStateName() - { - $this->markTestIncomplete('testGetHostStateName is not implemented yet'); - } - - /** - * Test for Monlib_Gui_Util::GetServiceStateName() - * Note: This method is static! - * - **/ - public function testGetServiceStateName() - { - $this->markTestIncomplete('testGetServiceStateName is not implemented yet'); - } - -} diff --git a/test/php/library/Icinga/Application/BootstrapTest.php b/test/php/library/Icinga/Application/BootstrapTest.php deleted file mode 100644 index 79d78f470..000000000 --- a/test/php/library/Icinga/Application/BootstrapTest.php +++ /dev/null @@ -1,135 +0,0 @@ -markTestIncomplete('testAddModule is not implemented yet'); - } - - /** - * Test for Bootstrap::GetApplicationDir() - * - **/ - public function testGetApplicationDir() - { - $this->markTestIncomplete('testGetApplicationDir is not implemented yet'); - } - - /** - * Test for Bootstrap::GetModuleDir() - * - **/ - public function testGetModuleDir() - { - $this->markTestIncomplete('testGetModuleDir is not implemented yet'); - } - - /** - * Test for Bootstrap::HasModule() - * - **/ - public function testHasModule() - { - $this->markTestIncomplete('testHasModule is not implemented yet'); - } - - /** - * Test for Bootstrap::IsLegacy() - * - **/ - public function testIsLegacy() - { - $this->markTestIncomplete('testIsLegacy is not implemented yet'); - } - - /** - * Test for Bootstrap::IsRunningOnCli() - * - **/ - public function testIsRunningOnCli() - { - $this->markTestIncomplete('testIsRunningOnCli is not implemented yet'); - } - - /** - * Test for Bootstrap::GetLecacyBasedir() - * - **/ - public function testGetLecacyBasedir() - { - $this->markTestIncomplete('testGetLecacyBasedir is not implemented yet'); - } - - /** - * Test for Bootstrap::Dispatch() - * - **/ - public function testDispatch() - { - $this->markTestIncomplete('testDispatch is not implemented yet'); - } - - /** - * Test for Bootstrap::Cli() - * Note: This method is static! - * - **/ - public function testCli() - { - $this->markTestIncomplete('testCli is not implemented yet'); - } - - /** - * Test for Bootstrap::ForIcingaWeb1x() - * Note: This method is static! - * - **/ - public function testForIcingaWeb1x() - { - $this->markTestIncomplete('testForIcingaWeb1x is not implemented yet'); - } - - /** - * Test for Bootstrap::Web() - * Note: This method is static! - * - **/ - public function testWeb() - { - $this->markTestIncomplete('testWeb is not implemented yet'); - } - - /** - * Test for Bootstrap::Embedded() - * Note: This method is static! - * - **/ - public function testEmbedded() - { - $this->markTestIncomplete('testEmbedded is not implemented yet'); - } - - /** - * Test for Bootstrap::GetInstance() - * Note: This method is static! - * - **/ - public function testGetInstance() - { - $this->markTestIncomplete('testGetInstance is not implemented yet'); - } - -} diff --git a/test/php/library/Icinga/Application/SessionTest.php b/test/php/library/Icinga/Application/SessionTest.php deleted file mode 100644 index acf6cf1ec..000000000 --- a/test/php/library/Icinga/Application/SessionTest.php +++ /dev/null @@ -1,23 +0,0 @@ -markTestIncomplete('testGetInstance is not implemented yet'); - } - -} diff --git a/test/php/library/Icinga/Authentication/CredentialsTest.php b/test/php/library/Icinga/Authentication/CredentialsTest.php deleted file mode 100644 index 91e14e5b3..000000000 --- a/test/php/library/Icinga/Authentication/CredentialsTest.php +++ /dev/null @@ -1,67 +0,0 @@ -markTestIncomplete('testGetUsername is not implemented yet'); - } - - /** - * Test for Credentials::SetUsername() - * - **/ - public function testSetUsername() - { - $this->markTestIncomplete('testSetUsername is not implemented yet'); - } - - /** - * Test for Credentials::GetPassword() - * - **/ - public function testGetPassword() - { - $this->markTestIncomplete('testGetPassword is not implemented yet'); - } - - /** - * Test for Credentials::SetPassword() - * - **/ - public function testSetPassword() - { - $this->markTestIncomplete('testSetPassword is not implemented yet'); - } - - /** - * Test for Credentials::GetDomain() - * - **/ - public function testGetDomain() - { - $this->markTestIncomplete('testGetDomain is not implemented yet'); - } - - /** - * Test for Credentials::SetDomain() - * - **/ - public function testSetDomain() - { - $this->markTestIncomplete('testSetDomain is not implemented yet'); - } - -} diff --git a/test/php/library/Icinga/Authentication/UserBackendTest.php b/test/php/library/Icinga/Authentication/UserBackendTest.php deleted file mode 100644 index d4ac95e6e..000000000 --- a/test/php/library/Icinga/Authentication/UserBackendTest.php +++ /dev/null @@ -1,31 +0,0 @@ -markTestIncomplete('testHasUsername is not implemented yet'); - } - - /** - * Test for UserBackend::Authenticate() - * - **/ - public function testAuthenticate() - { - $this->markTestIncomplete('testAuthenticate is not implemented yet'); - } - -} diff --git a/test/php/library/Icinga/BackendTest.php b/test/php/library/Icinga/BackendTest.php deleted file mode 100755 index 34658682a..000000000 --- a/test/php/library/Icinga/BackendTest.php +++ /dev/null @@ -1,23 +0,0 @@ -markTestIncomplete('testGetInstance is not implemented yet'); - } - -} diff --git a/test/php/library/Icinga/BenchmarkTest.php b/test/php/library/Icinga/BenchmarkTest.php deleted file mode 100755 index 889029b73..000000000 --- a/test/php/library/Icinga/BenchmarkTest.php +++ /dev/null @@ -1,73 +0,0 @@ -markTestIncomplete('testMeasure is not implemented yet'); - } - - /** - * Test for Benchmark::Reset() - * Note: This method is static! - * - **/ - public function testReset() - { - $this->markTestIncomplete('testReset is not implemented yet'); - } - - /** - * Test for Benchmark::GetStartTime() - * Note: This method is static! - * - **/ - public function testGetStartTime() - { - $this->markTestIncomplete('testGetStartTime is not implemented yet'); - } - - /** - * Test for Benchmark::Dump() - * Note: This method is static! - * - **/ - public function testDump() - { - $this->markTestIncomplete('testDump is not implemented yet'); - } - - /** - * Test for Benchmark::RenderToText() - * Note: This method is static! - * - **/ - public function testRenderToText() - { - $this->markTestIncomplete('testRenderToText is not implemented yet'); - } - - /** - * Test for Benchmark::RenderToHtml() - * Note: This method is static! - * - **/ - public function testRenderToHtml() - { - $this->markTestIncomplete('testRenderToHtml is not implemented yet'); - } - -} diff --git a/test/php/library/Icinga/FormatTest.php b/test/php/library/Icinga/FormatTest.php deleted file mode 100755 index 751b8cc5a..000000000 --- a/test/php/library/Icinga/FormatTest.php +++ /dev/null @@ -1,23 +0,0 @@ -markTestIncomplete('testBytes is not implemented yet'); - } - -} diff --git a/test/php/library/Icinga/Ido/DbTest.php b/test/php/library/Icinga/Ido/DbTest.php deleted file mode 100755 index 6bd102c54..000000000 --- a/test/php/library/Icinga/Ido/DbTest.php +++ /dev/null @@ -1,40 +0,0 @@ -markTestIncomplete('testModule is not implemented yet'); - } - - /** - * Test for Db::GetDb() - * - **/ - public function testGetDb() - { - $this->markTestIncomplete('testGetDb is not implemented yet'); - } - - /** - * Test for Db::GetPrefix() - * - **/ - public function testGetPrefix() - { - $this->markTestIncomplete('testGetPrefix is not implemented yet'); - } - -} diff --git a/test/php/library/Icinga/Protocol/Ldap/ConnectionTest.php b/test/php/library/Icinga/Protocol/Ldap/ConnectionTest.php deleted file mode 100644 index 70d2c00a8..000000000 --- a/test/php/library/Icinga/Protocol/Ldap/ConnectionTest.php +++ /dev/null @@ -1,67 +0,0 @@ -markTestIncomplete('testGetDN is not implemented yet'); - } - - /** - * Test for Connection::Root() - * - **/ - public function testRoot() - { - $this->markTestIncomplete('testRoot is not implemented yet'); - } - - /** - * Test for Connection::Select() - * - **/ - public function testSelect() - { - $this->markTestIncomplete('testSelect is not implemented yet'); - } - - /** - * Test for Connection::FetchOne() - * - **/ - public function testFetchOne() - { - $this->markTestIncomplete('testFetchOne is not implemented yet'); - } - - /** - * Test for Connection::FetchRow() - * - **/ - public function testFetchRow() - { - $this->markTestIncomplete('testFetchRow is not implemented yet'); - } - - /** - * Test for Connection::FetchAll() - * - **/ - public function testFetchAll() - { - $this->markTestIncomplete('testFetchAll is not implemented yet'); - } - -} diff --git a/test/php/library/Icinga/Protocol/Ldap/LdapUtilsTest.php b/test/php/library/Icinga/Protocol/Ldap/LdapUtilsTest.php deleted file mode 100644 index 9cf55b0b7..000000000 --- a/test/php/library/Icinga/Protocol/Ldap/LdapUtilsTest.php +++ /dev/null @@ -1,53 +0,0 @@ -markTestIncomplete('testExplodeDN is not implemented yet'); - } - - /** - * Test for LdapUtils::ImplodeDN() - * Note: This method is static! - * - **/ - public function testImplodeDN() - { - $this->markTestIncomplete('testImplodeDN is not implemented yet'); - } - - /** - * Test for LdapUtils::QuoteForDN() - * Note: This method is static! - * - **/ - public function testQuoteForDN() - { - $this->markTestIncomplete('testQuoteForDN is not implemented yet'); - } - - /** - * Test for LdapUtils::QuoteForSearch() - * Note: This method is static! - * - **/ - public function testQuoteForSearch() - { - $this->markTestIncomplete('testQuoteForSearch is not implemented yet'); - } - -} diff --git a/test/php/library/Icinga/Protocol/Ldap/NodeTest.php b/test/php/library/Icinga/Protocol/Ldap/NodeTest.php deleted file mode 100644 index 1ec9d61f0..000000000 --- a/test/php/library/Icinga/Protocol/Ldap/NodeTest.php +++ /dev/null @@ -1,50 +0,0 @@ -markTestIncomplete('testGetRDN is not implemented yet'); - } - - /** - * Test for Node::GetDN() - * - **/ - public function testGetDN() - { - $this->markTestIncomplete('testGetDN is not implemented yet'); - } - - /** - * Test for Node::__get() - * - **/ - public function test__get() - { - $this->markTestIncomplete('test__get is not implemented yet'); - } - - /** - * Test for Node::CreateWithRDN() - * Note: This method is static! - * - **/ - public function testCreateWithRDN() - { - $this->markTestIncomplete('testCreateWithRDN is not implemented yet'); - } - -} diff --git a/test/php/library/Icinga/Protocol/Ldap/RootTest.php b/test/php/library/Icinga/Protocol/Ldap/RootTest.php deleted file mode 100644 index d321acbed..000000000 --- a/test/php/library/Icinga/Protocol/Ldap/RootTest.php +++ /dev/null @@ -1,77 +0,0 @@ -markTestIncomplete('testHasParent is not implemented yet'); - } - - /** - * Test for Root::GetConnection() - * - **/ - public function testGetConnection() - { - $this->markTestIncomplete('testGetConnection is not implemented yet'); - } - - /** - * Test for Root::HasBeenChanged() - * - **/ - public function testHasBeenChanged() - { - $this->markTestIncomplete('testHasBeenChanged is not implemented yet'); - } - - /** - * Test for Root::GetRDN() - * - **/ - public function testGetRDN() - { - $this->markTestIncomplete('testGetRDN is not implemented yet'); - } - - /** - * Test for Root::GetDN() - * - **/ - public function testGetDN() - { - $this->markTestIncomplete('testGetDN is not implemented yet'); - } - - /** - * Test for Root::__get() - * - **/ - public function test__get() - { - $this->markTestIncomplete('test__get is not implemented yet'); - } - - /** - * Test for Root::ForConnection() - * Note: This method is static! - * - **/ - public function testForConnection() - { - $this->markTestIncomplete('testForConnection is not implemented yet'); - } - -} diff --git a/test/php/library/Icinga/Protocol/Livestatus/ConnectionTest.php b/test/php/library/Icinga/Protocol/Livestatus/ConnectionTest.php index 58ecbef9c..87c45217a 100755 --- a/test/php/library/Icinga/Protocol/Livestatus/ConnectionTest.php +++ b/test/php/library/Icinga/Protocol/Livestatus/ConnectionTest.php @@ -18,15 +18,6 @@ require_once('../../library/Icinga/Protocol/Livestatus/Query.php'); class ConnectionTest extends TestCase { - /** - * Test for Connection::HasTable() - * - **/ - public function testHasTable() - { - $this->markTestIncomplete('testHasTable is not implemented yet'); - } - /** * Test for Connection::Select() * @@ -39,31 +30,4 @@ class ConnectionTest extends TestCase unlink($socket); } - /** - * Test for Connection::FetchAll() - * - **/ - public function testFetchAll() - { - $this->markTestIncomplete('testFetchAll is not implemented yet'); - } - - /** - * Test for Connection::Disconnect() - * - **/ - public function testDisconnect() - { - $this->markTestIncomplete('testDisconnect is not implemented yet'); - } - - /** - * Test for Connection::__destruct() - * - **/ - public function test__destruct() - { - $this->markTestIncomplete('test__destruct is not implemented yet'); - } - } diff --git a/test/php/library/Icinga/Protocol/Livestatus/QueryTest.php b/test/php/library/Icinga/Protocol/Livestatus/QueryTest.php deleted file mode 100755 index 020396ebc..000000000 --- a/test/php/library/Icinga/Protocol/Livestatus/QueryTest.php +++ /dev/null @@ -1,148 +0,0 @@ -markTestIncomplete('testCompare is not implemented yet'); - } - - /** - * Test for Query::HasOrder() - * - **/ - public function testHasOrder() - { - $this->markTestIncomplete('testHasOrder is not implemented yet'); - } - - /** - * Test for Query::Where() - * - **/ - public function testWhere() - { - $this->markTestIncomplete('testWhere is not implemented yet'); - } - - /** - * Test for Query::Order() - * - **/ - public function testOrder() - { - $this->markTestIncomplete('testOrder is not implemented yet'); - } - - /** - * Test for Query::Limit() - * - **/ - public function testLimit() - { - $this->markTestIncomplete('testLimit is not implemented yet'); - } - - /** - * Test for Query::HasLimit() - * - **/ - public function testHasLimit() - { - $this->markTestIncomplete('testHasLimit is not implemented yet'); - } - - /** - * Test for Query::HasOffset() - * - **/ - public function testHasOffset() - { - $this->markTestIncomplete('testHasOffset is not implemented yet'); - } - - /** - * Test for Query::GetLimit() - * - **/ - public function testGetLimit() - { - $this->markTestIncomplete('testGetLimit is not implemented yet'); - } - - /** - * Test for Query::GetOffset() - * - **/ - public function testGetOffset() - { - $this->markTestIncomplete('testGetOffset is not implemented yet'); - } - - /** - * Test for Query::From() - * - **/ - public function testFrom() - { - $this->markTestIncomplete('testFrom is not implemented yet'); - } - - /** - * Test for Query::HasColumns() - * - **/ - public function testHasColumns() - { - $this->markTestIncomplete('testHasColumns is not implemented yet'); - } - - /** - * Test for Query::GetColumns() - * - **/ - public function testGetColumns() - { - $this->markTestIncomplete('testGetColumns is not implemented yet'); - } - - /** - * Test for Query::__toString() - * - **/ - public function test__toString() - { - $this->markTestIncomplete('test__toString is not implemented yet'); - } - - /** - * Test for Query::__destruct() - * - **/ - public function test__destruct() - { - $this->markTestIncomplete('test__destruct is not implemented yet'); - } - -} diff --git a/test/php/library/Icinga/Web/ActionControllerTest.php b/test/php/library/Icinga/Web/ActionControllerTest.php deleted file mode 100755 index 9e7ed9e66..000000000 --- a/test/php/library/Icinga/Web/ActionControllerTest.php +++ /dev/null @@ -1,6 +0,0 @@ - + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + + +namespace Tests\Icinga\Web; + +/** + * Request mock that implements all methods required by the + * Url class + * + */ +class RequestMock +{ + /** + * The path of the request + * + * @var string + */ + public $path = ""; + + /** + * The baseUrl of the request + * + * @var string + */ + public $baseUrl = '/'; + + /** + * An array of query parameters that the request should resemble + * + * @var array + */ + public $query = array(); + + /** + * Returns the path set for the request + * + * @return string + */ + public function getPathInfo() + { + return $this->path; + } + + /** + * Returns the baseUrl set for the request + * + * @return string + */ + public function getBaseUrl() + { + return $this->baseUrl; + } + + /** + * Returns the query set for the request + * + * @return array + */ + public function getQuery() + { + return $this->query; + } +} \ No newline at end of file diff --git a/test/php/library/Icinga/Web/UrlTest.php b/test/php/library/Icinga/Web/UrlTest.php index 6caa89cbe..6488b7d9c 100644 --- a/test/php/library/Icinga/Web/UrlTest.php +++ b/test/php/library/Icinga/Web/UrlTest.php @@ -2,69 +2,10 @@ namespace Tests\Icinga\Web; require_once('../../library/Icinga/Web/Url.php'); +require_once('library/Icinga/Web/RequestMock.php'); use Icinga\Web\Url; - - -/** - * Request mock that implements all methods required by the - * Url class - * - */ -class RequestMock -{ - /** - * The path of the request - * - * @var string - */ - public $path = ""; - - /** - * The baseUrl of the request - * - * @var string - */ - public $baseUrl = ""; - - /** - * An array of query parameters that the request should resemble - * - * @var array - */ - public $query = array(); - - /** - * Returns the path set for the request - * - * @return string - */ - public function getPathInfo() - { - return $this->path; - } - - /** - * Returns the baseUrl set for the request - * - * @return string - */ - public function getBaseUrl() - { - return $this->baseUrl; - } - - /** - * Returns the query set for the request - * - * @return array - */ - public function getQuery() - { - return $this->query; - } -} - +use Tests\Icinga\Web\RequestMock; /** * Tests for the Icinga\Web\Url class that provides convenient access to Url manipulation method diff --git a/test/php/library/Icinga/Web/ViewMock.php b/test/php/library/Icinga/Web/ViewMock.php new file mode 100644 index 000000000..68a413cc3 --- /dev/null +++ b/test/php/library/Icinga/Web/ViewMock.php @@ -0,0 +1,47 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + + +namespace Tests\Icinga\Web; + +require_once('Zend/View/Abstract.php'); +use \Zend_View_Abstract; + +/** + * ViewMock that does absolutely nothing + * + */ +class ViewMock extends Zend_View_Abstract +{ + /** + * No operation is performed here + */ + protected function _run() + { + } +} \ No newline at end of file diff --git a/test/php/library/Icinga/Web/Widget/TabTest.php b/test/php/library/Icinga/Web/Widget/TabTest.php new file mode 100644 index 000000000..baf94cc83 --- /dev/null +++ b/test/php/library/Icinga/Web/Widget/TabTest.php @@ -0,0 +1,164 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Tests\Icinga\Web\Widget; + +require_once('../../library/Icinga/Web/Widget/Widget.php'); +require_once('../../library/Icinga/Web/Widget/Tab.php'); +require_once('../../library/Icinga/Web/Url.php'); +require_once('library/Icinga/Web/RequestMock.php'); +require_once('library/Icinga/Web/ViewMock.php'); +require_once('Zend/View/Abstract.php'); + +use Icinga\Web\View; +use Icinga\Web\Widget\Tab; +use Icinga\Web\Url; +use Tests\Icinga\Web\RequestMock; +use \Zend_View_Abstract; +use \PHPUnit_Framework_TestCase; + +use Tests\Icinga\Web\ViewMock; + +/** + * Test creation and rendering of tabs + * + */ +class TabTest extends PHPUnit_Framework_TestCase +{ + + /** + * Test whether rendering a tab without URL is done correctly + * + */ + public function testRenderWithoutUrl() + { + $tab = new Tab(array("name" => "tab", "title" => "Title text")); + $html = $tab->render(new ViewMock()); + + $this->assertEquals( + 1, + preg_match( + '/
  • *Title text *<\/li> */i', + $html + ), + "Asserting an tab without url only showing a title, , got " . $html + ); + } + + /** + * Test whether rendering an active tab adds the 'class' property + * + */ + public function testActiveTab() + { + $tab = new Tab(array("name" => "tab", "title" => "Title text")); + $tab->setActive(true); + + $html = $tab->render(new ViewMock()); + $this->assertEquals( + 1, + preg_match( + '/
  • *Title text *<\/li> */i', + $html + ), + "Asserting an active tab having the 'active' class provided, got " . $html + ); + } + + /** + * Test whether rendering a tab with URL adds a n >a< tag correctly + * + */ + public function testTabWithUrl() + { + $tab = new Tab( + array( + "name" => "tab", + "title" => "Title text", + "url" => Url::fromPath("my/url", array(), new RequestMock()) + ) + ); + $html = $tab->render(new ViewMock()); + $this->assertEquals( + 1, + preg_match( + '/
  • Title text<\/a><\/li>/i', + $html + ), + 'Asserting an url being rendered inside an HTML anchor. got ' . $html + ); + } + + /** + * Test wheter the 'icon' property adds an img tag + * + */ + public function testTabWithIconImage() + { + $tab = new Tab( + array( + "name" => "tab", + "title" => "Title text", + "icon" => Url::fromPath("my/url", array(), new RequestMock()) + ) + ); + $html = $tab->render(new ViewMock()); + $this->assertEquals( + 1, + preg_match( + '/
  • Title text<\/li>/i', + $html + ), + 'Asserting an url being rendered inside an HTML anchor. got ' . $html + ); + } + + /** + * Test wheter the iconCls property adds an i tag with the icon + * + */ + public function testTabWithIconClass() + { + $tab = new Tab( + array( + "name" => "tab", + "title" => "Title text", + "iconCls" => "myIcon" + ) + ); + $html = $tab->render(new ViewMock()); + $this->assertEquals( + 1, + preg_match( + '/
  • <\/i> Title text<\/li>/i', + $html + ), + 'Asserting an url being rendered inside an HTML anchor. got ' . $html + ); + } +} \ No newline at end of file diff --git a/test/php/library/Icinga/Web/Widget/Tabextension/OutputFormatTest.php b/test/php/library/Icinga/Web/Widget/Tabextension/OutputFormatTest.php new file mode 100644 index 000000000..03606f0a9 --- /dev/null +++ b/test/php/library/Icinga/Web/Widget/Tabextension/OutputFormatTest.php @@ -0,0 +1,88 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Tests\Icinga\Web\Widget\Tabextension; + +require_once('../../library/Icinga/Web/Widget/Widget.php'); +require_once('../../library/Icinga/Web/Widget/Tab.php'); +require_once('../../library/Icinga/Web/Widget/Tabs.php'); +require_once('../../library/Icinga/Web/Widget/Tabextension/TabExtension.php'); +require_once('../../library/Icinga/Web/Widget/Tabextension/OutputFormat.php'); +require_once('../../library/Icinga/Web/Url.php'); + +require_once('library/Icinga/Web/RequestMock.php'); +require_once('library/Icinga/Web/ViewMock.php'); + +require_once('Zend/View/Abstract.php'); + +use Icinga\Web\View; +use Icinga\Web\Url; +use Icinga\Web\Widget\Tabextension\OutputFormat; +use PHPUnit_Framework_TestCase; +use Icinga\Web\Widget\Tabs; +use Tests\Icinga\Web\RequestMock; +use Tests\Icinga\Web\ViewMock; +use \Zend_View_Abstract; + + +/** + * Test for the OutputFormat Tabextension + * + */ +class OutputFormatTest extends PHPUnit_Framework_TestCase +{ + /** + * Test if a simple apply adds all tabs from the extender + * + */ + public function testApply() + { + $tabs = new Tabs(); + Url::$overwrittenRequest = new RequestMock(); + $tabs->extend(new OutputFormat()); + $this->assertEquals(3, $tabs->count(), "Asserting new tabs being available after extending the tab bar"); + Url::$overwrittenRequest = null; + } + + /** + * Test if an apply with disabled output formats doesn't add these tabs + * + */ + public function testDisableOutputFormat() + { + Url::$overwrittenRequest = new RequestMock(); + $tabs = new Tabs(); + $tabs->extend(new OutputFormat(array(OutputFormat::TYPE_PDF))); + $this->assertEquals( + 2, + $tabs->count(), + "Asserting two tabs being available after extending the tab bar and ignoring PDF" + ); + Url::$overwrittenRequest = null; + } +} \ No newline at end of file diff --git a/test/php/library/Icinga/Web/Widget/TabsTest.php b/test/php/library/Icinga/Web/Widget/TabsTest.php new file mode 100644 index 000000000..91c793bd7 --- /dev/null +++ b/test/php/library/Icinga/Web/Widget/TabsTest.php @@ -0,0 +1,111 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + + +namespace Tests\Icinga\Web\Widget; + +require_once('../../library/Icinga/Web/Widget/Widget.php'); +require_once('../../library/Icinga/Web/Widget/Tab.php'); +require_once('../../library/Icinga/Web/Widget/Tabs.php'); +require_once('../../library/Icinga/Web/Url.php'); + +require_once('library/Icinga/Web/ViewMock.php'); +require_once('Zend/View/Abstract.php'); + +use Icinga\Web\View; +use Icinga\Web\Url; +use Icinga\Web\Widget\Tabs; +use Tests\Icinga\Web\ViewMock; + +use \Zend_View_Abstract; +use \PHPUnit_Framework_TestCase; + +/** + * Test rendering of tabs and corretct tab management + * + */ +class TabsTest extends PHPUnit_Framework_TestCase +{ + + /** + * Test adding tabs and asserting for correct count + * + */ + public function testAddTabs() + { + $tabs = new Tabs(); + $this->assertEquals(0, $tabs->count(), 'Asserting a tab bar starting with no items'); + $tabs->add('tab1', array('title' => 'Tab 1')); + $tabs->add('tab2', array('title' => 'Tab 2')); + $this->assertEquals(2, $tabs->count(), 'Asserting a tab bar containing 2 items after being added'); + + $this->assertTrue( + $tabs->has('tab1'), + 'Asserting the tab bar to determine the existence of added tabs correctly (tab1)' + ); + + $this->assertTrue( + $tabs->has('tab2'), + 'Asserting the tab bar to determine the existence of added tabs correctly (tab2)' + ); + } + + /** + * Test rendering of tabs when no dropdown is requested + * + */ + public function testRenderTabsWithoutDropdown() + { + $tabs = new Tabs(); + + $tabs->add('tab1', array('title' => 'Tab 1')); + $tabs->add('tab2', array('title' => 'Tab 2')); + + $html = $tabs->render(new ViewMock()); + $this->assertContains('
  • Tab 1
  • ', $html, 'Asserting tab 1 being rendered correctly' . $html); + $this->assertContains('
  • Tab 2
  • ', $html, 'Asserting tab 2 being rendered correctly' . $html); + $this->assertNotContains('class="dropdown ', 'Asserting the dropdown to not be rendered' . $html); + } + + /** + * Test rendering of tabs when dropdown is requested + * + */ + public function testRenderDropdown() + { + $tabs = new Tabs(); + + $tabs->add('tab1', array('title' => 'Tab 1')); + $tabs->addAsDropdown('tab2', array('title' => 'Tab 2')); + + $html = $tabs->render(new ViewMock()); + $this->assertContains('
  • Tab 1
  • ', $html, 'Asserting tab 1 being rendered correctly ' . $html); + $this->assertContains('
  • Tab 2
  • ', $html, 'Asserting tab 2 being rendered correctly ' . $html); + $this->assertContains('class="dropdown ', 'Asserting the dropdown to be rendered, got ' . $html); + } +} \ No newline at end of file From 49d56f1eabd99b412c2d323fe5a8a6a4210e831a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannis=20Mo=C3=9Fhammer?= Date: Mon, 12 Aug 2013 09:49:59 +0200 Subject: [PATCH 2/6] Fix capitalization error in test require refs #4512 --- .../library/Icinga/Web/Widget/Tabextension/OutputFormatTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/php/library/Icinga/Web/Widget/Tabextension/OutputFormatTest.php b/test/php/library/Icinga/Web/Widget/Tabextension/OutputFormatTest.php index 03606f0a9..bc6fc8500 100644 --- a/test/php/library/Icinga/Web/Widget/Tabextension/OutputFormatTest.php +++ b/test/php/library/Icinga/Web/Widget/Tabextension/OutputFormatTest.php @@ -31,7 +31,7 @@ namespace Tests\Icinga\Web\Widget\Tabextension; require_once('../../library/Icinga/Web/Widget/Widget.php'); require_once('../../library/Icinga/Web/Widget/Tab.php'); require_once('../../library/Icinga/Web/Widget/Tabs.php'); -require_once('../../library/Icinga/Web/Widget/Tabextension/TabExtension.php'); +require_once('../../library/Icinga/Web/Widget/Tabextension/Tabextension.php'); require_once('../../library/Icinga/Web/Widget/Tabextension/OutputFormat.php'); require_once('../../library/Icinga/Web/Url.php'); From 0b479e3796b2722ed17a62ab52f86269303210b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannis=20Mo=C3=9Fhammer?= Date: Wed, 14 Aug 2013 16:00:19 +0200 Subject: [PATCH 3/6] Code style fixes, fix documentation, fix tab parameters not being overwritten refs #4512 --- doc/widgets.md | 6 ++--- .../Web/Controller/ModuleActionController.php | 1 + library/Icinga/Web/Url.php | 19 ++++++++++++--- library/Icinga/Web/Widget/Dashboard.php | 16 ++++++------- library/Icinga/Web/Widget/Tab.php | 10 +++----- .../Web/Widget/Tabextension/BasketAction.php | 23 +++++++++++-------- .../Widget/Tabextension/DashboardAction.php | 11 +++++---- .../Web/Widget/Tabextension/OutputFormat.php | 6 ++++- .../Web/Widget/Tabextension/Tabextension.php | 2 +- library/Icinga/Web/Widget/Tabs.php | 8 +++---- .../controllers/SummaryController.php | 1 - public/js/icinga/components/mainDetail.js | 4 +--- test/php/library/Icinga/Web/RequestMock.php | 2 +- test/php/library/Icinga/Web/ViewMock.php | 5 +++- 14 files changed, 67 insertions(+), 47 deletions(-) diff --git a/doc/widgets.md b/doc/widgets.md index 8a8710f20..75d7eedac 100644 --- a/doc/widgets.md +++ b/doc/widgets.md @@ -12,7 +12,7 @@ simple interface, only providing a 'render' method that takes a view and returns public function render(Zend_View_Abstract $view); } -When implementing own Widgets you just have to make sure that your provide this render method. +When implementing own Widgets you just have to make sure that you provide this render method. ## Using widgets @@ -24,7 +24,7 @@ Widgets are normally created in the controller and added to the view: $this->view->myWidget = new MyWidget(); } - The HTML is then rendered in the template using the *render()* method described above. As the '$this' scope in a view is your + The HTML is then rendered in the template using the *render()* method described above. As the '$this' scope in a view is a reference to your current view, you can just pass it to the *render()* method: // in your template @@ -41,7 +41,7 @@ Tab bar, you just have to call: $tabbar = new Tabs(); -**Note** : When using an ActionController, there's already an empty tabs object created unter $this->view->tabs. This is +**Note** : When using an ActionController, there's already an empty tabs object created under $this->view->tabs. This is done in the preDispatch function ### Adding tabs diff --git a/library/Icinga/Web/Controller/ModuleActionController.php b/library/Icinga/Web/Controller/ModuleActionController.php index fccf700b9..1063b7821 100644 --- a/library/Icinga/Web/Controller/ModuleActionController.php +++ b/library/Icinga/Web/Controller/ModuleActionController.php @@ -30,6 +30,7 @@ * Module action controller */ namespace Icinga\Web\Controller; + /** * Base class for all module action controllers * diff --git a/library/Icinga/Web/Url.php b/library/Icinga/Web/Url.php index 6c99fbbdb..061726a68 100644 --- a/library/Icinga/Web/Url.php +++ b/library/Icinga/Web/Url.php @@ -201,8 +201,8 @@ class Url /** * Add a set of parameters to the query part if the keys don't exist yet * - * @param array $params The parameters to add - * @return $this + * @param array $params The parameters to add + * @return self */ public function addParams(array $params) { @@ -210,6 +210,18 @@ class Url return $this; } + /** + * Set and overwrite the given params if one if the same key already exists + * + * @param array $params The parameters to set + * @return self + */ + public function overwriteParams(array $params) + { + $this->params = array_merge($this->params, $params); + return $this; + } + /** * Overwrite the parameters used in the query part * @@ -338,7 +350,8 @@ class Url * Alias for @see Url::getAbsoluteUrl() * @return mixed */ - public function __toString() { + public function __toString() + { return $this->getAbsoluteUrl(); } } diff --git a/library/Icinga/Web/Widget/Dashboard.php b/library/Icinga/Web/Widget/Dashboard.php index 7500246aa..724c5ccb0 100644 --- a/library/Icinga/Web/Widget/Dashboard.php +++ b/library/Icinga/Web/Widget/Dashboard.php @@ -28,16 +28,16 @@ namespace Icinga\Web\Widget; -use Icinga\Application\Icinga; +use \Icinga\Application\Icinga; use \Icinga\Application\Config as IcingaConfig; -use Icinga\Application\Logger; -use Icinga\Exception\ConfigurationError; -use Icinga\Web\Widget\Widget; -use Icinga\Web\Widget\Dashboard\Pane; -use Icinga\Web\Widget\Dashboard\Component as DashboardComponent; +use \Icinga\Application\Logger; +use \Icinga\Exception\ConfigurationError; +use \Icinga\Web\Widget\Widget; +use \Icinga\Web\Widget\Dashboard\Pane; +use \Icinga\Web\Widget\Dashboard\Component as DashboardComponent; -use Icinga\Web\Url; -use Zend_View_Abstract; +use \Icinga\Web\Url; +use \Zend_View_Abstract; /** * Dashboards display multiple views on a single page diff --git a/library/Icinga/Web/Widget/Tab.php b/library/Icinga/Web/Widget/Tab.php index fd923ad72..95f972159 100644 --- a/library/Icinga/Web/Widget/Tab.php +++ b/library/Icinga/Web/Widget/Tab.php @@ -28,9 +28,8 @@ namespace Icinga\Web\Widget; -use Icinga\Exception\ProgrammingError; -use Icinga\Web\Url; -use Zend_View_Abstract; +use \Icinga\Web\Url; +use \Zend_View_Abstract; /** * A single tab, usually used through the tabs widget @@ -45,9 +44,6 @@ use Zend_View_Abstract; * base URL * @property string $urlParams Action URL Parameters * - * @copyright Copyright (c) 2013 Icinga-Web Team - * @author Icinga-Web Team - * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License */ class Tab implements Widget { @@ -221,7 +217,7 @@ class Tab implements Widget $caption = ' ' . $caption; } if ($this->url !== null) { - $this->url->addParams($this->urlParams); + $this->url->overwriteParams($this->urlParams); $tab = '
    ' . $caption . ''; } else { $tab = $caption; diff --git a/library/Icinga/Web/Widget/Tabextension/BasketAction.php b/library/Icinga/Web/Widget/Tabextension/BasketAction.php index 8e5fdcd9b..0e6a99d82 100644 --- a/library/Icinga/Web/Widget/Tabextension/BasketAction.php +++ b/library/Icinga/Web/Widget/Tabextension/BasketAction.php @@ -28,8 +28,8 @@ namespace Icinga\Web\Widget\Tabextension; -use Icinga\Web\Widget\Tabs; -use Icinga\Web\Url; +use \Icinga\Web\Widget\Tabs; +use \Icinga\Web\Url; /** * Tabextension that adds the basket command @@ -43,13 +43,16 @@ class BasketAction implements Tabextension */ public function apply(Tabs $tabs) { - $tabs->addAsDropdown('basket', array( - 'title' => 'URL Basket', - 'icon' => 'img/classic/basket.png', - 'url' => Url::fromPath('basket/add'), - 'urlParams' => array( - 'url' => Url::fromRequest()->getRelativeUrl() + $tabs->addAsDropdown( + 'basket', + array( + 'title' => 'URL Basket', + 'icon' => 'img/classic/basket.png', + 'url' => Url::fromPath('basket/add'), + 'urlParams' => array( + 'url' => Url::fromRequest()->getRelativeUrl() + ) ) - )); + ); } -} \ No newline at end of file +} diff --git a/library/Icinga/Web/Widget/Tabextension/DashboardAction.php b/library/Icinga/Web/Widget/Tabextension/DashboardAction.php index cd5227628..9b5fe3865 100644 --- a/library/Icinga/Web/Widget/Tabextension/DashboardAction.php +++ b/library/Icinga/Web/Widget/Tabextension/DashboardAction.php @@ -28,10 +28,10 @@ namespace Icinga\Web\Widget\Tabextension; -use Icinga\Web\Url; -use Icinga\Config\Config as IcingaConfig; -use Icinga\Web\Widget\Tabs; -use Icinga\Web\Widget\Dashboard; +use \Icinga\Web\Url; +use \Icinga\Config\Config as IcingaConfig; +use \Icinga\Web\Widget\Tabs; +use \Icinga\Web\Widget\Dashboard; /** * Tabextension that allows to add the current URL to a dashboard @@ -41,6 +41,9 @@ use Icinga\Web\Widget\Dashboard; class DashboardAction implements Tabextension { /** + * Applies the dashboard actions to the provided tabset + * + * @param Tabs The tabs object to extend with * @see Tabextension::apply() */ public function apply(Tabs $tabs) diff --git a/library/Icinga/Web/Widget/Tabextension/OutputFormat.php b/library/Icinga/Web/Widget/Tabextension/OutputFormat.php index d84f0d7e8..cbc2a72e4 100644 --- a/library/Icinga/Web/Widget/Tabextension/OutputFormat.php +++ b/library/Icinga/Web/Widget/Tabextension/OutputFormat.php @@ -117,6 +117,10 @@ class OutputFormat implements Tabextension } /** + * Applies the format selectio to the provided tabset + * + * @param Tabs The tabs object to extend with + * * @see Tabextension::apply() */ public function apply(Tabs $tabs) @@ -125,4 +129,4 @@ class OutputFormat implements Tabextension $tabs->addAsDropdown($tab->getName(), $tab); } } -} \ No newline at end of file +} diff --git a/library/Icinga/Web/Widget/Tabextension/Tabextension.php b/library/Icinga/Web/Widget/Tabextension/Tabextension.php index b301039a8..edf26518d 100644 --- a/library/Icinga/Web/Widget/Tabextension/Tabextension.php +++ b/library/Icinga/Web/Widget/Tabextension/Tabextension.php @@ -28,7 +28,7 @@ namespace Icinga\Web\Widget\Tabextension; -use Icinga\Web\Widget\Tabs; +use \Icinga\Web\Widget\Tabs; /** * Tabextension interface that allows to extend a tabbar with reusable components. diff --git a/library/Icinga/Web/Widget/Tabs.php b/library/Icinga/Web/Widget/Tabs.php index 0ffe3e273..2596cc6e5 100644 --- a/library/Icinga/Web/Widget/Tabs.php +++ b/library/Icinga/Web/Widget/Tabs.php @@ -28,11 +28,11 @@ namespace Icinga\Web\Widget; -use Icinga\Exception\ProgrammingError; -use Icinga\Web\Widget\Tabextension\Tabextension; -use Zend_View_Abstract; +use \Icinga\Exception\ProgrammingError; +use \Icinga\Web\Widget\Tabextension\Tabextension; +use \Zend_View_Abstract; -use Countable; +use \Countable; /** * Navigation tab widget diff --git a/modules/monitoring/application/controllers/SummaryController.php b/modules/monitoring/application/controllers/SummaryController.php index 23c1d6422..5f4699385 100644 --- a/modules/monitoring/application/controllers/SummaryController.php +++ b/modules/monitoring/application/controllers/SummaryController.php @@ -90,6 +90,5 @@ class Monitoring_SummaryController extends ModuleActionController $this->view->summary = $query->paginate(); } - } // @codingStandardsIgnoreEnd diff --git a/public/js/icinga/components/mainDetail.js b/public/js/icinga/components/mainDetail.js index 359f2d925..b6aa160d8 100755 --- a/public/js/icinga/components/mainDetail.js +++ b/public/js/icinga/components/mainDetail.js @@ -87,9 +87,7 @@ var onLinkTagClick = function(ev) { '.layout-main-detail * a' : { 'click' : onLinkTagClick }, -/* 'a' : { - 'click' : onOuterLinkClick - },*/ + '.layout-main-detail .icinga-container#icinga-detail' : { 'focus' : expandDetailView } diff --git a/test/php/library/Icinga/Web/RequestMock.php b/test/php/library/Icinga/Web/RequestMock.php index fca867b13..cc9414712 100644 --- a/test/php/library/Icinga/Web/RequestMock.php +++ b/test/php/library/Icinga/Web/RequestMock.php @@ -86,4 +86,4 @@ class RequestMock { return $this->query; } -} \ No newline at end of file +} diff --git a/test/php/library/Icinga/Web/ViewMock.php b/test/php/library/Icinga/Web/ViewMock.php index 68a413cc3..85061177d 100644 --- a/test/php/library/Icinga/Web/ViewMock.php +++ b/test/php/library/Icinga/Web/ViewMock.php @@ -1,4 +1,5 @@ Date: Fri, 16 Aug 2013 14:56:23 +0200 Subject: [PATCH 4/6] Application/Controllers: Follow our Coding Standards refs #4512 --- .../controllers/AuthenticationController.php | 44 ++++++++-------- application/controllers/ConfigController.php | 52 +++++++++---------- .../controllers/DashboardController.php | 27 ++++------ application/controllers/ErrorController.php | 18 +++---- application/controllers/IndexController.php | 17 ++---- .../controllers/PreferenceController.php | 30 +++++------ application/controllers/StaticController.php | 27 +++++----- 7 files changed, 95 insertions(+), 120 deletions(-) diff --git a/application/controllers/AuthenticationController.php b/application/controllers/AuthenticationController.php index ad8603273..f346f44cc 100644 --- a/application/controllers/AuthenticationController.php +++ b/application/controllers/AuthenticationController.php @@ -4,21 +4,21 @@ /** * Icinga 2 Web - Head for multiple monitoring frontends * Copyright (C) 2013 Icinga Development Team - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * + * * @copyright 2013 Icinga Development Team * @author Icinga Development Team */ @@ -26,32 +26,36 @@ # namespace Icinga\Application\Controllers; -use Icinga\Web\Controller\ActionController; -use Icinga\Authentication\Credentials; -use Icinga\Authentication\Manager as AuthManager; -use Icinga\Form\Authentication\LoginForm; +use \Icinga\Web\Controller\ActionController; +use \Icinga\Authentication\Credentials; +use \Icinga\Authentication\Manager as AuthManager; +use \Icinga\Form\Authentication\LoginForm; +use \Icinga\Exception\ConfigurationError; /** - * Class AuthenticationController - * @package Icinga\Application\Controllers + * Application wide controller for authentication */ class AuthenticationController extends ActionController { /** - * Flag indicates authentication handling + * This controller handles authentication + * * @var bool */ protected $handlesAuthentication = true; /** - * Flag indicates session modification + * This controller modifies the session + * * @var bool + * + * @see \Icinga\Web\Controller\ActionController::$modifiesSession */ protected $modifiesSession = true; /** - * Action to handle login + * Log into the application */ public function loginAction() { @@ -62,7 +66,7 @@ class AuthenticationController extends ActionController try { $auth = AuthManager::getInstance(null, array( - "writeSession" => true + 'writeSession' => $this->modifiesSession )); if ($auth->isAuthenticated()) { @@ -74,30 +78,28 @@ class AuthenticationController extends ActionController $credentials->setPassword($this->view->form->getValue('password')); if (!$auth->authenticate($credentials)) { - $this->view->form->getElement('password')->addError(t('Please provide a valid username and password')); + $this->view->form->getElement('password') + ->addError(t('Please provide a valid username and password')); } else { $this->redirectNow('index?_render=body'); } } - } catch (\Icinga\Exception\ConfigurationError $configError) { + } catch (ConfigurationError $configError) { $this->view->errorInfo = $configError->getMessage(); } } - - /** - * Action handle logout + * Log out the current user */ public function logoutAction() { $auth = AuthManager::getInstance(null, array( - "writeSession" => true + 'writeSession' => $this->modifiesSession )); $this->replaceLayout = true; $auth->removeAuthorization(); $this->redirect('login'); } } - // @codingStandardsIgnoreEnd diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index 6418d1ad8..4f7adf963 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -4,67 +4,66 @@ /** * Icinga 2 Web - Head for multiple monitoring frontends * Copyright (C) 2013 Icinga Development Team - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * + * * @copyright 2013 Icinga Development Team * @author Icinga Development Team */ // {{{ICINGA_LICENSE_HEADER}}} -use Icinga\Application\Benchmark; -use Icinga\Authentication\Manager; -use Icinga\Web\Controller\BaseConfigController; -use Icinga\Web\Widget\Tab; -use Icinga\Web\Url; -use Icinga\Web\Hook\Configuration\ConfigurationTabBuilder; -use Icinga\Application\Icinga; +use \Icinga\Application\Benchmark; +use \Icinga\Authentication\Manager; +use \Icinga\Web\Controller\BaseConfigController; +use \Icinga\Web\Widget\Tab; +use \Icinga\Web\Url; +use \Icinga\Web\Hook\Configuration\ConfigurationTabBuilder; +use \Icinga\Application\Icinga; /** * Application wide controller for application preferences - * */ class ConfigController extends BaseConfigController { /** * Create tabs for this configuration controller * - * @return array - * @see BaseConfigController::createProvidedTabs + * @return array + * + * @see BaseConfigController::createProvidedTabs() */ public static function createProvidedTabs() { return array( - "index" => new Tab( + 'index' => new Tab( array( - "name" => "index", - "title" => "Configuration", - "iconCls" => "wrench", - "url" => Url::fromPath("/config") + 'name' => 'index', + 'title' => 'Configuration', + 'iconCls' => 'wrench', + 'url' => Url::fromPath('/config') ) ), - "modules" => new Tab( + 'modules' => new Tab( array( - "name" => "modules", - "title" => "Modules", - "iconCls" => "puzzle-piece", - "url" => Url::fromPath("/config/moduleoverview") + 'name' => 'modules', + 'title' => 'Modules', + 'iconCls' => 'puzzle-piece', + 'url' => Url::fromPath('/config/moduleoverview') ) ) ); - } /** @@ -95,7 +94,6 @@ class ConfigController extends BaseConfigController $manager = Icinga::app()->getModuleManager(); $manager->enableModule($this->_getParam('name')); $manager->loadModule($this->_getParam('name')); - $this->redirectNow('config/moduleoverview?_render=body'); } @@ -109,4 +107,4 @@ class ConfigController extends BaseConfigController $this->redirectNow('config/moduleoverview?_render=body'); } } -// @codingStandardsIgnoreEnd \ No newline at end of file +// @codingStandardsIgnoreEnd diff --git a/application/controllers/DashboardController.php b/application/controllers/DashboardController.php index 65a132890..15f17e5bd 100644 --- a/application/controllers/DashboardController.php +++ b/application/controllers/DashboardController.php @@ -27,13 +27,13 @@ */ // {{{ICINGA_LICENSE_HEADER}}} -use Icinga\Web\Controller\ActionController; -use Icinga\Web\Url; -use Icinga\Application\Icinga; -use Icinga\Web\Widget\Dashboard; +use \Icinga\Web\Controller\ActionController; +use \Icinga\Web\Url; +use \Icinga\Application\Icinga; +use \Icinga\Web\Widget\Dashboard; use \Icinga\Application\Config as IcingaConfig; -use Icinga\Form\Dashboard\AddUrlForm; -use Icinga\Exception\ConfigurationError; +use \Icinga\Form\Dashboard\AddUrlForm; +use \Icinga\Exception\ConfigurationError; /** * Handle creation, removal and displaying of dashboards, panes and components @@ -42,13 +42,12 @@ use Icinga\Exception\ConfigurationError; */ class DashboardController extends ActionController { - /** * Retrieve a dashboard from the provided config * - * @param string $config The config to read the dashboard from, or 'dashboard/dashboard' if none is given + * @param string $config The config to read the dashboard from, or 'dashboard/dashboard' if none is given * - * @return Dashboard + * @return \Icinga\Web\Widget\Dashboard */ private function getDashboard($config = 'dashboard/dashboard') { @@ -59,7 +58,6 @@ class DashboardController extends ActionController /** * Remove a component from the pane identified by the 'pane' parameter - * */ public function removecomponentAction() { @@ -72,24 +70,20 @@ class DashboardController extends ActionController )->store(); $this->redirectNow(Url::fromPath('dashboard', array('pane' => $pane))); } catch (ConfigurationError $exc ) { - $this->_helper->viewRenderer('show_configuration'); $this->view->exceptionMessage = $exc->getMessage(); $this->view->iniConfigurationString = $dashboard->toIni(); } } - /** * Display the form for adding new components or add the new component if submitted - * */ public function addurlAction() { $form = new AddUrlForm(); $form->setRequest($this->_request); $this->view->form = $form; - if ($form->isSubmittedAndValid()) { $dashboard = $this->getDashboard(); $dashboard->setComponentUrl( @@ -115,12 +109,10 @@ class DashboardController extends ActionController * * If no pane is submitted or the submitted one doesn't exist, the default pane is * displayed (normally the first one) - * */ public function indexAction() { $dashboard = $this->getDashboard(); - if ($this->_getParam('pane')) { $pane = $this->_getParam('pane'); $dashboard->activate($pane); @@ -137,5 +129,4 @@ class DashboardController extends ActionController $this->view->dashboard = $dashboard; } } - -// @codingStandardsIgnoreEnd \ No newline at end of file +// @codingStandardsIgnoreEnd diff --git a/application/controllers/ErrorController.php b/application/controllers/ErrorController.php index 8fdfd99b8..0448cf979 100755 --- a/application/controllers/ErrorController.php +++ b/application/controllers/ErrorController.php @@ -4,21 +4,21 @@ /** * Icinga 2 Web - Head for multiple monitoring frontends * Copyright (C) 2013 Icinga Development Team - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * + * * @copyright 2013 Icinga Development Team * @author Icinga Development Team */ @@ -26,21 +26,19 @@ # namespace Icinga\Application\Controllers; -use Icinga\Web\Controller\ActionController; +use \Icinga\Web\Controller\ActionController; /** - * Class ErrorController - * @package Icinga\Application\Controllers + * Application wide controller for displaying exceptions */ class ErrorController extends ActionController { /** - * + * Display exception */ public function errorAction() { $errors = $this->_getParam('error_handler'); - switch ($errors->type) { case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: @@ -59,9 +57,7 @@ class ErrorController extends ActionController if ($this->getInvokeArg('displayExceptions') == true) { $this->view->exception = $errors->exception; } - $this->view->request = $errors->request; } } - // @codingStandardsIgnoreEnd diff --git a/application/controllers/IndexController.php b/application/controllers/IndexController.php index ea33553e8..4d3d7a836 100644 --- a/application/controllers/IndexController.php +++ b/application/controllers/IndexController.php @@ -29,22 +29,16 @@ # namespace Icinga\Application\Controllers; -use Icinga\Web\Controller\ActionController; -use Icinga\Application\Icinga; +use \Icinga\Web\Controller\ActionController; +use \Icinga\Application\Icinga; /** - * Class IndexController + * Application wide index controller */ class IndexController extends ActionController { - /** - * @var bool - */ - protected $modifiesSession = true; - - /** - * + * Always authenticate */ public function preDispatch() { @@ -55,11 +49,10 @@ class IndexController extends ActionController } /** - * + * Application's start page */ public function welcomeAction() { } } - // @codingStandardsIgnoreEnd diff --git a/application/controllers/PreferenceController.php b/application/controllers/PreferenceController.php index bd3ace003..d8bacbf1b 100644 --- a/application/controllers/PreferenceController.php +++ b/application/controllers/PreferenceController.php @@ -3,24 +3,24 @@ // {{{ICINGA_LICENSE_HEADER}}} /** * This file is part of Icinga 2 Web. - * + * * Icinga 2 Web - Head for multiple monitoring backends. * Copyright (C) 2013 Icinga Development Team - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * + * * @copyright 2013 Icinga Development Team * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 * @author Icinga Development Team @@ -33,26 +33,25 @@ use \Icinga\Web\Url; /** * Application wide preference controller for user preferences - * */ class PreferenceController extends BasePreferenceController { - /** * Create tabs for this preference controller * - * @return array - * @see BasePreferenceController::createProvidedTabs + * @return array + * + * @see BasePreferenceController::createProvidedTabs() */ public static function createProvidedTabs() { return array( - "preference" => new Tab( + 'preference' => new Tab( array( - "name" => "preferences", - "iconCls" => "user", - "title" => "Preferences", - "url" => Url::fromPath("/preference") + 'name' => 'preferences', + 'iconCls' => 'user', + 'title' => 'Preferences', + 'url' => Url::fromPath('/preference') ) ) ); @@ -60,11 +59,10 @@ class PreferenceController extends BasePreferenceController /** * @TODO: Implement User preferences (feature #5425) - * */ public function indexAction() { } } -// @codingStandardsIgnoreEnd \ No newline at end of file +// @codingStandardsIgnoreEnd diff --git a/application/controllers/StaticController.php b/application/controllers/StaticController.php index 8b1007d39..e40201dec 100644 --- a/application/controllers/StaticController.php +++ b/application/controllers/StaticController.php @@ -27,13 +27,15 @@ */ // {{{ICINGA_LICENSE_HEADER}}} -use Icinga\Web\Controller\ActionController; -use Icinga\Application\Icinga, - Zend_Controller_Action_Exception as ActionException; +use \Zend_Controller_Action_Exception as ActionException; +use \Icinga\Web\Controller\ActionController; +use \Icinga\Application\Icinga; class StaticController extends ActionController { - + /** + * @TODO: Bug #4572 + */ protected $handlesAuthentication = true; public function init() @@ -45,11 +47,10 @@ class StaticController extends ActionController private function getModuleList() { $modules = Icinga::app()->getModuleManager()->getLoadedModules(); - // preliminary static definition $result = array(); foreach ($modules as $name => $module) { - $hasJs = file_exists($module->getBasedir() . "/public/js/$name.js"); + $hasJs = file_exists($module->getBasedir() . '/public/js/' . $name . '.js'); $result[] = array( 'name' => $name, 'active' => true, @@ -62,11 +63,10 @@ class StaticController extends ActionController public function modulelistAction() { - $this->_helper->viewRenderer->setNoRender(true); $this->_helper->layout()->disableLayout(); - $this->getResponse()->setHeader("Content-Type","application/json"); - echo "define(function() { return ".json_encode($this->getModuleList(),true)."; })"; + $this->getResponse()->setHeader('Content-Type', 'application/json'); + echo 'define(function() { return ' . json_encode($this->getModuleList(), true) . '; })'; exit; } @@ -74,7 +74,7 @@ class StaticController extends ActionController { $module = $this->_getParam('module_name'); $file = $this->_getParam('file'); - + $basedir = Icinga::app()->getModuleManager()->getModule($module)->getBaseDir(); $filePath = $basedir . '/public/img/' . $file; @@ -112,14 +112,14 @@ class StaticController extends ActionController $file = $this->_getParam('file'); if (!Icinga::app()->getModuleManager()->hasEnabled($module)) { - echo "/** Module not enabled **/"; + echo '/** Module not enabled **/'; return; } $basedir = Icinga::app()->getModuleManager()->getModule($module)->getBaseDir(); $filePath = $basedir . '/public/js/' . $file; if (!file_exists($filePath)) { - echo "/** Module has no js files **/"; + echo '/** Module has no js files **/'; return; } $hash = md5_file($filePath); @@ -143,10 +143,7 @@ class StaticController extends ActionController } else { readfile($filePath); } - return; } - } - // @codingStandardsIgnoreEnd From 7dc2f78b63a09b923f6f2b9161a4fd3b5f3041fc Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 16 Aug 2013 15:05:03 +0200 Subject: [PATCH 5/6] CS: Fix docstrings in Icinga/Web/Widget/* and Icinga/Web/Controller/ActionController.php refs #4512 --- .../Web/Controller/ActionController.php | 74 ++++++++-------- .../Web/Widget/Tabextension/BasketAction.php | 14 +-- .../Widget/Tabextension/DashboardAction.php | 13 +-- .../Web/Widget/Tabextension/OutputFormat.php | 16 ++-- .../Web/Widget/Tabextension/Tabextension.php | 23 ++--- library/Icinga/Web/Widget/Tabs.php | 85 ++++++++++--------- 6 files changed, 115 insertions(+), 110 deletions(-) diff --git a/library/Icinga/Web/Controller/ActionController.php b/library/Icinga/Web/Controller/ActionController.php index f60fa340e..c0395a4ce 100755 --- a/library/Icinga/Web/Controller/ActionController.php +++ b/library/Icinga/Web/Controller/ActionController.php @@ -2,29 +2,30 @@ // {{{ICINGA_LICENSE_HEADER}}} /** * This file is part of Icinga 2 Web. - * + * * Icinga 2 Web - Head for multiple monitoring backends. * Copyright (C) 2013 Icinga Development Team - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * + * * @copyright 2013 Icinga Development Team * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 * @author Icinga Development Team */ // {{{ICINGA_LICENSE_HEADER}}} + namespace Icinga\Web\Controller; use \Icinga\Authentication\Manager as AuthManager; @@ -50,38 +51,37 @@ use \Zend_Controller_Action_HelperBroker as ZfActionHelper; */ class ActionController extends ZfController { - /** - * True to mark this layout to not render the full layout - * - * @var bool - */ + * True to mark this layout to not render the full layout + * + * @var bool + */ protected $replaceLayout = false; /** - * If true, this controller will be shown even when no authentication is available - * Needed mainly for the authentication controller - * - * @var bool - */ + * If true, this controller will be shown even when no authentication is available + * Needed mainly for the authentication controller + * + * @var bool + */ protected $handlesAuthentication = false; /** - * Set true when this controller modifies the session. - * - * otherwise the session will be written back to disk and closed before the controller - * action is executed, leading to every modification in the session to be lost after - * the response is submitted - * - * @var bool - */ + * Set true when this controller modifies the session + * + * otherwise the session will be written back to disk and closed before the controller + * action is executed, leading to every modification in the session to be lost after + * the response is submitted + * + * @var bool + */ protected $modifiesSession = false; /** - * True if authentication suceeded, otherwise false - * - * @var bool - **/ + * True if authentication suceeded, otherwise false + * + * @var bool + */ protected $allowAccess = false; @@ -107,15 +107,13 @@ class ActionController extends ZfController */ protected $action_name; - - /** * The constructor starts benchmarking, loads the configuration and sets * other useful controller properties * - * @param ZfRequest $request - * @param ZfResponse $response - * @param array $invokeArgs Any additional invocation arguments + * @param ZfRequest $request + * @param ZfResponse $response + * @param array $invokeArgs Any additional invocation arguments */ public function __construct( ZfRequest $request, @@ -148,10 +146,10 @@ class ActionController extends ZfController } /** - * Return the @see \Icinga\Widget\Web\Tabs of this view - * - * @return Tabs - **/ + * Return the tabs + * + * @return \Icinga\Widget\Web\Tabs + */ public function getTabs() { return $this->view->tabs; @@ -186,7 +184,7 @@ class ActionController extends ZfController * Assert the current user has the given permission * * TODO: This has not been implemented yet (Feature #4111) - * + * * @return self */ final protected function assertPermission() @@ -230,7 +228,7 @@ class ActionController extends ZfController /** * Redirect to a specific url, updating the browsers URL field - * + * * @param Url|string $url The target to redirect to **/ public function redirectNow($url) diff --git a/library/Icinga/Web/Widget/Tabextension/BasketAction.php b/library/Icinga/Web/Widget/Tabextension/BasketAction.php index 0e6a99d82..cc4d3a606 100644 --- a/library/Icinga/Web/Widget/Tabextension/BasketAction.php +++ b/library/Icinga/Web/Widget/Tabextension/BasketAction.php @@ -39,18 +39,22 @@ use \Icinga\Web\Url; class BasketAction implements Tabextension { /** - * @see Tabextension::apply() + * Applies the dashboard actions to the provided tabset + * + * @param Tabs $tabs The tabs object to extend with + * + * @see \Icinga\Web\Widget\Tabextension::apply() */ public function apply(Tabs $tabs) { $tabs->addAsDropdown( 'basket', array( - 'title' => 'URL Basket', - 'icon' => 'img/classic/basket.png', - 'url' => Url::fromPath('basket/add'), + 'title' => 'URL Basket', + 'icon' => 'img/classic/basket.png', + 'url' => Url::fromPath('basket/add'), 'urlParams' => array( - 'url' => Url::fromRequest()->getRelativeUrl() + 'url' => Url::fromRequest()->getRelativeUrl() ) ) ); diff --git a/library/Icinga/Web/Widget/Tabextension/DashboardAction.php b/library/Icinga/Web/Widget/Tabextension/DashboardAction.php index 9b5fe3865..2f9d1163e 100644 --- a/library/Icinga/Web/Widget/Tabextension/DashboardAction.php +++ b/library/Icinga/Web/Widget/Tabextension/DashboardAction.php @@ -43,19 +43,20 @@ class DashboardAction implements Tabextension /** * Applies the dashboard actions to the provided tabset * - * @param Tabs The tabs object to extend with - * @see Tabextension::apply() + * @param Tabs $tabs The tabs object to extend with + * + * @see \Icinga\Web\Widget\Tabextension::apply() */ public function apply(Tabs $tabs) { $tabs->addAsDropdown( 'dashboard', array( - 'title' => 'Add to Dashboard', - 'iconCls' => 'dashboard', - 'url' => Url::fromPath('dashboard/addurl'), + 'title' => 'Add to Dashboard', + 'iconCls' => 'dashboard', + 'url' => Url::fromPath('dashboard/addurl'), 'urlParams' => array( - 'url' => Url::fromRequest()->getRelativeUrl() + 'url' => Url::fromRequest()->getRelativeUrl() ) ) ); diff --git a/library/Icinga/Web/Widget/Tabextension/OutputFormat.php b/library/Icinga/Web/Widget/Tabextension/OutputFormat.php index cbc2a72e4..47cef18d1 100644 --- a/library/Icinga/Web/Widget/Tabextension/OutputFormat.php +++ b/library/Icinga/Web/Widget/Tabextension/OutputFormat.php @@ -28,15 +28,13 @@ namespace Icinga\Web\Widget\Tabextension; -use Icinga\Application\Logger; -use Icinga\Web\Widget\Tab; -use Icinga\Web\Widget\Tabs; -use Icinga\Web\Url; +use \Icinga\Application\Logger; +use \Icinga\Web\Widget\Tab; +use \Icinga\Web\Widget\Tabs; +use \Icinga\Web\Url; /** * Tabextension that offers different output formats for the user in the dropdown area - * - * */ class OutputFormat implements Tabextension { @@ -97,7 +95,7 @@ class OutputFormat implements Tabextension * In general, it's assumed that all types are supported when an outputFormat extension * is added, so this class offers to remove specific types instead of adding ones * - * @param array $disabled An array of output types to not show. + * @param array $disabled An array of output types to not show. * */ public function __construct(array $disabled = array()) @@ -119,9 +117,9 @@ class OutputFormat implements Tabextension /** * Applies the format selectio to the provided tabset * - * @param Tabs The tabs object to extend with + * @param Tabs $tabs The tabs object to extend with * - * @see Tabextension::apply() + * @see Tabextension::apply() */ public function apply(Tabs $tabs) { diff --git a/library/Icinga/Web/Widget/Tabextension/Tabextension.php b/library/Icinga/Web/Widget/Tabextension/Tabextension.php index edf26518d..c8c064801 100644 --- a/library/Icinga/Web/Widget/Tabextension/Tabextension.php +++ b/library/Icinga/Web/Widget/Tabextension/Tabextension.php @@ -31,19 +31,20 @@ namespace Icinga\Web\Widget\Tabextension; use \Icinga\Web\Widget\Tabs; /** -* Tabextension interface that allows to extend a tabbar with reusable components. -* -* Tabs can be either extended by creating a tabextension and calling the apply method -* or by calling the tabs @see \Icinga\Web\Widget\Tabs::extend() method and providing -* a tab extension. -* -**/ + * Tabextension interface that allows to extend a tabbar with reusable components + * + * Tabs can be either extended by creating a `Tabextension` and calling the `apply()` method + * or by calling the `\Icinga\Web\Widget\Tabs` `extend()` method and providing + * a tab extension + * + * @see \Icinga\Web\Widget\Tabs::extend() + */ interface Tabextension { /** - * Apply this tabextension to the provided tabs - * - * @param Tabs $tabs The tabbar to modify - **/ + * Apply this tabextension to the provided tabs + * + * @param Tabs $tabs The tabbar to modify + */ public function apply(Tabs $tabs); } diff --git a/library/Icinga/Web/Widget/Tabs.php b/library/Icinga/Web/Widget/Tabs.php index 2596cc6e5..530efdccb 100644 --- a/library/Icinga/Web/Widget/Tabs.php +++ b/library/Icinga/Web/Widget/Tabs.php @@ -31,12 +31,10 @@ namespace Icinga\Web\Widget; use \Icinga\Exception\ProgrammingError; use \Icinga\Web\Widget\Tabextension\Tabextension; use \Zend_View_Abstract; - use \Countable; /** * Navigation tab widget - * */ class Tabs implements Countable, Widget { @@ -45,11 +43,11 @@ class Tabs implements Countable, Widget * * @var string */ - private $baseTpl =<<<'EOT' - EOT; /** @@ -57,13 +55,15 @@ EOT; * * @var string */ - private $dropdownTpl =<<<'EOT' - + private $dropdownTpl = <<< 'EOT' + EOT; @@ -93,11 +93,12 @@ EOT; * * If another tab is currently active it will be deactivated * - * @param string $name Name of the tab going to be activated + * @param string $name Name of the tab going to be activated * - * @throws ProgrammingError if given tab name doesn't exist + * @return self + * + * @throws ProgrammingError When the given tab name doesn't exist * - * @return self */ public function activate($name) { @@ -124,9 +125,9 @@ EOT; /** * Set the CSS class name(s) for the <ul> element * - * @param string $name CSS class name(s) + * @param string $name CSS class name(s) * - * @return self + * @return self */ public function setClass($name) { @@ -137,9 +138,9 @@ EOT; /** * Whether the given tab name exists * - * @param string $name Tab name + * @param string $name Tab name * - * @return bool + * @return bool */ public function has($name) { @@ -149,11 +150,11 @@ EOT; /** * Whether the given tab name exists * - * @param string $name The tab you're interested in + * @param string $name The tab you're interested in * - * @throws ProgrammingError if given tab name doesn't exist + * @return Tab * - * @return Tab + * @throws ProgrammingError When the given tab name doesn't exist */ public function get($name) { @@ -169,12 +170,12 @@ EOT; * A unique tab name is required, the Tab itself can either be an array * with tab properties or an instance of an existing Tab * - * @param string $name The new tab name - * @param array|Tab The tab itself of it's properties + * @param string $name The new tab name + * @param array|Tab $tab The tab itself of it's properties * - * @throws ProgrammingError if tab name already exists + * @return self * - * @return self + * @throws ProgrammingError When the tab name already exists */ public function add($name, $tab) { @@ -196,10 +197,10 @@ EOT; * exists. The tab can either be an array with tab properties or an instance * of an existing Tab * - * @param string $name The new tab name - * @param array|Tab The tab itself of it's properties + * @param string $name The new tab name + * @param array|Tab $tab The tab itself of it's properties * - * @return self + * @return self */ public function set($name, $tab) { @@ -227,9 +228,9 @@ EOT; /** * Render the dropdown area with it's tabs and return the resulting HTML * - * @param Zend_View_Abstract $view The view used for rendering + * @param Zend_View_Abstract $view The view used for rendering * - * @return mixed|string + * @return mixed|string */ private function renderDropdownTabs(Zend_View_Abstract $view) { @@ -244,15 +245,15 @@ EOT; } $tabs .= $tab->render($view); } - return str_replace("{TABS}", $tabs, $this->dropdownTpl); + return str_replace('{TABS}', $tabs, $this->dropdownTpl); } /** * Render all tabs, except the ones in dropdown area and return the resulting HTML * - * @param Zend_View_Abstract $view The view used for rendering + * @param Zend_View_Abstract $view The view used for rendering * - * @return string + * @return string */ private function renderTabs(Zend_View_Abstract $view) { @@ -268,6 +269,8 @@ EOT; } /** + * Render to HTML + * * @see Widget::render */ public function render(Zend_View_Abstract $view) @@ -277,17 +280,17 @@ EOT; } $html = $this->baseTpl; - $html = str_replace("{TABS}", $this->renderTabs($view), $html); - $html = str_replace("{DROPDOWN}", $this->renderDropdownTabs($view), $html); + $html = str_replace('{TABS}', $this->renderTabs($view), $html); + $html = str_replace('{DROPDOWN}', $this->renderDropdownTabs($view), $html); return $html; } /** * Return the number of tabs * - * @see Countable + * @return int * - * @return int + * @see Countable */ public function count() { @@ -307,9 +310,9 @@ EOT; /** * Apply a Tabextension on this tabs object * - * @param Tabextension $tabextension + * @param Tabextension $tabextension * - * @return self + * @return self */ public function extend(Tabextension $tabextension) { From 920f3494d84a7a66381f9dc9a5866b2420e00ff0 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 16 Aug 2013 15:05:28 +0200 Subject: [PATCH 6/6] Widgets: Fix example code in documention not following our Coding Standards refs #4512 --- doc/widgets.md | 62 +++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/doc/widgets.md b/doc/widgets.md index 75d7eedac..336cce58c 100644 --- a/doc/widgets.md +++ b/doc/widgets.md @@ -5,7 +5,7 @@ Widgets are reusable UI components that are able to render themselves and return ## Basic interface The interface needed for implementing widgets can be found under library/Icinga/Web/Widget/Widget.php. This is a rather -simple interface, only providing a 'render' method that takes a view and returns HTML: +simple interface, only providing a `render()` method that takes a view and returns HTML: interface Widget { @@ -19,13 +19,14 @@ When implementing own Widgets you just have to make sure that you provide this r Widgets are normally created in the controller and added to the view: // in your Controller + public function myControllerAction() { $this->view->myWidget = new MyWidget(); } - The HTML is then rendered in the template using the *render()* method described above. As the '$this' scope in a view is - a reference to your current view, you can just pass it to the *render()* method: +The HTML is then rendered in the template using the `render()` method described above. As the '$this' scope in a view is +a reference to your current view, you can just pass it to the `render()` method: // in your template @@ -36,37 +37,43 @@ Widgets are normally created in the controller and added to the view: ## The 'Tabs' widget -The Tabs (Icinga\Web\Widgets\Tabs) widget handles creation of Tab bars and allows you to create and add single tabs to this view. To create an empty -Tab bar, you just have to call: +The Tabs `\Icinga\Web\Widgets\Tabs` widget handles creation of Tab bars and allows you to create and add single tabs to +this view. To create an empty Tab bar, you just have to call: $tabbar = new Tabs(); -**Note** : When using an ActionController, there's already an empty tabs object created under $this->view->tabs. This is - done in the preDispatch function +> **Note**: Controllers subclassing `\Icinga\Web\Controller\ActionController` (which all existing controller do so and +> yours should too) have already an empty tabs object created under `$this->view->tabs`. This is done in the +> `preDispatch` function. ### Adding tabs -Afterwards you can add tabs by calling the add($name, $tab) function, whereas $name is the name of your tab and $tab -is either an array with tab parameters or an existing Tab object. +Afterwards you can add tabs by calling the `add($name, $tab)` function, whereas `$name` is the name of your tab and +`$tab` is either an array with tab parameters or an existing Tab object. - // Adding tabs: - $tabbar->add("myTab", array( - "title" => "My hosts", // displayed as the tab text - "iconCls" => "myicon", // icon-myicon will be used as an icon in a tag - "url" => "/my/url", // the url to use - "urlParams" => array("host" => "localhost") // will be used as GET parameter - )); + // Add a tab + + $tabbar->add( + 'myTab', + array( + 'title' => 'My hosts', // Displayed as the tab text + 'iconCls' => 'myicon', // icon-myicon will be used as an icon in a tag + 'url' => '/my/url', // The url to use + 'urlParams' => array('host' => 'localhost') // Will be used as GET parameter + ) + ); ### Adding tabs to the dropdown list -Sometimes you want additional actions to be displayed in your tabbar. This can be accomplished with the 'addAsDropdown' -method. This one is similar to the *add* method, but displays your tab in a dropdown list on the right side of the tabbar. +Sometimes you want additional actions to be displayed in your tabbar. This can be accomplished with the +`addAsDropdown()` method. This one is similar to the `add()` method, but displays your tab in a dropdown list on the +right side of the tabbar. ## Using tabextensions Often you find yourself adding the same tabs over and over again. You can write a Tabextension that does this for you -and just apply them on your tabs. Tabextensions are locate the Icinga/Web/Widgets/Tabextension/ and use the simple -Tabextension interface that just defines *apply(Tabs $tab)*. A simple example is the DashboardAction Tabextender which +and just apply them on your tabs. Tabextensions are located at Icinga/Web/Widgets/Tabextension/ and they use the simple +Tabextension interface that just defines `apply(Tabs $tab)`. A simple example is the DashboardAction Tabextender which just adds a new field to the dropdown list: class DashboardAction implements Tabextension @@ -79,19 +86,18 @@ just adds a new field to the dropdown list: $tabs->addAsDropdown( 'dashboard', array( - 'title' => 'Add to Dashboard', - 'iconCls' => 'dashboard', - 'url' => Url::fromPath('dashboard/addurl'), + 'title' => 'Add to Dashboard', + 'iconCls' => 'dashboard', + 'url' => Url::fromPath('dashboard/addurl'), 'urlParams' => array( - 'url' => Url::fromRequest()->getRelativeUrl() + 'url' => Url::fromRequest()->getRelativeUrl() ) ) ); } } -You can now either extend your Tabs object using the DashboardAction's *apply()* method or by calling the Tabs *extend* -method (which is more fluent): - - $tabs->extend(new DashboardAction()) +You can now either extend your Tabs object using the DashboardAction's `apply()` method or by calling the Tabs +`extend()` method (which is more fluent): + $tabs->extend(new DashboardAction());