diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php
index 9bc7d8381..381f20d43 100644
--- a/application/controllers/ConfigController.php
+++ b/application/controllers/ConfigController.php
@@ -24,8 +24,6 @@
*/
// {{{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;
@@ -179,7 +177,6 @@ class ConfigController extends BaseConfigController
$form->setCurrentOrder($order);
$form->setRequest($this->_request);
-
if (!$showOnly && $form->isSubmittedAndValid()) {
if ($this->writeAuthenticationFile($form->getReorderedConfig($config))) {
$this->view->successMessage = 'Authentication Order Updated';
diff --git a/application/controllers/PreferenceController.php b/application/controllers/PreferenceController.php
index 97f92ef3e..d8bb8c0b4 100644
--- a/application/controllers/PreferenceController.php
+++ b/application/controllers/PreferenceController.php
@@ -90,7 +90,7 @@ class PreferenceController extends BasePreferenceController
}
try {
$userPreferences->commit();
- $this->view->success = true;
+ $this->view->successMessage = "Preferences Updated Successfully";
// recreate form to show new values
$form = new GeneralForm();
diff --git a/application/forms/Config/Authentication/BaseBackendForm.php b/application/forms/Config/Authentication/BaseBackendForm.php
index 799b86af8..cd176504c 100644
--- a/application/forms/Config/Authentication/BaseBackendForm.php
+++ b/application/forms/Config/Authentication/BaseBackendForm.php
@@ -30,9 +30,6 @@
namespace Icinga\Form\Config\Authentication;
use \Zend_Config;
-use \Icinga\Application\Config as IcingaConfig;
-use \Icinga\Application\Icinga;
-use \Icinga\Application\Logger;
use \Icinga\Web\Form\Decorator\HelpText;
use \Icinga\Application\DbAdapterFactory;
use \Icinga\Web\Form;
diff --git a/application/forms/Config/Authentication/DbBackendForm.php b/application/forms/Config/Authentication/DbBackendForm.php
index daeb38079..ccd3a7093 100644
--- a/application/forms/Config/Authentication/DbBackendForm.php
+++ b/application/forms/Config/Authentication/DbBackendForm.php
@@ -30,12 +30,7 @@
namespace Icinga\Form\Config\Authentication;
use \Icinga\Authentication\Backend\DbUserBackend;
-use \Zend_Config;
-use \Icinga\Application\Config as IcingaConfig;
-use \Icinga\Application\Icinga;
-use \Icinga\Application\Logger;
use \Icinga\Application\DbAdapterFactory;
-use \Icinga\Web\Form;
/**
* Form class for adding/modifying database authentication backends
diff --git a/application/forms/Config/Authentication/LdapBackendForm.php b/application/forms/Config/Authentication/LdapBackendForm.php
index ffe34f593..f5667394a 100644
--- a/application/forms/Config/Authentication/LdapBackendForm.php
+++ b/application/forms/Config/Authentication/LdapBackendForm.php
@@ -31,10 +31,6 @@ namespace Icinga\Form\Config\Authentication;
use \Icinga\Authentication\Backend\LdapUserBackend;
use \Exception;
use \Zend_Config;
-use \Icinga\Application\Config as IcingaConfig;
-use \Icinga\Application\Icinga;
-use \Icinga\Application\Logger;
-use \Icinga\Application\DbAdapterFactory;
use \Icinga\Web\Form;
/**
diff --git a/application/forms/Config/Authentication/ReorderForm.php b/application/forms/Config/Authentication/ReorderForm.php
index 6bd4a4dd0..7c5f2ffb4 100644
--- a/application/forms/Config/Authentication/ReorderForm.php
+++ b/application/forms/Config/Authentication/ReorderForm.php
@@ -29,10 +29,6 @@
namespace Icinga\Form\Config\Authentication;
use \Zend_Config;
-use \Icinga\Application\Config as IcingaConfig;
-use \Icinga\Application\Icinga;
-use \Icinga\Application\Logger;
-use \Icinga\Application\DbAdapterFactory;
use \Icinga\Web\Form;
use \Icinga\Web\Url;
diff --git a/application/forms/Config/GeneralForm.php b/application/forms/Config/GeneralForm.php
index 406cee54c..f80a12c65 100644
--- a/application/forms/Config/GeneralForm.php
+++ b/application/forms/Config/GeneralForm.php
@@ -33,7 +33,6 @@ use \Zend_Config;
use \Zend_Form_Element_Text;
use \Zend_Form_Element_Select;
use \Icinga\Application\Config as IcingaConfig;
-use \Icinga\Application\Icinga;
use \Icinga\Application\DbAdapterFactory;
use \Icinga\Web\Form;
use \Icinga\Web\Form\Validator\WritablePathValidator;
diff --git a/application/forms/Dashboard/AddUrlForm.php b/application/forms/Dashboard/AddUrlForm.php
index 1784517f9..af6f5fc3f 100644
--- a/application/forms/Dashboard/AddUrlForm.php
+++ b/application/forms/Dashboard/AddUrlForm.php
@@ -129,7 +129,7 @@ class AddUrlForm extends Form
protected function create()
{
$dashboard = new Dashboard();
-
+ $this->setName('form_dashboard_add');
$dashboard->readConfig(IcingaConfig::app('dashboard/dashboard'));
$this->addElement(
'text',
@@ -144,7 +144,8 @@ class AddUrlForm extends Form
if (empty($elems) || // show textfield instead of combobox when no pane is available
($this->getRequest()->getPost('create_new_pane', '0') && // or when a new pane should be created (+ button)
- !$this->getRequest()->getPost('use_existing_dashboard', '0')) // and the user didn't click the 'use existing' button
+ !$this->getRequest()->getPost('use_existing_dashboard', '0')) // and the user didn't click the 'use
+ // existing' button
) {
$this->addNewPaneTextField();
} else {
diff --git a/application/forms/Preference/GeneralForm.php b/application/forms/Preference/GeneralForm.php
index 5d14429bf..9c43a2bbc 100644
--- a/application/forms/Preference/GeneralForm.php
+++ b/application/forms/Preference/GeneralForm.php
@@ -34,7 +34,6 @@ use \Zend_Form_Element_Text;
use \Zend_Form_Element_Select;
use \Icinga\Application\Config as IcingaConfig;
use \Icinga\Application\Icinga;
-use \Icinga\Application\DbAdapterFactory;
use \Icinga\User\Preferences;
use \Icinga\Web\Form;
use \Icinga\Web\Form\Validator\TimeFormatValidator;
@@ -215,6 +214,7 @@ class GeneralForm extends Form
if ($this->config === null) {
$this->config = new Zend_Config(array());
}
+ $this->setName('form_preference_set');
$global = $this->config->global;
if ($global === null) {
$global = new Zend_Config(array());
diff --git a/application/views/scripts/preference/index.phtml b/application/views/scripts/preference/index.phtml
index d83e1bd97..0a3749eb8 100644
--- a/application/views/scripts/preference/index.phtml
+++ b/application/views/scripts/preference/index.phtml
@@ -1,8 +1,8 @@
= $this->tabs->render($this); ?>
-success)) : ?>
+successMessage)) : ?>
-
Preferences Updated Successfully
+ {{SUCCESS_ICON}} = $this->successMessage ?>
diff --git a/doc/CONFIG.md b/doc/CONFIG.md
index 5ebaa607b..af7b03bd3 100644
--- a/doc/CONFIG.md
+++ b/doc/CONFIG.md
@@ -1,5 +1,7 @@
# Application and Module Configuration
+## Basic usage
+
The \Icinga\Application\Config class is a general purpose service to help you find, load and save
configuration data. It is used both by the Icinga 2 Web modules and the framework itself. With
INI files as source it enables you to store configuration in a familiar format. Icinga 2 Web
@@ -22,3 +24,10 @@ keep their main configuration in the INI file called config.ini. Here's some exa
// The following example loads values from the example module's extra.ini:
IcingaConfig::module('example', 'extra')->logging->get('enabled', true);
+## Reload from disk
+
+If you want to force reading a configuration from disk (i.e. after you modified it), you can use the $fromDisk flag in
+the IcingaConfig::app/IcingaConfig::module call:
+
+ IcingaConfig::app('authentication', true)-> ... // read authentication from disk
+ IcingaConfig::module('example', 'extra', true)->... // read module configuration from disk
diff --git a/library/Icinga/Application/Config.php b/library/Icinga/Application/Config.php
index ba55da19f..e5fe14a9e 100644
--- a/library/Icinga/Application/Config.php
+++ b/library/Icinga/Application/Config.php
@@ -106,17 +106,19 @@ class Config extends Zend_Config_Ini
/**
* Retrieve a module config instance
*
- * @param string $modulename
- * @param string $configname
- * @return Config
+ * @param string $modulename The name of the module to look for configurations
+ * @param string $configname The configuration name (without ini suffix) to read and return
+ * @param string $fromDisk Whether to read the configuration from disk
+ *
+ * @return Config The configuration object that has been requested
*/
- public static function module($modulename, $configname = 'config')
+ public static function module($modulename, $configname = 'config', $fromDisk = false)
{
if (!isset(self::$modules[$modulename])) {
self::$modules[$modulename] = array();
}
$moduleConfigs = self::$modules[$modulename];
- if (!isset($moduleConfigs[$configname])) {
+ if (!isset($moduleConfigs[$configname]) || $fromDisk) {
$filename = self::$configDir . '/modules/' . $modulename . '/' . $configname . '.ini';
if (file_exists($filename)) {
$moduleConfigs[$configname] = new Config(realpath($filename));
diff --git a/test/php/application/forms/Config/AuthenticationFormTest.php b/test/php/application/forms/Config/AuthenticationFormTest.php
index 92745576a..8dc104035 100644
--- a/test/php/application/forms/Config/AuthenticationFormTest.php
+++ b/test/php/application/forms/Config/AuthenticationFormTest.php
@@ -38,17 +38,21 @@ use Icinga\Test\BaseTestCase;
require_once 'Zend/Form.php';
require_once 'Zend/Config.php';
require_once 'Zend/Config/Ini.php';
+
+require_once BaseTestCase::$testDir . '/library/Icinga/Web/RequestMock.php';
+
require_once BaseTestCase::$libDir . '/Web/Form.php';
-require_once BaseTestCase::$appDir . '/forms/Config/AuthenticationForm.php';
+require_once BaseTestCase::$libDir . '/Web/Url.php';
+
require_once BaseTestCase::$appDir . '/forms/Config/Authentication/BaseBackendForm.php';
require_once BaseTestCase::$appDir . '/forms/Config/Authentication/DbBackendForm.php';
require_once BaseTestCase::$appDir . '/forms/Config/Authentication/LdapBackendForm.php';
// @codingStandardsIgnoreEnd
use \Icinga\Web\Form;
-use \DOMDocument;
+use Icinga\Web\Url;
+use Tests\Icinga\Web\RequestMock;
use \Zend_Config;
-use \Zend_View;
/**
* Test for the authentication provider form
@@ -92,27 +96,26 @@ class AuthenticationFormTest extends BaseTestCase
public function testLdapProvider()
{
$this->requireFormLibraries();
- $form = $this->createForm('Icinga\Form\Config\AuthenticationForm');
+ $form = $this->createForm('Icinga\Form\Config\Authentication\LdapBackendForm');
$config = new Zend_Config(
array(
- 'test-ldap' => array(
- 'backend' => 'ldap',
- 'target' => 'user',
- 'hostname' => 'test host',
- 'root_dn' => 'ou=test,dc=icinga,dc=org',
- 'bind_dn' => 'cn=testuser,cn=config',
- 'bind_pw' => 'password',
- 'user_class' => 'testClass',
- 'user_name_attribute' => 'testAttribute'
- )
+ 'backend' => 'ldap',
+ 'target' => 'user',
+ 'hostname' => 'test host',
+ 'root_dn' => 'ou=test,dc=icinga,dc=org',
+ 'bind_dn' => 'cn=testuser,cn=config',
+ 'bind_pw' => 'password',
+ 'user_class' => 'testClass',
+ 'user_name_attribute' => 'testAttribute'
)
);
- $form->setConfiguration($config);
+ $form->setBackendName('testldap');
+ $form->setBackend($config);
$form->create();
// parameters to be hidden
$notShown = array('backend', 'target');
- foreach ($config->get('test-ldap')->toArray() as $name => $value) {
+ foreach ($config->toArray() as $name => $value) {
if (in_array($name, $notShown)) {
continue;
}
@@ -123,22 +126,19 @@ class AuthenticationFormTest extends BaseTestCase
);
}
}
-
+/*
/**
* Test the database provider form population from config
- *
*/
public function testDbProvider()
{
$this->requireFormLibraries();
- $form = $this->createForm('Icinga\Form\Config\AuthenticationForm');
+ $form = $this->createForm('Icinga\Form\Config\Authentication\DbBackendForm');
$config = new Zend_Config(
array(
- 'test-db' => array(
- 'backend' => 'db',
- 'target' => 'user',
- 'resource' => 'db_resource'
- )
+ 'backend' => 'db',
+ 'target' => 'user',
+ 'resource' => 'db_resource'
)
);
$form->setResources(
@@ -149,12 +149,13 @@ class AuthenticationFormTest extends BaseTestCase
)
);
- $form->setConfiguration($config);
+ $form->setBackendName('test-db');
+ $form->setBackend($config);
$form->create();
// parameters to be hidden
$notShown = array('backend', 'target');
- foreach ($config->get('test-db')->toArray() as $name => $value) {
+ foreach ($config->toArray() as $name => $value) {
if (in_array($name, $notShown)) {
continue;
}
@@ -169,171 +170,70 @@ class AuthenticationFormTest extends BaseTestCase
/**
* Test whether order modifications via 'priority' are considered
*
+ * @backupStaticAttributes enabled
*/
- public function testShowModifiedOrder()
+ public function testModifyOrder()
{
+ Url::$overwrittenRequest = new RequestMock();
$this->requireFormLibraries();
- $form = $this->createForm(
- 'Icinga\Form\Config\AuthenticationForm',
- array(
- 'priority' => 'test-ldap,test-db'
- )
- );
- $config = $this->getTestConfig();
- $form->setResources(
- array(
- 'db_resource' => array(
- 'type' => 'db'
- )
- )
- );
+ $form = $this->createForm('Icinga\Form\Config\Authentication\ReorderForm');
+ $form->setAuthenticationBackend('backend2');
+ $form->setCurrentOrder(array('backend1', 'backend2', 'backend3', 'backend4'));
- $form->setConfiguration($config);
$form->create();
+ $this->assertSame(
+ 2,
+ count($form->getSubForms()),
+ 'Assert that a form for moving backend up and down exists'
+ );
+ $this->assertTrue(
+ $form->upForm->getElement('form_backend_order') !== null,
+ 'Assert that a "move backend up" button exists'
+ );
+ $this->assertSame(
+ array('backend2', 'backend1', 'backend3', 'backend4'),
+ explode(',', $form->upForm->getElement('form_backend_order')->getValue()),
+ 'Assert the "move backend up" button containing the correct order'
+ );
- $prio = array_keys($form->getConfig());
- $this->assertEquals('test-ldap', $prio[0], "Asserting priority changes to be persisted");
- $this->assertEquals('test-db', $prio[1], "Asserting priority changes to be persisted");
+ $this->assertTrue(
+ $form->downForm->getElement('form_backend_order') !== null,
+ 'Assert that a "move backend down" button exists'
+ );
+ $this->assertSame(
+ array('backend1', 'backend3', 'backend2', 'backend4'),
+ explode(',', $form->downForm->getElement('form_backend_order')->getValue()),
+ 'Assert the "move backend up" button containing the correct order'
+ );
}
/**
- * Test whether configuration changes are correctly returned when calling getConfig
+ * Test whether the reorder form doesn't display senseless ordering (like moving the uppermost element up or
+ * the lowermose down)
*
+ * @backupStaticAttributes enabled
*/
- public function testConfigurationCreation()
+ public function testInvalidOrderingNotShown()
{
+ Url::$overwrittenRequest = new RequestMock();
$this->requireFormLibraries();
- $form = $this->createForm(
- 'Icinga\Form\Config\AuthenticationForm',
- array(
- 'priority' => 'test-ldap,test-db',
- 'backend_testdb_resource' => 'db_resource_2',
- 'backend_testldap_hostname' => 'modified_host',
- 'backend_testldap_root_dn' => 'modified_root_dn',
- 'backend_testldap_bind_dn' => 'modified_bind_dn',
- 'backend_testldap_bind_pw' => 'modified_bind_pw',
- 'backend_testldap_user_class' => 'modified_user_class',
- 'backend_testldap_user_name_attribute' => 'modified_user_name_attribute'
- )
- );
+ $form = $this->createForm('Icinga\Form\Config\Authentication\ReorderForm');
+ $form->setAuthenticationBackend('backend1');
+ $form->setCurrentOrder(array('backend1', 'backend2', 'backend3', 'backend4'));
- $form->setResources(
- array(
- 'db_resource' => array(
- 'type' => 'db'
- ),
- 'db_resource_2' => array(
- 'type' => 'db'
- )
- )
- );
-
- $form->setConfiguration($this->getTestConfig());
$form->create();
-
- $modified = new Zend_Config($form->getConfig());
- $this->assertEquals(
- 'db_resource_2',
- $modified->get('test-db')->resource,
- 'Asserting database resource modifications to be applied'
+ $this->assertSame(
+ 2,
+ count($form->getSubForms()),
+ 'Assert that a form for moving backend up and down exists, even when moving up is not possible'
);
- $this->assertEquals(
- 'user',
- $modified->get('test-db')->target,
- 'Asserting database target still being user when modifying'
+ $this->assertTrue(
+ $form->downForm->getElement('form_backend_order') !== null,
+ 'Assert that a "move backend down" button exists when moving up is not possible'
);
- $this->assertEquals(
- 'db',
- $modified->get('test-db')->backend,
- 'Asserting database backend still being db when modifying'
+ $this->assertTrue(
+ $form->upForm->getElement('form_backend_order') === null,
+ 'Assert that a "move backend up" button does not exist when moving up is not possible'
);
-
- $ldap = $modified->get('test-ldap');
- $this->assertEquals(
- 'modified_host',
- $ldap->hostname,
- 'Asserting hostname modifications to be applied when modifying ldap authentication backends'
- );
-
- $this->assertEquals(
- 'modified_root_dn',
- $ldap->root_dn,
- 'Asserting root dn modifications to be applied when modifying ldap authentication backends'
- );
-
- $this->assertEquals(
- 'modified_bind_dn',
- $ldap->bind_dn,
- 'Asserting bind dn modifications to be applied when modifying ldap authentication backends'
- );
-
- $this->assertEquals(
- 'modified_bind_pw',
- $ldap->bind_pw,
- 'Asserting bind pw modifications to be applied when modifying ldap authentication backends'
- );
-
- $this->assertEquals(
- 'modified_user_class',
- $ldap->user_class,
- 'Asserting user class modifications to be applied when modifying ldap authentication backends'
- );
-
- $this->assertEquals(
- 'modified_user_name_attribute',
- $ldap->user_name_attribute,
- 'Asserting user name attribute modifications to be applied when modifying ldap authentication backends'
- );
- }
-
- /**
- * Test correct behaviour when ticking the 'remove backend' option
- */
- public function testBackendRemoval()
- {
- $this->requireFormLibraries();
- $form = $this->createForm(
- 'Icinga\Form\Config\AuthenticationForm',
- array(
- 'priority' => 'test-ldap,test-db',
- 'backend_testdb_resource' => 'db_resource_2',
- 'backend_testldap_remove' => 1,
- 'backend_testldap_hostname' => 'modified_host',
- 'backend_testldap_root_dn' => 'modified_root_dn',
- 'backend_testldap_bind_dn' => 'modified_bind_dn',
- 'backend_testldap_bind_pw' => 'modified_bind_pw',
- 'backend_testldap_user_class' => 'modified_user_class',
- 'backend_testldap_user_name_attribute' => 'modified_user_name_attribute'
- )
- );
-
- $form->setResources(
- array(
- 'db_resource' => array(
- 'type' => 'db'
- ),
- 'db_resource_2' => array(
- 'type' => 'db'
- )
- )
- );
-
- $form->setConfiguration($this->getTestConfig());
- $form->create();
- $view = new Zend_View();
-
- $html = new DOMDocument();
- $html->loadHTML($form->render($view));
- $this->assertEquals(
- null,
- $html->getElementById('backend_testldap_hostname-element'),
- 'Asserting configuration to be hidden when an authentication is marked as to be removed'
- );
- $config = $form->getConfig();
- $this->assertFalse(
- isset($config['test-ldap']),
- 'Asserting deleted backends not being persisted in the configuration'
- );
-
}
}
diff --git a/test/php/application/forms/Preference/GeneralFormTest.php b/test/php/application/forms/Preference/GeneralFormTest.php
index 1299ae856..a12c50f88 100644
--- a/test/php/application/forms/Preference/GeneralFormTest.php
+++ b/test/php/application/forms/Preference/GeneralFormTest.php
@@ -87,7 +87,7 @@ class GeneralFormTest extends BaseTestCase
* Test whether fields with preferences are enabled
*
*/
- public function testEnsableFormIfUsingPreference()
+ public function testEnableFormIfUsingPreference()
{
$this->requireFormLibraries();
$form = $this->createForm('Icinga\Form\Preference\GeneralForm');