parent
3676c95afc
commit
6e3e3c358b
|
@ -120,7 +120,7 @@ abstract class AbstractCommand extends Form
|
|||
/**
|
||||
* Purge messages from stack
|
||||
*/
|
||||
public function purgeNotes()
|
||||
public function clearNotes()
|
||||
{
|
||||
$this->notes = array();
|
||||
}
|
||||
|
@ -207,10 +207,10 @@ abstract class AbstractCommand extends Form
|
|||
|
||||
$authorField = new Zend_Form_Element_Hidden(
|
||||
array(
|
||||
'name' => 'author',
|
||||
'label' => t('Author name'),
|
||||
'value' => $authorName,
|
||||
'required' => true
|
||||
'name' => 'author',
|
||||
'label' => t('Author name'),
|
||||
'value' => $authorName,
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ class RescheduleNextCheck extends WithChildrenCommand
|
|||
array(
|
||||
'name' => 'checktime',
|
||||
'label' => t('Check time'),
|
||||
'value' => $now->format('Y-m-d H:i:s')
|
||||
'value' => $now->format($this->getDateFormat())
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -210,6 +210,7 @@ class ScheduleDowntime extends WithChildrenCommand
|
|||
'childobjects',
|
||||
array(
|
||||
'label' => t('Child objects'),
|
||||
'required' => true,
|
||||
'multiOptions' => array(
|
||||
0 => t('Do nothing with child objects'),
|
||||
1 => t('Schedule triggered downtime for all child objects'),
|
||||
|
|
|
@ -105,7 +105,7 @@ class SubmitPassiveCheckResult extends AbstractCommand
|
|||
* @return array
|
||||
* @throws \Icinga\Exception\ProgrammingError
|
||||
*/
|
||||
private function getOptions()
|
||||
public function getOptions()
|
||||
{
|
||||
if (in_array($this->getType(), array(self::TYPE_HOST, self::TYPE_SERVICE)) === false) {
|
||||
throw new ProgrammingError('Type is not valid');
|
||||
|
|
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
|
||||
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\Monitoring\Forms\Command {
|
||||
|
||||
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
|
||||
require_once 'Zend/Form.php';
|
||||
require_once 'Zend/View.php';
|
||||
require_once 'Zend/Form/Element/Submit.php';
|
||||
require_once 'Zend/Form/Element/Reset.php';
|
||||
require_once 'Zend/Form/Element/Checkbox.php';
|
||||
require_once 'Zend/Validate/Date.php';
|
||||
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Exception/ProgrammingError.php';
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php';
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php';
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/DateTime.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/AbstractCommand.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommand.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/Acknowledge.php';
|
||||
|
||||
use Monitoring\Form\Command\Acknowledge;
|
||||
use \Zend_View;
|
||||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
||||
|
||||
class AcknowledgeTest extends Zend_Test_PHPUnit_ControllerTestCase
|
||||
{
|
||||
public function testForm()
|
||||
{
|
||||
$form = new Acknowledge();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->buildForm();
|
||||
|
||||
$this->assertCount(11, $form->getElements());
|
||||
}
|
||||
|
||||
public function testValidation1()
|
||||
{
|
||||
$form = new Acknowledge();
|
||||
$form->setRequest($this->getRequest());
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isValid(
|
||||
array(
|
||||
'author' => 'test1',
|
||||
'comment' => 'test comment',
|
||||
'persistent' => '0',
|
||||
'expire' => '0',
|
||||
'expiretime' => '',
|
||||
'sticky' => '0',
|
||||
'notify' => '0'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValid(
|
||||
array(
|
||||
'author' => 'test1',
|
||||
'comment' => '',
|
||||
'persistent' => '0',
|
||||
'expire' => '0',
|
||||
'expiretime' => '',
|
||||
'sticky' => '0',
|
||||
'notify' => '0'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValid(
|
||||
array(
|
||||
'author' => 'test1',
|
||||
'comment' => 'test comment',
|
||||
'persistent' => '0',
|
||||
'expire' => '1',
|
||||
'expiretime' => '',
|
||||
'sticky' => '0',
|
||||
'notify' => '0'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValid(
|
||||
array(
|
||||
'author' => 'test1',
|
||||
'comment' => 'test comment',
|
||||
'persistent' => '0',
|
||||
'expire' => '1',
|
||||
'expiretime' => 'NOT A DATE',
|
||||
'sticky' => '0',
|
||||
'notify' => '0'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isValid(
|
||||
array(
|
||||
'author' => 'test1',
|
||||
'comment' => 'test comment',
|
||||
'persistent' => '0',
|
||||
'expire' => '1',
|
||||
'expiretime' => '2013-07-10 17:32:16',
|
||||
'sticky' => '0',
|
||||
'notify' => '0'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
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\Monitoring\Forms\Command {
|
||||
|
||||
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
|
||||
require_once 'Zend/Form.php';
|
||||
require_once 'Zend/View.php';
|
||||
require_once 'Zend/Form/Element/Submit.php';
|
||||
require_once 'Zend/Form/Element/Reset.php';
|
||||
require_once 'Zend/Form/Element/Checkbox.php';
|
||||
require_once 'Zend/Validate/Date.php';
|
||||
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Exception/ProgrammingError.php';
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php';
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php';
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/DateTime.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/AbstractCommand.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommand.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/Comment.php';
|
||||
|
||||
use Monitoring\Form\Command\Comment;
|
||||
use \Zend_View;
|
||||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
||||
|
||||
class CommentTest extends Zend_Test_PHPUnit_ControllerTestCase
|
||||
{
|
||||
public function testForm()
|
||||
{
|
||||
$form = new Comment();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->buildForm();
|
||||
|
||||
$this->assertCount(6, $form->getElements());
|
||||
}
|
||||
|
||||
public function testValidation()
|
||||
{
|
||||
$form = new Comment();
|
||||
$form->setRequest($this->getRequest());
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isValid(
|
||||
array(
|
||||
'author' => 'test1',
|
||||
'comment' => 'test2',
|
||||
'sticky' => '0'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValid(
|
||||
array(
|
||||
'author' => 'test1',
|
||||
'comment' => '',
|
||||
'sticky' => '0'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValid(
|
||||
array(
|
||||
'author' => '',
|
||||
'comment' => 'test2',
|
||||
'sticky' => '0'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
namespace Test\Monitoring\Forms\Command;
|
||||
|
||||
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
|
||||
require_once 'Zend/Form.php';
|
||||
require_once 'Zend/View.php';
|
||||
require_once 'Zend/Form/Element/Submit.php';
|
||||
require_once 'Zend/Form/Element/Reset.php';
|
||||
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php';
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/AbstractCommand.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/Confirmation.php';
|
||||
|
||||
|
||||
use \Zend_View;
|
||||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
||||
use Monitoring\Form\Command\Confirmation;
|
||||
|
||||
class ConfirmationTest extends Zend_Test_PHPUnit_ControllerTestCase
|
||||
{
|
||||
public function testForm1()
|
||||
{
|
||||
$view = new Zend_View();
|
||||
$form = new Confirmation();
|
||||
|
||||
$form->setRequest($this->getRequest());
|
||||
|
||||
$form->setSubmitLabel('111TEST_SUBMIT');
|
||||
|
||||
$form->setCancelLabel('888TEST_RESET');
|
||||
|
||||
$form->addNote('444 NOTE 1');
|
||||
$form->addNote('555 NOTE 2');
|
||||
|
||||
$content = $form->render($view);
|
||||
|
||||
$this->assertContains('<input type="submit" name="submit" id="submit" value="111TEST_SUBMIT" class="btn btn-primary pull-right">', $content);
|
||||
$this->assertContains('<input type="reset" name="reset" id="reset" value="888TEST_RESET" class="btn pull-right"></dd>', $content);
|
||||
$this->assertContains('<dd id="note_0-element">', $content);
|
||||
$this->assertContains('<dd id="note_1-element">', $content);
|
||||
$this->assertContains('444 NOTE 1</dd>', $content);
|
||||
$this->assertContains('555 NOTE 2</dd>', $content);
|
||||
}
|
||||
|
||||
public function testNotes1()
|
||||
{
|
||||
$form = new Confirmation();
|
||||
$form->addNote('test1');
|
||||
$form->addNote('test2');
|
||||
|
||||
$reference = array('test1', 'test2');
|
||||
$this->assertCount(2, $form->getNotes());
|
||||
$this->assertEquals($reference, $form->getNotes());
|
||||
|
||||
$form->clearNotes();
|
||||
$this->assertCount(0, $form->getNotes());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
|
||||
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\Monitoring\Forms\Command {
|
||||
|
||||
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
|
||||
require_once 'Zend/Form.php';
|
||||
require_once 'Zend/View.php';
|
||||
require_once 'Zend/Form/Element/Submit.php';
|
||||
require_once 'Zend/Form/Element/Reset.php';
|
||||
require_once 'Zend/Form/Element/Checkbox.php';
|
||||
require_once 'Zend/Validate/Date.php';
|
||||
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Exception/ProgrammingError.php';
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php';
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php';
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/DateTime.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/AbstractCommand.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommand.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/ConfirmationWithIdentifier.php';
|
||||
|
||||
use Monitoring\Form\Command\ConfirmationWithIdentifier;
|
||||
use \Zend_View;
|
||||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
||||
|
||||
class ConfirmationWithIdentifierTest extends Zend_Test_PHPUnit_ControllerTestCase
|
||||
{
|
||||
public function testForm()
|
||||
{
|
||||
$form = new ConfirmationWithIdentifier();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setSubmitLabel('DING DING');
|
||||
$form->buildForm();
|
||||
|
||||
$this->assertCount(4, $form->getElements());
|
||||
}
|
||||
|
||||
public function testValidation()
|
||||
{
|
||||
$form = new ConfirmationWithIdentifier();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setFieldLabel('Test1');
|
||||
$form->setFieldName('testval');
|
||||
$form->setSubmitLabel('DING DING');
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isValid(
|
||||
array(
|
||||
'testval' => 123
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValid(
|
||||
array(
|
||||
'testval' => ''
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValid(
|
||||
array(
|
||||
'testval' => 'NaN'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testRequestBridge()
|
||||
{
|
||||
$this->getRequest()->setPost(
|
||||
array(
|
||||
'objectid' => 123123666
|
||||
)
|
||||
);
|
||||
|
||||
$form = new ConfirmationWithIdentifier();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->buildForm();
|
||||
|
||||
$this->assertTrue($form->isValid(null));
|
||||
$this->assertTrue($form->isValid($this->getRequest()));
|
||||
|
||||
$this->assertEquals('123123666', $form->getElement('objectid')->getValue());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
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\Monitoring\Forms\Command {
|
||||
|
||||
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
|
||||
require_once 'Zend/Form.php';
|
||||
require_once 'Zend/View.php';
|
||||
require_once 'Zend/Form/Element/Submit.php';
|
||||
require_once 'Zend/Form/Element/Reset.php';
|
||||
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php';
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/AbstractCommand.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/CustomNotification.php';
|
||||
|
||||
|
||||
use Monitoring\Form\Command\CustomNotification;
|
||||
use \Zend_View;
|
||||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
||||
|
||||
class CustomNotificationTest extends Zend_Test_PHPUnit_ControllerTestCase
|
||||
{
|
||||
public function testForm1()
|
||||
{
|
||||
$this->getRequest()->setPost(
|
||||
array(
|
||||
'comment' => 'TEST COMMENT',
|
||||
'author' => 'LAOLA'
|
||||
)
|
||||
);
|
||||
|
||||
$form = new CustomNotification();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->buildForm();
|
||||
|
||||
$this->assertCount(7, $form->getElements());
|
||||
$this->assertTrue($form->isValid(null));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
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\Monitoring\Forms\Command {
|
||||
|
||||
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
|
||||
require_once 'Zend/Form.php';
|
||||
require_once 'Zend/View.php';
|
||||
require_once 'Zend/Form/Element/Submit.php';
|
||||
require_once 'Zend/Form/Element/Reset.php';
|
||||
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php';
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/AbstractCommand.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/DelayNotification.php';
|
||||
|
||||
|
||||
use \Zend_View;
|
||||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
||||
use Monitoring\Form\Command\DelayNotification;
|
||||
|
||||
class DelayNotificationTest extends Zend_Test_PHPUnit_ControllerTestCase
|
||||
{
|
||||
public function testForm1()
|
||||
{
|
||||
$this->getRequest()->setPost(
|
||||
array(
|
||||
'minutes' => 12
|
||||
)
|
||||
);
|
||||
|
||||
$form = new DelayNotification();
|
||||
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->buildForm();
|
||||
|
||||
$this->assertCount(5, $form->getElements());
|
||||
|
||||
$element = $form->getElement('minutes');
|
||||
$this->assertInstanceOf('Zend_Form_Element_Text', $element);
|
||||
$this->assertEquals('0', $element->getValue());
|
||||
$this->assertTrue($element->isRequired());
|
||||
|
||||
$this->assertTrue($form->isValid(null));
|
||||
|
||||
$this->assertEquals('12', $form->getValue('minutes'));
|
||||
}
|
||||
|
||||
public function testValidation()
|
||||
{
|
||||
$this->getRequest()->setPost(
|
||||
array(
|
||||
'minutes' => 'SCHAHH-LAHH-LAHH'
|
||||
)
|
||||
);
|
||||
|
||||
$form = new DelayNotification();
|
||||
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->buildForm();
|
||||
|
||||
$this->assertFalse($form->isValid(null));
|
||||
|
||||
$errors = $form->getErrors('minutes');
|
||||
$this->assertEquals('notBetween', $errors[0]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
|
||||
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\Monitoring\Forms\Command {
|
||||
|
||||
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
|
||||
require_once 'Zend/Form.php';
|
||||
require_once 'Zend/View.php';
|
||||
require_once 'Zend/Form/Element/Submit.php';
|
||||
require_once 'Zend/Form/Element/Reset.php';
|
||||
require_once 'Zend/Form/Element/Checkbox.php';
|
||||
require_once 'Zend/Validate/Date.php';
|
||||
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php';
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php';
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/DateTime.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/AbstractCommand.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommand.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/RescheduleNextCheck.php';
|
||||
|
||||
|
||||
use Monitoring\Form\Command\RescheduleNextCheck;
|
||||
use \Zend_View;
|
||||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
||||
|
||||
class RescheduleNextCheckTest extends Zend_Test_PHPUnit_ControllerTestCase
|
||||
{
|
||||
public function testForm1()
|
||||
{
|
||||
$this->getRequest()->setPost(
|
||||
array(
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
$form = new RescheduleNextCheck();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->buildForm();
|
||||
|
||||
$this->assertCount(6, $form->getElements());
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isValid(
|
||||
array(
|
||||
'checktime' => '2013-10-19 17:30:00',
|
||||
'forcecheck' => 1
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isValid(
|
||||
array(
|
||||
'checktime' => '2013-10-19 17:30:00',
|
||||
'forcecheck' => 0
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValid(
|
||||
array(
|
||||
'checktime' => '2013-24-12 17:30:00',
|
||||
'forcecheck' => 1
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValid(
|
||||
array(
|
||||
'checktime' => 'AHAHA',
|
||||
'forcecheck' => 1
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testChildrenFlag()
|
||||
{
|
||||
|
||||
$form = new RescheduleNextCheck();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setWithChildren(true);
|
||||
$form->buildForm();
|
||||
$notes1 = $form->getNotes();
|
||||
$form = null;
|
||||
|
||||
$form = new RescheduleNextCheck();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setWithChildren(false);
|
||||
$form->buildForm();
|
||||
$notes2 = $form->getNotes();
|
||||
$form = null;
|
||||
|
||||
$form = new RescheduleNextCheck();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setWithChildren();
|
||||
$form->buildForm();
|
||||
$notes3 = $form->getNotes();
|
||||
$form = null;
|
||||
|
||||
$this->assertEquals($notes1, $notes3);
|
||||
$this->assertNotEquals($notes1, $notes2);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,317 @@
|
|||
<?php
|
||||
|
||||
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\Monitoring\Forms\Command {
|
||||
|
||||
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
|
||||
require_once 'Zend/Form.php';
|
||||
require_once 'Zend/View.php';
|
||||
require_once 'Zend/Form/Element/Submit.php';
|
||||
require_once 'Zend/Form/Element/Reset.php';
|
||||
require_once 'Zend/Form/Element/Checkbox.php';
|
||||
require_once 'Zend/Validate/Date.php';
|
||||
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php';
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php';
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/DateTime.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/AbstractCommand.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommand.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/ScheduleDowntime.php';
|
||||
|
||||
use Monitoring\Form\Command\ScheduleDowntime;
|
||||
use \Zend_View;
|
||||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
||||
|
||||
class ScheduleDowntimeTest extends Zend_Test_PHPUnit_ControllerTestCase
|
||||
{
|
||||
public function testFormElements1()
|
||||
{
|
||||
$this->getRequest()->setPost(
|
||||
array(
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
$form = new ScheduleDowntime();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->buildForm();
|
||||
|
||||
$this->assertCount(13, $form->getElements());
|
||||
|
||||
$form = new ScheduleDowntime();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setWithChildren(true);
|
||||
$form->buildForm();
|
||||
|
||||
$this->assertCount(12, $form->getElements());
|
||||
}
|
||||
|
||||
|
||||
public function testFormValidation1()
|
||||
{
|
||||
$this->getRequest()->setPost(
|
||||
array(
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
$form = new ScheduleDowntime();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setWithChildren(true);
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isValid(
|
||||
array(
|
||||
'author' => 'TEST_AUTHOR',
|
||||
'comment' => 'DING DING',
|
||||
'triggered' => '4',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'endtime' => '2013-07-17 10:30:00',
|
||||
'type' => ScheduleDowntime::TYPE_FIXED,
|
||||
'hours' => '',
|
||||
'minutes' => '',
|
||||
// 'childobjects' => '',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValid(
|
||||
array(
|
||||
'author' => 'TEST_AUTHOR',
|
||||
'comment' => 'DING DING',
|
||||
'triggered' => '4',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'endtime' => '2013-07-17 10:30:00',
|
||||
'type' => ScheduleDowntime::TYPE_FLEXIBLE,
|
||||
'hours' => '',
|
||||
'minutes' => '',
|
||||
// 'childobjects' => '',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isValid(
|
||||
array(
|
||||
'author' => 'TEST_AUTHOR',
|
||||
'comment' => 'DING DING',
|
||||
'triggered' => '4',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'endtime' => '2013-07-17 10:30:00',
|
||||
'type' => ScheduleDowntime::TYPE_FLEXIBLE,
|
||||
'hours' => '10',
|
||||
'minutes' => '10',
|
||||
// 'childobjects' => '',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValid(
|
||||
array(
|
||||
'author' => '',
|
||||
'comment' => 'DING DING',
|
||||
'triggered' => '4',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'endtime' => '2013-07-17 10:30:00',
|
||||
'type' => ScheduleDowntime::TYPE_FIXED,
|
||||
'hours' => '',
|
||||
'minutes' => '',
|
||||
// 'childobjects' => '',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValid(
|
||||
array(
|
||||
'author' => 'OK',
|
||||
'comment' => '',
|
||||
'triggered' => '4',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'endtime' => '2013-07-17 10:30:00',
|
||||
'type' => ScheduleDowntime::TYPE_FIXED,
|
||||
'hours' => '',
|
||||
'minutes' => '',
|
||||
// 'childobjects' => '',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValid(
|
||||
array(
|
||||
'author' => 'OK',
|
||||
'comment' => 'OK',
|
||||
'triggered' => 'HAHA',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'endtime' => '2013-07-17 10:30:00',
|
||||
'type' => ScheduleDowntime::TYPE_FIXED,
|
||||
'hours' => '',
|
||||
'minutes' => '',
|
||||
// 'childobjects' => '',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValid(
|
||||
array(
|
||||
'author' => 'OK',
|
||||
'comment' => 'OK',
|
||||
'triggered' => '123',
|
||||
'starttime' => '2013-07-17',
|
||||
'endtime' => '2013-07-17 10:30:00',
|
||||
'type' => ScheduleDowntime::TYPE_FIXED,
|
||||
'hours' => '',
|
||||
'minutes' => '',
|
||||
// 'childobjects' => '',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValid(
|
||||
array(
|
||||
'author' => 'OK',
|
||||
'comment' => 'OK',
|
||||
'triggered' => '123',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'endtime' => 'DING',
|
||||
'type' => ScheduleDowntime::TYPE_FIXED,
|
||||
'hours' => '',
|
||||
'minutes' => '',
|
||||
// 'childobjects' => '',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValid(
|
||||
array(
|
||||
'author' => 'OK',
|
||||
'comment' => 'OK',
|
||||
'triggered' => '123',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'endtime' => '2013-07-17 09:30:00',
|
||||
'type' => ScheduleDowntime::TYPE_FLEXIBLE,
|
||||
'hours' => '-1',
|
||||
'minutes' => '12',
|
||||
// 'childobjects' => '',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValid(
|
||||
array(
|
||||
'author' => 'OK',
|
||||
'comment' => 'OK',
|
||||
'triggered' => '123',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'endtime' => '2013-07-17 09:30:00',
|
||||
'type' => ScheduleDowntime::TYPE_FLEXIBLE,
|
||||
'hours' => '12',
|
||||
'minutes' => 'DING',
|
||||
// 'childobjects' => '',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function testFormValidation2()
|
||||
{
|
||||
$this->getRequest()->setPost(
|
||||
array(
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
$form = new ScheduleDowntime();
|
||||
$form->setWithChildren(false);
|
||||
$form->setRequest($this->getRequest());
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isValid(
|
||||
array(
|
||||
'author' => 'TEST_AUTHOR',
|
||||
'comment' => 'DING DING',
|
||||
'triggered' => '4',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'endtime' => '2013-07-17 10:30:00',
|
||||
'type' => ScheduleDowntime::TYPE_FIXED,
|
||||
'hours' => '',
|
||||
'minutes' => '',
|
||||
'childobjects' => '0',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValid(
|
||||
array(
|
||||
'author' => 'TEST_AUTHOR',
|
||||
'comment' => 'DING DING',
|
||||
'triggered' => '4',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'endtime' => '2013-07-17 10:30:00',
|
||||
'type' => ScheduleDowntime::TYPE_FIXED,
|
||||
'hours' => '',
|
||||
'minutes' => '',
|
||||
'childobjects' => 'AHA',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValid(
|
||||
array(
|
||||
'author' => 'TEST_AUTHOR',
|
||||
'comment' => 'DING DING',
|
||||
'triggered' => '4',
|
||||
'starttime' => '2013-07-17 10:30:00',
|
||||
'endtime' => '2013-07-17 10:30:00',
|
||||
'type' => ScheduleDowntime::TYPE_FIXED,
|
||||
'hours' => '',
|
||||
'minutes' => '',
|
||||
'childobjects' => '4',
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testTimeRange()
|
||||
{
|
||||
$this->getRequest()->setPost(
|
||||
array(
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
$form = new ScheduleDowntime();
|
||||
$form->setWithChildren(false);
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->buildForm();
|
||||
|
||||
$time1 = strtotime($form->getElement('starttime')->getValue());
|
||||
$time2 = strtotime($form->getElement('endtime')->getValue());
|
||||
|
||||
$this->assertEquals(3600, ($time2 - $time1));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
|
||||
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\Monitoring\Forms\Command {
|
||||
|
||||
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
|
||||
require_once 'Zend/Form.php';
|
||||
require_once 'Zend/View.php';
|
||||
require_once 'Zend/Form/Element/Submit.php';
|
||||
require_once 'Zend/Form/Element/Reset.php';
|
||||
require_once 'Zend/Form/Element/Checkbox.php';
|
||||
require_once 'Zend/Validate/Date.php';
|
||||
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Exception/ProgrammingError.php';
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form.php';
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/Note.php';
|
||||
require_once __DIR__. '/../../../../../../../library/Icinga/Web/Form/Element/DateTime.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/AbstractCommand.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommand.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/SubmitPassiveCheckResult.php';
|
||||
|
||||
use Monitoring\Form\Command\SubmitPassiveCheckResult;
|
||||
use \Zend_View;
|
||||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
||||
|
||||
class SubmitPassiveCheckResultTest extends Zend_Test_PHPUnit_ControllerTestCase
|
||||
{
|
||||
public function testStateTypes()
|
||||
{
|
||||
$form = new SubmitPassiveCheckResult();
|
||||
$form->setRequest($this->getRequest());
|
||||
|
||||
$form->setType(SubmitPassiveCheckResult::TYPE_SERVICE);
|
||||
$options = $form->getOptions();
|
||||
$this->assertCount(4, $options);
|
||||
$this->assertEquals('OK', $options[0]);
|
||||
$this->assertEquals('WARNING', $options[1]);
|
||||
$this->assertEquals('CRITICAL', $options[2]);
|
||||
$this->assertEquals('UNKNOWN', $options[3]);
|
||||
|
||||
$form->setType(SubmitPassiveCheckResult::TYPE_HOST);
|
||||
$options = $form->getOptions();
|
||||
$this->assertCount(3, $options);
|
||||
$this->assertEquals('UP', $options[0]);
|
||||
$this->assertEquals('DOWN', $options[1]);
|
||||
$this->assertEquals('UNREACHABLE', $options[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Icinga\Exception\ProgrammingError
|
||||
* @expectedExceptionMessage Type is not valid
|
||||
*/
|
||||
public function testForm1()
|
||||
{
|
||||
$form = new SubmitPassiveCheckResult();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->buildForm();
|
||||
}
|
||||
|
||||
public function testForm2()
|
||||
{
|
||||
$form = new SubmitPassiveCheckResult();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setType(SubmitPassiveCheckResult::TYPE_SERVICE);
|
||||
$form->buildForm();
|
||||
|
||||
$this->assertCount(6, $form->getElements());
|
||||
}
|
||||
|
||||
public function testValidation1()
|
||||
{
|
||||
$form = new SubmitPassiveCheckResult();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setType(SubmitPassiveCheckResult::TYPE_SERVICE);
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isValid(
|
||||
array(
|
||||
'pluginstate' => 0,
|
||||
'checkoutput' => 'DING',
|
||||
'performancedata' => ''
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValid(
|
||||
array(
|
||||
'pluginstate' => 0,
|
||||
'checkoutput' => '',
|
||||
'performancedata' => ''
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValid(
|
||||
array(
|
||||
'pluginstate' => 'LA',
|
||||
'checkoutput' => 'DING',
|
||||
'performancedata' => ''
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<phpunit>
|
||||
<phpunit processIsolation="true">
|
||||
<testsuites>
|
||||
<!--
|
||||
Unit testing
|
||||
|
@ -27,5 +27,5 @@
|
|||
<directory suffix=".php">/usr/share/php</directory>
|
||||
<directory suffix=".php">/usr/lib</directory>
|
||||
</blacklist>
|
||||
</filter>
|
||||
</filter>
|
||||
</phpunit>
|
||||
|
|
Loading…
Reference in New Issue