Update command form tests

Update command form tests so that they reflect the new dynamic
functionality and the correct purpose of "isSubmittedAndValid".

refs #4439
This commit is contained in:
Johannes Meyer 2013-08-05 11:07:29 +02:00
parent 8efbe6f613
commit f26af0eb12
9 changed files with 75 additions and 49 deletions

View File

@ -309,7 +309,11 @@ abstract class Form extends \Zend_Form
$checkData = $this->getRequest()->getParams(); $checkData = $this->getRequest()->getParams();
$this->assertValidCsrfToken($checkData); $this->assertValidCsrfToken($checkData);
$submitted = isset($checkData['btn_submit']); $submitted = true;
if ($this->getSubmitLabel()) {
$submitted = isset($checkData['btn_submit']);
}
if ($submitted) { if ($submitted) {
$this->preValidation($checkData); $this->preValidation($checkData);
} }

View File

@ -17,16 +17,20 @@ use \Zend_Test_PHPUnit_ControllerTestCase;
class AcknowledgeFormTest extends BaseFormTest class AcknowledgeFormTest extends BaseFormTest
{ {
const FORMCLASS = "Monitoring\Form\Command\AcknowledgeForm"; const FORMCLASS = "Monitoring\Form\Command\AcknowledgeForm";
public function testForm() public function testForm()
{ {
$form = $this->getRequestForm(array(), self::FORMCLASS); $formWithoutExpiration = $this->getRequestForm(array(), self::FORMCLASS);
$form->buildForm(); $formWithoutExpiration->buildForm();
$formWithExpiration = $this->getRequestForm(array(
'expire' => '1'
), self::FORMCLASS);
$formWithExpiration->buildForm();
$this->assertCount(11, $form->getElements()); $this->assertCount(10, $formWithoutExpiration->getElements());
$this->assertCount(11, $formWithExpiration->getElements());
} }
public function testValidateCorrectForm() public function testValidateCorrectForm()
{ {
$form = $this->getRequestForm(array( $form = $this->getRequestForm(array(
@ -34,9 +38,9 @@ class AcknowledgeFormTest extends BaseFormTest
'comment' => 'test comment', 'comment' => 'test comment',
'persistent' => '0', 'persistent' => '0',
'expire' => '0', 'expire' => '0',
'expiretime' => '',
'sticky' => '0', 'sticky' => '0',
'notify' => '0' 'notify' => '0',
'btn_submit' => 'foo'
), self::FORMCLASS); ), self::FORMCLASS);
$this->assertTrue( $this->assertTrue(
@ -52,9 +56,9 @@ class AcknowledgeFormTest extends BaseFormTest
'comment' => '', 'comment' => '',
'persistent' => '0', 'persistent' => '0',
'expire' => '0', 'expire' => '0',
'expiretime' => '',
'sticky' => '0', 'sticky' => '0',
'notify' => '0', 'notify' => '0',
'btn_submit' => 'foo'
), self::FORMCLASS); ), self::FORMCLASS);
$this->assertFalse( $this->assertFalse(
$form->isSubmittedAndValid(), $form->isSubmittedAndValid(),
@ -71,7 +75,8 @@ class AcknowledgeFormTest extends BaseFormTest
'expire' => '1', 'expire' => '1',
'expiretime' => '', 'expiretime' => '',
'sticky' => '0', 'sticky' => '0',
'notify' => '0' 'notify' => '0',
'btn_submit' => 'foo'
), self::FORMCLASS); ), self::FORMCLASS);
$this->assertFalse( $this->assertFalse(
$form->isSubmittedAndValid(), $form->isSubmittedAndValid(),
@ -88,7 +93,8 @@ class AcknowledgeFormTest extends BaseFormTest
'expire' => '1', 'expire' => '1',
'expiretime' => 'NOT A DATE', 'expiretime' => 'NOT A DATE',
'sticky' => '0', 'sticky' => '0',
'notify' => '0' 'notify' => '0',
'btn_submit' => 'foo'
), self::FORMCLASS); ), self::FORMCLASS);
$this->assertFalse( $this->assertFalse(
$form->isSubmittedAndValid(), $form->isSubmittedAndValid(),
@ -105,7 +111,8 @@ class AcknowledgeFormTest extends BaseFormTest
'expire' => '1', 'expire' => '1',
'expiretime' => '2013-07-10 17:32:16', 'expiretime' => '2013-07-10 17:32:16',
'sticky' => '0', 'sticky' => '0',
'notify' => '0' 'notify' => '0',
'btn_submit' => 'foo'
), self::FORMCLASS); ), self::FORMCLASS);
$this->assertTrue( $this->assertTrue(
$form->isSubmittedAndValid(), $form->isSubmittedAndValid(),

View File

@ -28,9 +28,10 @@ class CommentFormTest extends BaseFormTest
public function testCorrectCommentValidation() public function testCorrectCommentValidation()
{ {
$form = $this->getRequestForm(array( $form = $this->getRequestForm(array(
'author' => 'test1', 'author' => 'test1',
'comment' => 'test2', 'comment' => 'test2',
'sticky' => '0' 'sticky' => '0',
'btn_submit' => 'foo'
), self::FORMCLASS); ), self::FORMCLASS);
$this->assertTrue( $this->assertTrue(

View File

@ -28,7 +28,8 @@ class ConfirmationWithIdentifierFormTest extends BaseFormTest
{ {
$form = $this->getRequestForm(array( $form = $this->getRequestForm(array(
'testval' => 123 'testval' => 123,
'btn_submit' => 'foo'
), self::FORMCLASS); ), self::FORMCLASS);
$form->setFieldLabel('Test1'); $form->setFieldLabel('Test1');

View File

@ -16,8 +16,9 @@ class CustomNotificationFormTest extends BaseFormTest
public function testForm1() public function testForm1()
{ {
$form = $this->getRequestForm(array( $form = $this->getRequestForm(array(
'comment' => 'TEST COMMENT', 'comment' => 'TEST COMMENT',
'author' => 'LAOLA' 'author' => 'LAOLA',
'btn_submit' => 'foo'
), "Monitoring\Form\Command\CustomNotificationForm"); ), "Monitoring\Form\Command\CustomNotificationForm");
$form->buildForm(); $form->buildForm();

View File

@ -16,7 +16,8 @@ class DelayNotificationFormFormTest extends BaseFormTest
public function testValidForm() public function testValidForm()
{ {
$form = $this->getRequestForm(array( $form = $this->getRequestForm(array(
'minutes' => 12 'minutes' => 12,
'btn_submit' => 'foo'
), 'Monitoring\Form\Command\DelayNotificationForm'); ), 'Monitoring\Form\Command\DelayNotificationForm');
$form->buildForm(); $form->buildForm();

View File

@ -25,7 +25,8 @@ class RescheduleNextCheckFormTest extends BaseFormTest
$form = $this->getRequestForm(array( $form = $this->getRequestForm(array(
'checktime' => '2013-10-19 17:30:00', 'checktime' => '2013-10-19 17:30:00',
'forcecheck' => 1 'forcecheck' => 1,
'btn_submit' => 'foo'
), self::FORMCLASS); ), self::FORMCLASS);
$form->buildForm(); $form->buildForm();
@ -37,7 +38,8 @@ class RescheduleNextCheckFormTest extends BaseFormTest
); );
$form = $this->getRequestForm(array( $form = $this->getRequestForm(array(
'checktime' => '2013-10-19 17:30:00', 'checktime' => '2013-10-19 17:30:00',
'forcecheck' => 0 'forcecheck' => 0,
'btn_submit' => 'foo'
), self::FORMCLASS); ), self::FORMCLASS);
$this->assertTrue( $this->assertTrue(

View File

@ -16,10 +16,15 @@ class ScheduleDowntimeFormTest extends BaseFormTest
const FORMCLASS = 'Monitoring\Form\Command\ScheduleDowntimeForm'; const FORMCLASS = 'Monitoring\Form\Command\ScheduleDowntimeForm';
public function testCorrectFormElementCreation() public function testCorrectFormElementCreation()
{ {
$form = $this->getRequestForm(array(), self::FORMCLASS); $formFixed = $this->getRequestForm(array(), self::FORMCLASS);
$form->buildForm(); $formFixed->buildForm();
$formFlexible = $this->getRequestForm(array(
'type' => 'flexible'
), self::FORMCLASS);
$formFlexible->buildForm();
$this->assertCount(13, $form->getElements()); $this->assertCount(11, $formFixed->getElements());
$this->assertCount(13, $formFlexible->getElements());
$form = $this->getRequestForm(array(), self::FORMCLASS); $form = $this->getRequestForm(array(), self::FORMCLASS);
$form->setWithChildren(true); $form->setWithChildren(true);
@ -32,14 +37,15 @@ class ScheduleDowntimeFormTest extends BaseFormTest
public function testCorrectValidationWithChildrend() public function testCorrectValidationWithChildrend()
{ {
$form = $this->getRequestForm(array( $form = $this->getRequestForm(array(
'author' => 'TEST_AUTHOR', 'author' => 'TEST_AUTHOR',
'comment' => 'DING DING', 'comment' => 'DING DING',
'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' => ScheduleDowntimeForm::TYPE_FIXED, 'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '', 'hours' => '',
'minutes' => '', 'minutes' => '',
'btn_submit' => 'foo',
// 'childobjects' => '', // 'childobjects' => '',
), self::FORMCLASS); ), self::FORMCLASS);
@ -51,14 +57,15 @@ class ScheduleDowntimeFormTest extends BaseFormTest
'Asserting a correct fixed downtime form to be considered valid' 'Asserting a correct fixed downtime form to be considered valid'
); );
$form = $this->getRequestForm(array( $form = $this->getRequestForm(array(
'author' => 'TEST_AUTHOR', 'author' => 'TEST_AUTHOR',
'comment' => 'DING DING', 'comment' => 'DING DING',
'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' => ScheduleDowntimeForm::TYPE_FLEXIBLE, 'type' => ScheduleDowntimeForm::TYPE_FLEXIBLE,
'hours' => '10', 'hours' => '10',
'minutes' => '10', 'minutes' => '10',
'btn_submit' => 'foo'
// 'childobjects' => '', // 'childobjects' => '',
), self::FORMCLASS); ), self::FORMCLASS);
$form->setWithChildren(true); $form->setWithChildren(true);
@ -247,14 +254,15 @@ class ScheduleDowntimeFormTest extends BaseFormTest
public function testCorrectScheduleDowntimeWithoutChildrenForm() public function testCorrectScheduleDowntimeWithoutChildrenForm()
{ {
$form = $this->getRequestForm(array( $form = $this->getRequestForm(array(
'author' => 'TEST_AUTHOR', 'author' => 'TEST_AUTHOR',
'comment' => 'DING DING', 'comment' => 'DING DING',
'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' => ScheduleDowntimeForm::TYPE_FIXED, 'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '', 'hours' => '',
'minutes' => '', 'minutes' => '',
'btn_submit' => 'foo',
'childobjects' => '0', 'childobjects' => '0',
), self::FORMCLASS); ), self::FORMCLASS);
$form->setWithChildren(false); $form->setWithChildren(false);

View File

@ -59,7 +59,8 @@ class SubmitPassiveCheckResultFormTest extends BaseFormTest
$form = $this->getRequestForm(array( $form = $this->getRequestForm(array(
'pluginstate' => 0, 'pluginstate' => 0,
'checkoutput' => 'DING', 'checkoutput' => 'DING',
'performancedata' => '' 'performancedata' => '',
'btn_submit' => 'foo'
), self::FORMCLASS); ), self::FORMCLASS);
$form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE); $form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);