mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-26 07:14:35 +02:00
parent
26f7b740c5
commit
5e85dd1c06
@ -58,9 +58,10 @@ class RescheduleNextCheckForm extends WithChildrenCommandForm
|
|||||||
$this->addElement(
|
$this->addElement(
|
||||||
new DateTimePicker(
|
new DateTimePicker(
|
||||||
array(
|
array(
|
||||||
'name' => 'checktime',
|
'name' => 'checktime',
|
||||||
'label' => t('Check Time'),
|
'label' => t('Check Time'),
|
||||||
'value' => DateTimeFactory::create()->getTimestamp()
|
'value' => DateTimeFactory::create()->getTimestamp(),
|
||||||
|
'required' => !$this->getRequest()->getPost('forcecheck')
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -1,102 +1,70 @@
|
|||||||
<?php
|
<?php
|
||||||
|
// @codingStandardsIgnoreStart
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
namespace Test\Monitoring\Forms\Command;
|
namespace Test\Monitoring\Forms\Command;
|
||||||
|
|
||||||
|
require_once realpath(__DIR__ . '/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 __DIR__. '/BaseFormTest.php';
|
use \Monitoring\Form\Command\RescheduleNextCheckForm; // Used by constant FORM_CLASS
|
||||||
require_once __DIR__. '/../../../../../application/forms/Command/CommandForm.php';
|
use \DateTimeZone;
|
||||||
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommandForm.php';
|
use \Icinga\Util\DateTimeFactory;
|
||||||
require_once __DIR__. '/../../../../../application/forms/Command/RescheduleNextCheckForm.php';
|
|
||||||
|
|
||||||
|
|
||||||
use Monitoring\Form\Command\RescheduleNextCheckForm;
|
|
||||||
use \Zend_View;
|
|
||||||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
|
||||||
|
|
||||||
class RescheduleNextCheckFormTest extends BaseFormTest
|
class RescheduleNextCheckFormTest extends BaseFormTest
|
||||||
{
|
{
|
||||||
|
const FORM_CLASS = 'Monitoring\Form\Command\RescheduleNextCheckForm';
|
||||||
|
|
||||||
const FORMCLASS = 'Monitoring\Form\Command\RescheduleNextCheckForm';
|
/**
|
||||||
|
* Set up the default time zone
|
||||||
public function testValidRescheduleSubmissions()
|
*
|
||||||
|
* Utilizes singleton DateTimeFactory
|
||||||
|
*
|
||||||
|
* @backupStaticAttributes enabled
|
||||||
|
*/
|
||||||
|
public function setUp()
|
||||||
{
|
{
|
||||||
|
date_default_timezone_set('UTC');
|
||||||
$form = $this->getRequestForm(array(
|
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
||||||
'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'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInValidRescheduleChecktimeSubmissions()
|
public function testFormInvalidWhenChecktimeIsIncorrect()
|
||||||
{
|
{
|
||||||
$form = $this->getRequestForm(array(
|
$form = $this->getRequestForm(array(
|
||||||
'checktime' => '2013-24-12 17:30:00',
|
'checktime' => '2013-24-12 17:30:00',
|
||||||
'forcecheck' => 1
|
'forcecheck' => 0,
|
||||||
), self::FORMCLASS);
|
'btn_submit' => 'Submit'
|
||||||
|
), self::FORM_CLASS);
|
||||||
|
|
||||||
$this->assertFalse(
|
$this->assertFalse(
|
||||||
$form->isSubmittedAndValid(),
|
$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(
|
$form2 = $this->getRequestForm(array(
|
||||||
'checktime' => 'AHAHA',
|
'checktime' => 'Captain Morgan',
|
||||||
'forcecheck' => 1
|
'forcecheck' => 1,
|
||||||
), self::FORMCLASS);
|
'btn_submit' => 'Submit'
|
||||||
|
), self::FORM_CLASS);
|
||||||
|
|
||||||
$this->assertFalse(
|
$this->assertFalse(
|
||||||
$form->isSubmittedAndValid(),
|
$form2->isSubmittedAndValid(),
|
||||||
'Asserting an invalid non-numeric checktime to be considered as invalid reschedule data'
|
'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();
|
$this->assertFalse(
|
||||||
$form->setRequest($this->getRequest());
|
$form3->isSubmittedAndValid(),
|
||||||
$form->setWithChildren(true);
|
'Missing checktime must be considered invalid'
|
||||||
$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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// @codingStandardsIgnoreStop
|
||||||
|
Loading…
x
Reference in New Issue
Block a user