Monitoring/Tests: Replace BaseFormTest with BaseTestCase

refs #4586
This commit is contained in:
Eric Lippmann 2013-09-03 14:23:01 +02:00 committed by Jannis Moßhammer
parent 6f383abdd1
commit 3e4d1aa2fb
8 changed files with 290 additions and 307 deletions

View File

@ -1,27 +1,27 @@
<?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Test\Monitoring\Forms\Command;
require_once realpath('library/Icinga/Web/Form/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__ . '/../../../../../../../library/Icinga/Test/BaseTestCase.php');
use Icinga\Test\BaseTestCase;
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/CommandForm.php';
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/AcknowledgeForm.php';
require_once BaseTestCase::$libDir . '/Util/ConfigAwareFactory.php';
require_once BaseTestCase::$libDir . '/Util/DateTimeFactory.php';
use \DateTimeZone;
use \Icinga\Module\Monitoring\Form\Command\AcknowledgeForm; // Used by constant FORMCLASS
use \Icinga\Util\DateTimeFactory;
use \Test\Icinga\Web\Form\BaseFormTest;
use Icinga\Util\DateTimeFactory;
class AcknowledgeFormTest extends BaseFormTest
class AcknowledgeFormTest extends BaseTestCase
{
const FORMCLASS = '\Icinga\Module\Monitoring\Form\Command\AcknowledgeForm';
const FORM_CLASS = 'Icinga\Module\Monitoring\Form\Command\AcknowledgeForm';
/**
* Set up the default time zone
* Set DateTimeFactory's time zone to UTC
*
* Utilizes singleton DateTimeFactory
*
@ -29,38 +29,41 @@ class AcknowledgeFormTest extends BaseFormTest
*/
public function setUp()
{
date_default_timezone_set('UTC');
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
}
public function testFormValid()
{
$form = $this->getRequestForm(array(
'author' => 'Author',
'comment' => 'Comment',
'persistent' => '0',
'expire' => '0',
'sticky' => '0',
'notify' => '0',
'btn_submit' => 'Submit'
), self::FORMCLASS);
$form = $this->createForm(
self::FORM_CLASS,
array(
'author' => 'Author',
'comment' => 'Comment',
'persistent' => '0',
'expire' => '0',
'sticky' => '0',
'notify' => '0',
'btn_submit' => 'Submit'
)
);
$this->assertTrue(
$form->isSubmittedAndValid(),
'Legal request data without expire time must be considered valid'
);
$formWithExpireTime = $this->getRequestForm(array(
'author' => 'Author',
'comment' => 'Comment',
'persistent' => '0',
'expire' => '1',
'expiretime' => '10/07/2013 5:32 PM',
'sticky' => '0',
'notify' => '0',
'btn_submit' => 'Submit'
), self::FORMCLASS);
$formWithExpireTime = $this->createForm(
self::FORM_CLASS,
array(
'author' => 'Author',
'comment' => 'Comment',
'persistent' => '0',
'expire' => '1',
'expiretime' => '10/07/2013 5:32 PM',
'sticky' => '0',
'notify' => '0',
'btn_submit' => 'Submit'
)
);
$this->assertTrue(
$formWithExpireTime->isSubmittedAndValid(),
'Legal request data with expire time must be considered valid'
@ -69,16 +72,18 @@ class AcknowledgeFormTest extends BaseFormTest
public function testFormInvalidWhenCommentMissing()
{
$form = $this->getRequestForm(array(
'author' => 'Author',
'comment' => '',
'persistent' => '0',
'expire' => '0',
'sticky' => '0',
'notify' => '0',
'btn_submit' => 'Submit'
), self::FORMCLASS);
$form = $this->createForm(
self::FORM_CLASS,
array(
'author' => 'Author',
'comment' => '',
'persistent' => '0',
'expire' => '0',
'sticky' => '0',
'notify' => '0',
'btn_submit' => 'Submit'
)
);
$this->assertFalse(
$form->isSubmittedAndValid(),
'Missing comment must be considered not valid'
@ -87,16 +92,18 @@ class AcknowledgeFormTest extends BaseFormTest
public function testFormInvalidWhenExpireTimeMissingAndExpireSet()
{
$form = $this->getRequestForm(array(
'author' => 'Author',
'comment' => 'Comment',
'persistent' => '0',
'expire' => '1',
'sticky' => '0',
'notify' => '0',
'btn_submit' => 'Submit'
), self::FORMCLASS);
$form = $this->createForm(
self::FORM_CLASS,
array(
'author' => 'Author',
'comment' => 'Comment',
'persistent' => '0',
'expire' => '1',
'sticky' => '0',
'notify' => '0',
'btn_submit' => 'Submit'
)
);
$this->assertFalse(
$form->isSubmittedAndValid(),
'If expire is set and expire time is missing, the form must not be valid'
@ -105,21 +112,22 @@ class AcknowledgeFormTest extends BaseFormTest
public function testFormInvalidWhenExpireTimeIsIncorrectAndExpireSet()
{
$form = $this->getRequestForm(array(
'author' => 'Author',
'comment' => 'Comment',
'persistent' => '0',
'expire' => '1',
'expiretime' => 'Not a date',
'sticky' => '0',
'notify' => '0',
'btn_submit' => 'Submit'
), self::FORMCLASS);
$form = $this->createForm(
self::FORM_CLASS,
array(
'author' => 'Author',
'comment' => 'Comment',
'persistent' => '0',
'expire' => '1',
'expiretime' => 'Not a date',
'sticky' => '0',
'notify' => '0',
'btn_submit' => 'Submit'
)
);
$this->assertFalse(
$form->isSubmittedAndValid(),
'If expire is set and expire time is incorrect, the form must not be valid'
);
}
}
// @codingStandardsIgnoreStop

View File

@ -1,29 +1,31 @@
<?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Test\Monitoring\Forms\Command;
require_once realpath('library/Icinga/Web/Form/BaseFormTest.php');
require_once realpath(__DIR__ . '/../../../../../../../modules/monitoring/application/forms/Command/CommentForm.php');
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Test/BaseTestCase.php');
use \Icinga\Module\Monitoring\Form\Command\CommentForm; // Used by constant FORMCLASS
use \Test\Icinga\Web\Form\BaseFormTest;
use Icinga\Test\BaseTestCase;
class CommentFormTest extends BaseFormTest
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/CommandForm.php';
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/CommentForm.php';
class CommentFormTest extends BaseTestCase
{
const FORMCLASS = '\Icinga\Module\Monitoring\Form\Command\CommentForm';
const FORM_CLASS = 'Icinga\Module\Monitoring\Form\Command\CommentForm';
public function testCorrectCommentValidation()
{
$form = $this->getRequestForm(array(
'author' => 'Author',
'comment' => 'Comment',
'sticky' => '0',
'btn_submit' => 'Submit'
), self::FORMCLASS);
$form = $this->createForm(
self::FORM_CLASS,
array(
'author' => 'Author',
'comment' => 'Comment',
'sticky' => '0',
'btn_submit' => 'Submit'
)
);
$this->assertTrue(
$form->isSubmittedAndValid(),
'Legal request data must be considered valid'
@ -32,14 +34,16 @@ class CommentFormTest extends BaseFormTest
public function testFormInvalidWhenCommentMissing()
{
$form = $this->getRequestForm(array(
'author' => 'Author',
'comment' => '',
'sticky' => '0',
'btn_submit' => 'Submit'
), self::FORMCLASS);
$form = $this->createForm(
self::FORM_CLASS,
array(
'author' => 'Author',
'comment' => '',
'sticky' => '0',
'btn_submit' => 'Submit'
)
);
$this->assertFalse(
$form->isSubmittedAndValid(),
'Missing comment must be considered not valid'
@ -48,17 +52,18 @@ class CommentFormTest extends BaseFormTest
public function testFormInvalidWhenAuthorMissing()
{
$form = $this->getRequestForm(array(
'author' => '',
'comment' => 'Comment',
'sticky' => '0',
'btn_submit' => 'Submit'
), self::FORMCLASS);
$form = $this->createForm(
self::FORM_CLASS,
array(
'author' => '',
'comment' => 'Comment',
'sticky' => '0',
'btn_submit' => 'Submit'
)
);
$this->assertFalse(
$form->isSubmittedAndValid(),
'Missing author must be considered not valid'
);
}
}
// @codingStandardsIgnoreEnd

View File

@ -1,81 +1,63 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Test\Monitoring\Forms\Command;
require_once realpath('library/Icinga/Web/Form/BaseFormTest.php');
require_once __DIR__. '/../../../../../application/forms/Command/CommandForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommandForm.php';
require_once __DIR__. '/../../../../../application/forms/Command/CommandWithIdentifierForm.php';
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Test/BaseTestCase.php');
use \Icinga\Module\Monitoring\Form\Command\CommandWithIdentifierForm;
use \Zend_View;
use \Zend_Test_PHPUnit_ControllerTestCase;
use \Test\Icinga\Web\Form\BaseFormTest;
use Icinga\Test\BaseTestCase;
class CommandWithIdentifierFormTest extends BaseFormTest
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/CommandForm.php';
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/WithChildrenCommandForm.php';
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/CommandWithIdentifierForm.php';
class CommandWithIdentifierFormTest extends BaseTestCase
{
const FORMCLASS = "\Icinga\Module\Monitoring\Form\Command\CommandWithIdentifierForm";
public function testForm()
const FORM_CLASS = '\Icinga\Module\Monitoring\Form\Command\CommandWithIdentifierForm';
public function testFormInvalidWhenObjectIdMissing()
{
$form = $this->getRequestForm(array(), self::FORMCLASS);
$form->setSubmitLabel('DING DING');
$form->buildForm();
$this->assertCount(4, $form->getElements());
}
public function testCorrectFormValidation()
{
$form = $this->getRequestForm(array(
'testval' => 123,
'btn_submit' => 'foo'
), self::FORMCLASS);
$form->setFieldLabel('Test1');
$form->setFieldName('testval');
$form->setSubmitLabel('DING DING');
$this->assertTrue(
$form->isSubmittedAndValid(),
"Asserting correct confirmation with id to be valid"
$form = $this->createForm(
self::FORM_CLASS,
array(
'object_id' => '',
'btn_submit' => 'Submit'
)
);
}
public function testInvalidValueValidationErrors()
{
$form = $this->getRequestForm(array(
'testval' => ''
), self::FORMCLASS);
$this->assertFalse(
$form->isSubmittedAndValid(),
"Asserting an invalid (empty) value to cause validation errors"
'Missing object_id must be considered not valid'
);
}
public function testNonNumericValueValidationErrors()
public function testFormInvalidWhenObjectIdNonDigit()
{
$form = $this->getRequestForm(array(
'testval' => 'NaN'
), self::FORMCLASS);
$form = $this->createForm(
self::FORM_CLASS,
array(
'object_id' => 'A Service',
'btn_submit' => 'Submit'
)
);
$this->assertFalse(
$form->isSubmittedAndValid(),
"Asserting an non numeric value to cause validation errors"
'Non numeric input must be considered not valid'
);
}
public function testRequestBridge()
public function testFormValidWhenObjectIdIsDigit()
{
$form = $this->getRequestForm(array(
'objectid' => 123123666
), self::FORMCLASS);
$form->buildForm();
$this->assertTrue($form->isSubmittedAndValid());
$this->assertEquals('123123666', $form->getElement('objectid')->getValue());
$form = $this->createForm(
self::FORM_CLASS,
array(
'object_id' => 1,
'btn_submit' => 'Submit'
)
);
$this->assertFalse(
$form->isSubmittedAndValid(),
'Digits must be considered valid'
);
}
}

View File

@ -1,32 +1,33 @@
<?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Test\Monitoring\Forms\Command;
require_once realpath('library/Icinga/Web/Form/BaseFormTest.php');
require_once realpath(__DIR__ . '/../../../../../application/forms/Command/CustomNotificationForm.php');
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Test/BaseTestCase.php');
use \Test\Icinga\Web\Form\BaseFormTest;
use \Icinga\Module\Monitoring\Form\Command\CustomNotificationForm; // Used by constant FORM_CLASS
use Icinga\Test\BaseTestCase;
class CustomNotificationFormTest extends BaseFormTest
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/CommandForm.php';
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/CustomNotificationForm.php';
class CustomNotificationFormTest extends BaseTestCase
{
const FORM_CLASS = '\Icinga\Module\Monitoring\Form\Command\CustomNotificationForm';
const FORM_CLASS = 'Icinga\Module\Monitoring\Form\Command\CustomNotificationForm';
public function testFormInvalidWhenCommentMissing()
{
$form = $this->getRequestForm(array(
'author' => 'Author',
'comment' => '',
'btn_submit' => 'Submit'
), self::FORM_CLASS);
$form = $this->createForm(
self::FORM_CLASS,
array(
'author' => 'Author',
'comment' => '',
'btn_submit' => 'Submit'
)
);
$this->assertFalse(
$form->isSubmittedAndValid(),
'Missing comment must be considered not valid'
);
}
}
// @codingStandardsIgnoreEnd

View File

@ -1,27 +1,31 @@
<?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Test\Monitoring\Forms\Command;
require_once realpath('library/Icinga/Web/Form/BaseFormTest.php');
require_once realpath(__DIR__ . '/../../../../../application/forms/Command/DelayNotificationForm.php');
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Test/BaseTestCase.php');
use \Test\Icinga\Web\Form\BaseFormTest;
use \Icinga\Module\Monitoring\Form\Command\DelayNotificationForm; // Used by constant FORM_CLASS
use Icinga\Test\BaseTestCase;
class DelayNotificationFormTest extends BaseFormTest
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/CommandForm.php';
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/DelayNotificationForm.php';
use Icinga\Module\Monitoring\Form\Command\DelayNotificationForm;
class DelayNotificationFormTest extends BaseTestCase
{
const FORM_CLASS = '\Icinga\Module\Monitoring\Form\Command\DelayNotificationForm';
const FORM_CLASS = 'Icinga\Module\Monitoring\Form\Command\DelayNotificationForm';
public function testFormInvalidWhenNotificationDelayMissing()
{
$form = $this->getRequestForm(array(
'minutes' => '',
'btn_submit' => 'Submit'
), self::FORM_CLASS);
$form = $this->createForm(
self::FORM_CLASS,
array(
'minutes' => '',
'btn_submit' => 'Submit'
)
);
$this->assertFalse(
$form->isSubmittedAndValid(),
'Missing notification delay must be considered invalid'
@ -30,11 +34,13 @@ class DelayNotificationFormTest extends BaseFormTest
public function testFormInvalidWhenNotificationDelayNaN()
{
$form = $this->getRequestForm(array(
'minutes' => 'A String',
'btn_submit' => 'Submit'
), self::FORM_CLASS);
$form = $this->createForm(
self::FORM_CLASS,
array(
'minutes' => 'A String',
'btn_submit' => 'Submit'
)
);
$this->assertFalse(
$form->isSubmittedAndValid(),
'Incorrect notification delay, i.e. NaN must be considered invalid'
@ -43,15 +49,16 @@ class DelayNotificationFormTest extends BaseFormTest
public function testFormInvalidWhenNotificationDelayOverflows()
{
$form = $this->getRequestForm(array(
'minutes' => DelayNotificationForm::MAX_DELAY + 1,
'btn_submit' => 'Submit'
), self::FORM_CLASS);
$form = $this->createForm(
self::FORM_CLASS,
array(
'minutes' => DelayNotificationForm::MAX_DELAY + 1,
'btn_submit' => 'Submit'
)
);
$this->assertFalse(
$form->isSubmittedAndValid(),
'Notification delay bigger than constant "DelayNotificationForm::MAX_DELAY" must be considered invalid'
);
}
}
// @codingStandardsIgnoreEnd

View File

@ -1,26 +1,28 @@
<?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Test\Monitoring\Forms\Command;
require_once realpath('library/Icinga/Web/Form/BaseFormTest.php');
require_once realpath(__DIR__ . '/../../../../../application/forms/Command/RescheduleNextCheckForm.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/Test/BaseTestCase.php');
use Icinga\Test\BaseTestCase;
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/CommandForm.php';
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/WithChildrenCommandForm.php';
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/RescheduleNextCheckForm.php';
require_once BaseTestCase::$libDir . '/Util/ConfigAwareFactory.php';
require_once BaseTestCase::$libDir . '/Util/DateTimeFactory.php';
use \Icinga\Module\Monitoring\Form\Command\RescheduleNextCheckForm; // Used by constant FORM_CLASS
use \DateTimeZone;
use \Icinga\Util\DateTimeFactory;
use \Test\Icinga\Web\Form\BaseFormTest;
use Icinga\Util\DateTimeFactory;
class RescheduleNextCheckFormTest extends BaseFormTest
class RescheduleNextCheckFormTest extends BaseTestCase
{
const FORM_CLASS = '\Icinga\Module\Monitoring\Form\Command\RescheduleNextCheckForm';
const FORM_CLASS = 'Icinga\Module\Monitoring\Form\Command\RescheduleNextCheckForm';
/**
* Set up the default time zone
* Set DateTimeFactory's time zone to UTC
*
* Utilizes singleton DateTimeFactory
*
@ -28,44 +30,48 @@ class RescheduleNextCheckFormTest extends BaseFormTest
*/
public function setUp()
{
date_default_timezone_set('UTC');
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
}
public function testFormInvalidWhenChecktimeIsIncorrect()
{
$form = $this->getRequestForm(array(
'checktime' => '2013-24-12 17:30:00',
'forcecheck' => 0,
'btn_submit' => 'Submit'
), self::FORM_CLASS);
$form = $this->createForm(
self::FORM_CLASS,
array(
'checktime' => '2013-24-12 17:30:00',
'forcecheck' => 0,
'btn_submit' => 'Submit'
)
);
$this->assertFalse(
$form->isSubmittedAndValid(),
'Asserting a logically incorrect checktime as invalid'
);
$form2 = $this->getRequestForm(array(
'checktime' => 'Captain Morgan',
'forcecheck' => 1,
'btn_submit' => 'Submit'
), self::FORM_CLASS);
$form2 = $this->createForm(
self::FORM_CLASS,
array(
'checktime' => 'Captain Morgan',
'forcecheck' => 1,
'btn_submit' => 'Submit'
)
);
$this->assertFalse(
$form2->isSubmittedAndValid(),
'Providing arbitrary strings as checktime must be considered invalid'
);
$form3 = $this->getRequestForm(array(
'checktime' => '',
'forcecheck' => 0,
'btn_submit' => 'Submit'
), self::FORM_CLASS);
$form3 = $this->createForm(
self::FORM_CLASS,
array(
'checktime' => '',
'forcecheck' => 0,
'btn_submit' => 'Submit'
)
);
$this->assertFalse(
$form3->isSubmittedAndValid(),
'Missing checktime must be considered invalid'
);
}
}
// @codingStandardsIgnoreStop

View File

@ -1,68 +1,87 @@
<?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Test\Monitoring\Forms\Command;
require_once realpath('library/Icinga/Web/Form/BaseFormTest.php');
require_once realpath(__DIR__ . '/../../../../../application/forms/Command/SubmitPassiveCheckResultForm.php');
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Test/BaseTestCase.php');
use \Test\Icinga\Web\Form\BaseFormTest;
use \Icinga\Module\Monitoring\Form\Command\SubmitPassiveCheckResultForm; // Used by constant FORM_CLASS
use Icinga\Test\BaseTestCase;
class SubmitPassiveCheckResultFormTest extends BaseFormTest
require_once BaseTestCase::$libDir . '/Exception/ProgrammingError.php';
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/CommandForm.php';
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/SubmitPassiveCheckResultForm.php';
use Icinga\Module\Monitoring\Form\Command\SubmitPassiveCheckResultForm;
class SubmitPassiveCheckResultFormTest extends BaseTestCase
{
const FORM_CLASS = '\Icinga\Module\Monitoring\Form\Command\SubmitPassiveCheckResultForm';
const FORM_CLASS = 'Icinga\Module\Monitoring\Form\Command\SubmitPassiveCheckResultForm';
public function testStateTypes()
{
$form = $this->getRequestForm(array(), self::FORM_CLASS);
$form = $this->createForm(self::FORM_CLASS, array());
$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->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->assertEquals(
'UNREACHABLE',
$options[2],
'Assert UNREACHABLE state to be available in host passive check form'
);
}
/**
* @expectedException Icinga\Exception\ProgrammingError
* @expectedExceptionMessage Type is not valid
* @expectedException Icinga\Exception\ProgrammingError
* @expectedExceptionMessage Type is not valid
*/
public function testMissingTypeThrowingException()
{
$form = $this->getRequestForm(array(), self::FORM_CLASS);
$form = $this->createForm(self::FORM_CLASS, array());
$form->buildForm();
}
public function testCorrectFormCreation()
{
$form = $this->getRequestForm(array(), self::FORM_CLASS);
$form = $this->createForm(self::FORM_CLASS, array());
$form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
$form->buildForm();
}
public function testCorrectServicePassiveCheckSubmission()
{
$form = $this->getRequestForm(array(
'pluginstate' => 0,
'checkoutput' => 'DING',
'performancedata' => '',
'btn_submit' => 'foo'
), self::FORM_CLASS);
$form = $this->createForm(
self::FORM_CLASS,
array(
'pluginstate' => 0,
'checkoutput' => 'DING',
'performancedata' => '',
'btn_submit' => 'foo'
)
);
$form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
$this->assertTrue(
$form->isSubmittedAndValid(),
'Assert a correct passive service check form to pass form validation'
@ -71,13 +90,15 @@ class SubmitPassiveCheckResultFormTest extends BaseFormTest
public function testIncorrectCheckoutputRecognition()
{
$form = $this->getRequestForm(array(
'pluginstate' => 0,
'checkoutput' => '',
'performancedata' => ''
), self::FORM_CLASS);
$form = $this->createForm(
self::FORM_CLASS,
array(
'pluginstate' => 0,
'checkoutput' => '',
'performancedata' => ''
)
);
$form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
$this->assertFalse(
$form->isSubmittedAndValid(),
'Assert empty checkoutput to cause validation errors in passive service check '
@ -86,13 +107,15 @@ class SubmitPassiveCheckResultFormTest extends BaseFormTest
public function testIncorrectStateRecognition()
{
$form = $this->getRequestForm(array(
'pluginstate' => 'LA',
'checkoutput' => 'DING',
'performancedata' => ''
), self::FORM_CLASS);
$form = $this->createForm(
self::FORM_CLASS,
array(
'pluginstate' => 'LA',
'checkoutput' => 'DING',
'performancedata' => ''
)
);
$form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
$this->assertFalse(
$form->isSubmittedAndValid(),
'Assert invalid (non-numeric) state to cause validation errors in passive service check'

View File

@ -1,49 +0,0 @@
<?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace {
if (!function_exists('t')) {
function t() {
return func_get_arg(0);
}
}
if (!function_exists('mt')) {
function mt() {
return func_get_arg(0);
}
}
}
namespace Test\Icinga\Web\Form {
require_once realpath('../../library/Icinga/Test/BaseTestCase.php');
use \Icinga\Test\BaseTestCase;
/**
* Base test to be extended for testing forms
*/
class BaseFormTest extends BaseTestCase
{
/**
* Temporary wrapper for BaseTestCase::createForm until this testcase is not used anymore
*/
public function getRequestForm(array $data, $formClass)
{
return $this->createForm($formClass, $data);
}
/**
* This is just a test to avoid warnings being submitted from the testrunner
*
*/
public function testForRemovingWarnings()
{
$this->assertTrue(true);
}
}
}