Implement isPostAndValid, fix CSRF in forms, update tests

Form provides isPostAndValid for validation, using the
request for fetching POST data.
The tests are now updated to use the CSRF protection and
are cleaner now

refs #4355
This commit is contained in:
Jannis Moßhammer 2013-07-24 10:56:41 +02:00
parent 849eee2cf2
commit ddfbf915ed
13 changed files with 887 additions and 914 deletions

View File

@ -26,6 +26,7 @@
namespace Icinga\Web;
use Icinga\Exception\ProgrammingError;
use Icinga\Web\Form\InvalidCSRFTokenException;
use Zend_Form_Exception;
use Zend_View_Interface;
@ -68,16 +69,55 @@ abstract class Form extends \Zend_Form
*/
private $created = false;
/**
* Session id required for CSRF token generation
* @var numeric|bool
*/
private $sessionId = false;
/**
* Returns the session ID stored in this form instance
* @return mixed
*/
public function getSessionId()
{
if (!$this->sessionId) {
$this->sessionId = session_id();
}
return $this->sessionId;
}
/**
* Overwrites the currently set session id to a user
* provided one, helpful when testing
*
* @param $sessionId The session id to use for CSRF generation
*/
public function setSessionId($sessionId)
{
$this->sessionId = $sessionId;
}
/**
* @see Zend_Form::init
*/
public function init()
{
if (!$this->tokenDisabled) {
$this->initCsrfToken();
}
/**
* Returns the html-element name of the CSRF token
* field
*
* @return string
*/
public function getTokenElementName()
{
return $this->tokenElementName;
}
/**
* Render the form to html
* @param Zend_View_Interface $view
@ -86,7 +126,6 @@ abstract class Form extends \Zend_Form
public function render(Zend_View_Interface $view = null)
{
// Elements must be there to render the form
$this->buildForm();
return parent::render($view);
}
@ -126,6 +165,7 @@ abstract class Form extends \Zend_Form
public function buildForm()
{
if ($this->created === false) {
$this->initCsrfToken();
$this->create();
// Empty action if not safe
@ -137,17 +177,6 @@ abstract class Form extends \Zend_Form
}
}
/**
* Overridden to assert form creation
* @param array $data
* @return bool
*/
public function isValid($data)
{
$this->buildForm();
$this->preValidation($data);
return parent::isValid($data);
}
/**
@ -163,23 +192,22 @@ abstract class Form extends \Zend_Form
}
$checkData = $this->getRequest()->getParams();
$this->buildForm();
$this->assertValidCsrfToken($checkData);
$this->preValidation($checkData);
return parent::isValid($checkData);
}
/**
* Enable CSRF counter measure
*/
final public function enableCsrfToken()
{
$this->tokenDisabled = false;
}
/**
* Disable CSRF counter measure and remove its field if already added
*/
final public function disableCsrfToken()
final public function setTokenDisabled($value)
{
$this->tokenDisabled = true;
$this->tokenDisabled = $value;
if ($value == true)
$this->removeElement($this->tokenElementName);
}
@ -191,62 +219,89 @@ abstract class Form extends \Zend_Form
if ($this->tokenDisabled || $this->getElement($this->tokenElementName)) {
return;
}
list($seed, $token) = $this->generateCsrfToken($this->tokenTimeout);
$this->addElement(
'hidden',
$this->tokenElementName,
array(
'value' => sprintf('%s\|/%s', $seed, $token),
'value' => $this->generateCsrfTokenAsString(),
'decorators' => array('ViewHelper')
)
);
}
/**
* Tests the submitted data for a correct CSRF token, if needed
*
* @param Array $checkData The POST data send by the user
* @throws Form\InvalidCSRFTokenException When CSRF Validation fails
*/
final public function assertValidCsrfToken(array $checkData)
{
if ($this->tokenDisabled) {
return;
}
if (!isset($checkData[$this->tokenElementName]) || !$this->hasValidCsrfToken($checkData[$this->tokenElementName])) {
throw new InvalidCSRFTokenException();
}
}
/**
* Check whether the form's CSRF token-field has a valid value
*
* @param int $maxAge Max allowed token age
* @param string $sessionId A specific session id
*
* @return bool
*/
final private function hasValidCsrfToken($maxAge, $sessionId = null)
final private function hasValidCsrfToken($checkData)
{
if ($this->tokenDisabled) {
return true;
}
if ($this->getElement($this->tokenElementName) === null) {
return false;
}
$elementValue = $this->getElement($this->tokenElementName)->getValue();
list($seed, $token) = explode($elementValue, '\|/');
$elementValue = $checkData;
if (strpos($elementValue, '|') === false) {
return false;
}
list($seed, $token) = explode('|', $elementValue);
if (!is_numeric($seed)) {
return false;
}
$seed -= intval(time() / $maxAge) * $maxAge;
$sessionId = $sessionId ? $sessionId : session_id();
return $token === hash('sha256', $sessionId . $seed);
$seed -= intval(time() / $this->tokenTimeout) * $this->tokenTimeout;
return $token === hash('sha256', $this->getSessionId() . $seed);
}
/**
* Generate a new (seed, token) pair
*
* @param int $maxAge Max allowed token age
* @param string $sessionId A specific session id
*
* @return array
*/
final private function generateCsrfToken($maxAge, $sessionId = null)
final public function generateCsrfToken()
{
$sessionId = $sessionId ? $sessionId : session_id();
$seed = mt_rand();
$hash = hash('sha256', $sessionId . $seed);
$seed += intval(time() / $maxAge) * $maxAge;
$hash = hash('sha256', $this->getSessionId() . $seed);
$seed += intval(time() / $this->tokenTimeout) * $this->tokenTimeout;
return array($seed, $hash);
}
/**
* Returns the string representation of the CSRF seed/token pair
*
* @return string
*/
final public function generateCsrfTokenAsString()
{
list ($seed, $token) = $this->generateCsrfToken($this->getSessionId());
return sprintf('%s|%s', $seed, $token);
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace Icinga\Web\Form;
class InvalidCSRFTokenException extends \Exception {
}

View File

@ -136,7 +136,8 @@ class AcknowledgeForm extends ConfirmationForm
*/
protected function preValidation(array $data)
{
if (isset($data['expire']) && $data['expire'] === '1') {
if (isset($data['expire']) && intval($data['expire']) === 1 ) {
$expireTime = $this->getElement('expiretime');
$expireTime->setRequired(true);
$expireTime->addValidator($this->createDateTimeValidator(), true);

View File

@ -1,60 +1,35 @@
<?php
namespace {
if (!function_exists('t')) {
function t() {
return func_get_arg(0);
}
}
if (!function_exists('mt')) {
function mt() {
return func_get_arg(0);
}
}
}
namespace Test\Monitoring\Forms\Command {
namespace Test\Monitoring\Forms\Command;
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
require_once 'Zend/Form.php';
require_once 'Zend/View.php';
require_once 'Zend/Form/Element/Submit.php';
require_once 'Zend/Form/Element/Reset.php';
require_once 'Zend/Form/Element/Checkbox.php';
require_once 'Zend/Validate/Date.php';
require_once __DIR__.'/BaseFormTest.php';
$base = __DIR__.'/../../../../../../../';
require_once $base.'modules/monitoring/application/forms/Command/ConfirmationForm.php';
require_once realpath($base.'modules/monitoring/application/forms/Command/WithChildrenCommandForm.php');
require_once realpath($base.'modules/monitoring/application/forms/Command/AcknowledgeForm.php');
require_once __DIR__. '/../../../../../../../library/Icinga/Exception/ProgrammingError.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/DateTime.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\AcknowledgeForm;
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
use Monitoring\Form\Command\AcknowledgeForm;
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
class AcknowledgeFormTest extends Zend_Test_PHPUnit_ControllerTestCase
{
class AcknowledgeFormTest extends BaseFormTest
{
const FORMCLASS = "Monitoring\Form\Command\AcknowledgeForm";
public function testForm()
{
$form = new AcknowledgeForm();
$form->setRequest($this->getRequest());
$form = $this->getRequestForm(array(), self::FORMCLASS);
$form->buildForm();
$this->assertCount(11, $form->getElements());
}
public function testValidation1()
{
$form = new AcknowledgeForm();
$form->setRequest($this->getRequest());
$this->assertTrue(
$form->isValid(
array(
public function testValidateCorrectForm()
{
$form = $this->getRequestForm(array(
'author' => 'test1',
'comment' => 'test comment',
'persistent' => '0',
@ -62,27 +37,34 @@ namespace Test\Monitoring\Forms\Command {
'expiretime' => '',
'sticky' => '0',
'notify' => '0'
)
)
);
), self::FORMCLASS);
$this->assertFalse(
$form->isValid(
array(
$this->assertTrue(
$form->isPostAndValid(),
"Asserting a correct form to be validated correctly"
);
}
public function testDetectMissingAcknowledgementComment()
{
$form = $this->getRequestForm(array(
'author' => 'test1',
'comment' => '',
'persistent' => '0',
'expire' => '0',
'expiretime' => '',
'sticky' => '0',
'notify' => '0'
)
)
);
'notify' => '0',
), self::FORMCLASS);
$this->assertFalse(
$form->isValid(
array(
$form->isPostAndValid(),
"Asserting a missing comment text to cause validation errors"
);
}
public function testValidateMissingExpireTime()
{
$form = $this->getRequestForm(array(
'author' => 'test1',
'comment' => 'test comment',
'persistent' => '0',
@ -90,13 +72,16 @@ namespace Test\Monitoring\Forms\Command {
'expiretime' => '',
'sticky' => '0',
'notify' => '0'
)
)
);
), self::FORMCLASS);
$this->assertFalse(
$form->isValid(
array(
$form->isPostAndValid(),
"Asserting a missing expire time to cause validation errors when expire is 1"
);
}
public function testValidateIncorrectExpireTime()
{
$form = $this->getRequestForm(array(
'author' => 'test1',
'comment' => 'test comment',
'persistent' => '0',
@ -104,13 +89,16 @@ namespace Test\Monitoring\Forms\Command {
'expiretime' => 'NOT A DATE',
'sticky' => '0',
'notify' => '0'
)
)
), self::FORMCLASS);
$this->assertFalse(
$form->isPostAndValid(),
"Assert incorrect dates to be recognized when validating expiretime"
);
}
$this->assertTrue(
$form->isValid(
array(
public function testValidateCorrectAcknowledgementWithExpireTime()
{
$form = $this->getRequestForm(array(
'author' => 'test1',
'comment' => 'test comment',
'persistent' => '0',
@ -118,9 +106,11 @@ namespace Test\Monitoring\Forms\Command {
'expiretime' => '2013-07-10 17:32:16',
'sticky' => '0',
'notify' => '0'
)
)
), self::FORMCLASS);
$this->assertTrue(
$form->isPostAndValid(),
"Assert that correct expire time acknowledgement is considered valid"
);
}
}
}

View File

@ -0,0 +1,56 @@
<?php
namespace {
if (!function_exists('t')) {
function t() {
return func_get_arg(0);
}
}
if (!function_exists('mt')) {
function mt() {
return func_get_arg(0);
}
}
}
namespace Test\Monitoring\Forms\Command {
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
require_once 'Zend/Form.php';
require_once 'Zend/View.php';
require_once 'Zend/Form/Element/Submit.php';
require_once 'Zend/Form/Element/Reset.php';
require_once 'Zend/Form/Element/Checkbox.php';
require_once 'Zend/Form/Element/Hidden.php';
require_once 'Zend/Validate/Date.php';
$base = __DIR__.'/../../../../../../../';
require_once realpath($base.'library/Icinga/Exception/ProgrammingError.php');
require_once realpath($base.'library/Icinga/Web/Form.php');
require_once realpath($base.'library/Icinga/Web/Form/InvalidCSRFTokenException.php');
require_once realpath($base.'library/Icinga/Web/Form/Element/Note.php');
require_once realpath($base.'library/Icinga/Web/Form/Element/DateTime.php');
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
class BaseFormTest extends Zend_Test_PHPUnit_ControllerTestCase
{
public function getRequestForm(array $data, $formClass)
{
$form = new $formClass();
$form->setSessionId("test");
$form->initCsrfToken();
$request = $this->getRequest();
$data[$form->getTokenElementName()] = $form->getValue($form->getTokenElementName());
$request->setMethod("POST")->setPost($data);
$form->setRequest($request);
return $form;
}
}
}

View File

@ -1,43 +1,20 @@
<?php
namespace {
if (!function_exists('t')) {
function t() {
return func_get_arg(0);
}
}
namespace Test\Monitoring\Forms\Command;
if (!function_exists('mt')) {
function mt() {
return func_get_arg(0);
}
}
}
namespace Test\Monitoring\Forms\Command {
require_once __DIR__.'/BaseFormTest.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';
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
require_once 'Zend/Form.php';
require_once 'Zend/View.php';
require_once 'Zend/Form/Element/Submit.php';
require_once 'Zend/Form/Element/Reset.php';
require_once 'Zend/Form/Element/Checkbox.php';
require_once 'Zend/Validate/Date.php';
use Monitoring\Form\Command\CommentForm;
use \Zend_View;
require_once __DIR__. '/../../../../../../../library/Icinga/Exception/ProgrammingError.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/DateTime.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\CommentForm;
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
class CommentFormTest extends Zend_Test_PHPUnit_ControllerTestCase
{
class CommentFormTest extends BaseFormTest
{
const FORMCLASS = "Monitoring\Form\Command\CommentForm";
public function testForm()
{
$form = new CommentForm();
@ -47,40 +24,45 @@ namespace Test\Monitoring\Forms\Command {
$this->assertCount(6, $form->getElements());
}
public function testValidation()
{
$form = new CommentForm();
$form->setRequest($this->getRequest());
$this->assertTrue(
$form->isValid(
array(
public function testCorrectCommentValidation()
{
$form = $this->getRequestForm(array(
'author' => 'test1',
'comment' => 'test2',
'sticky' => '0'
)
)
);
), self::FORMCLASS);
$this->assertFalse(
$form->isValid(
array(
$this->assertTrue(
$form->isPostAndValid(),
"Asserting correct comment form to be considered valid"
);
}
public function testRecognizeMissingCommentText()
{
$form = $this->getRequestForm(array(
'author' => 'test1',
'comment' => '',
'sticky' => '0'
)
)
);
), self::FORMCLASS);
$this->assertFalse(
$form->isValid(
array(
$form->isPostAndValid(),
"Asserting missing comment text in comment form to cause validation errors"
);
}
public function testRecognizeMissingCommentAuthor()
{
$form = $this->getRequestForm(array(
'author' => '',
'comment' => 'test2',
'sticky' => '0'
)
)
), self::FORMCLASS);
$this->assertFalse(
$form->isPostAndValid(),
"Asserting missing comment author to cause validation errors"
);
}
}
}

View File

@ -1,12 +1,7 @@
<?php
namespace Test\Monitoring\Forms\Command;
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
require_once 'Zend/Form.php';
require_once 'Zend/View.php';
require_once 'Zend/Form/Element/Submit.php';
require_once 'Zend/Form/Element/Reset.php';
require_once __DIR__.'/BaseFormTest.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/ConfirmationForm.php';
@ -16,9 +11,9 @@ use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
use Monitoring\Form\Command\ConfirmationForm;
class ConfirmationFormTest extends Zend_Test_PHPUnit_ControllerTestCase
class ConfirmationFormTest extends BaseFormTest
{
public function testForm1()
public function testFormCreation()
{
$view = new Zend_View();
$form = new ConfirmationForm();
@ -31,7 +26,7 @@ class ConfirmationFormTest extends Zend_Test_PHPUnit_ControllerTestCase
$form->addNote('444 NOTE 1');
$form->addNote('555 NOTE 2');
$form->buildForm();
$content = $form->render($view);
$this->assertContains('<input type="submit" name="submit" id="submit" value="111TEST_SUBMIT" class="btn btn-primary pull-right">', $content);
@ -42,7 +37,7 @@ class ConfirmationFormTest extends Zend_Test_PHPUnit_ControllerTestCase
$this->assertContains('555 NOTE 2</dd>', $content);
}
public function testNotes1()
public function testFormNotes()
{
$form = new ConfirmationForm();
$form->addNote('test1');

View File

@ -1,102 +1,79 @@
<?php
namespace {
if (!function_exists('t')) {
function t() {
return func_get_arg(0);
}
}
if (!function_exists('mt')) {
function mt() {
return func_get_arg(0);
}
}
}
namespace Test\Monitoring\Forms\Command;
namespace Test\Monitoring\Forms\Command {
require_once __DIR__. '/BaseFormTest.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';
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
require_once 'Zend/Form.php';
require_once 'Zend/View.php';
require_once 'Zend/Form/Element/Submit.php';
require_once 'Zend/Form/Element/Reset.php';
require_once 'Zend/Form/Element/Checkbox.php';
require_once 'Zend/Validate/Date.php';
use Monitoring\Form\Command\ConfirmationWithIdentifierForm;
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
require_once __DIR__. '/../../../../../../../library/Icinga/Exception/ProgrammingError.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/DateTime.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\ConfirmationWithIdentifierForm;
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
class ConfirmationWithIdentifierFormTest extends Zend_Test_PHPUnit_ControllerTestCase
{
class ConfirmationWithIdentifierFormTest extends BaseFormTest
{
const FORMCLASS = "Monitoring\Form\Command\ConfirmationWithIdentifierForm";
public function testForm()
{
$form = new ConfirmationWithIdentifierForm();
$form->setRequest($this->getRequest());
$form = $this->getRequestForm(array(), self::FORMCLASS);
$form->setSubmitLabel('DING DING');
$form->buildForm();
$this->assertCount(4, $form->getElements());
}
public function testValidation()
public function testCorrectFormValidation()
{
$form = new ConfirmationWithIdentifierForm();
$form->setRequest($this->getRequest());
$form = $this->getRequestForm(array(
'testval' => 123
), self::FORMCLASS);
$form->setFieldLabel('Test1');
$form->setFieldName('testval');
$form->setSubmitLabel('DING DING');
$this->assertTrue(
$form->isValid(
array(
'testval' => 123
)
)
$form->isPostAndValid(),
"Asserting correct confirmation with id to be valid"
);
}
$this->assertFalse(
$form->isValid(
array(
public function testInvalidValueValidationErrors()
{
$form = $this->getRequestForm(array(
'testval' => ''
)
)
);
), self::FORMCLASS);
$this->assertFalse(
$form->isValid(
array(
$form->isPostAndValid(),
"Asserting an invalid (empty) value to cause validation errors"
);
}
public function testNonNumericValueValidationErrors()
{
$form = $this->getRequestForm(array(
'testval' => 'NaN'
)
)
), self::FORMCLASS);
$this->assertFalse(
$form->isPostAndValid(),
"Asserting an non numeric value to cause validation errors"
);
}
public function testRequestBridge()
{
$this->getRequest()->setMethod('POST');
$this->getRequest()->setPost(
array(
$form = $this->getRequestForm(array(
'objectid' => 123123666
)
);
$form = new ConfirmationWithIdentifierForm();
$form->setRequest($this->getRequest());
), self::FORMCLASS);
$form->buildForm();
$this->assertTrue($form->isPostAndValid());
$this->assertEquals('123123666', $form->getElement('objectid')->getValue());
}
}
}

View File

@ -1,55 +1,28 @@
<?php
namespace {
if (!function_exists('t')) {
function t() {
return func_get_arg(0);
}
}
namespace Test\Monitoring\Forms\Command;
if (!function_exists('mt')) {
function mt() {
return func_get_arg(0);
}
}
}
namespace Test\Monitoring\Forms\Command {
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
require_once 'Zend/Form.php';
require_once 'Zend/View.php';
require_once 'Zend/Form/Element/Submit.php';
require_once 'Zend/Form/Element/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/ConfirmationForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/CustomNotificationForm.php';
require_once __DIR__. '/BaseFormTest.php';
require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/CustomNotificationForm.php';
use Monitoring\Form\Command\CustomNotificationForm;
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
use Monitoring\Form\Command\CustomNotificationForm;
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
class CustomNotificationFormTest extends Zend_Test_PHPUnit_ControllerTestCase
{
class CustomNotificationFormTest extends BaseFormTest
{
public function testForm1()
{
$this->getRequest()->setMethod('POST');
$this->getRequest()->setPost(
array(
$form = $this->getRequestForm(array(
'comment' => 'TEST COMMENT',
'author' => 'LAOLA'
)
);
$form = new CustomNotificationForm();
$form->setRequest($this->getRequest());
), "Monitoring\Form\Command\CustomNotificationForm");
$form->buildForm();
$this->assertCount(7, $form->getElements());
$this->assertTrue($form->isPostAndValid());
}
}
}

View File

@ -1,84 +1,55 @@
<?php
namespace {
if (!function_exists('t')) {
function t() {
return func_get_arg(0);
}
}
namespace Test\Monitoring\Forms\Command;
if (!function_exists('mt')) {
function mt() {
return func_get_arg(0);
}
}
}
namespace Test\Monitoring\Forms\Command {
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
require_once 'Zend/Form.php';
require_once 'Zend/View.php';
require_once 'Zend/Form/Element/Submit.php';
require_once 'Zend/Form/Element/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/ConfirmationForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/DelayNotificationForm.php';
require_once __DIR__. '/BaseFormTest.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\DelayNotificationForm;
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
use Monitoring\Form\Command\DelayNotificationForm;
class DelayNotificationFormFormTest extends Zend_Test_PHPUnit_ControllerTestCase
class DelayNotificationFormFormTest extends BaseFormTest
{
public function testValidForm()
{
public function testForm1()
{
$this->getRequest()->setMethod('POST');
$this->getRequest()->setPost(
array(
$form = $this->getRequestForm(array(
'minutes' => 12
)
);
), 'Monitoring\Form\Command\DelayNotificationForm');
$form = new DelayNotificationForm();
$form->setRequest($this->getRequest());
$form->buildForm();
$this->assertCount(5, $form->getElements());
$element = $form->getElement('minutes');
$this->assertInstanceOf('Zend_Form_Element_Text', $element);
$this->assertEquals('0', $element->getValue());
$this->assertTrue($element->isRequired());
$this->assertEquals('0', $element->getValue(), "Assert a correct default value in minutes");
$this->assertTrue($element->isRequired(), "Assert minutes to be declared as required");
$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'
)
$this->assertTrue(
$form->isPostAndValid(),
"Assert a correct DelayNotificationForm to be considered valid"
);
$form = new DelayNotificationForm();
$this->assertEquals('12', $form->getValue('minutes'), "Assert the minutes field to be correctly populated");
}
public function testInvalidMinuteValue()
{
$form = $this->getRequestForm(array(
'minutes' => 'SCHAHH-LAHH-LAHH'
), 'Monitoring\Form\Command\DelayNotificationForm');
$form->setRequest($this->getRequest());
$form->buildForm();
$this->assertFalse($form->isPostAndValid());
$this->assertFalse(
$form->isPostAndValid(),
"Asserting invalid minutes (NaN) to cause validation errors"
);
$errors = $form->getErrors('minutes');
$this->assertEquals('notBetween', $errors[0]);
$this->assertEquals('notBetween', $errors[0], "Assert correct error message");
}
}
}

View File

@ -1,91 +1,72 @@
<?php
namespace {
if (!function_exists('t')) {
function t() {
return func_get_arg(0);
}
}
if (!function_exists('mt')) {
function mt() {
return func_get_arg(0);
}
}
}
namespace Test\Monitoring\Forms\Command {
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
require_once 'Zend/Form.php';
require_once 'Zend/View.php';
require_once 'Zend/Form/Element/Submit.php';
require_once 'Zend/Form/Element/Reset.php';
require_once 'Zend/Form/Element/Checkbox.php';
require_once 'Zend/Validate/Date.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/DateTime.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\RescheduleNextCheckForm;
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
namespace Test\Monitoring\Forms\Command;
class RescheduleNextCheckFormTest extends Zend_Test_PHPUnit_ControllerTestCase
require_once __DIR__. '/BaseFormTest.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\RescheduleNextCheckForm;
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
class RescheduleNextCheckFormTest extends BaseFormTest
{
const FORMCLASS = 'Monitoring\Form\Command\RescheduleNextCheckForm';
public function testValidRescheduleSubmissions()
{
public function testForm1()
{
$this->getRequest()->setPost(
array(
)
);
$form = new RescheduleNextCheckForm();
$form->setRequest($this->getRequest());
$form = $this->getRequestForm(array(
'checktime' => '2013-10-19 17:30:00',
'forcecheck' => 1
), self::FORMCLASS);
$form->buildForm();
$this->assertCount(6, $form->getElements());
$this->assertTrue(
$form->isValid(
array(
'checktime' => '2013-10-19 17:30:00',
'forcecheck' => 1
)
)
$form->isPostAndValid(),
'Asserting a reschedule form with correct time and forececheck=1 to be valid'
);
$this->assertTrue(
$form->isValid(
array(
$form = $this->getRequestForm(array(
'checktime' => '2013-10-19 17:30:00',
'forcecheck' => 0
)
)
);
), self::FORMCLASS);
$this->assertFalse(
$form->isValid(
array(
$this->assertTrue(
$form->isPostAndValid(),
'Asserting a reschedule form with correct time and forecheck=0 to be valid'
);
}
public function testInValidRescheduleChecktimeSubmissions()
{
$form = $this->getRequestForm(array(
'checktime' => '2013-24-12 17:30:00',
'forcecheck' => 1
)
)
);
), self::FORMCLASS);
$this->assertFalse(
$form->isValid(
array(
$form->isPostAndValid(),
'Asserting an logically invalid checktime to be considered as invalid reschedule data'
);
$form = $this->getRequestForm(array(
'checktime' => 'AHAHA',
'forcecheck' => 1
)
)
), self::FORMCLASS);
$this->assertFalse(
$form->isPostAndValid(),
'Asserting an invalid non-numeric checktime to be considered as invalid reschedule data'
);
}
@ -116,5 +97,5 @@ namespace Test\Monitoring\Forms\Command {
$this->assertEquals($notes1, $notes3);
$this->assertNotEquals($notes1, $notes2);
}
}
}

View File

@ -1,58 +1,27 @@
<?php
namespace {
if (!function_exists('t')) {
function t() {
return func_get_arg(0);
}
}
namespace Test\Monitoring\Forms\Command;
if (!function_exists('mt')) {
function mt() {
return func_get_arg(0);
}
}
}
require_once __DIR__. '/BaseFormTest.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';
namespace Test\Monitoring\Forms\Command {
use Monitoring\Form\Command\ScheduleDowntimeForm;
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
require_once 'Zend/Form.php';
require_once 'Zend/View.php';
require_once 'Zend/Form/Element/Submit.php';
require_once 'Zend/Form/Element/Reset.php';
require_once 'Zend/Form/Element/Checkbox.php';
require_once 'Zend/Validate/Date.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/DateTime.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\ScheduleDowntimeForm;
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
class ScheduleDowntimeFormTest extends Zend_Test_PHPUnit_ControllerTestCase
class ScheduleDowntimeFormTest extends BaseFormTest
{
const FORMCLASS = 'Monitoring\Form\Command\ScheduleDowntimeForm';
public function testCorrectFormElementCreation()
{
public function testFormElements1()
{
$this->getRequest()->setPost(
array(
)
);
$form = new ScheduleDowntimeForm();
$form->setRequest($this->getRequest());
$form = $this->getRequestForm(array(), self::FORMCLASS);
$form->buildForm();
$this->assertCount(13, $form->getElements());
$form = new ScheduleDowntimeForm();
$form->setRequest($this->getRequest());
$form = $this->getRequestForm(array(), self::FORMCLASS);
$form->setWithChildren(true);
$form->buildForm();
@ -60,21 +29,9 @@ namespace Test\Monitoring\Forms\Command {
}
public function testFormValidation1()
public function testCorrectValidationWithChildrend()
{
$this->getRequest()->setPost(
array(
)
);
$form = new ScheduleDowntimeForm();
$form->setRequest($this->getRequest());
$form->setWithChildren(true);
$this->assertTrue(
$form->isValid(
array(
$form = $this->getRequestForm(array(
'author' => 'TEST_AUTHOR',
'comment' => 'DING DING',
'triggered' => '4',
@ -84,29 +41,16 @@ namespace Test\Monitoring\Forms\Command {
'hours' => '',
'minutes' => '',
// 'childobjects' => '',
)
)
);
), self::FORMCLASS);
$this->assertFalse(
$form->isValid(
array(
'author' => 'TEST_AUTHOR',
'comment' => 'DING DING',
'triggered' => '4',
'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 10:30:00',
'type' => ScheduleDowntimeForm::TYPE_FLEXIBLE,
'hours' => '',
'minutes' => '',
// 'childobjects' => '',
)
)
);
$form->setWithChildren(true);
$this->assertTrue(
$form->isValid(
array(
$form->isPostAndValid(),
'Asserting a correct fixed downtime form to be considered valid'
);
$form = $this->getRequestForm(array(
'author' => 'TEST_AUTHOR',
'comment' => 'DING DING',
'triggered' => '4',
@ -116,13 +60,41 @@ namespace Test\Monitoring\Forms\Command {
'hours' => '10',
'minutes' => '10',
// 'childobjects' => '',
)
)
), self::FORMCLASS);
$form->setWithChildren(true);
$this->assertTrue(
$form->isPostAndValid(),
'Asserting a correct flexible downtime form to be considered valid'
);
}
public function testMissingFlexibleDurationRecognition()
{
$form = $this->getRequestForm(array(
'author' => 'TEST_AUTHOR',
'comment' => 'DING DING',
'triggered' => '4',
'starttime' => '2013-07-17 10:30:00',
'endtime' => '2013-07-17 10:30:00',
'type' => ScheduleDowntimeForm::TYPE_FLEXIBLE,
'hours' => '',
'minutes' => '',
// 'childobjects' => '',
), self::FORMCLASS);
$form->setWithChildren(true);
$this->assertFalse(
$form->isValid(
array(
$form->isPostAndValid(),
'Assert missing hours and minutes in downtime form to cause failing validation'
);
}
public function testMissingAuthorRecognition()
{
$form = $this->getRequestForm(array(
'author' => '',
'comment' => 'DING DING',
'triggered' => '4',
@ -132,13 +104,19 @@ namespace Test\Monitoring\Forms\Command {
'hours' => '',
'minutes' => '',
// 'childobjects' => '',
)
)
);
), self::FORMCLASS);
$form->setWithChildren(true);
$this->assertFalse(
$form->isValid(
array(
$form->isPostAndValid(),
'Assert missing author to cause validation errors in fixed downtime'
);
}
public function testMissingCommentRecognition()
{
$form = $this->getRequestForm(array(
'author' => 'OK',
'comment' => '',
'triggered' => '4',
@ -148,13 +126,19 @@ namespace Test\Monitoring\Forms\Command {
'hours' => '',
'minutes' => '',
// 'childobjects' => '',
)
)
);
), self::FORMCLASS);
$form->setWithChildren(true);
$this->assertFalse(
$form->isValid(
array(
$form->isPostAndValid(),
'Assert missing comment to cause validation errors in fixed downtime'
);
}
public function testInvalidTriggeredFieldValueRecognition()
{
$form = $this->getRequestForm(array(
'author' => 'OK',
'comment' => 'OK',
'triggered' => 'HAHA',
@ -164,13 +148,18 @@ namespace Test\Monitoring\Forms\Command {
'hours' => '',
'minutes' => '',
// 'childobjects' => '',
)
)
);
), self::FORMCLASS);
$form->setWithChildren(true);
$this->assertFalse(
$form->isValid(
array(
$form->isPostAndValid(),
'Assert invalid trigger field to cause validation to fail'
);
}
public function testInvalidStartTimeRecognition()
{
$form = $this->getRequestForm(array(
'author' => 'OK',
'comment' => 'OK',
'triggered' => '123',
@ -180,13 +169,19 @@ namespace Test\Monitoring\Forms\Command {
'hours' => '',
'minutes' => '',
// 'childobjects' => '',
)
)
);
), self::FORMCLASS);
$form->setWithChildren(true);
$this->assertFalse(
$form->isValid(
array(
$form->isPostAndValid(),
'Assert incorrect start time to cause validation errors in fixed downtime'
);
}
public function testInvalidEndTimeRecognition()
{
$form = $this->getRequestForm(array(
'author' => 'OK',
'comment' => 'OK',
'triggered' => '123',
@ -196,13 +191,19 @@ namespace Test\Monitoring\Forms\Command {
'hours' => '',
'minutes' => '',
// 'childobjects' => '',
)
)
);
), self::FORMCLASS);
$form->setWithChildren(true);
$this->assertFalse(
$form->isValid(
array(
$form->isPostAndValid(),
'Assert invalid endtime to cause validation errors in fixed downtime'
);
}
public function testInvalidHoursValueRecognitionInFlexibleDowntime()
{
$form = $this->getRequestForm(array(
'author' => 'OK',
'comment' => 'OK',
'triggered' => '123',
@ -212,13 +213,18 @@ namespace Test\Monitoring\Forms\Command {
'hours' => '-1',
'minutes' => '12',
// 'childobjects' => '',
)
)
);
), self::FORMCLASS);
$form->setWithChildren(true);
$this->assertFalse(
$form->isValid(
array(
$form->isPostAndValid(),
'Assert negative hours to cause validation errors in flexible downtime'
);
}
public function testInvalidMinutesValueRecognitionInFlexibleDowntime()
{
$form = $this->getRequestForm(array(
'author' => 'OK',
'comment' => 'OK',
'triggered' => '123',
@ -228,27 +234,19 @@ namespace Test\Monitoring\Forms\Command {
'hours' => '12',
'minutes' => 'DING',
// 'childobjects' => '',
)
)
), self::FORMCLASS);
$form->setWithChildren(true);
$this->assertFalse(
$form->isPostAndValid(),
'Assert non numeric valud to cause validation errors in flexible downtime '
);
}
public function testFormValidation2()
public function testCorrectScheduleDowntimeWithoutChildrenForm()
{
$this->getRequest()->setPost(
array(
)
);
$form = new ScheduleDowntimeForm();
$form->setWithChildren(false);
$form->setRequest($this->getRequest());
$this->assertTrue(
$form->isValid(
array(
$form = $this->getRequestForm(array(
'author' => 'TEST_AUTHOR',
'comment' => 'DING DING',
'triggered' => '4',
@ -258,13 +256,18 @@ namespace Test\Monitoring\Forms\Command {
'hours' => '',
'minutes' => '',
'childobjects' => '0',
)
)
);
), self::FORMCLASS);
$form->setWithChildren(false);
$this->assertFalse(
$form->isValid(
array(
$this->assertTrue(
$form->isPostAndValid(),
"Assert a correct schedule downtime without children form to be considered valid"
);
}
public function testIncorrectChildObjectsRecognition() {
$form = $this->getRequestForm(array(
'author' => 'TEST_AUTHOR',
'comment' => 'DING DING',
'triggered' => '4',
@ -274,13 +277,15 @@ namespace Test\Monitoring\Forms\Command {
'hours' => '',
'minutes' => '',
'childobjects' => 'AHA',
)
)
);
), self::FORMCLASS);
$form->setWithChildren(false);
$this->assertFalse(
$form->isValid(
array(
$form->isPostAndValid(),
"Assert and incorrect (non-numeric) childobjects value to cause validation errors"
);
$form = $this->getRequestForm(array(
'author' => 'TEST_AUTHOR',
'comment' => 'DING DING',
'triggered' => '4',
@ -290,22 +295,18 @@ namespace Test\Monitoring\Forms\Command {
'hours' => '',
'minutes' => '',
'childobjects' => '4',
)
)
), self::FORMCLASS);
$form->setWithChildren(false);
$this->assertFalse(
$form->isPostAndValid(),
"Assert and incorrect (numeric) childobjects value to cause validation errors"
);
}
public function testTimeRange()
{
$this->getRequest()->setPost(
array(
)
);
$form = new ScheduleDowntimeForm();
$form->setWithChildren(false);
$form->setRequest($this->getRequest());
$form = $this->getRequestForm(array(), self::FORMCLASS);
$form->buildForm();
$time1 = strtotime($form->getElement('starttime')->getValue());
@ -313,5 +314,5 @@ namespace Test\Monitoring\Forms\Command {
$this->assertEquals(3600, ($time2 - $time1));
}
}
}

View File

@ -1,120 +1,103 @@
<?php
namespace {
if (!function_exists('t')) {
function t() {
return func_get_arg(0);
}
}
namespace Test\Monitoring\Forms\Command;
if (!function_exists('mt')) {
function mt() {
return func_get_arg(0);
}
}
}
require_once __DIR__. '/BaseFormTest.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';
namespace Test\Monitoring\Forms\Command {
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
require_once 'Zend/Form.php';
require_once 'Zend/View.php';
require_once 'Zend/Form/Element/Submit.php';
require_once 'Zend/Form/Element/Reset.php';
require_once 'Zend/Form/Element/Checkbox.php';
require_once 'Zend/Validate/Date.php';
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
use Monitoring\Form\Command\SubmitPassiveCheckResultForm;
require_once __DIR__. '/../../../../../../../library/Icinga/Exception/ProgrammingError.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/DateTime.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\SubmitPassiveCheckResultForm;
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
class SubmitPassiveCheckResultFormTest extends Zend_Test_PHPUnit_ControllerTestCase
{
class SubmitPassiveCheckResultFormTest extends BaseFormTest
{
const FORMCLASS = "Monitoring\Form\Command\SubmitPassiveCheckResultForm";
public function testStateTypes()
{
$form = new SubmitPassiveCheckResultForm();
$form->setRequest($this->getRequest());
$form = $this->getRequestForm(array(), self::FORMCLASS);
$form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
$options = $form->getOptions();
$this->assertCount(4, $options);
$this->assertEquals('OK', $options[0]);
$this->assertEquals('WARNING', $options[1]);
$this->assertEquals('CRITICAL', $options[2]);
$this->assertEquals('UNKNOWN', $options[3]);
$this->assertCount(4, $options, "Assert correct number of states in service passive checks form");
$this->assertEquals('OK', $options[0], "Assert OK state to be available in service passive check form");
$this->assertEquals('WARNING', $options[1], "Assert WARNING state to be available in service passive check form");
$this->assertEquals('CRITICAL', $options[2], "Assert CRITICAL state to be available in service passive check form");
$this->assertEquals('UNKNOWN', $options[3], "Assert UNKNOWN state to be available in service passive check form");
$form->setType(SubmitPassiveCheckResultForm::TYPE_HOST);
$options = $form->getOptions();
$this->assertCount(3, $options);
$this->assertEquals('UP', $options[0]);
$this->assertEquals('DOWN', $options[1]);
$this->assertEquals('UNREACHABLE', $options[2]);
$this->assertCount(3, $options, "Assert correct number of states in host passive checks form");
$this->assertEquals('UP', $options[0], "Assert UP state to be available in host passive check form");
$this->assertEquals('DOWN', $options[1], "Assert DOWN state to be available in host passive check form");
$this->assertEquals('UNREACHABLE', $options[2], "Assert UNREACHABLE state to be available in host passive check form");
}
/**
* @expectedException Icinga\Exception\ProgrammingError
* @expectedExceptionMessage Type is not valid
*/
public function testForm1()
public function testMissingTypeThrowingException()
{
$form = new SubmitPassiveCheckResultForm();
$form->setRequest($this->getRequest());
$form = $this->getRequestForm(array(), self::FORMCLASS);
$form->buildForm();
}
public function testForm2()
public function testCorrectFormCreation()
{
$form = new SubmitPassiveCheckResultForm();
$form->setRequest($this->getRequest());
$form = $this->getRequestForm(array(), self::FORMCLASS);
$form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
$form->buildForm();
$this->assertCount(6, $form->getElements());
$this->assertCount(6, $form->getElements(), "Assert correct number of elements in form");
}
public function testValidation1()
public function testCorrectServicePassiveCheckSubmission()
{
$form = new SubmitPassiveCheckResultForm();
$form->setRequest($this->getRequest());
$form = $this->getRequestForm(array(
'pluginstate' => 0,
'checkoutput' => 'DING',
'performancedata' => ''
), self::FORMCLASS);
$form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
$this->assertTrue(
$form->isValid(
array(
'pluginstate' => 0,
'checkoutput' => 'DING',
'performancedata' => ''
)
)
$form->isPostAndValid(),
"Assert a correct passive service check form to pass form validation"
);
}
$this->assertFalse(
$form->isValid(
array(
public function testIncorrectCheckoutputRecognition()
{
$form = $this->getRequestForm(array(
'pluginstate' => 0,
'checkoutput' => '',
'performancedata' => ''
)
)
);
), self::FORMCLASS);
$form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
$this->assertFalse(
$form->isValid(
array(
$form->isPostAndValid(),
"Assert empty checkoutput to cause validation errors in passive service check "
);
}
public function testIncorrectStateRecognition()
{
$form = $this->getRequestForm(array(
'pluginstate' => 'LA',
'checkoutput' => 'DING',
'performancedata' => ''
)
)
), self::FORMCLASS);
$form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
$this->assertFalse(
$form->isPostAndValid(),
"Assert invalid (non-numeric) state to cause validation errors in passive service check"
);
}
}
}