From a45409c5f37e2ad2098ae30c36d4af6a2449daf8 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 16 Aug 2013 13:32:54 +0200 Subject: [PATCH] Monitoring/Commands/Forms/Tests: Follow our Coding Standards refs #4524 --- .../forms/Command/AcknowledgeFormTest.php | 4 +- .../forms/Command/BaseFormTest.php | 2 + .../forms/Command/CommentFormTest.php | 6 +- .../Command/DelayNotificationFormTest.php | 4 +- .../Command/ScheduleDowntimeFormTest.php | 84 ++++++++++--------- .../Command/SubmitPassiveCheckResultTest.php | 55 ++++++------ 6 files changed, 78 insertions(+), 77 deletions(-) diff --git a/modules/monitoring/test/php/application/forms/Command/AcknowledgeFormTest.php b/modules/monitoring/test/php/application/forms/Command/AcknowledgeFormTest.php index dfd3c94b1..1e0e08f44 100644 --- a/modules/monitoring/test/php/application/forms/Command/AcknowledgeFormTest.php +++ b/modules/monitoring/test/php/application/forms/Command/AcknowledgeFormTest.php @@ -6,11 +6,9 @@ namespace Test\Monitoring\Forms\Command; require_once realpath(__DIR__ . '/BaseFormTest.php'); -require_once realpath(__DIR__ . '/../../../../../../../modules/monitoring/application/forms/Command/CommandForm.php'); +require_once realpath(__DIR__ . '/../../../../../../../modules/monitoring/application/forms/Command/AcknowledgeForm.php'); require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Util/ConfigAwareFactory.php'); require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Util/DateTimeFactory.php'); -require_once realpath(__DIR__ . '/../../../../../../../modules/monitoring/application/forms/Command/WithChildrenCommandForm.php'); -require_once realpath(__DIR__ . '/../../../../../../../modules/monitoring/application/forms/Command/AcknowledgeForm.php'); use \DateTimeZone; use \Monitoring\Form\Command\AcknowledgeForm; // Used by constant FORMCLASS diff --git a/modules/monitoring/test/php/application/forms/Command/BaseFormTest.php b/modules/monitoring/test/php/application/forms/Command/BaseFormTest.php index ed849436c..aaba6575c 100644 --- a/modules/monitoring/test/php/application/forms/Command/BaseFormTest.php +++ b/modules/monitoring/test/php/application/forms/Command/BaseFormTest.php @@ -30,6 +30,8 @@ namespace Test\Monitoring\Forms\Command { require_once realpath($base.'library/Icinga/Web/Form/InvalidCSRFTokenException.php'); require_once realpath($base.'library/Icinga/Web/Form/Element/Note.php'); require_once realpath($base.'library/Icinga/Web/Form/Element/DateTimePicker.php'); + require_once realpath($base . 'modules/monitoring/application/forms/Command/CommandForm.php'); + require_once realpath($base . 'modules/monitoring/application/forms/Command/WithChildrenCommandForm.php'); use \Zend_View; use \Zend_Form; diff --git a/modules/monitoring/test/php/application/forms/Command/CommentFormTest.php b/modules/monitoring/test/php/application/forms/Command/CommentFormTest.php index 8b7aa7a7f..354aad114 100644 --- a/modules/monitoring/test/php/application/forms/Command/CommentFormTest.php +++ b/modules/monitoring/test/php/application/forms/Command/CommentFormTest.php @@ -5,10 +5,8 @@ namespace Test\Monitoring\Forms\Command; -require_once __DIR__ .'/BaseFormTest.php'; -require_once __DIR__ . '/../../../../../application/forms/Command/CommandForm.php'; -require_once __DIR__ . '/../../../../../application/forms/Command/WithChildrenCommandForm.php'; -require_once __DIR__ . '/../../../../../application/forms/Command/CommentForm.php'; +require_once realpath(__DIR__ . '/BaseFormTest.php'); +require_once realpath(__DIR__ . '/../../../../../../../modules/monitoring/application/forms/Command/CommentForm.php'); use \Monitoring\Form\Command\CommentForm; // Used by constant FORMCLASS diff --git a/modules/monitoring/test/php/application/forms/Command/DelayNotificationFormTest.php b/modules/monitoring/test/php/application/forms/Command/DelayNotificationFormTest.php index 2891bfef5..dd7ade4ed 100644 --- a/modules/monitoring/test/php/application/forms/Command/DelayNotificationFormTest.php +++ b/modules/monitoring/test/php/application/forms/Command/DelayNotificationFormTest.php @@ -6,13 +6,11 @@ namespace Test\Monitoring\Forms\Command; require_once realpath(__DIR__ . '/BaseFormTest.php'); -require_once realpath(__DIR__ . '/../../../../../application/forms/Command/CommandForm.php'); require_once realpath(__DIR__ . '/../../../../../application/forms/Command/DelayNotificationForm.php'); - use \Monitoring\Form\Command\DelayNotificationForm; // Used by constant FORM_CLASS -class DelayNotificationFormFormTest extends BaseFormTest +class DelayNotificationFormTest extends BaseFormTest { const FORM_CLASS = 'Monitoring\Form\Command\DelayNotificationForm'; diff --git a/modules/monitoring/test/php/application/forms/Command/ScheduleDowntimeFormTest.php b/modules/monitoring/test/php/application/forms/Command/ScheduleDowntimeFormTest.php index 5d5d43331..8b60a0ca7 100644 --- a/modules/monitoring/test/php/application/forms/Command/ScheduleDowntimeFormTest.php +++ b/modules/monitoring/test/php/application/forms/Command/ScheduleDowntimeFormTest.php @@ -1,39 +1,50 @@ new DateTimeZone('UTC'))); + } + public function testCorrectFormElementCreation() { - $formFixed = $this->getRequestForm(array(), self::FORMCLASS); + $formFixed = $this->getRequestForm(array(), self::FORM_CLASS); $formFixed->buildForm(); $formFlexible = $this->getRequestForm(array( 'type' => 'flexible' - ), self::FORMCLASS); + ), self::FORM_CLASS); $formFlexible->buildForm(); - $this->assertCount(11, $formFixed->getElements()); - $this->assertCount(13, $formFlexible->getElements()); - - $form = $this->getRequestForm(array(), self::FORMCLASS); + $form = $this->getRequestForm(array(), self::FORM_CLASS); $form->setWithChildren(true); $form->buildForm(); - - $this->assertCount(12, $form->getElements()); } - public function testCorrectValidationWithChildrend() { $form = $this->getRequestForm(array( @@ -47,8 +58,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest 'minutes' => '', 'btn_submit' => 'foo', // 'childobjects' => '', - ), self::FORMCLASS); - + ), self::FORM_CLASS); $form->setWithChildren(true); @@ -67,14 +77,13 @@ class ScheduleDowntimeFormTest extends BaseFormTest 'minutes' => '10', 'btn_submit' => 'foo' // 'childobjects' => '', - ), self::FORMCLASS); + ), self::FORM_CLASS); $form->setWithChildren(true); $this->assertTrue( $form->isSubmittedAndValid(), 'Asserting a correct flexible downtime form to be considered valid' ); - } public function testMissingFlexibleDurationRecognition() @@ -89,7 +98,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest 'hours' => '', 'minutes' => '', // 'childobjects' => '', - ), self::FORMCLASS); + ), self::FORM_CLASS); $form->setWithChildren(true); $this->assertFalse( @@ -100,7 +109,6 @@ class ScheduleDowntimeFormTest extends BaseFormTest public function testMissingAuthorRecognition() { - $form = $this->getRequestForm(array( 'author' => '', 'comment' => 'DING DING', @@ -111,7 +119,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest 'hours' => '', 'minutes' => '', // 'childobjects' => '', - ), self::FORMCLASS); + ), self::FORM_CLASS); $form->setWithChildren(true); @@ -133,7 +141,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest 'hours' => '', 'minutes' => '', // 'childobjects' => '', - ), self::FORMCLASS); + ), self::FORM_CLASS); $form->setWithChildren(true); @@ -155,7 +163,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest 'hours' => '', 'minutes' => '', // 'childobjects' => '', - ), self::FORMCLASS); + ), self::FORM_CLASS); $form->setWithChildren(true); $this->assertFalse( @@ -176,7 +184,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest 'hours' => '', 'minutes' => '', // 'childobjects' => '', - ), self::FORMCLASS); + ), self::FORM_CLASS); $form->setWithChildren(true); $this->assertFalse( @@ -187,7 +195,6 @@ class ScheduleDowntimeFormTest extends BaseFormTest public function testInvalidEndTimeRecognition() { - $form = $this->getRequestForm(array( 'author' => 'OK', 'comment' => 'OK', @@ -198,7 +205,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest 'hours' => '', 'minutes' => '', // 'childobjects' => '', - ), self::FORMCLASS); + ), self::FORM_CLASS); $form->setWithChildren(true); $this->assertFalse( @@ -220,7 +227,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest 'hours' => '-1', 'minutes' => '12', // 'childobjects' => '', - ), self::FORMCLASS); + ), self::FORM_CLASS); $form->setWithChildren(true); $this->assertFalse( @@ -241,7 +248,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest 'hours' => '12', 'minutes' => 'DING', // 'childobjects' => '', - ), self::FORMCLASS); + ), self::FORM_CLASS); $form->setWithChildren(true); $this->assertFalse( @@ -264,13 +271,13 @@ class ScheduleDowntimeFormTest extends BaseFormTest 'minutes' => '', 'btn_submit' => 'foo', 'childobjects' => '0', - ), self::FORMCLASS); + ), self::FORM_CLASS); $form->setWithChildren(false); $this->assertTrue( $form->isSubmittedAndValid(), - "Assert a correct schedule downtime without children form to be considered valid" + 'Assert a correct schedule downtime without children form to be considered valid' ); } @@ -285,12 +292,12 @@ class ScheduleDowntimeFormTest extends BaseFormTest 'hours' => '', 'minutes' => '', 'childobjects' => 'AHA', - ), self::FORMCLASS); + ), self::FORM_CLASS); $form->setWithChildren(false); $this->assertFalse( $form->isSubmittedAndValid(), - "Assert and incorrect (non-numeric) childobjects value to cause validation errors" + 'Assert and incorrect (non-numeric) childobjects value to cause validation errors' ); $form = $this->getRequestForm(array( @@ -303,18 +310,18 @@ class ScheduleDowntimeFormTest extends BaseFormTest 'hours' => '', 'minutes' => '', 'childobjects' => '4', - ), self::FORMCLASS); + ), self::FORM_CLASS); $form->setWithChildren(false); $this->assertFalse( $form->isSubmittedAndValid(), - "Assert and incorrect (numeric) childobjects value to cause validation errors" + 'Assert and incorrect (numeric) childobjects value to cause validation errors' ); } public function testTimeRange() { - $form = $this->getRequestForm(array(), self::FORMCLASS); + $form = $this->getRequestForm(array(), self::FORM_CLASS); $form->buildForm(); $time1 = $form->getElement('starttime')->getValue(); @@ -323,3 +330,4 @@ class ScheduleDowntimeFormTest extends BaseFormTest $this->assertEquals(3600, ($time2 - $time1)); } } +// @codingStandardsIgnoreStop diff --git a/modules/monitoring/test/php/application/forms/Command/SubmitPassiveCheckResultTest.php b/modules/monitoring/test/php/application/forms/Command/SubmitPassiveCheckResultTest.php index 6074a90ac..e469658bf 100644 --- a/modules/monitoring/test/php/application/forms/Command/SubmitPassiveCheckResultTest.php +++ b/modules/monitoring/test/php/application/forms/Command/SubmitPassiveCheckResultTest.php @@ -1,38 +1,37 @@ getRequestForm(array(), self::FORMCLASS); + $form = $this->getRequestForm(array(), self::FORM_CLASS); $form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE); $options = $form->getOptions(); - $this->assertCount(4, $options, "Assert correct number of states in service passive checks form"); - $this->assertEquals('OK', $options[0], "Assert OK state to be available in service passive check form"); - $this->assertEquals('WARNING', $options[1], "Assert WARNING state to be available in service passive check form"); - $this->assertEquals('CRITICAL', $options[2], "Assert CRITICAL state to be available in service passive check form"); - $this->assertEquals('UNKNOWN', $options[3], "Assert UNKNOWN state to be available in service passive check form"); + $this->assertCount(4, $options, 'Assert correct number of states in service passive checks form'); + $this->assertEquals('OK', $options[0], 'Assert OK state to be available in service passive check form'); + $this->assertEquals('WARNING', $options[1], 'Assert WARNING state to be available in service passive check form'); + $this->assertEquals('CRITICAL', $options[2], 'Assert CRITICAL state to be available in service passive check form'); + $this->assertEquals('UNKNOWN', $options[3], 'Assert UNKNOWN state to be available in service passive check form'); $form->setType(SubmitPassiveCheckResultForm::TYPE_HOST); $options = $form->getOptions(); - $this->assertCount(3, $options, "Assert correct number of states in host passive checks form"); - $this->assertEquals('UP', $options[0], "Assert UP state to be available in host passive check form"); - $this->assertEquals('DOWN', $options[1], "Assert DOWN state to be available in host passive check form"); - $this->assertEquals('UNREACHABLE', $options[2], "Assert UNREACHABLE state to be available in host passive check form"); + $this->assertCount(3, $options, 'Assert correct number of states in host passive checks form'); + $this->assertEquals('UP', $options[0], 'Assert UP state to be available in host passive check form'); + $this->assertEquals('DOWN', $options[1], 'Assert DOWN state to be available in host passive check form'); + $this->assertEquals('UNREACHABLE', $options[2], 'Assert UNREACHABLE state to be available in host passive check form'); } /** @@ -41,17 +40,15 @@ class SubmitPassiveCheckResultFormTest extends BaseFormTest */ public function testMissingTypeThrowingException() { - $form = $this->getRequestForm(array(), self::FORMCLASS); + $form = $this->getRequestForm(array(), self::FORM_CLASS); $form->buildForm(); } public function testCorrectFormCreation() { - $form = $this->getRequestForm(array(), self::FORMCLASS); + $form = $this->getRequestForm(array(), self::FORM_CLASS); $form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE); $form->buildForm(); - - $this->assertCount(6, $form->getElements(), "Assert correct number of elements in form"); } public function testCorrectServicePassiveCheckSubmission() @@ -61,13 +58,13 @@ class SubmitPassiveCheckResultFormTest extends BaseFormTest 'checkoutput' => 'DING', 'performancedata' => '', 'btn_submit' => 'foo' - ), self::FORMCLASS); + ), self::FORM_CLASS); $form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE); $this->assertTrue( $form->isSubmittedAndValid(), - "Assert a correct passive service check form to pass form validation" + 'Assert a correct passive service check form to pass form validation' ); } @@ -77,12 +74,12 @@ class SubmitPassiveCheckResultFormTest extends BaseFormTest 'pluginstate' => 0, 'checkoutput' => '', 'performancedata' => '' - ), self::FORMCLASS); + ), self::FORM_CLASS); $form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE); $this->assertFalse( $form->isSubmittedAndValid(), - "Assert empty checkoutput to cause validation errors in passive service check " + 'Assert empty checkoutput to cause validation errors in passive service check ' ); } @@ -92,12 +89,12 @@ class SubmitPassiveCheckResultFormTest extends BaseFormTest 'pluginstate' => 'LA', 'checkoutput' => 'DING', 'performancedata' => '' - ), self::FORMCLASS); + ), self::FORM_CLASS); $form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE); $this->assertFalse( $form->isSubmittedAndValid(), - "Assert invalid (non-numeric) state to cause validation errors in passive service check" + 'Assert invalid (non-numeric) state to cause validation errors in passive service check' ); } }