diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php index 381981a3c..a75884be2 100644 --- a/library/Icinga/Web/Form.php +++ b/library/Icinga/Web/Form.php @@ -309,7 +309,11 @@ abstract class Form extends \Zend_Form $checkData = $this->getRequest()->getParams(); $this->assertValidCsrfToken($checkData); - $submitted = isset($checkData['btn_submit']); + $submitted = true; + if ($this->getSubmitLabel()) { + $submitted = isset($checkData['btn_submit']); + } + if ($submitted) { $this->preValidation($checkData); } diff --git a/modules/monitoring/test/php/application/forms/Command/AcknowledgeFormTest.php b/modules/monitoring/test/php/application/forms/Command/AcknowledgeFormTest.php index 00fdd5fcb..e309b3dc0 100644 --- a/modules/monitoring/test/php/application/forms/Command/AcknowledgeFormTest.php +++ b/modules/monitoring/test/php/application/forms/Command/AcknowledgeFormTest.php @@ -17,16 +17,20 @@ use \Zend_Test_PHPUnit_ControllerTestCase; class AcknowledgeFormTest extends BaseFormTest { const FORMCLASS = "Monitoring\Form\Command\AcknowledgeForm"; + public function testForm() { - $form = $this->getRequestForm(array(), self::FORMCLASS); - $form->buildForm(); + $formWithoutExpiration = $this->getRequestForm(array(), self::FORMCLASS); + $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() { $form = $this->getRequestForm(array( @@ -34,9 +38,9 @@ class AcknowledgeFormTest extends BaseFormTest 'comment' => 'test comment', 'persistent' => '0', 'expire' => '0', - 'expiretime' => '', 'sticky' => '0', - 'notify' => '0' + 'notify' => '0', + 'btn_submit' => 'foo' ), self::FORMCLASS); $this->assertTrue( @@ -52,9 +56,9 @@ class AcknowledgeFormTest extends BaseFormTest 'comment' => '', 'persistent' => '0', 'expire' => '0', - 'expiretime' => '', 'sticky' => '0', 'notify' => '0', + 'btn_submit' => 'foo' ), self::FORMCLASS); $this->assertFalse( $form->isSubmittedAndValid(), @@ -71,7 +75,8 @@ class AcknowledgeFormTest extends BaseFormTest 'expire' => '1', 'expiretime' => '', 'sticky' => '0', - 'notify' => '0' + 'notify' => '0', + 'btn_submit' => 'foo' ), self::FORMCLASS); $this->assertFalse( $form->isSubmittedAndValid(), @@ -88,7 +93,8 @@ class AcknowledgeFormTest extends BaseFormTest 'expire' => '1', 'expiretime' => 'NOT A DATE', 'sticky' => '0', - 'notify' => '0' + 'notify' => '0', + 'btn_submit' => 'foo' ), self::FORMCLASS); $this->assertFalse( $form->isSubmittedAndValid(), @@ -105,7 +111,8 @@ class AcknowledgeFormTest extends BaseFormTest 'expire' => '1', 'expiretime' => '2013-07-10 17:32:16', 'sticky' => '0', - 'notify' => '0' + 'notify' => '0', + 'btn_submit' => 'foo' ), self::FORMCLASS); $this->assertTrue( $form->isSubmittedAndValid(), diff --git a/modules/monitoring/test/php/application/forms/Command/CommentFormTest.php b/modules/monitoring/test/php/application/forms/Command/CommentFormTest.php index 201d3cc8e..9e4eb4422 100644 --- a/modules/monitoring/test/php/application/forms/Command/CommentFormTest.php +++ b/modules/monitoring/test/php/application/forms/Command/CommentFormTest.php @@ -28,9 +28,10 @@ class CommentFormTest extends BaseFormTest public function testCorrectCommentValidation() { $form = $this->getRequestForm(array( - 'author' => 'test1', - 'comment' => 'test2', - 'sticky' => '0' + 'author' => 'test1', + 'comment' => 'test2', + 'sticky' => '0', + 'btn_submit' => 'foo' ), self::FORMCLASS); $this->assertTrue( diff --git a/modules/monitoring/test/php/application/forms/Command/ConfirmationWithIdentifierFormTest.php b/modules/monitoring/test/php/application/forms/Command/ConfirmationWithIdentifierFormTest.php index 4ede9cf68..4d6e5d77c 100644 --- a/modules/monitoring/test/php/application/forms/Command/ConfirmationWithIdentifierFormTest.php +++ b/modules/monitoring/test/php/application/forms/Command/ConfirmationWithIdentifierFormTest.php @@ -28,7 +28,8 @@ class ConfirmationWithIdentifierFormTest extends BaseFormTest { $form = $this->getRequestForm(array( - 'testval' => 123 + 'testval' => 123, + 'btn_submit' => 'foo' ), self::FORMCLASS); $form->setFieldLabel('Test1'); diff --git a/modules/monitoring/test/php/application/forms/Command/CustomNotificationFormTest.php b/modules/monitoring/test/php/application/forms/Command/CustomNotificationFormTest.php index 826c1038f..0b023eea2 100644 --- a/modules/monitoring/test/php/application/forms/Command/CustomNotificationFormTest.php +++ b/modules/monitoring/test/php/application/forms/Command/CustomNotificationFormTest.php @@ -16,8 +16,9 @@ class CustomNotificationFormTest extends BaseFormTest public function testForm1() { $form = $this->getRequestForm(array( - 'comment' => 'TEST COMMENT', - 'author' => 'LAOLA' + 'comment' => 'TEST COMMENT', + 'author' => 'LAOLA', + 'btn_submit' => 'foo' ), "Monitoring\Form\Command\CustomNotificationForm"); $form->buildForm(); diff --git a/modules/monitoring/test/php/application/forms/Command/DelayNotificationFormTest.php b/modules/monitoring/test/php/application/forms/Command/DelayNotificationFormTest.php index 5f3b504f9..6bc73f81b 100644 --- a/modules/monitoring/test/php/application/forms/Command/DelayNotificationFormTest.php +++ b/modules/monitoring/test/php/application/forms/Command/DelayNotificationFormTest.php @@ -16,7 +16,8 @@ class DelayNotificationFormFormTest extends BaseFormTest public function testValidForm() { $form = $this->getRequestForm(array( - 'minutes' => 12 + 'minutes' => 12, + 'btn_submit' => 'foo' ), 'Monitoring\Form\Command\DelayNotificationForm'); $form->buildForm(); diff --git a/modules/monitoring/test/php/application/forms/Command/RescheduleNextCheckFormTest.php b/modules/monitoring/test/php/application/forms/Command/RescheduleNextCheckFormTest.php index 0d7ba71b1..8b5c6bb3b 100644 --- a/modules/monitoring/test/php/application/forms/Command/RescheduleNextCheckFormTest.php +++ b/modules/monitoring/test/php/application/forms/Command/RescheduleNextCheckFormTest.php @@ -25,7 +25,8 @@ class RescheduleNextCheckFormTest extends BaseFormTest $form = $this->getRequestForm(array( 'checktime' => '2013-10-19 17:30:00', - 'forcecheck' => 1 + 'forcecheck' => 1, + 'btn_submit' => 'foo' ), self::FORMCLASS); $form->buildForm(); @@ -37,7 +38,8 @@ class RescheduleNextCheckFormTest extends BaseFormTest ); $form = $this->getRequestForm(array( 'checktime' => '2013-10-19 17:30:00', - 'forcecheck' => 0 + 'forcecheck' => 0, + 'btn_submit' => 'foo' ), self::FORMCLASS); $this->assertTrue( diff --git a/modules/monitoring/test/php/application/forms/Command/ScheduleDowntimeFormTest.php b/modules/monitoring/test/php/application/forms/Command/ScheduleDowntimeFormTest.php index 0ec1f6f8a..b541419d2 100644 --- a/modules/monitoring/test/php/application/forms/Command/ScheduleDowntimeFormTest.php +++ b/modules/monitoring/test/php/application/forms/Command/ScheduleDowntimeFormTest.php @@ -16,10 +16,15 @@ class ScheduleDowntimeFormTest extends BaseFormTest const FORMCLASS = 'Monitoring\Form\Command\ScheduleDowntimeForm'; public function testCorrectFormElementCreation() { - $form = $this->getRequestForm(array(), self::FORMCLASS); - $form->buildForm(); + $formFixed = $this->getRequestForm(array(), self::FORMCLASS); + $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->setWithChildren(true); @@ -32,14 +37,15 @@ class ScheduleDowntimeFormTest extends BaseFormTest public function testCorrectValidationWithChildrend() { $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_FIXED, - 'hours' => '', - 'minutes' => '', + '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_FIXED, + 'hours' => '', + 'minutes' => '', + 'btn_submit' => 'foo', // 'childobjects' => '', ), self::FORMCLASS); @@ -51,14 +57,15 @@ class ScheduleDowntimeFormTest extends BaseFormTest 'Asserting a correct fixed downtime form to be considered valid' ); $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' => '10', - 'minutes' => '10', + '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' => '10', + 'minutes' => '10', + 'btn_submit' => 'foo' // 'childobjects' => '', ), self::FORMCLASS); $form->setWithChildren(true); @@ -247,14 +254,15 @@ class ScheduleDowntimeFormTest extends BaseFormTest public function testCorrectScheduleDowntimeWithoutChildrenForm() { $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_FIXED, - 'hours' => '', - 'minutes' => '', + '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_FIXED, + 'hours' => '', + 'minutes' => '', + 'btn_submit' => 'foo', 'childobjects' => '0', ), self::FORMCLASS); $form->setWithChildren(false); diff --git a/modules/monitoring/test/php/application/forms/Command/SubmitPassiveCheckResultTest.php b/modules/monitoring/test/php/application/forms/Command/SubmitPassiveCheckResultTest.php index 2de9a866e..ea504e5ee 100644 --- a/modules/monitoring/test/php/application/forms/Command/SubmitPassiveCheckResultTest.php +++ b/modules/monitoring/test/php/application/forms/Command/SubmitPassiveCheckResultTest.php @@ -59,7 +59,8 @@ class SubmitPassiveCheckResultFormTest extends BaseFormTest $form = $this->getRequestForm(array( 'pluginstate' => 0, 'checkoutput' => 'DING', - 'performancedata' => '' + 'performancedata' => '', + 'btn_submit' => 'foo' ), self::FORMCLASS); $form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);