Code style, Form tests and bugfixes

This commit summarizes the bugfixes made in this branch. As the frontend the fixes required a lot of stuff to be fixed afterwards and #4602 was used as a larger example regression test, this affects a few tickets:

- (Bug 4491) Frontend tests will hang randomly: CasperJS now operates on the installed version, so this shouldn't happen anymore
- (Bug 4602) Configuration Interface - Authentication: Backends moved when pushing enter: The authentication interface is reworked and does not persist a state over pages
- (Bug 4605) /tmp should not be the default log path: Now it is the application relative var/log path
- (Bug 4606) Configuration: Show message that changes were saved successfully: Implemented and tested with casperjs
- (Bug 4641) Installation/Testing fix configure/make: This has been reworked
- (Bug 4642) Allow Application placeholder in config: This was required for implementimg 4605
- (Bug 4643) Application doesn't work with older Zend Versions: A fallback __call has been implemented for this

refs #4491
refs #4602
refs #4605
refs #4606
refs #4641
refs #4642
refs #4643
This commit is contained in:
Jannis Moßhammer 2013-08-28 13:31:18 +02:00
parent 3d7df520f5
commit 2c97ab26a4
14 changed files with 98 additions and 206 deletions

View File

@ -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';

View File

@ -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();

View File

@ -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;

View File

@ -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

View File

@ -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;
/**

View File

@ -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;

View File

@ -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;

View File

@ -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 {

View File

@ -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());

View File

@ -1,8 +1,8 @@
<?= $this->tabs->render($this); ?>
<?php if (isset($this->success)) : ?>
<?php if (isset($this->successMessage)) : ?>
<div class="alert alert-success">
<h4>Preferences Updated Successfully</h4>
<h4>{{SUCCESS_ICON}} <?= $this->successMessage ?></h4>
</div>
<?php endif; ?>

View File

@ -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

View File

@ -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));

View File

@ -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'
);
}
}

View File

@ -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');