Fix broken tests

fixes #4878
This commit is contained in:
Marius Hein 2013-10-15 13:20:09 +02:00
parent a992964721
commit 8e2549febe
3 changed files with 2 additions and 203 deletions

View File

@ -1,139 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Form\Command;
use \Zend_Form_Element_Hidden;
/**
* Form to handle confirmations with a single value processed
*/
class CommandWithIdentifierForm extends CommandForm
{
/**
* Identifier for data field
*
* @var string
*/
private $fieldName = 'objectid';
/**
* Label for the field
*
* Human readable sting, must be translated before.
*
* @var string
*/
private $fieldLabel;
/**
* Setter for field label
*
* @param string $fieldLabel
*/
public function setFieldLabel($fieldLabel)
{
$this->fieldLabel = $fieldLabel;
}
/**
* Getter for field label
*
* @return string
*/
public function getFieldLabel()
{
return $this->fieldLabel;
}
/**
* Setter for field name
*
* @param string $fieldName
*/
public function setFieldName($fieldName)
{
$this->fieldName = $fieldName;
}
/**
* Getter for field name
*
* @return string
*/
public function getFieldName()
{
return $this->fieldName;
}
/**
* Create corresponding field for object configuration
* @return Zend_Form_Element_Hidden
*/
private function createObjectField()
{
$value = $this->getRequest()->getParam($this->getFieldName());
$fieldLabel = $this->getFieldLabel();
$hiddenField = new Zend_Form_Element_Hidden($this->getFieldName());
$hiddenField->setValue($value);
$hiddenField->setRequired(true);
$hiddenField->addValidator(
'digits',
true
);
$hiddenField->removeDecorator('Label');
$hiddenField->addDecorator(
'Callback',
array(
'callback' => function () use ($value, $fieldLabel) {
return sprintf(
'%s %s <strong>"%s"</strong>',
$fieldLabel,
t('is'),
(isset($value)) ? $value : t('unset')
);
}
)
);
return $hiddenField;
}
/**
* Interface method to build the form
* @see CommandForm::create
*/
protected function create()
{
$this->addElement($this->createObjectField());
parent::create();
}
}

View File

@ -1,63 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Test\Monitoring\Forms\Command;
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/CommandWithIdentifierForm.php';
class CommandWithIdentifierFormTest extends BaseTestCase
{
const FORM_CLASS = '\Icinga\Module\Monitoring\Form\Command\CommandWithIdentifierForm';
public function testFormInvalidWhenObjectIdMissing()
{
$form = $this->createForm(
self::FORM_CLASS,
array(
'object_id' => '',
'btn_submit' => 'Submit'
)
);
$this->assertFalse(
$form->isSubmittedAndValid(),
'Missing object_id must be considered not valid'
);
}
public function testFormInvalidWhenObjectIdNonDigit()
{
$form = $this->createForm(
self::FORM_CLASS,
array(
'object_id' => 'A Service',
'btn_submit' => 'Submit'
)
);
$this->assertFalse(
$form->isSubmittedAndValid(),
'Non numeric input must be considered not valid'
);
}
public function testFormValidWhenObjectIdIsDigit()
{
$form = $this->createForm(
self::FORM_CLASS,
array(
'object_id' => 1,
'btn_submit' => 'Submit'
)
);
$this->assertFalse(
$form->isSubmittedAndValid(),
'Digits must be considered valid'
);
}
}

View File

@ -228,7 +228,8 @@ abstract class MonitoringControllerTest extends Zend_Test_PHPUnit_ControllerTest
*/
public function requireController($controller, $backend)
{
require_once($this->moduleDir.'/application/controllers/'.$controller.'.php');
require_once($this->moduleDir . '/library/Monitoring/Controller.php');
require_once($this->moduleDir . '/application/controllers/'.$controller.'.php');
$controllerName = '\Monitoring_'.ucfirst($controller);
$request = $this->getRequest();
if ($backend == 'statusdat') {