diff --git a/application/forms/TestForm.php b/application/forms/TestForm.php deleted file mode 100644 index ff6008c22..000000000 --- a/application/forms/TestForm.php +++ /dev/null @@ -1,34 +0,0 @@ - - * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 - * @author Icinga Development Team - * - */ -// {{{ICINGA_LICENSE_HEADER}}} - -namespace Icinga\Form; - -class TestForm -{ -} diff --git a/test/php/application/forms/Config/GeneralFormTest.php b/test/php/application/forms/Config/GeneralFormTest.php deleted file mode 100644 index 82d173080..000000000 --- a/test/php/application/forms/Config/GeneralFormTest.php +++ /dev/null @@ -1,197 +0,0 @@ -viewMock = Mockery::mock('\Zend_View'); - $this->viewMock->shouldReceive('icon')->andReturn(''); - } - - private function isHiddenElement($value, $htmlString) - { - $html = new DOMDocument(); - $html->loadHTML($htmlString); - $hidden = $html->getElementsByTagName('noscript'); - - foreach ($hidden as $node) { - foreach ($node->childNodes as $child) { - if ($child->hasAttributes() === false) { - continue; - } - if (strpos($child->attributes->getNamedItem('id')->value, $value . '-element') !== false) { - return true; - } - } - } - return false; - } - - public function testCorrectFieldPopulation() - { - $form = $this->createForm('Icinga\Form\Config\GeneralForm'); - $form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest())); - $form->setConfiguration( - new Zend_Config( - array( - 'global' => array( - 'environment' => 'development', - 'timezone' => 'Europe/Berlin', - 'indexModule' => 'monitoring', - 'indexController' => 'dashboard', - 'moduleFolder' => '/my/module/path', - 'dateFormat' => 'd-m/Y', - 'timeFormat' => 'A:i' - ), - 'preferences' => array( - 'type' => 'ini', - 'configPath' => './my/path' - ) - ) - ) - ); - $form->setResources( - array( - 'db' => array( - 'type' => 'db' - ) - ) - ); - $form->setConfigDir('/tmp'); - $form->setView($this->viewMock); - - $form->create(); - - $this->assertEquals( - 1, - $form->getValue('environment'), - 'Asserting the checkbox for devlopment being set to true' - ); - $this->assertEquals( - 'Europe/Berlin', - $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() - { - $form = $this->createForm('Icinga\Form\Config\GeneralForm'); - $form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest())); - $form->setConfiguration( - new Zend_Config( - array( - 'preferences' => array( - 'type' => 'ini', - 'configPath' => './my/path' - ) - ) - ) - ); - $form->setConfigDir('/tmp'); - $form->setResources( - array( - 'db' => array( - 'type' => 'db' - ) - ) - ); - $form->setView($this->viewMock); - - $form->create(); - $view = new Zend_View(); - - $this->assertFalse( - $this->isHiddenElement('preferences_ini_path', $form->render($view)), - "Asserting the ini path field to be displayed when an ini preference is set" - ); - $this->assertTrue( - $this->isHiddenElement('preferences_db_resource', $form->render($view)), - "Asserting the db resource to be hidden when an ini preference is set" - ); - } - - public function testCorrectConditionalDbFieldRendering() - { - $form = $this->createForm('Icinga\Form\Config\GeneralForm'); - $form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest())); - $form->setConfiguration( - new Zend_Config( - array( - 'preferences' => array( - 'type' => 'db', - 'configPath' => './my/path', - 'resource' => 'my_resource' - ) - ) - ) - ); - $form->setConfigDir('/tmp'); - $form->setResources( - array( - 'db' => array( - 'type' => 'db' - ) - ) - ); - $form->setView($this->viewMock); - - $form->create(); - $view = new Zend_View(); - - $this->assertTrue( - $this->isHiddenElement('preferences_ini_path', $form->render($view)), - "Asserting the ini path field to be hidden when db preference is set" - ); - $this->assertFalse( - $this->isHiddenElement('preferences_ini_resource', $form->render($view)), - "Asserting the db resource to be displayed when db preference is set" - ); - } -} diff --git a/test/php/application/forms/Config/LoggingFormTest.php b/test/php/application/forms/Config/LoggingFormTest.php deleted file mode 100644 index 6bc22f824..000000000 --- a/test/php/application/forms/Config/LoggingFormTest.php +++ /dev/null @@ -1,136 +0,0 @@ -createForm('Icinga\Form\Config\LoggingForm'); - $config = new Zend_Config( - array( - 'logging' => array( - 'enable' => 1, - 'target' => '/some/path', - 'verbose' => 0, - 'type' => 'stream', - 'debug' => array( - 'enable' => 1, - 'target' => '/some/debug/path', - 'type' => 'stream' - ) - ) - ) - ); - $form->setConfiguration($config); - $form->setBaseDir('basedir'); - $form->create(); - - $this->assertEquals( - '0', - $form->getValue('logging_app_verbose'), - '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( - 1, - $form->getValue('logging_debug_enable'), - 'Asserting the debug log enable tick to be set' - ); - $this->assertEquals( - '/some/debug/path', - $form->getValue('logging_debug_target'), - 'Asserting the debug log path to be set' - ); - } - - /** - * Test the logging form to create correct modified configurations when submit - */ - public function testCorrectConfigCreation() - { - $form = $this->createForm( - 'Icinga\Form\Config\LoggingForm', - array( - 'logging_enable' => 1, - 'logging_app_target' => 'some/new/target', - 'logging_app_verbose' => 1, - 'logging_debug_enable' => 0, - 'logging_debug_target' => 'a/new/target' - ) - ); - $baseConfig = new Zend_Config( - array( - 'global' => array( - 'option' => 'value' - ), - 'logging' => array( - 'enable' => 1, - 'target' => '/some/path', - 'verbose' => 0, - 'type' => 'stream', - 'debug' => array( - 'enable' => 1, - 'target' => '/some/debug/path', - 'type' => 'stream' - ) - ) - ) - ); - $form->setConfiguration($baseConfig); - $form->setBaseDir('basedir'); - $form->create(); - $form->populate($this->getRequest()->getParams()); - $config = $form->getConfig(); - $this->assertEquals( - 'value', - $config->global->option, - 'Asserting global options not to be altered when changing log' - ); - $this->assertEquals( - 1, - $config->logging->enable, - 'Asserting logging to stay enabled when enable is ticked' - ); - $this->assertEquals( - 'some/new/target', - $config->logging->target, - 'Asserting target modifications to be applied' - ); - $this->assertEquals( - 1, - $config->logging->verbose, - 'Asserting ticking the verbose checkbox to be applied' - ); - $this->assertEquals( - 'stream', - $config->logging->type, - 'Asserting the type to stay "stream"' - ); - $this->assertEquals( - 0, - $config->logging->debug->enable, - 'Asserting debug log to be disabled' - ); - $this->assertEquals( - 'a/new/target', - $config->logging->debug->target, - 'Asserting the debug log target modifications to be applied' - ); - } -} diff --git a/test/php/application/forms/Preference/GeneralFormTest.php b/test/php/application/forms/Preference/GeneralFormTest.php deleted file mode 100644 index a397cc815..000000000 --- a/test/php/application/forms/Preference/GeneralFormTest.php +++ /dev/null @@ -1,58 +0,0 @@ -createForm('Icinga\Form\Preference\GeneralForm'); - $form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest())); - $form->setRequest($this->getRequest()); - $form->create(); - $this->assertSame( - 1, - $form->getElement('timezone')->getAttrib('disabled'), - 'Asserting form elements to be disabled when not set in a preference' - ); - } - - /** - * Test whether fields with preferences are enabled - */ - public function testEnableFormIfUsingPreference() - { - $form = $this->createForm('Icinga\Form\Preference\GeneralForm'); - $form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest())); - $form->setRequest($this->getRequest()); - $form->setUserPreferences( - new Preferences( - array( - 'app.timezone' => 'Europe/Berlin' - ) - ) - ); - $form->create(); - $this->assertSame( - null, - $form->getElement('timezone')->getAttrib('disabled'), - 'Asserting form elements to be disabled when not set in a preference' - ); - } -}