Command masks: Review changes [WIP]

refs #4355
This commit is contained in:
Marius Hein 2013-07-23 17:09:06 +02:00
parent 1511cc4662
commit 849eee2cf2
23 changed files with 182 additions and 241 deletions

View File

@ -24,27 +24,19 @@ In here you can add elements to your form, add validations and filters of your
choice. The creation method is invoked lazy just before a form is rendered or choice. The creation method is invoked lazy just before a form is rendered or
*isValid()* is called. *isValid()* is called.
#### Calling is *isValid()* #### Calling is *IsPostAndValid()*
*isValid()* is used to test of all needed parameters there. Our form class *IsPostAndValid()* is used to test of all needed parameters there. It combines
respects just a couple of data: testing for post request and pulls out the data from request object to handle
over an array for Zend native method *isValid()*
1. *null*. If a request was set before (*setRequest()*) and you provide null to #### Pre validation
this method, the data or the current request is used to validate
2. *Zend_Controller_Request_Abstract*. If you provide a Zend request class the
data to test validity is extracted from the request data.
3. *array*. The Zend default style, provide you test data as an array
#### Pre- and post validation
To handle dependend fields you can just override *preValid()* or *postValid()* To handle dependend fields you can just override *preValid()* or *postValid()*
to dynamically add or remove validations. This behaviour reduces the overhead to dynamically add or remove validations. This behaviour reduces the overhead
to write own validator classes. to write own validator classes.
* *preValid()* Work just before pre validation * *preValidation()* Work just before pre validation
* *postValid()* Override validation status afterwards
#### Autoloading of form code #### Autoloading of form code
@ -112,7 +104,7 @@ use an other namesoace for, e.g.
* Check dependent fields * Check dependent fields
* @param array $data * @param array $data
*/ */
protected function preValid(array $data) protected function preValidation(array $data)
{ {
if (isset($data['flag']) && $data['flag'] === '1') { if (isset($data['flag']) && $data['flag'] === '1') {
$textField = $this->getElement('flagValue'); $textField = $this->getElement('flagValue');
@ -164,20 +156,10 @@ interface methods:
* Pre validation * Pre validation
* @param array $data * @param array $data
*/ */
protected function preValid(array $data) protected function preValidation(array $data)
{ {
// Add depending filters or validation here // Add depending filters or validation here
} }
/**
* Post validation
* @param array $data
* @param bool $isValid
*/
protected function postValid(array $data, &$isValid)
{
// Test validation setting and overriding afterwards
}
} }
## Additional resources ## Additional resources

View File

@ -26,6 +26,7 @@
namespace Icinga\Web; namespace Icinga\Web;
use Icinga\Exception\ProgrammingError; use Icinga\Exception\ProgrammingError;
use Zend_Form_Exception;
use Zend_View_Interface; use Zend_View_Interface;
/** /**
@ -97,16 +98,7 @@ abstract class Form extends \Zend_Form
/** /**
* Method called before validation * Method called before validation
*/ */
protected function preValid(array $data) protected function preValidation(array $data)
{
}
/**
* Method called after validation
* @param array $data
* @param bool &$isValid
*/
protected function postValid(array $data, &$isValid)
{ {
} }
@ -146,33 +138,32 @@ abstract class Form extends \Zend_Form
} }
/** /**
* Test if data from array or request is valid * Overridden to assert form creation
* * @param array $data
* If $data is null, internal request is selected to test validity
*
* @param null|\Zend_Controller_Request_Abstract|array $data
* @return bool * @return bool
*/ */
public function isValid($data) public function isValid($data)
{ {
$checkData = null;
// Elements must be there to validate
$this->buildForm(); $this->buildForm();
$this->preValidation($data);
if ($data === null) { return parent::isValid($data);
$checkData = $this->getRequest()->getParams();
} elseif ($data instanceof \Zend_Controller_Request_Abstract) {
$checkData = $data->getParams();
} else {
$checkData = $data;
} }
$this->preValid($checkData);
$checkValue = parent::isValid($checkData);
$this->postValid($checkData, $checkValue);
return $checkValue; /**
* Test if data from array or request is valid
*
* If $data is null, internal request is selected to test validity
* @return bool
*/
public function isPostAndValid()
{
if ($this->getRequest()->isPost() === false) {
return false;
}
$checkData = $this->getRequest()->getParams();
return parent::isValid($checkData);
} }
/** /**

View File

@ -39,15 +39,15 @@ use Icinga\Protocol\Commandpipe\CommandPipe;
use Icinga\Protocol\Commandpipe\Acknowledgement; use Icinga\Protocol\Commandpipe\Acknowledgement;
use Icinga\Exception\ConfigurationError; use Icinga\Exception\ConfigurationError;
use Icinga\Exception\MissingParameterException; use Icinga\Exception\MissingParameterException;
use Monitoring\Form\Command\Acknowledge; use Monitoring\Form\Command\AcknowledgeForm;
use Monitoring\Form\Command\Comment as CommentForm; use Monitoring\Form\Command\CommentForm;
use Monitoring\Form\Command\Confirmation; use Monitoring\Form\Command\ConfirmationForm;
use Monitoring\Form\Command\ConfirmationWithIdentifier; use Monitoring\Form\Command\ConfirmationWithIdentifierForm;
use Monitoring\Form\Command\CustomNotification; use Monitoring\Form\Command\CustomNotificationForm;
use Monitoring\Form\Command\DelayNotification; use Monitoring\Form\Command\DelayNotificationForm;
use Monitoring\Form\Command\RescheduleNextCheck; use Monitoring\Form\Command\RescheduleNextCheckForm;
use Monitoring\Form\Command\ScheduleDowntime; use Monitoring\Form\Command\ScheduleDowntimeForm;
use Monitoring\Form\Command\SubmitPassiveCheckResult; use Monitoring\Form\Command\SubmitPassiveCheckResultForm;
/** /**
* Class Monitoring_CommandController * Class Monitoring_CommandController
@ -202,7 +202,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function disableactivechecksAction() public function disableactivechecksAction()
{ {
$form = new Confirmation(); $form = new ConfirmationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable active checks')); $form->setSubmitLabel(t('Disable active checks'));
$form->addNote(t('Disable active checks for this object.')); $form->addNote(t('Disable active checks for this object.'));
@ -219,7 +219,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function enableactivechecksAction() public function enableactivechecksAction()
{ {
$form = new Confirmation(); $form = new ConfirmationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable active checks')); $form->setSubmitLabel(t('Enable active checks'));
$form->addNote(t('Enable active checks for this object.')); $form->addNote(t('Enable active checks for this object.'));
@ -236,7 +236,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function reschedulenextcheckAction() public function reschedulenextcheckAction()
{ {
$form = new RescheduleNextCheck(); $form = new RescheduleNextCheckForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$this->setForm($form); $this->setForm($form);
@ -252,9 +252,9 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function submitpassivecheckresultAction() public function submitpassivecheckresultAction()
{ {
$type = SubmitPassiveCheckResult::TYPE_SERVICE; $type = SubmitPassiveCheckResultForm::TYPE_SERVICE;
$form = new SubmitPassiveCheckResult(); $form = new SubmitPassiveCheckResultForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setType($type); $form->setType($type);
@ -271,7 +271,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function stopobsessingAction() public function stopobsessingAction()
{ {
$form = new Confirmation(); $form = new ConfirmationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Stop obsessing')); $form->setSubmitLabel(t('Stop obsessing'));
$form->addNote(t('Stop obsessing over this object.')); $form->addNote(t('Stop obsessing over this object.'));
@ -288,7 +288,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function startobsessingAction() public function startobsessingAction()
{ {
$form = new Confirmation(); $form = new ConfirmationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Start obsessing')); $form->setSubmitLabel(t('Start obsessing'));
$form->addNote(t('Start obsessing over this object.')); $form->addNote(t('Start obsessing over this object.'));
@ -305,7 +305,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function stopacceptingpassivechecksAction() public function stopacceptingpassivechecksAction()
{ {
$form = new Confirmation(); $form = new ConfirmationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Stop accepting passive checks')); $form->setSubmitLabel(t('Stop accepting passive checks'));
$form->addNote(t('Passive checks for this object will be omitted.')); $form->addNote(t('Passive checks for this object will be omitted.'));
@ -322,7 +322,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function startacceptingpassivechecksAction() public function startacceptingpassivechecksAction()
{ {
$form = new Confirmation(); $form = new ConfirmationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Start accepting passive checks')); $form->setSubmitLabel(t('Start accepting passive checks'));
$form->addNote(t('Passive checks for this object will be accepted.')); $form->addNote(t('Passive checks for this object will be accepted.'));
@ -339,7 +339,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function disablenotificationsAction() public function disablenotificationsAction()
{ {
$form = new Confirmation(); $form = new ConfirmationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable notifications')); $form->setSubmitLabel(t('Disable notifications'));
$form->addNote(t('Notifications for this object will be disabled.')); $form->addNote(t('Notifications for this object will be disabled.'));
@ -356,7 +356,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function enablenotificationsAction() public function enablenotificationsAction()
{ {
$form = new Confirmation(); $form = new ConfirmationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable notifications')); $form->setSubmitLabel(t('Enable notifications'));
$form->addNote(t('Notifications for this object will be enabled.')); $form->addNote(t('Notifications for this object will be enabled.'));
@ -373,7 +373,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function sendcustomnotificationAction() public function sendcustomnotificationAction()
{ {
$form = new CustomNotification(); $form = new CustomNotificationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$this->setForm($form); $this->setForm($form);
@ -388,7 +388,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function scheduledowntimeAction() public function scheduledowntimeAction()
{ {
$form = new ScheduleDowntime(); $form = new ScheduleDowntimeForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setWithChildren(false); $form->setWithChildren(false);
$this->setForm($form); $this->setForm($form);
@ -404,7 +404,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function scheduledowntimeswithchildrenAction() public function scheduledowntimeswithchildrenAction()
{ {
$form = new ScheduleDowntime(); $form = new ScheduleDowntimeForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setWithChildren(true); $form->setWithChildren(true);
$this->setForm($form); $this->setForm($form);
@ -420,7 +420,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function removedowntimeswithchildrenAction() public function removedowntimeswithchildrenAction()
{ {
$form = new Confirmation(); $form = new ConfirmationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Remove downtime(s)')); $form->setSubmitLabel(t('Remove downtime(s)'));
$form->addNote(t('Remove downtime(s) from this host and its services.')); $form->addNote(t('Remove downtime(s) from this host and its services.'));
@ -437,7 +437,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function disablenotificationswithchildrenAction() public function disablenotificationswithchildrenAction()
{ {
$form = new Confirmation(); $form = new ConfirmationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable notifications')); $form->setSubmitLabel(t('Disable notifications'));
$form->addNote(t('Notifications for this host and its services will be disabled.')); $form->addNote(t('Notifications for this host and its services will be disabled.'));
@ -454,7 +454,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function enablenotificationswithchildrenAction() public function enablenotificationswithchildrenAction()
{ {
$form = new Confirmation(); $form = new ConfirmationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable notifications')); $form->setSubmitLabel(t('Enable notifications'));
$form->addNote(t('Notifications for this host and its services will be enabled.')); $form->addNote(t('Notifications for this host and its services will be enabled.'));
@ -471,7 +471,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function reschedulenextcheckwithchildrenAction() public function reschedulenextcheckwithchildrenAction()
{ {
$form = new RescheduleNextCheck(); $form = new RescheduleNextCheckForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setWithChildren(true); $form->setWithChildren(true);
@ -489,7 +489,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function disableactivecheckswithchildrenAction() public function disableactivecheckswithchildrenAction()
{ {
$form = new Confirmation(); $form = new ConfirmationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable active checks')); $form->setSubmitLabel(t('Disable active checks'));
$form->addNote(t('Disable active checks for this host and its services.')); $form->addNote(t('Disable active checks for this host and its services.'));
@ -506,7 +506,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function enableactivecheckswithchildrenAction() public function enableactivecheckswithchildrenAction()
{ {
$form = new Confirmation(); $form = new ConfirmationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable active checks')); $form->setSubmitLabel(t('Enable active checks'));
$form->addNote(t('Enable active checks for this host and its services.')); $form->addNote(t('Enable active checks for this host and its services.'));
@ -523,7 +523,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function disableeventhandlerAction() public function disableeventhandlerAction()
{ {
$form = new Confirmation(); $form = new ConfirmationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable event handler')); $form->setSubmitLabel(t('Disable event handler'));
$form->addNote(t('Disable event handler for this object.')); $form->addNote(t('Disable event handler for this object.'));
@ -540,7 +540,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function enableeventhandlerAction() public function enableeventhandlerAction()
{ {
$form = new Confirmation(); $form = new ConfirmationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable event handler')); $form->setSubmitLabel(t('Enable event handler'));
$form->addNote(t('Enable event handler for this object.')); $form->addNote(t('Enable event handler for this object.'));
@ -557,7 +557,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function disableflapdetectionAction() public function disableflapdetectionAction()
{ {
$form = new Confirmation(); $form = new ConfirmationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable flapping detection')); $form->setSubmitLabel(t('Disable flapping detection'));
$form->addNote(t('Disable flapping detection for this object.')); $form->addNote(t('Disable flapping detection for this object.'));
@ -574,7 +574,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function enableflapdetectionAction() public function enableflapdetectionAction()
{ {
$form = new Confirmation(); $form = new ConfirmationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable flapping detection')); $form->setSubmitLabel(t('Enable flapping detection'));
$form->addNote(t('Enable flapping detection for this object.')); $form->addNote(t('Enable flapping detection for this object.'));
@ -607,7 +607,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function resetattributesAction() public function resetattributesAction()
{ {
$form = new Confirmation(); $form = new ConfirmationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Reset attributes')); $form->setSubmitLabel(t('Reset attributes'));
$form->addNote(t('Reset modified attributes to its default.')); $form->addNote(t('Reset modified attributes to its default.'));
@ -624,7 +624,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function acknowledgeproblemAction() public function acknowledgeproblemAction()
{ {
$form = new Acknowledge(); $form = new AcknowledgeForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$this->setForm($form); $this->setForm($form);
@ -640,7 +640,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function removeacknowledgementAction() public function removeacknowledgementAction()
{ {
$form = new Confirmation(); $form = new ConfirmationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Remove problem acknowledgement')); $form->setSubmitLabel(t('Remove problem acknowledgement'));
$form->addNote(t('Remove problem acknowledgement for this object.')); $form->addNote(t('Remove problem acknowledgement for this object.'));
@ -657,7 +657,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function delaynotificationAction() public function delaynotificationAction()
{ {
$form = new DelayNotification(); $form = new DelayNotificationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$this->setForm($form); $this->setForm($form);
@ -673,7 +673,7 @@ class Monitoring_CommandController extends ModuleActionController
*/ */
public function removedowntimeAction() public function removedowntimeAction()
{ {
$form = new ConfirmationWithIdentifier(); $form = new ConfirmationWithIdentifierForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Delete downtime')); $form->setSubmitLabel(t('Delete downtime'));

View File

@ -36,11 +36,11 @@ use Icinga\Web\Form\Element\Note;
/** /**
* Form for acknowledge commands * Form for acknowledge commands
*/ */
class Acknowledge extends AbstractCommand class AcknowledgeForm extends ConfirmationForm
{ {
/** /**
* Interface method to build the form * Interface method to build the form
* @see Form::create() * @see ConfirmationForm::create
*/ */
protected function create() protected function create()
{ {
@ -131,9 +131,10 @@ class Acknowledge extends AbstractCommand
/** /**
* Add validator for dependent fields * Add validator for dependent fields
* @see Form::preValidation
* @param array $data * @param array $data
*/ */
protected function preValid(array $data) protected function preValidation(array $data)
{ {
if (isset($data['expire']) && $data['expire'] === '1') { if (isset($data['expire']) && $data['expire'] === '1') {
$expireTime = $this->getElement('expiretime'); $expireTime = $this->getElement('expiretime');

View File

@ -31,11 +31,11 @@ namespace Monitoring\Form\Command;
/** /**
* Form for adding comment commands * Form for adding comment commands
*/ */
class Comment extends AbstractCommand class CommentForm extends ConfirmationForm
{ {
/** /**
* Interface method to build the form * Interface method to build the form
* @see Form::create() * @see ConfirmationForm::create
*/ */
protected function create() protected function create()
{ {

View File

@ -1,38 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - 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 Monitoring\Form\Command;
/**
* Simple confirmation form
*
* Exist to make the abstract available as concrete class
*/
class Confirmation extends AbstractCommand
{
}

View File

@ -34,9 +34,9 @@ use \Zend_Form_Element_Hidden;
use \Zend_Validate_Date; use \Zend_Validate_Date;
/** /**
* Class AbstractCommand * Simple confirmation command
*/ */
abstract class AbstractCommand extends Form class ConfirmationForm extends Form
{ {
/** /**
* Default date format * Default date format
@ -148,6 +148,7 @@ abstract class AbstractCommand extends Form
/** /**
* Add elements to this form (used by extending classes) * Add elements to this form (used by extending classes)
* @see Form::create
*/ */
protected function create() protected function create()
{ {

View File

@ -33,7 +33,7 @@ use \Zend_Form_Element_Hidden;
/** /**
* Form to handle confirmations with a single value processed * Form to handle confirmations with a single value processed
*/ */
class ConfirmationWithIdentifier extends Confirmation class ConfirmationWithIdentifierForm extends ConfirmationForm
{ {
/** /**
* Identifier for data field * Identifier for data field
@ -124,7 +124,7 @@ class ConfirmationWithIdentifier extends Confirmation
/** /**
* Interface method to build the form * Interface method to build the form
* @see Form::create() * @see ConfirmationForm::create
*/ */
protected function create() protected function create()
{ {

View File

@ -33,11 +33,11 @@ use Zend_Form_Element_Hidden;
/** /**
* For for command CustomNotification * For for command CustomNotification
*/ */
class CustomNotification extends AbstractCommand class CustomNotificationForm extends ConfirmationForm
{ {
/** /**
* Interface method to build the form * Interface method to build the form
* @see Form::create() * @see ConfirmationForm::create
*/ */
protected function create() protected function create()
{ {

View File

@ -31,7 +31,7 @@ namespace Monitoring\Form\Command;
/** /**
* Form to handle DelayNotification command * Form to handle DelayNotification command
*/ */
class DelayNotification extends AbstractCommand class DelayNotificationForm extends ConfirmationForm
{ {
/** /**
* Biggest value for minutes * Biggest value for minutes
@ -39,7 +39,7 @@ class DelayNotification extends AbstractCommand
const MAX_VALUE = 1440; const MAX_VALUE = 1440;
/** /**
* Interface method to build the form * Interface method to build the form
* @see Form::create() * @see ConfirmationForm::create
*/ */
protected function create() protected function create()
{ {

View File

@ -35,11 +35,11 @@ use DateTime as PhpDateTime;
/** /**
* Form for RescheduleNextCheck * Form for RescheduleNextCheck
*/ */
class RescheduleNextCheck extends WithChildrenCommand class RescheduleNextCheckForm extends WithChildrenCommandForm
{ {
/** /**
* Interface method to build the form * Interface method to build the form
* @see Form::create() * @see ConfirmationForm::create
*/ */
protected function create() protected function create()
{ {

View File

@ -38,7 +38,7 @@ use \Zend_Validate_Digits;
/** /**
* Form for any ScheduleDowntime command * Form for any ScheduleDowntime command
*/ */
class ScheduleDowntime extends WithChildrenCommand class ScheduleDowntimeForm extends WithChildrenCommandForm
{ {
/** /**
* Default endtime interval definition * Default endtime interval definition
@ -88,7 +88,7 @@ class ScheduleDowntime extends WithChildrenCommand
/** /**
* Interface method to build the form * Interface method to build the form
* @see Form::create() * @see ConfirmationForm::create
*/ */
protected function create() protected function create()
{ {
@ -242,9 +242,10 @@ class ScheduleDowntime extends WithChildrenCommand
/** /**
* Change validators at runtime * Change validators at runtime
* @see Form::preValidation
* @param array $data * @param array $data
*/ */
protected function preValid(array $data) protected function preValidation(array $data)
{ {
/* /*
* Other values needed when downtime type change to flexible * Other values needed when downtime type change to flexible

View File

@ -33,7 +33,7 @@ use Icinga\Exception\ProgrammingError;
/** /**
* Form for command SubmitPassiveCheckResult * Form for command SubmitPassiveCheckResult
*/ */
class SubmitPassiveCheckResult extends AbstractCommand class SubmitPassiveCheckResultForm extends ConfirmationForm
{ {
/** /**
* Type constant for host form * Type constant for host form
@ -59,6 +59,7 @@ class SubmitPassiveCheckResult extends AbstractCommand
/** /**
* Setup plugin states * Setup plugin states
* @see Zend_Form::init
*/ */
public function init() public function init()
{ {
@ -116,7 +117,7 @@ class SubmitPassiveCheckResult extends AbstractCommand
/** /**
* Interface method to build the form * Interface method to build the form
* @see Form::create() * @see ConfirmationForm::create
*/ */
protected function create() protected function create()
{ {

View File

@ -31,7 +31,7 @@ namespace Monitoring\Form\Command;
/** /**
* Class handle specific command flags * Class handle specific command flags
*/ */
abstract class WithChildrenCommand extends AbstractCommand abstract class WithChildrenCommandForm extends ConfirmationForm
{ {
/** /**
* Flag if we handle child objects as well * Flag if we handle child objects as well

View File

@ -28,19 +28,19 @@ namespace Test\Monitoring\Forms\Command {
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php';
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php';
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/DateTime.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/DateTime.php';
require_once __DIR__. '/../../../../../application/forms/Command/AbstractCommand.php'; require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommand.php'; require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommandForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/Acknowledge.php'; require_once __DIR__. '/../../../../../application/forms/Command/AcknowledgeForm.php';
use Monitoring\Form\Command\Acknowledge; use Monitoring\Form\Command\AcknowledgeForm;
use \Zend_View; use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase; use \Zend_Test_PHPUnit_ControllerTestCase;
class AcknowledgeTest extends Zend_Test_PHPUnit_ControllerTestCase class AcknowledgeFormTest extends Zend_Test_PHPUnit_ControllerTestCase
{ {
public function testForm() public function testForm()
{ {
$form = new Acknowledge(); $form = new AcknowledgeForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->buildForm(); $form->buildForm();
@ -49,7 +49,7 @@ namespace Test\Monitoring\Forms\Command {
public function testValidation1() public function testValidation1()
{ {
$form = new Acknowledge(); $form = new AcknowledgeForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$this->assertTrue( $this->assertTrue(

View File

@ -28,19 +28,19 @@ namespace Test\Monitoring\Forms\Command {
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php';
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php';
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/DateTime.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/DateTime.php';
require_once __DIR__. '/../../../../../application/forms/Command/AbstractCommand.php'; require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommand.php'; require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommandForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/Comment.php'; require_once __DIR__. '/../../../../../application/forms/Command/CommentForm.php';
use Monitoring\Form\Command\Comment; use Monitoring\Form\Command\CommentForm;
use \Zend_View; use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase; use \Zend_Test_PHPUnit_ControllerTestCase;
class CommentTest extends Zend_Test_PHPUnit_ControllerTestCase class CommentFormTest extends Zend_Test_PHPUnit_ControllerTestCase
{ {
public function testForm() public function testForm()
{ {
$form = new Comment(); $form = new CommentForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->buildForm(); $form->buildForm();
@ -49,7 +49,7 @@ namespace Test\Monitoring\Forms\Command {
public function testValidation() public function testValidation()
{ {
$form = new Comment(); $form = new CommentForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$this->assertTrue( $this->assertTrue(

View File

@ -9,20 +9,19 @@ require_once 'Zend/Form/Element/Reset.php';
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php';
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php';
require_once __DIR__. '/../../../../../application/forms/Command/AbstractCommand.php'; require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/Confirmation.php';
use \Zend_View; use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase; use \Zend_Test_PHPUnit_ControllerTestCase;
use Monitoring\Form\Command\Confirmation; use Monitoring\Form\Command\ConfirmationForm;
class ConfirmationTest extends Zend_Test_PHPUnit_ControllerTestCase class ConfirmationFormTest extends Zend_Test_PHPUnit_ControllerTestCase
{ {
public function testForm1() public function testForm1()
{ {
$view = new Zend_View(); $view = new Zend_View();
$form = new Confirmation(); $form = new ConfirmationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
@ -45,7 +44,7 @@ class ConfirmationTest extends Zend_Test_PHPUnit_ControllerTestCase
public function testNotes1() public function testNotes1()
{ {
$form = new Confirmation(); $form = new ConfirmationForm();
$form->addNote('test1'); $form->addNote('test1');
$form->addNote('test2'); $form->addNote('test2');

View File

@ -28,19 +28,19 @@ namespace Test\Monitoring\Forms\Command {
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php';
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php';
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/DateTime.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/DateTime.php';
require_once __DIR__. '/../../../../../application/forms/Command/AbstractCommand.php'; require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommand.php'; require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommandForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationWithIdentifier.php'; require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationWithIdentifierForm.php';
use Monitoring\Form\Command\ConfirmationWithIdentifier; use Monitoring\Form\Command\ConfirmationWithIdentifierForm;
use \Zend_View; use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase; use \Zend_Test_PHPUnit_ControllerTestCase;
class ConfirmationWithIdentifierTest extends Zend_Test_PHPUnit_ControllerTestCase class ConfirmationWithIdentifierFormTest extends Zend_Test_PHPUnit_ControllerTestCase
{ {
public function testForm() public function testForm()
{ {
$form = new ConfirmationWithIdentifier(); $form = new ConfirmationWithIdentifierForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setSubmitLabel('DING DING'); $form->setSubmitLabel('DING DING');
$form->buildForm(); $form->buildForm();
@ -50,7 +50,7 @@ namespace Test\Monitoring\Forms\Command {
public function testValidation() public function testValidation()
{ {
$form = new ConfirmationWithIdentifier(); $form = new ConfirmationWithIdentifierForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setFieldLabel('Test1'); $form->setFieldLabel('Test1');
$form->setFieldName('testval'); $form->setFieldName('testval');
@ -83,18 +83,18 @@ namespace Test\Monitoring\Forms\Command {
public function testRequestBridge() public function testRequestBridge()
{ {
$this->getRequest()->setMethod('POST');
$this->getRequest()->setPost( $this->getRequest()->setPost(
array( array(
'objectid' => 123123666 'objectid' => 123123666
) )
); );
$form = new ConfirmationWithIdentifier(); $form = new ConfirmationWithIdentifierForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->buildForm(); $form->buildForm();
$this->assertTrue($form->isValid(null)); $this->assertTrue($form->isPostAndValid());
$this->assertTrue($form->isValid($this->getRequest()));
$this->assertEquals('123123666', $form->getElement('objectid')->getValue()); $this->assertEquals('123123666', $form->getElement('objectid')->getValue());
} }

View File

@ -24,18 +24,19 @@ namespace Test\Monitoring\Forms\Command {
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php';
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php';
require_once __DIR__. '/../../../../../application/forms/Command/AbstractCommand.php'; require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/CustomNotification.php'; require_once __DIR__. '/../../../../../application/forms/Command/CustomNotificationForm.php';
use Monitoring\Form\Command\CustomNotification; use Monitoring\Form\Command\CustomNotificationForm;
use \Zend_View; use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase; use \Zend_Test_PHPUnit_ControllerTestCase;
class CustomNotificationTest extends Zend_Test_PHPUnit_ControllerTestCase class CustomNotificationFormTest extends Zend_Test_PHPUnit_ControllerTestCase
{ {
public function testForm1() public function testForm1()
{ {
$this->getRequest()->setMethod('POST');
$this->getRequest()->setPost( $this->getRequest()->setPost(
array( array(
'comment' => 'TEST COMMENT', 'comment' => 'TEST COMMENT',
@ -43,12 +44,12 @@ namespace Test\Monitoring\Forms\Command {
) )
); );
$form = new CustomNotification(); $form = new CustomNotificationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->buildForm(); $form->buildForm();
$this->assertCount(7, $form->getElements()); $this->assertCount(7, $form->getElements());
$this->assertTrue($form->isValid(null)); $this->assertTrue($form->isPostAndValid());
} }
} }
} }

View File

@ -24,25 +24,26 @@ namespace Test\Monitoring\Forms\Command {
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php';
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php';
require_once __DIR__. '/../../../../../application/forms/Command/AbstractCommand.php'; require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/DelayNotification.php'; require_once __DIR__. '/../../../../../application/forms/Command/DelayNotificationForm.php';
use \Zend_View; use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase; use \Zend_Test_PHPUnit_ControllerTestCase;
use Monitoring\Form\Command\DelayNotification; use Monitoring\Form\Command\DelayNotificationForm;
class DelayNotificationTest extends Zend_Test_PHPUnit_ControllerTestCase class DelayNotificationFormFormTest extends Zend_Test_PHPUnit_ControllerTestCase
{ {
public function testForm1() public function testForm1()
{ {
$this->getRequest()->setMethod('POST');
$this->getRequest()->setPost( $this->getRequest()->setPost(
array( array(
'minutes' => 12 'minutes' => 12
) )
); );
$form = new DelayNotification(); $form = new DelayNotificationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->buildForm(); $form->buildForm();
@ -54,25 +55,26 @@ namespace Test\Monitoring\Forms\Command {
$this->assertEquals('0', $element->getValue()); $this->assertEquals('0', $element->getValue());
$this->assertTrue($element->isRequired()); $this->assertTrue($element->isRequired());
$this->assertTrue($form->isValid(null)); $this->assertTrue($form->isPostAndValid());
$this->assertEquals('12', $form->getValue('minutes')); $this->assertEquals('12', $form->getValue('minutes'));
} }
public function testValidation() public function testValidation()
{ {
$this->getRequest()->setMethod('POST');
$this->getRequest()->setPost( $this->getRequest()->setPost(
array( array(
'minutes' => 'SCHAHH-LAHH-LAHH' 'minutes' => 'SCHAHH-LAHH-LAHH'
) )
); );
$form = new DelayNotification(); $form = new DelayNotificationForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->buildForm(); $form->buildForm();
$this->assertFalse($form->isValid(null)); $this->assertFalse($form->isPostAndValid());
$errors = $form->getErrors('minutes'); $errors = $form->getErrors('minutes');
$this->assertEquals('notBetween', $errors[0]); $this->assertEquals('notBetween', $errors[0]);

View File

@ -27,16 +27,16 @@ namespace Test\Monitoring\Forms\Command {
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php';
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php';
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/DateTime.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/DateTime.php';
require_once __DIR__. '/../../../../../application/forms/Command/AbstractCommand.php'; require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommand.php'; require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommandForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/RescheduleNextCheck.php'; require_once __DIR__. '/../../../../../application/forms/Command/RescheduleNextCheckForm.php';
use Monitoring\Form\Command\RescheduleNextCheck; use Monitoring\Form\Command\RescheduleNextCheckForm;
use \Zend_View; use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase; use \Zend_Test_PHPUnit_ControllerTestCase;
class RescheduleNextCheckTest extends Zend_Test_PHPUnit_ControllerTestCase class RescheduleNextCheckFormTest extends Zend_Test_PHPUnit_ControllerTestCase
{ {
public function testForm1() public function testForm1()
{ {
@ -46,7 +46,7 @@ namespace Test\Monitoring\Forms\Command {
) )
); );
$form = new RescheduleNextCheck(); $form = new RescheduleNextCheckForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->buildForm(); $form->buildForm();
@ -92,21 +92,21 @@ namespace Test\Monitoring\Forms\Command {
public function testChildrenFlag() public function testChildrenFlag()
{ {
$form = new RescheduleNextCheck(); $form = new RescheduleNextCheckForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setWithChildren(true); $form->setWithChildren(true);
$form->buildForm(); $form->buildForm();
$notes1 = $form->getNotes(); $notes1 = $form->getNotes();
$form = null; $form = null;
$form = new RescheduleNextCheck(); $form = new RescheduleNextCheckForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setWithChildren(false); $form->setWithChildren(false);
$form->buildForm(); $form->buildForm();
$notes2 = $form->getNotes(); $notes2 = $form->getNotes();
$form = null; $form = null;
$form = new RescheduleNextCheck(); $form = new RescheduleNextCheckForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setWithChildren(); $form->setWithChildren();
$form->buildForm(); $form->buildForm();

View File

@ -27,15 +27,15 @@ namespace Test\Monitoring\Forms\Command {
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php';
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php';
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/DateTime.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/DateTime.php';
require_once __DIR__. '/../../../../../application/forms/Command/AbstractCommand.php'; require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommand.php'; require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommandForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/ScheduleDowntime.php'; require_once __DIR__. '/../../../../../application/forms/Command/ScheduleDowntimeForm.php';
use Monitoring\Form\Command\ScheduleDowntime; use Monitoring\Form\Command\ScheduleDowntimeForm;
use \Zend_View; use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase; use \Zend_Test_PHPUnit_ControllerTestCase;
class ScheduleDowntimeTest extends Zend_Test_PHPUnit_ControllerTestCase class ScheduleDowntimeFormTest extends Zend_Test_PHPUnit_ControllerTestCase
{ {
public function testFormElements1() public function testFormElements1()
{ {
@ -45,13 +45,13 @@ namespace Test\Monitoring\Forms\Command {
) )
); );
$form = new ScheduleDowntime(); $form = new ScheduleDowntimeForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->buildForm(); $form->buildForm();
$this->assertCount(13, $form->getElements()); $this->assertCount(13, $form->getElements());
$form = new ScheduleDowntime(); $form = new ScheduleDowntimeForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setWithChildren(true); $form->setWithChildren(true);
$form->buildForm(); $form->buildForm();
@ -68,7 +68,7 @@ namespace Test\Monitoring\Forms\Command {
) )
); );
$form = new ScheduleDowntime(); $form = new ScheduleDowntimeForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setWithChildren(true); $form->setWithChildren(true);
@ -80,7 +80,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '4', 'triggered' => '4',
'starttime' => '2013-07-17 10:30:00', 'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 10:30:00', 'endtime' => '2013-07-17 10:30:00',
'type' => ScheduleDowntime::TYPE_FIXED, 'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '', 'hours' => '',
'minutes' => '', 'minutes' => '',
// 'childobjects' => '', // 'childobjects' => '',
@ -96,7 +96,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '4', 'triggered' => '4',
'starttime' => '2013-07-17 10:30:00', 'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 10:30:00', 'endtime' => '2013-07-17 10:30:00',
'type' => ScheduleDowntime::TYPE_FLEXIBLE, 'type' => ScheduleDowntimeForm::TYPE_FLEXIBLE,
'hours' => '', 'hours' => '',
'minutes' => '', 'minutes' => '',
// 'childobjects' => '', // 'childobjects' => '',
@ -112,7 +112,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '4', 'triggered' => '4',
'starttime' => '2013-07-17 10:30:00', 'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 10:30:00', 'endtime' => '2013-07-17 10:30:00',
'type' => ScheduleDowntime::TYPE_FLEXIBLE, 'type' => ScheduleDowntimeForm::TYPE_FLEXIBLE,
'hours' => '10', 'hours' => '10',
'minutes' => '10', 'minutes' => '10',
// 'childobjects' => '', // 'childobjects' => '',
@ -128,7 +128,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '4', 'triggered' => '4',
'starttime' => '2013-07-17 10:30:00', 'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 10:30:00', 'endtime' => '2013-07-17 10:30:00',
'type' => ScheduleDowntime::TYPE_FIXED, 'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '', 'hours' => '',
'minutes' => '', 'minutes' => '',
// 'childobjects' => '', // 'childobjects' => '',
@ -144,7 +144,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '4', 'triggered' => '4',
'starttime' => '2013-07-17 10:30:00', 'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 10:30:00', 'endtime' => '2013-07-17 10:30:00',
'type' => ScheduleDowntime::TYPE_FIXED, 'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '', 'hours' => '',
'minutes' => '', 'minutes' => '',
// 'childobjects' => '', // 'childobjects' => '',
@ -160,7 +160,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => 'HAHA', 'triggered' => 'HAHA',
'starttime' => '2013-07-17 10:30:00', 'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 10:30:00', 'endtime' => '2013-07-17 10:30:00',
'type' => ScheduleDowntime::TYPE_FIXED, 'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '', 'hours' => '',
'minutes' => '', 'minutes' => '',
// 'childobjects' => '', // 'childobjects' => '',
@ -176,7 +176,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '123', 'triggered' => '123',
'starttime' => '2013-07-17', 'starttime' => '2013-07-17',
'endtime' => '2013-07-17 10:30:00', 'endtime' => '2013-07-17 10:30:00',
'type' => ScheduleDowntime::TYPE_FIXED, 'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '', 'hours' => '',
'minutes' => '', 'minutes' => '',
// 'childobjects' => '', // 'childobjects' => '',
@ -192,7 +192,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '123', 'triggered' => '123',
'starttime' => '2013-07-17 10:30:00', 'starttime' => '2013-07-17 10:30:00',
'endtime' => 'DING', 'endtime' => 'DING',
'type' => ScheduleDowntime::TYPE_FIXED, 'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '', 'hours' => '',
'minutes' => '', 'minutes' => '',
// 'childobjects' => '', // 'childobjects' => '',
@ -208,7 +208,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '123', 'triggered' => '123',
'starttime' => '2013-07-17 10:30:00', 'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 09:30:00', 'endtime' => '2013-07-17 09:30:00',
'type' => ScheduleDowntime::TYPE_FLEXIBLE, 'type' => ScheduleDowntimeForm::TYPE_FLEXIBLE,
'hours' => '-1', 'hours' => '-1',
'minutes' => '12', 'minutes' => '12',
// 'childobjects' => '', // 'childobjects' => '',
@ -224,7 +224,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '123', 'triggered' => '123',
'starttime' => '2013-07-17 10:30:00', 'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 09:30:00', 'endtime' => '2013-07-17 09:30:00',
'type' => ScheduleDowntime::TYPE_FLEXIBLE, 'type' => ScheduleDowntimeForm::TYPE_FLEXIBLE,
'hours' => '12', 'hours' => '12',
'minutes' => 'DING', 'minutes' => 'DING',
// 'childobjects' => '', // 'childobjects' => '',
@ -242,7 +242,7 @@ namespace Test\Monitoring\Forms\Command {
) )
); );
$form = new ScheduleDowntime(); $form = new ScheduleDowntimeForm();
$form->setWithChildren(false); $form->setWithChildren(false);
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
@ -254,7 +254,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '4', 'triggered' => '4',
'starttime' => '2013-07-17 10:30:00', 'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 10:30:00', 'endtime' => '2013-07-17 10:30:00',
'type' => ScheduleDowntime::TYPE_FIXED, 'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '', 'hours' => '',
'minutes' => '', 'minutes' => '',
'childobjects' => '0', 'childobjects' => '0',
@ -270,7 +270,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '4', 'triggered' => '4',
'starttime' => '2013-07-17 10:30:00', 'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 10:30:00', 'endtime' => '2013-07-17 10:30:00',
'type' => ScheduleDowntime::TYPE_FIXED, 'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '', 'hours' => '',
'minutes' => '', 'minutes' => '',
'childobjects' => 'AHA', 'childobjects' => 'AHA',
@ -286,7 +286,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '4', 'triggered' => '4',
'starttime' => '2013-07-17 10:30:00', 'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 10:30:00', 'endtime' => '2013-07-17 10:30:00',
'type' => ScheduleDowntime::TYPE_FIXED, 'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '', 'hours' => '',
'minutes' => '', 'minutes' => '',
'childobjects' => '4', 'childobjects' => '4',
@ -303,7 +303,7 @@ namespace Test\Monitoring\Forms\Command {
) )
); );
$form = new ScheduleDowntime(); $form = new ScheduleDowntimeForm();
$form->setWithChildren(false); $form->setWithChildren(false);
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->buildForm(); $form->buildForm();

View File

@ -28,22 +28,22 @@ namespace Test\Monitoring\Forms\Command {
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php';
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php';
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/DateTime.php'; require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/DateTime.php';
require_once __DIR__. '/../../../../../application/forms/Command/AbstractCommand.php'; require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommand.php'; require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommandForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/SubmitPassiveCheckResult.php'; require_once __DIR__. '/../../../../../application/forms/Command/SubmitPassiveCheckResultForm.php';
use Monitoring\Form\Command\SubmitPassiveCheckResult; use Monitoring\Form\Command\SubmitPassiveCheckResultForm;
use \Zend_View; use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase; use \Zend_Test_PHPUnit_ControllerTestCase;
class SubmitPassiveCheckResultTest extends Zend_Test_PHPUnit_ControllerTestCase class SubmitPassiveCheckResultFormTest extends Zend_Test_PHPUnit_ControllerTestCase
{ {
public function testStateTypes() public function testStateTypes()
{ {
$form = new SubmitPassiveCheckResult(); $form = new SubmitPassiveCheckResultForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setType(SubmitPassiveCheckResult::TYPE_SERVICE); $form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
$options = $form->getOptions(); $options = $form->getOptions();
$this->assertCount(4, $options); $this->assertCount(4, $options);
$this->assertEquals('OK', $options[0]); $this->assertEquals('OK', $options[0]);
@ -51,7 +51,7 @@ namespace Test\Monitoring\Forms\Command {
$this->assertEquals('CRITICAL', $options[2]); $this->assertEquals('CRITICAL', $options[2]);
$this->assertEquals('UNKNOWN', $options[3]); $this->assertEquals('UNKNOWN', $options[3]);
$form->setType(SubmitPassiveCheckResult::TYPE_HOST); $form->setType(SubmitPassiveCheckResultForm::TYPE_HOST);
$options = $form->getOptions(); $options = $form->getOptions();
$this->assertCount(3, $options); $this->assertCount(3, $options);
$this->assertEquals('UP', $options[0]); $this->assertEquals('UP', $options[0]);
@ -65,16 +65,16 @@ namespace Test\Monitoring\Forms\Command {
*/ */
public function testForm1() public function testForm1()
{ {
$form = new SubmitPassiveCheckResult(); $form = new SubmitPassiveCheckResultForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->buildForm(); $form->buildForm();
} }
public function testForm2() public function testForm2()
{ {
$form = new SubmitPassiveCheckResult(); $form = new SubmitPassiveCheckResultForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setType(SubmitPassiveCheckResult::TYPE_SERVICE); $form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
$form->buildForm(); $form->buildForm();
$this->assertCount(6, $form->getElements()); $this->assertCount(6, $form->getElements());
@ -82,9 +82,9 @@ namespace Test\Monitoring\Forms\Command {
public function testValidation1() public function testValidation1()
{ {
$form = new SubmitPassiveCheckResult(); $form = new SubmitPassiveCheckResultForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
$form->setType(SubmitPassiveCheckResult::TYPE_SERVICE); $form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
$this->assertTrue( $this->assertTrue(
$form->isValid( $form->isValid(