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();
$this->assertValidCsrfToken($checkData);
$submitted = true;
if ($this->getSubmitLabel()) {
$submitted = isset($checkData['btn_submit']);
}
if ($submitted) {
$this->preValidation($checkData);
}

View File

@ -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(),

View File

@ -30,7 +30,8 @@ class CommentFormTest extends BaseFormTest
$form = $this->getRequestForm(array(
'author' => 'test1',
'comment' => 'test2',
'sticky' => '0'
'sticky' => '0',
'btn_submit' => 'foo'
), self::FORMCLASS);
$this->assertTrue(

View File

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

View File

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

View File

@ -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();

View File

@ -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(

View File

@ -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);
@ -40,6 +45,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest
'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '',
'minutes' => '',
'btn_submit' => 'foo',
// 'childobjects' => '',
), self::FORMCLASS);
@ -59,6 +65,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest
'type' => ScheduleDowntimeForm::TYPE_FLEXIBLE,
'hours' => '10',
'minutes' => '10',
'btn_submit' => 'foo'
// 'childobjects' => '',
), self::FORMCLASS);
$form->setWithChildren(true);
@ -255,6 +262,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest
'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '',
'minutes' => '',
'btn_submit' => 'foo',
'childobjects' => '0',
), self::FORMCLASS);
$form->setWithChildren(false);

View File

@ -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);