Remove form tests that cover only graphical tests

refs #6011
This commit is contained in:
Johannes Meyer 2014-04-16 17:04:21 +02:00
parent 21b949758f
commit f7051ca992
4 changed files with 0 additions and 425 deletions

View File

@ -1,34 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga Web 2.
*
* Icinga Web 2 - 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 <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*
*/
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Form;
class TestForm
{
}

View File

@ -1,197 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Tests\Icinga\Form\Config;
// @codingStandardsIgnoreStart
require_once realpath(ICINGA_APPDIR . '/views/helpers/DateFormat.php');
// @codingStandardsIgnoreEnd
use \Mockery;
use \DOMDocument;
use \Zend_Config;
use \Zend_View;
use \Zend_View_Helper_DateFormat;
use Icinga\Test\BaseTestCase;
class GeneralFormTest extends BaseTestCase
{
public function setUp()
{
parent::setUp();
$this->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"
);
}
}

View File

@ -1,136 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Tests\Icinga\Form\Config;
use \Zend_Config;
Use Icinga\Test\BaseTestCase;
/**
* Test for the authentication provider form
*/
class LoggingFormTest extends BaseTestCase
{
/**
* Test the logging form to be correctly populated from configuration
*/
public function testLoggingFormPopulation()
{
$form = $this->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'
);
}
}

View File

@ -1,58 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Tests\Icinga\Form\Preference;
// @codingStandardsIgnoreStart
require_once realpath(ICINGA_APPDIR . '/views/helpers/DateFormat.php');
// @codingStandardsIgnoreEnd
use \Zend_View_Helper_DateFormat;
use Icinga\Test\BaseTestCase;
use Icinga\User\Preferences;
/**
* Test for general form, mainly testing enable/disable behaviour
*/
class GeneralFormTest extends BaseTestCase
{
/**
* Test whether fields using the default values have input disabled
*/
public function testDisableFormIfUsingDefault()
{
$form = $this->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'
);
}
}