Monitoring/Commands: Fix delay notification form tests

refs #4524
This commit is contained in:
Eric Lippmann 2013-08-16 12:38:37 +02:00 committed by Jannis Moßhammer
parent 9f1da2db1a
commit 26f7b740c5
2 changed files with 43 additions and 42 deletions

View File

@ -8,11 +8,11 @@ namespace Test\Monitoring\Forms\Command;
require_once realpath(__DIR__ . '/BaseFormTest.php'); require_once realpath(__DIR__ . '/BaseFormTest.php');
require_once realpath(__DIR__ . '/../../../../../application/forms/Command/CustomNotificationForm.php'); require_once realpath(__DIR__ . '/../../../../../application/forms/Command/CustomNotificationForm.php');
use \Monitoring\Form\Command\CustomNotificationForm; // Used by constant FORMCLASS use \Monitoring\Form\Command\CustomNotificationForm; // Used by constant FORM_CLASS
class CustomNotificationFormTest extends BaseFormTest class CustomNotificationFormTest extends BaseFormTest
{ {
const FORMCLASS = 'Monitoring\Form\Command\CustomNotificationForm'; const FORM_CLASS = 'Monitoring\Form\Command\CustomNotificationForm';
public function testFormInvalidWhenCommentMissing() public function testFormInvalidWhenCommentMissing()
{ {
@ -20,7 +20,7 @@ class CustomNotificationFormTest extends BaseFormTest
'author' => 'Author', 'author' => 'Author',
'comment' => '', 'comment' => '',
'btn_submit' => 'Submit' 'btn_submit' => 'Submit'
), self::FORMCLASS); ), self::FORM_CLASS);
$this->assertFalse( $this->assertFalse(
$form->isSubmittedAndValid(), $form->isSubmittedAndValid(),

View File

@ -1,57 +1,58 @@
<?php <?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Test\Monitoring\Forms\Command; namespace Test\Monitoring\Forms\Command;
require_once __DIR__. '/BaseFormTest.php'; require_once realpath(__DIR__ . '/BaseFormTest.php');
require_once __DIR__. '/../../../../../application/forms/Command/CommandForm.php'; require_once realpath(__DIR__ . '/../../../../../application/forms/Command/CommandForm.php');
require_once __DIR__. '/../../../../../application/forms/Command/DelayNotificationForm.php'; require_once realpath(__DIR__ . '/../../../../../application/forms/Command/DelayNotificationForm.php');
use \Zend_View; use \Monitoring\Form\Command\DelayNotificationForm; // Used by constant FORM_CLASS
use \Zend_Test_PHPUnit_ControllerTestCase;
use Monitoring\Form\Command\DelayNotificationForm;
class DelayNotificationFormFormTest extends BaseFormTest class DelayNotificationFormFormTest extends BaseFormTest
{ {
public function testValidForm() const FORM_CLASS = 'Monitoring\Form\Command\DelayNotificationForm';
public function testFormInvalidWhenNotificationDelayMissing()
{ {
$form = $this->getRequestForm(array( $form = $this->getRequestForm(array(
'minutes' => 12, 'minutes' => '',
'btn_submit' => 'foo' 'btn_submit' => 'Submit'
), 'Monitoring\Form\Command\DelayNotificationForm'); ), self::FORM_CLASS);
$form->buildForm();
$this->assertCount(5, $form->getElements());
$element = $form->getElement('minutes');
$this->assertInstanceOf('Zend_Form_Element_Text', $element);
$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->isSubmittedAndValid(),
"Assert a correct DelayNotificationForm to be considered valid"
);
$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',
'btn_submit' => 'foo'
), 'Monitoring\Form\Command\DelayNotificationForm');
$form->buildForm();
$this->assertFalse( $this->assertFalse(
$form->isSubmittedAndValid(), $form->isSubmittedAndValid(),
"Asserting invalid minutes (NaN) to cause validation errors" 'Missing notification delay must be considered invalid'
); );
}
$errors = $form->getErrors('minutes'); public function testFormInvalidWhenNotificationDelayNaN()
$this->assertCount(1, $errors, "Asserting an error to be added when the minutes value is invalid"); {
$this->assertEquals('notBetween', $errors[0], "Assert correct error message"); $form = $this->getRequestForm(array(
'minutes' => 'A String',
'btn_submit' => 'Submit'
), self::FORM_CLASS);
$this->assertFalse(
$form->isSubmittedAndValid(),
'Incorrect notification delay, i.e. NaN must be considered invalid'
);
}
public function testFormInvalidWhenNotificationDelayOverflows()
{
$form = $this->getRequestForm(array(
'minutes' => DelayNotificationForm::MAX_DELAY + 1,
'btn_submit' => 'Submit'
), self::FORM_CLASS);
$this->assertFalse(
$form->isSubmittedAndValid(),
'Notification delay bigger than constant "DelayNotificationForm::MAX_DELAY" must be considered invalid'
);
} }
} }
// @codingStandardsIgnoreEnd