From 5e85dd1c0664ec9e94ea385847d2a45e498abaee Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 16 Aug 2013 13:31:14 +0200 Subject: [PATCH] Monitoring/Commands: Fix reschedule next check form tests refs #4524 --- .../forms/Command/RescheduleNextCheckForm.php | 7 +- .../Command/RescheduleNextCheckFormTest.php | 120 +++++++----------- 2 files changed, 48 insertions(+), 79 deletions(-) diff --git a/modules/monitoring/application/forms/Command/RescheduleNextCheckForm.php b/modules/monitoring/application/forms/Command/RescheduleNextCheckForm.php index f5459d07a..772aff912 100644 --- a/modules/monitoring/application/forms/Command/RescheduleNextCheckForm.php +++ b/modules/monitoring/application/forms/Command/RescheduleNextCheckForm.php @@ -58,9 +58,10 @@ class RescheduleNextCheckForm extends WithChildrenCommandForm $this->addElement( new DateTimePicker( array( - 'name' => 'checktime', - 'label' => t('Check Time'), - 'value' => DateTimeFactory::create()->getTimestamp() + 'name' => 'checktime', + 'label' => t('Check Time'), + 'value' => DateTimeFactory::create()->getTimestamp(), + 'required' => !$this->getRequest()->getPost('forcecheck') ) ) ); diff --git a/modules/monitoring/test/php/application/forms/Command/RescheduleNextCheckFormTest.php b/modules/monitoring/test/php/application/forms/Command/RescheduleNextCheckFormTest.php index 442a367b6..33e1cf2b9 100644 --- a/modules/monitoring/test/php/application/forms/Command/RescheduleNextCheckFormTest.php +++ b/modules/monitoring/test/php/application/forms/Command/RescheduleNextCheckFormTest.php @@ -1,102 +1,70 @@ getRequestForm(array( - 'checktime' => '2013-10-19 17:30:00', - 'forcecheck' => 1, - 'btn_submit' => 'foo' - ), self::FORMCLASS); - $form->buildForm(); - - $this->assertCount(6, $form->getElements()); - - $this->assertTrue( - $form->isSubmittedAndValid(), - 'Asserting a reschedule form with correct time and forececheck=1 to be valid' - ); - $form = $this->getRequestForm(array( - 'checktime' => '2013-10-19 17:30:00', - 'forcecheck' => 0, - 'btn_submit' => 'foo' - ), self::FORMCLASS); - - $this->assertTrue( - $form->isSubmittedAndValid(), - 'Asserting a reschedule form with correct time and forecheck=0 to be valid' - ); + date_default_timezone_set('UTC'); + DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC'))); } - public function testInValidRescheduleChecktimeSubmissions() + public function testFormInvalidWhenChecktimeIsIncorrect() { $form = $this->getRequestForm(array( - 'checktime' => '2013-24-12 17:30:00', - 'forcecheck' => 1 - ), self::FORMCLASS); + 'checktime' => '2013-24-12 17:30:00', + 'forcecheck' => 0, + 'btn_submit' => 'Submit' + ), self::FORM_CLASS); $this->assertFalse( $form->isSubmittedAndValid(), - 'Asserting an logically invalid checktime to be considered as invalid reschedule data' + 'Asserting a logically incorrect checktime as invalid' ); - $form = $this->getRequestForm(array( - 'checktime' => 'AHAHA', - 'forcecheck' => 1 - ), self::FORMCLASS); - + $form2 = $this->getRequestForm(array( + 'checktime' => 'Captain Morgan', + 'forcecheck' => 1, + 'btn_submit' => 'Submit' + ), self::FORM_CLASS); $this->assertFalse( - $form->isSubmittedAndValid(), - 'Asserting an invalid non-numeric checktime to be considered as invalid reschedule data' + $form2->isSubmittedAndValid(), + 'Providing arbitrary strings as checktime must be considered invalid' ); - } - public function testChildrenFlag() - { + $form3 = $this->getRequestForm(array( + 'checktime' => '', + 'forcecheck' => 0, + 'btn_submit' => 'Submit' + ), self::FORM_CLASS); - $form = new RescheduleNextCheckForm(); - $form->setRequest($this->getRequest()); - $form->setWithChildren(true); - $form->buildForm(); - $notes1 = $form->getNotes(); - $form = null; - - $form = new RescheduleNextCheckForm(); - $form->setRequest($this->getRequest()); - $form->setWithChildren(false); - $form->buildForm(); - $notes2 = $form->getNotes(); - $form = null; - - $form = new RescheduleNextCheckForm(); - $form->setRequest($this->getRequest()); - $form->setWithChildren(); - $form->buildForm(); - $notes3 = $form->getNotes(); - $form = null; - - $this->assertEquals($notes1, $notes3); - $this->assertNotEquals($notes1, $notes2); + $this->assertFalse( + $form3->isSubmittedAndValid(), + 'Missing checktime must be considered invalid' + ); } } +// @codingStandardsIgnoreStop