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

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/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;

View File

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

View File

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

View File

@ -1,39 +1,50 @@
<?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
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/ScheduleDowntimeForm.php';
require_once realpath(__DIR__ . '/BaseFormTest.php');
require_once realpath(__DIR__ . '/../../../../../../../modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php');
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Util/ConfigAwareFactory.php');
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Util/DateTimeFactory.php');
use Monitoring\Form\Command\ScheduleDowntimeForm;
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
use \Monitoring\Form\Command\ScheduleDowntimeForm; // Used by constant FORM_CLASS
use \DateTimeZone;
use \Icinga\Util\DateTimeFactory;
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()
{
$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

View File

@ -1,38 +1,37 @@
<?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
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/SubmitPassiveCheckResultForm.php';
require_once realpath(__DIR__ . '/BaseFormTest.php');
require_once realpath(__DIR__ . '/../../../../../application/forms/Command/SubmitPassiveCheckResultForm.php');
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
use Monitoring\Form\Command\SubmitPassiveCheckResultForm;
use \Monitoring\Form\Command\SubmitPassiveCheckResultForm; // Used by constant FORM_CLASS
class SubmitPassiveCheckResultFormTest extends BaseFormTest
{
const FORMCLASS = "Monitoring\Form\Command\SubmitPassiveCheckResultForm";
const FORM_CLASS = 'Monitoring\Form\Command\SubmitPassiveCheckResultForm';
public function testStateTypes()
{
$form = $this->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'
);
}
}