Fix icinga application forms using BaseTestCase now

refs #4608
This commit is contained in:
Marius Hein 2013-08-26 13:25:20 +02:00
parent 1dfc578c00
commit dc71885eac
5 changed files with 163 additions and 88 deletions

View File

@ -119,6 +119,23 @@ class BaseTestCase extends Zend_Test_PHPUnit_ControllerTestCase implements DbTes
), ),
); );
/**
* Constructs a test case with the given name.
*
* @param string $name
* @param array $data
* @param string $dataName
* @see PHPUnit_Framework_TestCase::__construct
*/
public function __construct($name = null, array $data = array(), $dataName = '')
{
parent::__construct($name, $data, $dataName);
$tz = @date_default_timezone_get();
date_default_timezone_set('UTC');
}
/** /**
* Setup test path environment * Setup test path environment
* *
@ -318,11 +335,13 @@ class BaseTestCase extends Zend_Test_PHPUnit_ControllerTestCase implements DbTes
public function requireFormLibraries() public function requireFormLibraries()
{ {
// @codingStandardsIgnoreStart // @codingStandardsIgnoreStart
require_once 'Zend/Form/Decorator/Abstract.php'; require_once 'Zend/Form/Decorator/Abstract.php';
require_once 'Zend/Validate/Abstract.php'; require_once 'Zend/Validate/Abstract.php';
require_once 'Zend/Form/Element/Xhtml.php'; require_once 'Zend/Form/Element/Xhtml.php';
require_once 'Zend/Form/Element/Text.php';
require_once 'Zend/Form/Element/Submit.php';
require_once 'Zend/Form.php'; require_once 'Zend/Form.php';
require_once 'Zend/View.php';
require_once self::$libDir . '/Web/Form/InvalidCSRFTokenException.php'; require_once self::$libDir . '/Web/Form/InvalidCSRFTokenException.php';

View File

@ -28,16 +28,23 @@
namespace Test\Icinga\Form\Config; namespace Test\Icinga\Form\Config;
// @codingStandardsIgnoreStart
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
// @codingStandardsIgnoreEnd
require_once('Zend/Config.php'); use Icinga\Test\BaseTestCase;
require_once('Zend/Config/Ini.php');
require_once(realpath('library/Icinga/Web/Form/BaseFormTest.php')); // @codingStandardsIgnoreStart
require_once(realpath('../../application/forms/Config/AuthenticationForm.php')); require_once 'Zend/Form.php';
require_once(realpath('../../application/forms/Config/Authentication/BaseBackendForm.php')); require_once 'Zend/Config.php';
require_once(realpath('../../application/forms/Config/Authentication/DbBackendForm.php')); require_once 'Zend/Config/Ini.php';
require_once(realpath('../../application/forms/Config/Authentication/LdapBackendForm.php')); require_once BaseTestCase::$libDir . '/Web/Form.php';
require_once BaseTestCase::$appDir . '/forms/Config/AuthenticationForm.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 \Test\Icinga\Web\Form\BaseFormTest;
use \Icinga\Web\Form; use \Icinga\Web\Form;
use \DOMDocument; use \DOMDocument;
use \Zend_Config; use \Zend_Config;
@ -47,7 +54,7 @@ use \Zend_View;
* Test for the authentication provider form * Test for the authentication provider form
* *
*/ */
class AuthenticationFormTest extends \Test\Icinga\Web\Form\BaseFormTest class AuthenticationFormTest extends BaseTestCase
{ {
/** /**
@ -84,8 +91,8 @@ class AuthenticationFormTest extends \Test\Icinga\Web\Form\BaseFormTest
*/ */
public function testLdapProvider() public function testLdapProvider()
{ {
date_default_timezone_set('UTC'); $this->requireFormLibraries();
$form = $this->getRequestForm(array(), 'Icinga\Form\Config\AuthenticationForm'); $form = $this->createForm('Icinga\Form\Config\AuthenticationForm');
$config = new Zend_Config( $config = new Zend_Config(
array( array(
'test-ldap' => array( 'test-ldap' => array(
@ -121,9 +128,10 @@ class AuthenticationFormTest extends \Test\Icinga\Web\Form\BaseFormTest
* Test the database provider form population from config * Test the database provider form population from config
* *
*/ */
public function testDbProvider() { public function testDbProvider()
date_default_timezone_set('UTC'); {
$form = $this->getRequestForm(array(), 'Icinga\Form\Config\AuthenticationForm'); $this->requireFormLibraries();
$form = $this->createForm('Icinga\Form\Config\AuthenticationForm');
$config = new Zend_Config( $config = new Zend_Config(
array( array(
'test-db' => array( 'test-db' => array(
@ -164,10 +172,12 @@ class AuthenticationFormTest extends \Test\Icinga\Web\Form\BaseFormTest
*/ */
public function testShowModifiedOrder() public function testShowModifiedOrder()
{ {
date_default_timezone_set('UTC'); $this->requireFormLibraries();
$form = $this->getRequestForm( $form = $this->createForm(
array('priority' => 'test-ldap,test-db'), 'Icinga\Form\Config\AuthenticationForm',
'Icinga\Form\Config\AuthenticationForm' array(
'priority' => 'test-ldap,test-db'
)
); );
$config = $this->getTestConfig(); $config = $this->getTestConfig();
$form->setResources( $form->setResources(
@ -192,8 +202,9 @@ class AuthenticationFormTest extends \Test\Icinga\Web\Form\BaseFormTest
*/ */
public function testConfigurationCreation() public function testConfigurationCreation()
{ {
date_default_timezone_set('UTC'); $this->requireFormLibraries();
$form = $this->getRequestForm( $form = $this->createForm(
'Icinga\Form\Config\AuthenticationForm',
array( array(
'priority' => 'test-ldap,test-db', 'priority' => 'test-ldap,test-db',
'backend_testdb_resource' => 'db_resource_2', 'backend_testdb_resource' => 'db_resource_2',
@ -202,10 +213,8 @@ class AuthenticationFormTest extends \Test\Icinga\Web\Form\BaseFormTest
'backend_testldap_bind_dn' => 'modified_bind_dn', 'backend_testldap_bind_dn' => 'modified_bind_dn',
'backend_testldap_bind_pw' => 'modified_bind_pw', 'backend_testldap_bind_pw' => 'modified_bind_pw',
'backend_testldap_user_class' => 'modified_user_class', 'backend_testldap_user_class' => 'modified_user_class',
'backend_testldap_user_name_attribute' => 'modified_user_name_attribute', 'backend_testldap_user_name_attribute' => 'modified_user_name_attribute'
'backend_testdb_resource' => 'db_resource_2' )
),
'Icinga\Form\Config\AuthenticationForm'
); );
$form->setResources( $form->setResources(
@ -282,8 +291,9 @@ class AuthenticationFormTest extends \Test\Icinga\Web\Form\BaseFormTest
*/ */
public function testBackendRemoval() public function testBackendRemoval()
{ {
date_default_timezone_set('UTC'); $this->requireFormLibraries();
$form = $this->getRequestForm( $form = $this->createForm(
'Icinga\Form\Config\AuthenticationForm',
array( array(
'priority' => 'test-ldap,test-db', 'priority' => 'test-ldap,test-db',
'backend_testdb_resource' => 'db_resource_2', 'backend_testdb_resource' => 'db_resource_2',
@ -293,10 +303,8 @@ class AuthenticationFormTest extends \Test\Icinga\Web\Form\BaseFormTest
'backend_testldap_bind_dn' => 'modified_bind_dn', 'backend_testldap_bind_dn' => 'modified_bind_dn',
'backend_testldap_bind_pw' => 'modified_bind_pw', 'backend_testldap_bind_pw' => 'modified_bind_pw',
'backend_testldap_user_class' => 'modified_user_class', 'backend_testldap_user_class' => 'modified_user_class',
'backend_testldap_user_name_attribute' => 'modified_user_name_attribute', 'backend_testldap_user_name_attribute' => 'modified_user_name_attribute'
'backend_testdb_resource' => 'db_resource_2' )
),
'Icinga\Form\Config\AuthenticationForm'
); );
$form->setResources( $form->setResources(
@ -328,4 +336,4 @@ class AuthenticationFormTest extends \Test\Icinga\Web\Form\BaseFormTest
); );
} }
} }

View File

@ -28,29 +28,34 @@
namespace Test\Icinga\Form\Config; namespace Test\Icinga\Form\Config;
// @codingStandardsIgnoreStart
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
// @codingStandardsIgnoreEnd
require_once('Zend/Config.php'); use Icinga\Test\BaseTestCase;
require_once('Zend/Config/Ini.php'); // @codingStandardsIgnoreStart
require_once(realpath('library/Icinga/Web/Form/BaseFormTest.php')); require_once 'Zend/Form.php';
require_once(realpath('../../application/forms/Config/GeneralForm.php')); require_once 'Zend/Config.php';
require_once 'Zend/Config/Ini.php';
require_once BaseTestCase::$libDir . '/Web/Form.php';
require_once BaseTestCase::$appDir . '/forms/Config/GeneralForm.php';
// @codingStandardsIgnoreEnd
use Test\Icinga\Web\Form\BaseFormTest;
use \Icinga\Web\Form; use \Icinga\Web\Form;
use \DOMDocument; use \DOMDocument;
use \Zend_Config; use \Zend_Config;
use \Zend_View; use \Zend_View;
class GeneralFormTest extends \Test\Icinga\Web\Form\BaseFormTest class GeneralFormTest extends BaseTestCase
{ {
private function isHiddenElement($value, $htmlString) private function isHiddenElement($value, $htmlString)
{ {
$html = new DOMDocument(); $html = new DOMDocument();
$html->loadHTML($htmlString); $html->loadHTML($htmlString);
$hidden = $html->getElementsByTagName('noscript'); $hidden = $html->getElementsByTagName('noscript');
foreach($hidden as $node) { foreach ($hidden as $node) {
foreach($node->childNodes as $child) { foreach ($node->childNodes as $child) {
if ($child->hasAttributes() === false) { if ($child->hasAttributes() === false) {
continue; continue;
} }
@ -66,8 +71,8 @@ class GeneralFormTest extends \Test\Icinga\Web\Form\BaseFormTest
*/ */
public function testCorrectFieldPopulation() public function testCorrectFieldPopulation()
{ {
date_default_timezone_set('UTC'); $this->requireFormLibraries();
$form = $this->getRequestForm(array(), 'Icinga\Form\Config\GeneralForm'); $form = $this->createForm('Icinga\Form\Config\GeneralForm');
$form->setConfiguration( $form->setConfiguration(
new Zend_Config( new Zend_Config(
array( array(
@ -95,23 +100,54 @@ class GeneralFormTest extends \Test\Icinga\Web\Form\BaseFormTest
) )
); );
$form->setConfigDir('/tmp'); $form->setConfigDir('/tmp');
$view = new Zend_View();
$form->create(); $form->create();
$this->assertEquals(1, $form->getValue('environment'), 'Asserting the checkbox for devlopment being set to true'); $this->assertEquals(
$this->assertEquals('Europe/Berlin', $form->getValue('timezone'), 'Asserting the correct timezone to be displayed'); 1,
$this->assertEquals('/my/module/path', $form->getValue('module_folder'), 'Asserting the correct module folder to be set'); $form->getValue('environment'),
$this->assertEquals('d-m/Y', $form->getValue('date_format'), 'Asserting the correct data format to be set'); 'Asserting the checkbox for devlopment being set to true'
$this->assertEquals('A:i', $form->getValue('time_format'), 'Asserting the correct time to be set'); );
$this->assertEquals('ini', $form->getValue('preferences_type'), 'Asserting the correct preference type to be set'); $this->assertEquals(
$this->assertEquals('./my/path', $form->getValue('preferences_ini_path'), 'Asserting the correct ini path to be set'); 'Europe/Berlin',
$this->assertEquals('', $form->getValue('preferences_db_resource'), 'Asserting the database resource not to be set'); $form->getValue('timezone'),
'Asserting the correct timezone to be displayed'
);
$this->assertEquals(
'/my/module/path',
$form->getValue('module_folder'),
'Asserting the correct module folder to be set'
);
$this->assertEquals(
'd-m/Y',
$form->getValue('date_format'),
'Asserting the correct data format to be set'
);
$this->assertEquals(
'A:i',
$form->getValue('time_format'),
'Asserting the correct time to be set'
);
$this->assertEquals(
'ini',
$form->getValue('preferences_type'),
'Asserting the correct preference type to be set'
);
$this->assertEquals(
'./my/path',
$form->getValue('preferences_ini_path'),
'Asserting the correct ini path to be set'
);
$this->assertEquals(
'',
$form->getValue('preferences_db_resource'),
'Asserting the database resource not to be set'
);
} }
public function testCorrectConditionalIniFieldRendering() public function testCorrectConditionalIniFieldRendering()
{ {
date_default_timezone_set('UTC'); $this->requireFormLibraries();
$form = $this->getRequestForm(array(), 'Icinga\Form\Config\GeneralForm'); $form = $this->createForm('Icinga\Form\Config\GeneralForm');
$form->setConfiguration( $form->setConfiguration(
new Zend_Config( new Zend_Config(
array( array(
@ -146,8 +182,8 @@ class GeneralFormTest extends \Test\Icinga\Web\Form\BaseFormTest
public function testCorrectConditionalDbFieldRendering() public function testCorrectConditionalDbFieldRendering()
{ {
date_default_timezone_set('UTC'); $this->requireFormLibraries();
$form = $this->getRequestForm(array(), 'Icinga\Form\Config\GeneralForm'); $form = $this->createForm('Icinga\Form\Config\GeneralForm');
$form->setConfiguration( $form->setConfiguration(
new Zend_Config( new Zend_Config(
array( array(

View File

@ -28,13 +28,19 @@
namespace Test\Icinga\Form\Config; namespace Test\Icinga\Form\Config;
require_once('Zend/Config.php'); // @codingStandardsIgnoreStart
require_once('Zend/Config/Ini.php'); require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
require_once(realpath('library/Icinga/Web/Form/BaseFormTest.php')); // @codingStandardsIgnoreEnd
require_once(realpath('../../application/forms/Config/LoggingForm.php'));
require_once(realpath('../../library/Icinga/Application/Icinga.php')); use Icinga\Test\BaseTestCase;
// @codingStandardsIgnoreStart
require_once 'Zend/Form.php';
require_once 'Zend/Config.php';
require_once 'Zend/Config/Ini.php';
require_once BaseTestCase::$libDir . '/Web/Form.php';
require_once BaseTestCase::$appDir . '/forms/Config/GeneralForm.php';
// @codingStandardsIgnoreEnd
use \Test\Icinga\Web\Form\BaseFormTest;
use \Icinga\Web\Form; use \Icinga\Web\Form;
use \Zend_Config; use \Zend_Config;
@ -42,7 +48,7 @@ use \Zend_Config;
* Test for the authentication provider form * Test for the authentication provider form
* *
*/ */
class LoggingFormTest extends BaseFormTest class LoggingFormTest extends BaseTestCase
{ {
/** /**
@ -51,8 +57,8 @@ class LoggingFormTest extends BaseFormTest
*/ */
public function testLoggingFormPopulation() public function testLoggingFormPopulation()
{ {
date_default_timezone_set('UTC'); $this->requireFormLibraries();
$form = $this->getRequestForm(array(), 'Icinga\Form\Config\LoggingForm'); $form = $this->createForm('Icinga\Form\Config\LoggingForm');
$config = new Zend_Config( $config = new Zend_Config(
array( array(
'logging' => array( 'logging' => array(
@ -76,9 +82,12 @@ class LoggingFormTest extends BaseFormTest
'0', '0',
$form->getValue('logging_app_verbose'), $form->getValue('logging_app_verbose'),
'Asserting the logging verbose tick not to be set' 'Asserting the logging verbose tick not to be set'
); );
$this->assertEquals('/some/path', $form->getValue('logging_app_target'), 'Asserting the logging path to be set'); $this->assertEquals(
'/some/path',
$form->getValue('logging_app_target'),
'Asserting the logging path to be set'
);
$this->assertEquals( $this->assertEquals(
1, 1,
$form->getValue('logging_debug_enable'), $form->getValue('logging_debug_enable'),
@ -97,16 +106,16 @@ class LoggingFormTest extends BaseFormTest
*/ */
public function testCorrectConfigCreation() public function testCorrectConfigCreation()
{ {
date_default_timezone_set('UTC'); $this->requireFormLibraries();
$form = $this->getRequestForm( $form = $this->createForm(
'Icinga\Form\Config\LoggingForm',
array( array(
'logging_enable' => 1, 'logging_enable' => 1,
'logging_app_target' => 'some/new/target', 'logging_app_target' => 'some/new/target',
'logging_app_verbose' => 1, 'logging_app_verbose' => 1,
'logging_debug_enable' => 0, 'logging_debug_enable' => 0,
'logging_debug_target' => 'a/new/target' 'logging_debug_target' => 'a/new/target'
), )
'Icinga\Form\Config\LoggingForm'
); );
$baseConfig = new Zend_Config( $baseConfig = new Zend_Config(
array( array(

View File

@ -28,26 +28,30 @@
namespace Test\Icinga\Form\Preference; namespace Test\Icinga\Form\Preference;
// @codingStandardsIgnoreStart
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
// @codingStandardsIgnoreEnd
require_once('Zend/Config.php'); use Icinga\Test\BaseTestCase;
require_once('Zend/Config/Ini.php');
require_once('Zend/Form/Element/Select.php'); // @codingStandardsIgnoreStart
require_once(realpath('library/Icinga/Web/Form/BaseFormTest.php')); require_once 'Zend/Config.php';
require_once(realpath('../../application/forms/Preference/GeneralForm.php')); require_once 'Zend/Config/Ini.php';
require_once(realpath('../../library/Icinga/User/Preferences/ChangeSet.php')); require_once 'Zend/Form/Element/Select.php';
require_once(realpath('../../library/Icinga/User/Preferences.php')); require_once BaseTestCase::$libDir . '/User/Preferences.php';
require_once BaseTestCase::$libDir . '/Web/Form.php';
require_once BaseTestCase::$appDir . '/forms/Preference/GeneralForm.php';
require_once BaseTestCase::$libDir . '/User/Preferences/ChangeSet.php';
// @codingStandardsIgnoreEnd
use Test\Icinga\Web\Form\BaseFormTest;
use \Icinga\Web\Form; use \Icinga\Web\Form;
use \DOMDocument;
use \Zend_Config; use \Zend_Config;
use \Zend_View;
use Icinga\User\Preferences; use Icinga\User\Preferences;
/** /**
* Test for general form, mainly testing enable/disable behaviour * Test for general form, mainly testing enable/disable behaviour
*/ */
class GeneralFormTest extends \Test\Icinga\Web\Form\BaseFormTest class GeneralFormTest extends BaseTestCase
{ {
/** /**
@ -56,8 +60,8 @@ class GeneralFormTest extends \Test\Icinga\Web\Form\BaseFormTest
*/ */
public function testDisableFormIfUsingDefault() public function testDisableFormIfUsingDefault()
{ {
date_default_timezone_set('UTC'); $this->requireFormLibraries();
$form = $this->getRequestForm(array(), 'Icinga\Form\Preference\GeneralForm'); $form = $this->createForm('Icinga\Form\Preference\GeneralForm');
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setConfiguration( $form->setConfiguration(
new Zend_Config( new Zend_Config(
@ -85,8 +89,8 @@ class GeneralFormTest extends \Test\Icinga\Web\Form\BaseFormTest
*/ */
public function testEnsableFormIfUsingPreference() public function testEnsableFormIfUsingPreference()
{ {
date_default_timezone_set('UTC'); $this->requireFormLibraries();
$form = $this->getRequestForm(array(), 'Icinga\Form\Preference\GeneralForm'); $form = $this->createForm('Icinga\Form\Preference\GeneralForm');
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setConfiguration( $form->setConfiguration(
new Zend_Config( new Zend_Config(
@ -109,5 +113,4 @@ class GeneralFormTest extends \Test\Icinga\Web\Form\BaseFormTest
'Asserting form elements to be disabled when not set in a preference' 'Asserting form elements to be disabled when not set in a preference'
); );
} }
}
}