Adjust command forms and tests
Made those command forms using the DateTimePicker element compatible with its new validation. refs #4581
This commit is contained in:
parent
368bd3c9c7
commit
23f0962da1
|
@ -156,10 +156,7 @@ class LoggingForm extends Form
|
|||
'label' => 'Debug Log Path',
|
||||
'required' => $this->shouldDisplayDebugLog($debug),
|
||||
'condition' => $this->shouldDisplayDebugLog($debug),
|
||||
'value' => $debug->get(
|
||||
'target',
|
||||
$this->getBaseDir() . '/var/log/icinga2.debug.log'
|
||||
),
|
||||
'value' => $debug->get('target', $this->getBaseDir() . '/var/log/icinga2.debug.log'),
|
||||
'helptext' => 'Set the path to the debug log'
|
||||
)
|
||||
);
|
||||
|
|
|
@ -44,6 +44,7 @@ use \Zend_Db_Adapter_Pdo_Mysql;
|
|||
use \Zend_Db_Adapter_Pdo_Pgsql;
|
||||
use \Zend_Db_Adapter_Pdo_Oci;
|
||||
use \Icinga\Application\DbAdapterFactory;
|
||||
use \Icinga\User\Preferences;
|
||||
use \Icinga\Web\Form;
|
||||
|
||||
/**
|
||||
|
@ -327,12 +328,23 @@ class BaseTestCase extends Zend_Test_PHPUnit_ControllerTestCase implements DbTes
|
|||
|
||||
require_once $classFile;
|
||||
$form = new $formClass();
|
||||
$form->initCsrfToken();
|
||||
|
||||
$token = $form->getValue($form->getTokenElementName());
|
||||
if ($token !== null) {
|
||||
$requestData[$form->getTokenElementName()] = $token;
|
||||
}
|
||||
|
||||
$request = $this->getRequest();
|
||||
$request->setMethod('POST');
|
||||
$request->setPost($requestData);
|
||||
|
||||
$form->setRequest($request);
|
||||
$form->setUserPreferences(
|
||||
new Preferences(
|
||||
array()
|
||||
)
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
@ -366,6 +378,7 @@ class BaseTestCase extends Zend_Test_PHPUnit_ControllerTestCase implements DbTes
|
|||
|
||||
require_once self::$libDir . '/Web/Form.php';
|
||||
|
||||
require_once self::$libDir . '/User/Preferences.php';
|
||||
// @codingStandardsIgnoreEnd
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
|
||||
namespace Icinga\Web;
|
||||
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Zend_Controller_Request_Http;
|
||||
use Icinga\User;
|
||||
|
||||
|
|
|
@ -276,6 +276,7 @@ class Monitoring_CommandController extends ActionController
|
|||
$this->setSupportedParameters(array('host', 'service'));
|
||||
$form = new RescheduleNextCheckForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setConfiguration(Config::app());
|
||||
|
||||
$this->setForm($form);
|
||||
|
||||
|
@ -430,6 +431,7 @@ class Monitoring_CommandController extends ActionController
|
|||
$this->setSupportedParameters(array('host', 'service'));
|
||||
$form = new ScheduleDowntimeForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setConfiguration(Config::app());
|
||||
$form->setWithChildren(false);
|
||||
$this->setForm($form);
|
||||
|
||||
|
@ -446,6 +448,7 @@ class Monitoring_CommandController extends ActionController
|
|||
$this->setSupportedParameters(array('host'));
|
||||
$form = new ScheduleDowntimeForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setConfiguration(Config::app());
|
||||
$form->setWithChildren(true);
|
||||
$this->setForm($form);
|
||||
|
||||
|
@ -515,6 +518,7 @@ class Monitoring_CommandController extends ActionController
|
|||
$this->setSupportedParameters(array('host'));
|
||||
$form = new RescheduleNextCheckForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setConfiguration(Config::app());
|
||||
|
||||
$form->setWithChildren(true);
|
||||
|
||||
|
@ -676,6 +680,7 @@ class Monitoring_CommandController extends ActionController
|
|||
$this->setSupportedParameters(array('host', 'service'));
|
||||
$form = new AcknowledgeForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setConfiguration(Config::app());
|
||||
|
||||
$this->setForm($form);
|
||||
|
||||
|
|
|
@ -96,10 +96,11 @@ class AcknowledgeForm extends CommandForm
|
|||
$this->addElement(
|
||||
new DateTimePicker(
|
||||
array(
|
||||
'name' => 'expiretime',
|
||||
'label' => t('Expire Time'),
|
||||
'value' => $now->getTimestamp() + 3600,
|
||||
'helptext' => t(
|
||||
'name' => 'expiretime',
|
||||
'label' => t('Expire Time'),
|
||||
'value' => $now->getTimestamp() + 3600,
|
||||
'patterns' => $this->getValidDateTimeFormats(),
|
||||
'helptext' => t(
|
||||
'Enter the expire date/time for this acknowledgement here. Icinga will '
|
||||
. ' delete the acknowledgement after this date expired.'
|
||||
)
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
|
||||
namespace Monitoring\Form\Command;
|
||||
|
||||
use Icinga\Web\Form;
|
||||
use \Zend_Config;
|
||||
use \Icinga\Web\Form;
|
||||
use \Zend_Form_Element_Hidden;
|
||||
|
||||
/**
|
||||
|
@ -101,4 +102,28 @@ class CommandForm extends Form
|
|||
|
||||
return $authorField;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of valid datetime formats
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValidDateTimeFormats()
|
||||
{
|
||||
$config = $this->getConfiguration();
|
||||
$global = $config->global;
|
||||
if ($global === null) {
|
||||
$global = new Zend_Config(array());
|
||||
}
|
||||
$preferences = $this->getUserPreferences();
|
||||
return array(
|
||||
implode(
|
||||
' ',
|
||||
array(
|
||||
$preferences->get('app.dateFormat', $global->get('dateFormat', 'd/m/Y')),
|
||||
$preferences->get('app.timeFormat', $global->get('timeFormat', 'g:i A'))
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,11 +52,12 @@ class RescheduleNextCheckForm extends WithChildrenCommandForm
|
|||
$this->addElement(
|
||||
new DateTimePicker(
|
||||
array(
|
||||
'name' => 'checktime',
|
||||
'label' => t('Check Time'),
|
||||
'value' => DateTimeFactory::create()->getTimestamp(),
|
||||
'required' => !$this->getRequest()->getPost('forcecheck'),
|
||||
'helptext' => t('Set the date/time when this check should be executed.')
|
||||
'name' => 'checktime',
|
||||
'label' => t('Check Time'),
|
||||
'patterns' => $this->getValidDateTimeFormats(),
|
||||
'value' => DateTimeFactory::create()->getTimestamp(),
|
||||
'required' => !$this->getRequest()->getPost('forcecheck'),
|
||||
'helptext' => t('Set the date/time when this check should be executed.')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
|
|
@ -134,20 +134,22 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
$this->addElement(
|
||||
new DateTimePicker(
|
||||
array(
|
||||
'name' => 'starttime',
|
||||
'label' => t('Start Time'),
|
||||
'value' => $now->getTimestamp(),
|
||||
'helptext' => t('Set the start date/time for the downtime.')
|
||||
'name' => 'starttime',
|
||||
'label' => t('Start Time'),
|
||||
'value' => $now->getTimestamp(),
|
||||
'patterns' => $this->getValidDateTimeFormats(),
|
||||
'helptext' => t('Set the start date/time for the downtime.')
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
new DateTimePicker(
|
||||
array(
|
||||
'name' => 'endtime',
|
||||
'label' => t('End Time'),
|
||||
'value' => $now->getTimestamp() + 3600,
|
||||
'helptext' => t('Set the end date/time for the downtime.')
|
||||
'name' => 'endtime',
|
||||
'label' => t('End Time'),
|
||||
'value' => $now->getTimestamp() + 3600,
|
||||
'patterns' => $this->getValidDateTimeFormats(),
|
||||
'helptext' => t('Set the end date/time for the downtime.')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
|
|
@ -55,7 +55,7 @@ class AcknowledgeFormTest extends BaseFormTest
|
|||
'comment' => 'Comment',
|
||||
'persistent' => '0',
|
||||
'expire' => '1',
|
||||
'expiretime' => '2013-07-10 17:32:16',
|
||||
'expiretime' => '10/07/2013 5:32 PM',
|
||||
'sticky' => '0',
|
||||
'notify' => '0',
|
||||
'btn_submit' => 'Submit'
|
||||
|
|
|
@ -52,8 +52,8 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'author' => 'TEST_AUTHOR',
|
||||
'comment' => 'DING DING',
|
||||
'triggered' => '4',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'endtime' => '2013-07-17 10:30:00',
|
||||
'starttime' => '17/07/2013 10:30 AM',
|
||||
'endtime' => '18/07/2013 10:30 AM',
|
||||
'type' => ScheduleDowntimeForm::TYPE_FIXED,
|
||||
'hours' => '',
|
||||
'minutes' => '',
|
||||
|
@ -71,8 +71,8 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'author' => 'TEST_AUTHOR',
|
||||
'comment' => 'DING DING',
|
||||
'triggered' => '4',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'endtime' => '2013-07-17 10:30:00',
|
||||
'starttime' => '17/07/2013 10:30 AM',
|
||||
'endtime' => '18/07/2013 10:30 AM',
|
||||
'type' => ScheduleDowntimeForm::TYPE_FLEXIBLE,
|
||||
'hours' => '10',
|
||||
'minutes' => '10',
|
||||
|
@ -93,8 +93,8 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'author' => 'TEST_AUTHOR',
|
||||
'comment' => 'DING DING',
|
||||
'triggered' => '4',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'endtime' => '2013-07-17 10:30:00',
|
||||
'starttime' => '17/07/2013 10:30 AM',
|
||||
'endtime' => '18/07/2013 10:30 AM',
|
||||
'type' => ScheduleDowntimeForm::TYPE_FLEXIBLE,
|
||||
'hours' => '',
|
||||
'minutes' => '',
|
||||
|
@ -114,8 +114,8 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'author' => '',
|
||||
'comment' => 'DING DING',
|
||||
'triggered' => '4',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'endtime' => '2013-07-17 10:30:00',
|
||||
'starttime' => '17/07/2013 10:30 AM',
|
||||
'endtime' => '18/07/2013 10:30 AM',
|
||||
'type' => ScheduleDowntimeForm::TYPE_FIXED,
|
||||
'hours' => '',
|
||||
'minutes' => '',
|
||||
|
@ -136,8 +136,8 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'author' => 'OK',
|
||||
'comment' => '',
|
||||
'triggered' => '4',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'endtime' => '2013-07-17 10:30:00',
|
||||
'starttime' => '17/07/2013 10:30 AM',
|
||||
'endtime' => '18/07/2013 10:30 AM',
|
||||
'type' => ScheduleDowntimeForm::TYPE_FIXED,
|
||||
'hours' => '',
|
||||
'minutes' => '',
|
||||
|
@ -158,8 +158,8 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'author' => 'OK',
|
||||
'comment' => 'OK',
|
||||
'triggered' => 'HAHA',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'endtime' => '2013-07-17 10:30:00',
|
||||
'starttime' => '17/07/2013 10:30 AM',
|
||||
'endtime' => '18/07/2013 10:30 AM',
|
||||
'type' => ScheduleDowntimeForm::TYPE_FIXED,
|
||||
'hours' => '',
|
||||
'minutes' => '',
|
||||
|
@ -179,8 +179,8 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'author' => 'OK',
|
||||
'comment' => 'OK',
|
||||
'triggered' => '123',
|
||||
'starttime' => '2013-07-17',
|
||||
'endtime' => '2013-07-17 10:30:00',
|
||||
'starttime' => '17/07/2013',
|
||||
'endtime' => '18/07/2013 10:30 AM',
|
||||
'type' => ScheduleDowntimeForm::TYPE_FIXED,
|
||||
'hours' => '',
|
||||
'minutes' => '',
|
||||
|
@ -200,7 +200,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'author' => 'OK',
|
||||
'comment' => 'OK',
|
||||
'triggered' => '123',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'starttime' => '17/07/2013 10:30 AM',
|
||||
'endtime' => 'DING',
|
||||
'type' => ScheduleDowntimeForm::TYPE_FIXED,
|
||||
'hours' => '',
|
||||
|
@ -222,8 +222,8 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'author' => 'OK',
|
||||
'comment' => 'OK',
|
||||
'triggered' => '123',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'endtime' => '2013-07-17 09:30:00',
|
||||
'starttime' => '17/07/2013 10:30 AM',
|
||||
'endtime' => '18/07/2013 10:30 AM',
|
||||
'type' => ScheduleDowntimeForm::TYPE_FLEXIBLE,
|
||||
'hours' => '-1',
|
||||
'minutes' => '12',
|
||||
|
@ -243,8 +243,8 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'author' => 'OK',
|
||||
'comment' => 'OK',
|
||||
'triggered' => '123',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'endtime' => '2013-07-17 09:30:00',
|
||||
'starttime' => '17/07/2013 10:30 AM',
|
||||
'endtime' => '18/07/2013 10:30 AM',
|
||||
'type' => ScheduleDowntimeForm::TYPE_FLEXIBLE,
|
||||
'hours' => '12',
|
||||
'minutes' => 'DING',
|
||||
|
@ -265,8 +265,8 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'author' => 'TEST_AUTHOR',
|
||||
'comment' => 'DING DING',
|
||||
'triggered' => '4',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'endtime' => '2013-07-17 10:30:00',
|
||||
'starttime' => '17/07/2013 10:30 AM',
|
||||
'endtime' => '18/07/2013 10:30 AM',
|
||||
'type' => ScheduleDowntimeForm::TYPE_FIXED,
|
||||
'hours' => '',
|
||||
'minutes' => '',
|
||||
|
@ -287,8 +287,8 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'author' => 'TEST_AUTHOR',
|
||||
'comment' => 'DING DING',
|
||||
'triggered' => '4',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'endtime' => '2013-07-17 10:30:00',
|
||||
'starttime' => '17/07/2013 10:30 AM',
|
||||
'endtime' => '18/07/2013 10:30 AM',
|
||||
'type' => ScheduleDowntimeForm::TYPE_FIXED,
|
||||
'hours' => '',
|
||||
'minutes' => '',
|
||||
|
@ -305,8 +305,8 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'author' => 'TEST_AUTHOR',
|
||||
'comment' => 'DING DING',
|
||||
'triggered' => '4',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'endtime' => '2013-07-17 10:30:00',
|
||||
'starttime' => '17/07/2013 10:30 AM',
|
||||
'endtime' => '18/07/2013 10:30 AM',
|
||||
'type' => ScheduleDowntimeForm::TYPE_FIXED,
|
||||
'hours' => '',
|
||||
'minutes' => '',
|
||||
|
|
|
@ -35,21 +35,17 @@ require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCas
|
|||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once 'Zend/Config.php';
|
||||
require_once 'Zend/Config/Ini.php';
|
||||
require_once 'Zend/Form/Element/Select.php';
|
||||
require_once 'Zend/View/Helper/Abstract.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';
|
||||
require_once BaseTestCase::$appDir . '/views/helpers/DateFormat.php';
|
||||
require_once BaseTestCase::$libDir . '/Util/ConfigAwareFactory.php';
|
||||
require_once BaseTestCase::$libDir . '/Util/DateTimeFactory.php';
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use \DateTimeZone;
|
||||
use \Zend_Config;
|
||||
use \Icinga\User\Preferences;
|
||||
use \Zend_View_Helper_DateFormat;
|
||||
use \Icinga\Util\DateTimeFactory;
|
||||
|
@ -70,18 +66,6 @@ class GeneralFormTest extends BaseTestCase
|
|||
$form = $this->createForm('Icinga\Form\Preference\GeneralForm');
|
||||
$form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest()));
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setConfiguration(
|
||||
new Zend_Config(
|
||||
array(
|
||||
'timezone' => 'UTC'
|
||||
)
|
||||
)
|
||||
);
|
||||
$form->setUserPreferences(
|
||||
new Preferences(
|
||||
array()
|
||||
)
|
||||
);
|
||||
$form->create();
|
||||
$this->assertSame(
|
||||
1,
|
||||
|
@ -101,13 +85,6 @@ class GeneralFormTest extends BaseTestCase
|
|||
$form = $this->createForm('Icinga\Form\Preference\GeneralForm');
|
||||
$form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest()));
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setConfiguration(
|
||||
new Zend_Config(
|
||||
array(
|
||||
'timezone' => 'UTC'
|
||||
)
|
||||
)
|
||||
);
|
||||
$form->setUserPreferences(
|
||||
new Preferences(
|
||||
array(
|
||||
|
|
|
@ -20,59 +20,21 @@ namespace {
|
|||
|
||||
namespace Test\Icinga\Web\Form {
|
||||
|
||||
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
|
||||
require_once 'Zend/Form.php';
|
||||
require_once 'Zend/View.php';
|
||||
require_once 'Zend/Form/Element/Submit.php';
|
||||
require_once 'Zend/Form/Element/Text.php';
|
||||
require_once 'Zend/Form/Element/Password.php';
|
||||
require_once 'Zend/Form/Element/Reset.php';
|
||||
require_once 'Zend/Form/Element/Checkbox.php';
|
||||
require_once 'Zend/Form/Element/Hidden.php';
|
||||
require_once 'Zend/Form/Decorator/Abstract.php';
|
||||
require_once 'Zend/Validate/Date.php';
|
||||
$base = '../../';
|
||||
require_once realpath('../../library/Icinga/Test/BaseTestCase.php');
|
||||
|
||||
require_once realpath($base.'library/Icinga/Exception/ProgrammingError.php');
|
||||
require_once realpath($base.'library/Icinga/Web/Form.php');
|
||||
require_once realpath($base.'library/Icinga/Web/Form/InvalidCSRFTokenException.php');
|
||||
require_once realpath($base.'library/Icinga/Web/Form/Element/Note.php');
|
||||
require_once realpath($base.'library/Icinga/Web/Form/Element/DateTimePicker.php');
|
||||
require_once realpath('../../library/Icinga/Web/Form/Decorator/ConditionalHidden.php');
|
||||
require_once realpath('../../library/Icinga/Web/Form/Decorator/HelpText.php');
|
||||
require_once realpath('../../library/Icinga/Web/Form/Validator/WritablePathValidator.php');
|
||||
require_once realpath('../../library/Icinga/Web/Form/Validator/DateFormatValidator.php');
|
||||
require_once realpath('../../library/Icinga/Web/Form/Validator/TimeFormatValidator.php');
|
||||
|
||||
use \Zend_Form;
|
||||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
||||
use \Icinga\Test\BaseTestCase;
|
||||
|
||||
/**
|
||||
* Base test to be extended for testing forms
|
||||
*/
|
||||
class BaseFormTest extends Zend_Test_PHPUnit_ControllerTestCase
|
||||
class BaseFormTest extends BaseTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns a formclass with the given set of POST data applied
|
||||
*
|
||||
* @param array $data The POST parameters to ste
|
||||
* @param string $formClass The class name (full namespace) to return
|
||||
*
|
||||
* @return Zend_Form $form A form of type $formClass
|
||||
* Temporary wrapper for BaseTestCase::createForm until this testcase is not used anymore
|
||||
*/
|
||||
public function getRequestForm(array $data, $formClass)
|
||||
{
|
||||
$form = new $formClass();
|
||||
$form->setSessionId('test');
|
||||
$form->initCsrfToken();
|
||||
$request = $this->getRequest();
|
||||
$data[$form->getTokenElementName()] = $form->getValue($form->getTokenElementName());
|
||||
|
||||
$request->setMethod('POST')->setPost($data);
|
||||
$form->setRequest($request);
|
||||
|
||||
return $form;
|
||||
return $this->createForm($formClass, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -84,5 +46,4 @@ namespace Test\Icinga\Web\Form {
|
|||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue