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
*isValid()* is called.
#### Calling is *isValid()*
#### Calling is *IsPostAndValid()*
*isValid()* is used to test of all needed parameters there. Our form class
respects just a couple of data:
*IsPostAndValid()* is used to test of all needed parameters there. It combines
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
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
#### Pre validation
To handle dependend fields you can just override *preValid()* or *postValid()*
to dynamically add or remove validations. This behaviour reduces the overhead
to write own validator classes.
* *preValid()* Work just before pre validation
* *postValid()* Override validation status afterwards
* *preValidation()* Work just before pre validation
#### Autoloading of form code
@ -112,7 +104,7 @@ use an other namesoace for, e.g.
* Check dependent fields
* @param array $data
*/
protected function preValid(array $data)
protected function preValidation(array $data)
{
if (isset($data['flag']) && $data['flag'] === '1') {
$textField = $this->getElement('flagValue');
@ -164,20 +156,10 @@ interface methods:
* Pre validation
* @param array $data
*/
protected function preValid(array $data)
protected function preValidation(array $data)
{
// 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

View File

@ -26,6 +26,7 @@
namespace Icinga\Web;
use Icinga\Exception\ProgrammingError;
use Zend_Form_Exception;
use Zend_View_Interface;
/**
@ -97,16 +98,7 @@ abstract class Form extends \Zend_Form
/**
* Method called before validation
*/
protected function preValid(array $data)
{
}
/**
* Method called after validation
* @param array $data
* @param bool &$isValid
*/
protected function postValid(array $data, &$isValid)
protected function preValidation(array $data)
{
}
@ -146,33 +138,32 @@ abstract class Form extends \Zend_Form
}
/**
* Test if data from array or request is valid
*
* If $data is null, internal request is selected to test validity
*
* @param null|\Zend_Controller_Request_Abstract|array $data
* Overridden to assert form creation
* @param array $data
* @return bool
*/
public function isValid($data)
{
$checkData = null;
// Elements must be there to validate
$this->buildForm();
$this->preValidation($data);
return parent::isValid($data);
}
if ($data === null) {
$checkData = $this->getRequest()->getParams();
} elseif ($data instanceof \Zend_Controller_Request_Abstract) {
$checkData = $data->getParams();
} else {
$checkData = $data;
/**
* 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;
}
$this->preValid($checkData);
$checkValue = parent::isValid($checkData);
$this->postValid($checkData, $checkValue);
return $checkValue;
$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\Exception\ConfigurationError;
use Icinga\Exception\MissingParameterException;
use Monitoring\Form\Command\Acknowledge;
use Monitoring\Form\Command\Comment as CommentForm;
use Monitoring\Form\Command\Confirmation;
use Monitoring\Form\Command\ConfirmationWithIdentifier;
use Monitoring\Form\Command\CustomNotification;
use Monitoring\Form\Command\DelayNotification;
use Monitoring\Form\Command\RescheduleNextCheck;
use Monitoring\Form\Command\ScheduleDowntime;
use Monitoring\Form\Command\SubmitPassiveCheckResult;
use Monitoring\Form\Command\AcknowledgeForm;
use Monitoring\Form\Command\CommentForm;
use Monitoring\Form\Command\ConfirmationForm;
use Monitoring\Form\Command\ConfirmationWithIdentifierForm;
use Monitoring\Form\Command\CustomNotificationForm;
use Monitoring\Form\Command\DelayNotificationForm;
use Monitoring\Form\Command\RescheduleNextCheckForm;
use Monitoring\Form\Command\ScheduleDowntimeForm;
use Monitoring\Form\Command\SubmitPassiveCheckResultForm;
/**
* Class Monitoring_CommandController
@ -202,7 +202,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function disableactivechecksAction()
{
$form = new Confirmation();
$form = new ConfirmationForm();
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable active checks'));
$form->addNote(t('Disable active checks for this object.'));
@ -219,7 +219,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function enableactivechecksAction()
{
$form = new Confirmation();
$form = new ConfirmationForm();
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable active checks'));
$form->addNote(t('Enable active checks for this object.'));
@ -236,7 +236,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function reschedulenextcheckAction()
{
$form = new RescheduleNextCheck();
$form = new RescheduleNextCheckForm();
$form->setRequest($this->getRequest());
$this->setForm($form);
@ -252,9 +252,9 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function submitpassivecheckresultAction()
{
$type = SubmitPassiveCheckResult::TYPE_SERVICE;
$type = SubmitPassiveCheckResultForm::TYPE_SERVICE;
$form = new SubmitPassiveCheckResult();
$form = new SubmitPassiveCheckResultForm();
$form->setRequest($this->getRequest());
$form->setType($type);
@ -271,7 +271,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function stopobsessingAction()
{
$form = new Confirmation();
$form = new ConfirmationForm();
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Stop obsessing'));
$form->addNote(t('Stop obsessing over this object.'));
@ -288,7 +288,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function startobsessingAction()
{
$form = new Confirmation();
$form = new ConfirmationForm();
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Start obsessing'));
$form->addNote(t('Start obsessing over this object.'));
@ -305,7 +305,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function stopacceptingpassivechecksAction()
{
$form = new Confirmation();
$form = new ConfirmationForm();
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Stop accepting passive checks'));
$form->addNote(t('Passive checks for this object will be omitted.'));
@ -322,7 +322,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function startacceptingpassivechecksAction()
{
$form = new Confirmation();
$form = new ConfirmationForm();
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Start accepting passive checks'));
$form->addNote(t('Passive checks for this object will be accepted.'));
@ -339,7 +339,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function disablenotificationsAction()
{
$form = new Confirmation();
$form = new ConfirmationForm();
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable notifications'));
$form->addNote(t('Notifications for this object will be disabled.'));
@ -356,7 +356,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function enablenotificationsAction()
{
$form = new Confirmation();
$form = new ConfirmationForm();
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable notifications'));
$form->addNote(t('Notifications for this object will be enabled.'));
@ -373,7 +373,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function sendcustomnotificationAction()
{
$form = new CustomNotification();
$form = new CustomNotificationForm();
$form->setRequest($this->getRequest());
$this->setForm($form);
@ -388,7 +388,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function scheduledowntimeAction()
{
$form = new ScheduleDowntime();
$form = new ScheduleDowntimeForm();
$form->setRequest($this->getRequest());
$form->setWithChildren(false);
$this->setForm($form);
@ -404,7 +404,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function scheduledowntimeswithchildrenAction()
{
$form = new ScheduleDowntime();
$form = new ScheduleDowntimeForm();
$form->setRequest($this->getRequest());
$form->setWithChildren(true);
$this->setForm($form);
@ -420,7 +420,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function removedowntimeswithchildrenAction()
{
$form = new Confirmation();
$form = new ConfirmationForm();
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Remove downtime(s)'));
$form->addNote(t('Remove downtime(s) from this host and its services.'));
@ -437,7 +437,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function disablenotificationswithchildrenAction()
{
$form = new Confirmation();
$form = new ConfirmationForm();
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable notifications'));
$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()
{
$form = new Confirmation();
$form = new ConfirmationForm();
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable notifications'));
$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()
{
$form = new RescheduleNextCheck();
$form = new RescheduleNextCheckForm();
$form->setRequest($this->getRequest());
$form->setWithChildren(true);
@ -489,7 +489,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function disableactivecheckswithchildrenAction()
{
$form = new Confirmation();
$form = new ConfirmationForm();
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable active checks'));
$form->addNote(t('Disable active checks for this host and its services.'));
@ -506,7 +506,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function enableactivecheckswithchildrenAction()
{
$form = new Confirmation();
$form = new ConfirmationForm();
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable active checks'));
$form->addNote(t('Enable active checks for this host and its services.'));
@ -523,7 +523,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function disableeventhandlerAction()
{
$form = new Confirmation();
$form = new ConfirmationForm();
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable event handler'));
$form->addNote(t('Disable event handler for this object.'));
@ -540,7 +540,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function enableeventhandlerAction()
{
$form = new Confirmation();
$form = new ConfirmationForm();
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable event handler'));
$form->addNote(t('Enable event handler for this object.'));
@ -557,7 +557,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function disableflapdetectionAction()
{
$form = new Confirmation();
$form = new ConfirmationForm();
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable flapping detection'));
$form->addNote(t('Disable flapping detection for this object.'));
@ -574,7 +574,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function enableflapdetectionAction()
{
$form = new Confirmation();
$form = new ConfirmationForm();
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable flapping detection'));
$form->addNote(t('Enable flapping detection for this object.'));
@ -607,7 +607,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function resetattributesAction()
{
$form = new Confirmation();
$form = new ConfirmationForm();
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Reset attributes'));
$form->addNote(t('Reset modified attributes to its default.'));
@ -624,7 +624,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function acknowledgeproblemAction()
{
$form = new Acknowledge();
$form = new AcknowledgeForm();
$form->setRequest($this->getRequest());
$this->setForm($form);
@ -640,7 +640,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function removeacknowledgementAction()
{
$form = new Confirmation();
$form = new ConfirmationForm();
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Remove problem acknowledgement'));
$form->addNote(t('Remove problem acknowledgement for this object.'));
@ -657,7 +657,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function delaynotificationAction()
{
$form = new DelayNotification();
$form = new DelayNotificationForm();
$form->setRequest($this->getRequest());
$this->setForm($form);
@ -673,7 +673,7 @@ class Monitoring_CommandController extends ModuleActionController
*/
public function removedowntimeAction()
{
$form = new ConfirmationWithIdentifier();
$form = new ConfirmationWithIdentifierForm();
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Delete downtime'));

View File

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

View File

@ -31,11 +31,11 @@ namespace Monitoring\Form\Command;
/**
* Form for adding comment commands
*/
class Comment extends AbstractCommand
class CommentForm extends ConfirmationForm
{
/**
* Interface method to build the form
* @see Form::create()
* @see ConfirmationForm::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;
/**
* Class AbstractCommand
* Simple confirmation command
*/
abstract class AbstractCommand extends Form
class ConfirmationForm extends Form
{
/**
* Default date format
@ -148,6 +148,7 @@ abstract class AbstractCommand extends Form
/**
* Add elements to this form (used by extending classes)
* @see Form::create
*/
protected function create()
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -31,7 +31,7 @@ namespace Monitoring\Form\Command;
/**
* Class handle specific command flags
*/
abstract class WithChildrenCommand extends AbstractCommand
abstract class WithChildrenCommandForm extends ConfirmationForm
{
/**
* 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/Element/Note.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/WithChildrenCommand.php';
require_once __DIR__. '/../../../../../application/forms/Command/Acknowledge.php';
require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommandForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/AcknowledgeForm.php';
use Monitoring\Form\Command\Acknowledge;
use Monitoring\Form\Command\AcknowledgeForm;
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
class AcknowledgeTest extends Zend_Test_PHPUnit_ControllerTestCase
class AcknowledgeFormTest extends Zend_Test_PHPUnit_ControllerTestCase
{
public function testForm()
{
$form = new Acknowledge();
$form = new AcknowledgeForm();
$form->setRequest($this->getRequest());
$form->buildForm();
@ -49,7 +49,7 @@ namespace Test\Monitoring\Forms\Command {
public function testValidation1()
{
$form = new Acknowledge();
$form = new AcknowledgeForm();
$form->setRequest($this->getRequest());
$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/Element/Note.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/WithChildrenCommand.php';
require_once __DIR__. '/../../../../../application/forms/Command/Comment.php';
require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommandForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/CommentForm.php';
use Monitoring\Form\Command\Comment;
use Monitoring\Form\Command\CommentForm;
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
class CommentTest extends Zend_Test_PHPUnit_ControllerTestCase
class CommentFormTest extends Zend_Test_PHPUnit_ControllerTestCase
{
public function testForm()
{
$form = new Comment();
$form = new CommentForm();
$form->setRequest($this->getRequest());
$form->buildForm();
@ -49,7 +49,7 @@ namespace Test\Monitoring\Forms\Command {
public function testValidation()
{
$form = new Comment();
$form = new CommentForm();
$form->setRequest($this->getRequest());
$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/Element/Note.php';
require_once __DIR__. '/../../../../../application/forms/Command/AbstractCommand.php';
require_once __DIR__. '/../../../../../application/forms/Command/Confirmation.php';
require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationForm.php';
use \Zend_View;
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()
{
$view = new Zend_View();
$form = new Confirmation();
$form = new ConfirmationForm();
$form->setRequest($this->getRequest());
@ -45,7 +44,7 @@ class ConfirmationTest extends Zend_Test_PHPUnit_ControllerTestCase
public function testNotes1()
{
$form = new Confirmation();
$form = new ConfirmationForm();
$form->addNote('test1');
$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/Element/Note.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/WithChildrenCommand.php';
require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationWithIdentifier.php';
require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommandForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationWithIdentifierForm.php';
use Monitoring\Form\Command\ConfirmationWithIdentifier;
use Monitoring\Form\Command\ConfirmationWithIdentifierForm;
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
class ConfirmationWithIdentifierTest extends Zend_Test_PHPUnit_ControllerTestCase
class ConfirmationWithIdentifierFormTest extends Zend_Test_PHPUnit_ControllerTestCase
{
public function testForm()
{
$form = new ConfirmationWithIdentifier();
$form = new ConfirmationWithIdentifierForm();
$form->setRequest($this->getRequest());
$form->setSubmitLabel('DING DING');
$form->buildForm();
@ -50,7 +50,7 @@ namespace Test\Monitoring\Forms\Command {
public function testValidation()
{
$form = new ConfirmationWithIdentifier();
$form = new ConfirmationWithIdentifierForm();
$form->setRequest($this->getRequest());
$form->setFieldLabel('Test1');
$form->setFieldName('testval');
@ -83,18 +83,18 @@ namespace Test\Monitoring\Forms\Command {
public function testRequestBridge()
{
$this->getRequest()->setMethod('POST');
$this->getRequest()->setPost(
array(
'objectid' => 123123666
)
);
$form = new ConfirmationWithIdentifier();
$form = new ConfirmationWithIdentifierForm();
$form->setRequest($this->getRequest());
$form->buildForm();
$this->assertTrue($form->isValid(null));
$this->assertTrue($form->isValid($this->getRequest()));
$this->assertTrue($form->isPostAndValid());
$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/Element/Note.php';
require_once __DIR__. '/../../../../../application/forms/Command/AbstractCommand.php';
require_once __DIR__. '/../../../../../application/forms/Command/CustomNotification.php';
require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/CustomNotificationForm.php';
use Monitoring\Form\Command\CustomNotification;
use Monitoring\Form\Command\CustomNotificationForm;
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
class CustomNotificationTest extends Zend_Test_PHPUnit_ControllerTestCase
class CustomNotificationFormTest extends Zend_Test_PHPUnit_ControllerTestCase
{
public function testForm1()
{
$this->getRequest()->setMethod('POST');
$this->getRequest()->setPost(
array(
'comment' => 'TEST COMMENT',
@ -43,12 +44,12 @@ namespace Test\Monitoring\Forms\Command {
)
);
$form = new CustomNotification();
$form = new CustomNotificationForm();
$form->setRequest($this->getRequest());
$form->buildForm();
$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/Element/Note.php';
require_once __DIR__. '/../../../../../application/forms/Command/AbstractCommand.php';
require_once __DIR__. '/../../../../../application/forms/Command/DelayNotification.php';
require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/DelayNotificationForm.php';
use \Zend_View;
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()
{
$this->getRequest()->setMethod('POST');
$this->getRequest()->setPost(
array(
'minutes' => 12
)
);
$form = new DelayNotification();
$form = new DelayNotificationForm();
$form->setRequest($this->getRequest());
$form->buildForm();
@ -54,25 +55,26 @@ namespace Test\Monitoring\Forms\Command {
$this->assertEquals('0', $element->getValue());
$this->assertTrue($element->isRequired());
$this->assertTrue($form->isValid(null));
$this->assertTrue($form->isPostAndValid());
$this->assertEquals('12', $form->getValue('minutes'));
}
public function testValidation()
{
$this->getRequest()->setMethod('POST');
$this->getRequest()->setPost(
array(
'minutes' => 'SCHAHH-LAHH-LAHH'
)
);
$form = new DelayNotification();
$form = new DelayNotificationForm();
$form->setRequest($this->getRequest());
$form->buildForm();
$this->assertFalse($form->isValid(null));
$this->assertFalse($form->isPostAndValid());
$errors = $form->getErrors('minutes');
$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/Element/Note.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/WithChildrenCommand.php';
require_once __DIR__. '/../../../../../application/forms/Command/RescheduleNextCheck.php';
require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommandForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/RescheduleNextCheckForm.php';
use Monitoring\Form\Command\RescheduleNextCheck;
use Monitoring\Form\Command\RescheduleNextCheckForm;
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
class RescheduleNextCheckTest extends Zend_Test_PHPUnit_ControllerTestCase
class RescheduleNextCheckFormTest extends Zend_Test_PHPUnit_ControllerTestCase
{
public function testForm1()
{
@ -46,7 +46,7 @@ namespace Test\Monitoring\Forms\Command {
)
);
$form = new RescheduleNextCheck();
$form = new RescheduleNextCheckForm();
$form->setRequest($this->getRequest());
$form->buildForm();
@ -92,21 +92,21 @@ namespace Test\Monitoring\Forms\Command {
public function testChildrenFlag()
{
$form = new RescheduleNextCheck();
$form = new RescheduleNextCheckForm();
$form->setRequest($this->getRequest());
$form->setWithChildren(true);
$form->buildForm();
$notes1 = $form->getNotes();
$form = null;
$form = new RescheduleNextCheck();
$form = new RescheduleNextCheckForm();
$form->setRequest($this->getRequest());
$form->setWithChildren(false);
$form->buildForm();
$notes2 = $form->getNotes();
$form = null;
$form = new RescheduleNextCheck();
$form = new RescheduleNextCheckForm();
$form->setRequest($this->getRequest());
$form->setWithChildren();
$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/Element/Note.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/WithChildrenCommand.php';
require_once __DIR__. '/../../../../../application/forms/Command/ScheduleDowntime.php';
require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommandForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/ScheduleDowntimeForm.php';
use Monitoring\Form\Command\ScheduleDowntime;
use Monitoring\Form\Command\ScheduleDowntimeForm;
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
class ScheduleDowntimeTest extends Zend_Test_PHPUnit_ControllerTestCase
class ScheduleDowntimeFormTest extends Zend_Test_PHPUnit_ControllerTestCase
{
public function testFormElements1()
{
@ -45,13 +45,13 @@ namespace Test\Monitoring\Forms\Command {
)
);
$form = new ScheduleDowntime();
$form = new ScheduleDowntimeForm();
$form->setRequest($this->getRequest());
$form->buildForm();
$this->assertCount(13, $form->getElements());
$form = new ScheduleDowntime();
$form = new ScheduleDowntimeForm();
$form->setRequest($this->getRequest());
$form->setWithChildren(true);
$form->buildForm();
@ -68,7 +68,7 @@ namespace Test\Monitoring\Forms\Command {
)
);
$form = new ScheduleDowntime();
$form = new ScheduleDowntimeForm();
$form->setRequest($this->getRequest());
$form->setWithChildren(true);
@ -80,7 +80,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '4',
'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 10:30:00',
'type' => ScheduleDowntime::TYPE_FIXED,
'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '',
'minutes' => '',
// 'childobjects' => '',
@ -96,7 +96,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '4',
'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 10:30:00',
'type' => ScheduleDowntime::TYPE_FLEXIBLE,
'type' => ScheduleDowntimeForm::TYPE_FLEXIBLE,
'hours' => '',
'minutes' => '',
// 'childobjects' => '',
@ -112,7 +112,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '4',
'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 10:30:00',
'type' => ScheduleDowntime::TYPE_FLEXIBLE,
'type' => ScheduleDowntimeForm::TYPE_FLEXIBLE,
'hours' => '10',
'minutes' => '10',
// 'childobjects' => '',
@ -128,7 +128,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '4',
'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 10:30:00',
'type' => ScheduleDowntime::TYPE_FIXED,
'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '',
'minutes' => '',
// 'childobjects' => '',
@ -144,7 +144,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '4',
'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 10:30:00',
'type' => ScheduleDowntime::TYPE_FIXED,
'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '',
'minutes' => '',
// 'childobjects' => '',
@ -160,7 +160,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => 'HAHA',
'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 10:30:00',
'type' => ScheduleDowntime::TYPE_FIXED,
'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '',
'minutes' => '',
// 'childobjects' => '',
@ -176,7 +176,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '123',
'starttime' => '2013-07-17',
'endtime' => '2013-07-17 10:30:00',
'type' => ScheduleDowntime::TYPE_FIXED,
'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '',
'minutes' => '',
// 'childobjects' => '',
@ -192,7 +192,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '123',
'starttime' => '2013-07-17 10:30:00',
'endtime' => 'DING',
'type' => ScheduleDowntime::TYPE_FIXED,
'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '',
'minutes' => '',
// 'childobjects' => '',
@ -208,7 +208,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '123',
'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 09:30:00',
'type' => ScheduleDowntime::TYPE_FLEXIBLE,
'type' => ScheduleDowntimeForm::TYPE_FLEXIBLE,
'hours' => '-1',
'minutes' => '12',
// 'childobjects' => '',
@ -224,7 +224,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '123',
'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 09:30:00',
'type' => ScheduleDowntime::TYPE_FLEXIBLE,
'type' => ScheduleDowntimeForm::TYPE_FLEXIBLE,
'hours' => '12',
'minutes' => 'DING',
// 'childobjects' => '',
@ -242,7 +242,7 @@ namespace Test\Monitoring\Forms\Command {
)
);
$form = new ScheduleDowntime();
$form = new ScheduleDowntimeForm();
$form->setWithChildren(false);
$form->setRequest($this->getRequest());
@ -254,7 +254,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '4',
'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 10:30:00',
'type' => ScheduleDowntime::TYPE_FIXED,
'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '',
'minutes' => '',
'childobjects' => '0',
@ -270,7 +270,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '4',
'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 10:30:00',
'type' => ScheduleDowntime::TYPE_FIXED,
'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '',
'minutes' => '',
'childobjects' => 'AHA',
@ -286,7 +286,7 @@ namespace Test\Monitoring\Forms\Command {
'triggered' => '4',
'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 10:30:00',
'type' => ScheduleDowntime::TYPE_FIXED,
'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '',
'minutes' => '',
'childobjects' => '4',
@ -303,7 +303,7 @@ namespace Test\Monitoring\Forms\Command {
)
);
$form = new ScheduleDowntime();
$form = new ScheduleDowntimeForm();
$form->setWithChildren(false);
$form->setRequest($this->getRequest());
$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/Element/Note.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/WithChildrenCommand.php';
require_once __DIR__. '/../../../../../application/forms/Command/SubmitPassiveCheckResult.php';
require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommandForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/SubmitPassiveCheckResultForm.php';
use Monitoring\Form\Command\SubmitPassiveCheckResult;
use Monitoring\Form\Command\SubmitPassiveCheckResultForm;
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
class SubmitPassiveCheckResultTest extends Zend_Test_PHPUnit_ControllerTestCase
class SubmitPassiveCheckResultFormTest extends Zend_Test_PHPUnit_ControllerTestCase
{
public function testStateTypes()
{
$form = new SubmitPassiveCheckResult();
$form = new SubmitPassiveCheckResultForm();
$form->setRequest($this->getRequest());
$form->setType(SubmitPassiveCheckResult::TYPE_SERVICE);
$form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
$options = $form->getOptions();
$this->assertCount(4, $options);
$this->assertEquals('OK', $options[0]);
@ -51,7 +51,7 @@ namespace Test\Monitoring\Forms\Command {
$this->assertEquals('CRITICAL', $options[2]);
$this->assertEquals('UNKNOWN', $options[3]);
$form->setType(SubmitPassiveCheckResult::TYPE_HOST);
$form->setType(SubmitPassiveCheckResultForm::TYPE_HOST);
$options = $form->getOptions();
$this->assertCount(3, $options);
$this->assertEquals('UP', $options[0]);
@ -65,16 +65,16 @@ namespace Test\Monitoring\Forms\Command {
*/
public function testForm1()
{
$form = new SubmitPassiveCheckResult();
$form = new SubmitPassiveCheckResultForm();
$form->setRequest($this->getRequest());
$form->buildForm();
}
public function testForm2()
{
$form = new SubmitPassiveCheckResult();
$form = new SubmitPassiveCheckResultForm();
$form->setRequest($this->getRequest());
$form->setType(SubmitPassiveCheckResult::TYPE_SERVICE);
$form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
$form->buildForm();
$this->assertCount(6, $form->getElements());
@ -82,9 +82,9 @@ namespace Test\Monitoring\Forms\Command {
public function testValidation1()
{
$form = new SubmitPassiveCheckResult();
$form = new SubmitPassiveCheckResultForm();
$form->setRequest($this->getRequest());
$form->setType(SubmitPassiveCheckResult::TYPE_SERVICE);
$form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
$this->assertTrue(
$form->isValid(