Monitoring/Commands/Forms/Tests: Follow our Coding Standards

refs #4524
This commit is contained in:
Eric Lippmann 2013-08-16 13:32:54 +02:00 committed by Jannis Moßhammer
parent 5e85dd1c06
commit a45409c5f3
6 changed files with 78 additions and 77 deletions

View File

@ -6,11 +6,9 @@
namespace Test\Monitoring\Forms\Command; namespace Test\Monitoring\Forms\Command;
require_once realpath(__DIR__ . '/BaseFormTest.php'); 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/ConfigAwareFactory.php');
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Util/DateTimeFactory.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 \DateTimeZone;
use \Monitoring\Form\Command\AcknowledgeForm; // Used by constant FORMCLASS use \Monitoring\Form\Command\AcknowledgeForm; // Used by constant FORMCLASS

View File

@ -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/InvalidCSRFTokenException.php');
require_once realpath($base.'library/Icinga/Web/Form/Element/Note.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.'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_View;
use \Zend_Form; use \Zend_Form;

View File

@ -5,10 +5,8 @@
namespace Test\Monitoring\Forms\Command; namespace Test\Monitoring\Forms\Command;
require_once __DIR__ .'/BaseFormTest.php'; require_once realpath(__DIR__ . '/BaseFormTest.php');
require_once __DIR__ . '/../../../../../application/forms/Command/CommandForm.php'; require_once realpath(__DIR__ . '/../../../../../../../modules/monitoring/application/forms/Command/CommentForm.php');
require_once __DIR__ . '/../../../../../application/forms/Command/WithChildrenCommandForm.php';
require_once __DIR__ . '/../../../../../application/forms/Command/CommentForm.php';
use \Monitoring\Form\Command\CommentForm; // Used by constant FORMCLASS use \Monitoring\Form\Command\CommentForm; // Used by constant FORMCLASS

View File

@ -6,13 +6,11 @@
namespace Test\Monitoring\Forms\Command; namespace Test\Monitoring\Forms\Command;
require_once realpath(__DIR__ . '/BaseFormTest.php'); require_once realpath(__DIR__ . '/BaseFormTest.php');
require_once realpath(__DIR__ . '/../../../../../application/forms/Command/CommandForm.php');
require_once realpath(__DIR__ . '/../../../../../application/forms/Command/DelayNotificationForm.php'); require_once realpath(__DIR__ . '/../../../../../application/forms/Command/DelayNotificationForm.php');
use \Monitoring\Form\Command\DelayNotificationForm; // Used by constant FORM_CLASS 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'; const FORM_CLASS = 'Monitoring\Form\Command\DelayNotificationForm';

View File

@ -1,39 +1,50 @@
<?php <?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Test\Monitoring\Forms\Command; namespace Test\Monitoring\Forms\Command;
require_once __DIR__. '/BaseFormTest.php'; require_once realpath(__DIR__ . '/BaseFormTest.php');
require_once __DIR__. '/../../../../../application/forms/Command/CommandForm.php'; require_once realpath(__DIR__ . '/../../../../../../../modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php');
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommandForm.php'; require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Util/ConfigAwareFactory.php');
require_once __DIR__. '/../../../../../application/forms/Command/ScheduleDowntimeForm.php'; require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Util/DateTimeFactory.php');
use Monitoring\Form\Command\ScheduleDowntimeForm; use \Monitoring\Form\Command\ScheduleDowntimeForm; // Used by constant FORM_CLASS
use \Zend_View; use \DateTimeZone;
use \Zend_Test_PHPUnit_ControllerTestCase; use \Icinga\Util\DateTimeFactory;
class ScheduleDowntimeFormTest extends BaseFormTest class ScheduleDowntimeFormTest extends BaseFormTest
{ {
const FORMCLASS = 'Monitoring\Form\Command\ScheduleDowntimeForm'; const FORM_CLASS = 'Monitoring\Form\Command\ScheduleDowntimeForm';
/**
* Set up the default time zone
*
* Utilizes singleton DateTimeFactory
*
* @backupStaticAttributes enabled
*/
public function setUp()
{
date_default_timezone_set('UTC');
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
}
public function testCorrectFormElementCreation() public function testCorrectFormElementCreation()
{ {
$formFixed = $this->getRequestForm(array(), self::FORMCLASS); $formFixed = $this->getRequestForm(array(), self::FORM_CLASS);
$formFixed->buildForm(); $formFixed->buildForm();
$formFlexible = $this->getRequestForm(array( $formFlexible = $this->getRequestForm(array(
'type' => 'flexible' 'type' => 'flexible'
), self::FORMCLASS); ), self::FORM_CLASS);
$formFlexible->buildForm(); $formFlexible->buildForm();
$this->assertCount(11, $formFixed->getElements()); $form = $this->getRequestForm(array(), self::FORM_CLASS);
$this->assertCount(13, $formFlexible->getElements());
$form = $this->getRequestForm(array(), self::FORMCLASS);
$form->setWithChildren(true); $form->setWithChildren(true);
$form->buildForm(); $form->buildForm();
$this->assertCount(12, $form->getElements());
} }
public function testCorrectValidationWithChildrend() public function testCorrectValidationWithChildrend()
{ {
$form = $this->getRequestForm(array( $form = $this->getRequestForm(array(
@ -47,8 +58,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest
'minutes' => '', 'minutes' => '',
'btn_submit' => 'foo', 'btn_submit' => 'foo',
// 'childobjects' => '', // 'childobjects' => '',
), self::FORMCLASS); ), self::FORM_CLASS);
$form->setWithChildren(true); $form->setWithChildren(true);
@ -67,14 +77,13 @@ class ScheduleDowntimeFormTest extends BaseFormTest
'minutes' => '10', 'minutes' => '10',
'btn_submit' => 'foo' 'btn_submit' => 'foo'
// 'childobjects' => '', // 'childobjects' => '',
), self::FORMCLASS); ), self::FORM_CLASS);
$form->setWithChildren(true); $form->setWithChildren(true);
$this->assertTrue( $this->assertTrue(
$form->isSubmittedAndValid(), $form->isSubmittedAndValid(),
'Asserting a correct flexible downtime form to be considered valid' 'Asserting a correct flexible downtime form to be considered valid'
); );
} }
public function testMissingFlexibleDurationRecognition() public function testMissingFlexibleDurationRecognition()
@ -89,7 +98,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest
'hours' => '', 'hours' => '',
'minutes' => '', 'minutes' => '',
// 'childobjects' => '', // 'childobjects' => '',
), self::FORMCLASS); ), self::FORM_CLASS);
$form->setWithChildren(true); $form->setWithChildren(true);
$this->assertFalse( $this->assertFalse(
@ -100,7 +109,6 @@ class ScheduleDowntimeFormTest extends BaseFormTest
public function testMissingAuthorRecognition() public function testMissingAuthorRecognition()
{ {
$form = $this->getRequestForm(array( $form = $this->getRequestForm(array(
'author' => '', 'author' => '',
'comment' => 'DING DING', 'comment' => 'DING DING',
@ -111,7 +119,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest
'hours' => '', 'hours' => '',
'minutes' => '', 'minutes' => '',
// 'childobjects' => '', // 'childobjects' => '',
), self::FORMCLASS); ), self::FORM_CLASS);
$form->setWithChildren(true); $form->setWithChildren(true);
@ -133,7 +141,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest
'hours' => '', 'hours' => '',
'minutes' => '', 'minutes' => '',
// 'childobjects' => '', // 'childobjects' => '',
), self::FORMCLASS); ), self::FORM_CLASS);
$form->setWithChildren(true); $form->setWithChildren(true);
@ -155,7 +163,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest
'hours' => '', 'hours' => '',
'minutes' => '', 'minutes' => '',
// 'childobjects' => '', // 'childobjects' => '',
), self::FORMCLASS); ), self::FORM_CLASS);
$form->setWithChildren(true); $form->setWithChildren(true);
$this->assertFalse( $this->assertFalse(
@ -176,7 +184,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest
'hours' => '', 'hours' => '',
'minutes' => '', 'minutes' => '',
// 'childobjects' => '', // 'childobjects' => '',
), self::FORMCLASS); ), self::FORM_CLASS);
$form->setWithChildren(true); $form->setWithChildren(true);
$this->assertFalse( $this->assertFalse(
@ -187,7 +195,6 @@ class ScheduleDowntimeFormTest extends BaseFormTest
public function testInvalidEndTimeRecognition() public function testInvalidEndTimeRecognition()
{ {
$form = $this->getRequestForm(array( $form = $this->getRequestForm(array(
'author' => 'OK', 'author' => 'OK',
'comment' => 'OK', 'comment' => 'OK',
@ -198,7 +205,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest
'hours' => '', 'hours' => '',
'minutes' => '', 'minutes' => '',
// 'childobjects' => '', // 'childobjects' => '',
), self::FORMCLASS); ), self::FORM_CLASS);
$form->setWithChildren(true); $form->setWithChildren(true);
$this->assertFalse( $this->assertFalse(
@ -220,7 +227,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest
'hours' => '-1', 'hours' => '-1',
'minutes' => '12', 'minutes' => '12',
// 'childobjects' => '', // 'childobjects' => '',
), self::FORMCLASS); ), self::FORM_CLASS);
$form->setWithChildren(true); $form->setWithChildren(true);
$this->assertFalse( $this->assertFalse(
@ -241,7 +248,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest
'hours' => '12', 'hours' => '12',
'minutes' => 'DING', 'minutes' => 'DING',
// 'childobjects' => '', // 'childobjects' => '',
), self::FORMCLASS); ), self::FORM_CLASS);
$form->setWithChildren(true); $form->setWithChildren(true);
$this->assertFalse( $this->assertFalse(
@ -264,13 +271,13 @@ class ScheduleDowntimeFormTest extends BaseFormTest
'minutes' => '', 'minutes' => '',
'btn_submit' => 'foo', 'btn_submit' => 'foo',
'childobjects' => '0', 'childobjects' => '0',
), self::FORMCLASS); ), self::FORM_CLASS);
$form->setWithChildren(false); $form->setWithChildren(false);
$this->assertTrue( $this->assertTrue(
$form->isSubmittedAndValid(), $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' => '', 'hours' => '',
'minutes' => '', 'minutes' => '',
'childobjects' => 'AHA', 'childobjects' => 'AHA',
), self::FORMCLASS); ), self::FORM_CLASS);
$form->setWithChildren(false); $form->setWithChildren(false);
$this->assertFalse( $this->assertFalse(
$form->isSubmittedAndValid(), $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( $form = $this->getRequestForm(array(
@ -303,18 +310,18 @@ class ScheduleDowntimeFormTest extends BaseFormTest
'hours' => '', 'hours' => '',
'minutes' => '', 'minutes' => '',
'childobjects' => '4', 'childobjects' => '4',
), self::FORMCLASS); ), self::FORM_CLASS);
$form->setWithChildren(false); $form->setWithChildren(false);
$this->assertFalse( $this->assertFalse(
$form->isSubmittedAndValid(), $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() public function testTimeRange()
{ {
$form = $this->getRequestForm(array(), self::FORMCLASS); $form = $this->getRequestForm(array(), self::FORM_CLASS);
$form->buildForm(); $form->buildForm();
$time1 = $form->getElement('starttime')->getValue(); $time1 = $form->getElement('starttime')->getValue();
@ -323,3 +330,4 @@ class ScheduleDowntimeFormTest extends BaseFormTest
$this->assertEquals(3600, ($time2 - $time1)); $this->assertEquals(3600, ($time2 - $time1));
} }
} }
// @codingStandardsIgnoreStop

View File

@ -1,38 +1,37 @@
<?php <?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Test\Monitoring\Forms\Command; namespace Test\Monitoring\Forms\Command;
require_once __DIR__. '/BaseFormTest.php'; require_once realpath(__DIR__ . '/BaseFormTest.php');
require_once __DIR__. '/../../../../../application/forms/Command/CommandForm.php'; require_once realpath(__DIR__ . '/../../../../../application/forms/Command/SubmitPassiveCheckResultForm.php');
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommandForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/SubmitPassiveCheckResultForm.php';
use \Monitoring\Form\Command\SubmitPassiveCheckResultForm; // Used by constant FORM_CLASS
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
use Monitoring\Form\Command\SubmitPassiveCheckResultForm;
class SubmitPassiveCheckResultFormTest extends BaseFormTest class SubmitPassiveCheckResultFormTest extends BaseFormTest
{ {
const FORMCLASS = "Monitoring\Form\Command\SubmitPassiveCheckResultForm"; const FORM_CLASS = 'Monitoring\Form\Command\SubmitPassiveCheckResultForm';
public function testStateTypes() public function testStateTypes()
{ {
$form = $this->getRequestForm(array(), self::FORMCLASS); $form = $this->getRequestForm(array(), self::FORM_CLASS);
$form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE); $form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
$options = $form->getOptions(); $options = $form->getOptions();
$this->assertCount(4, $options, "Assert correct number of states in service passive checks 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('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('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('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->assertEquals('UNKNOWN', $options[3], 'Assert UNKNOWN state to be available in service passive check form');
$form->setType(SubmitPassiveCheckResultForm::TYPE_HOST); $form->setType(SubmitPassiveCheckResultForm::TYPE_HOST);
$options = $form->getOptions(); $options = $form->getOptions();
$this->assertCount(3, $options, "Assert correct number of states in host passive checks 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('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('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->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() public function testMissingTypeThrowingException()
{ {
$form = $this->getRequestForm(array(), self::FORMCLASS); $form = $this->getRequestForm(array(), self::FORM_CLASS);
$form->buildForm(); $form->buildForm();
} }
public function testCorrectFormCreation() public function testCorrectFormCreation()
{ {
$form = $this->getRequestForm(array(), self::FORMCLASS); $form = $this->getRequestForm(array(), self::FORM_CLASS);
$form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE); $form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
$form->buildForm(); $form->buildForm();
$this->assertCount(6, $form->getElements(), "Assert correct number of elements in form");
} }
public function testCorrectServicePassiveCheckSubmission() public function testCorrectServicePassiveCheckSubmission()
@ -61,13 +58,13 @@ class SubmitPassiveCheckResultFormTest extends BaseFormTest
'checkoutput' => 'DING', 'checkoutput' => 'DING',
'performancedata' => '', 'performancedata' => '',
'btn_submit' => 'foo' 'btn_submit' => 'foo'
), self::FORMCLASS); ), self::FORM_CLASS);
$form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE); $form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
$this->assertTrue( $this->assertTrue(
$form->isSubmittedAndValid(), $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, 'pluginstate' => 0,
'checkoutput' => '', 'checkoutput' => '',
'performancedata' => '' 'performancedata' => ''
), self::FORMCLASS); ), self::FORM_CLASS);
$form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE); $form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
$this->assertFalse( $this->assertFalse(
$form->isSubmittedAndValid(), $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', 'pluginstate' => 'LA',
'checkoutput' => 'DING', 'checkoutput' => 'DING',
'performancedata' => '' 'performancedata' => ''
), self::FORMCLASS); ), self::FORM_CLASS);
$form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE); $form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
$this->assertFalse( $this->assertFalse(
$form->isSubmittedAndValid(), $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'
); );
} }
} }