mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 07:44:04 +02:00
Remove auto class requirement from BaseTestCase::createForm()
The tests for the respective forms must require the form class. refs #4586
This commit is contained in:
parent
092c5780ea
commit
74b9731df5
@ -293,43 +293,24 @@ class BaseTestCase extends Zend_Test_PHPUnit_ControllerTestCase implements DbTes
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiate a new form object
|
* Instantiate a form
|
||||||
*
|
*
|
||||||
* @param string $formClass Form class to instantiate
|
* If the form has CSRF protection enabled, creates the form's token element and adds the generated token to the
|
||||||
* @param array $requestData Request data for the form
|
* request data
|
||||||
|
*
|
||||||
|
* @param string $formClass Qualified class name of the form to create. Note that the class has to be
|
||||||
|
* defined as no attempt is made to require the class before instantiating.
|
||||||
|
* @param array $requestData Request data for the form
|
||||||
*
|
*
|
||||||
* @return Form
|
* @return Form
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
public function createForm($formClass, array $requestData = array())
|
public function createForm($formClass, array $requestData = array())
|
||||||
{
|
{
|
||||||
$this->requireFormLibraries();
|
$form = new $formClass;
|
||||||
|
// If the form has CSRF protection enabled, add the token to the request data, else all calls to
|
||||||
$classParts = explode('\\', $formClass);
|
// isSubmittedAndValid will fail
|
||||||
$identifier = array_shift($classParts);
|
|
||||||
array_shift($classParts); // Throw away
|
|
||||||
$fixedPathComponent = '/forms';
|
|
||||||
|
|
||||||
if (strtolower($identifier) == 'icinga') {
|
|
||||||
$startPathComponent = self::$appDir . $fixedPathComponent;
|
|
||||||
} else {
|
|
||||||
$startPathComponent = self::$moduleDir
|
|
||||||
. '/'
|
|
||||||
. strtolower($identifier)
|
|
||||||
. '/application'
|
|
||||||
.$fixedPathComponent;
|
|
||||||
}
|
|
||||||
|
|
||||||
$classFile = $startPathComponent . '/' . implode('/', $classParts) . '.php';
|
|
||||||
|
|
||||||
if (!file_exists($classFile)) {
|
|
||||||
throw new RuntimeException('Class file for form "' . $formClass . '" not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
require_once $classFile;
|
|
||||||
$form = new $formClass();
|
|
||||||
$form->initCsrfToken();
|
$form->initCsrfToken();
|
||||||
|
|
||||||
$token = $form->getValue($form->getTokenElementName());
|
$token = $form->getValue($form->getTokenElementName());
|
||||||
if ($token !== null) {
|
if ($token !== null) {
|
||||||
$requestData[$form->getTokenElementName()] = $token;
|
$requestData[$form->getTokenElementName()] = $token;
|
||||||
@ -338,14 +319,12 @@ class BaseTestCase extends Zend_Test_PHPUnit_ControllerTestCase implements DbTes
|
|||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$request->setMethod('POST');
|
$request->setMethod('POST');
|
||||||
$request->setPost($requestData);
|
$request->setPost($requestData);
|
||||||
|
|
||||||
$form->setRequest($request);
|
$form->setRequest($request);
|
||||||
$form->setUserPreferences(
|
$form->setUserPreferences(
|
||||||
new Preferences(
|
new Preferences(
|
||||||
array()
|
array()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,4 +383,4 @@ class BaseTestCase extends Zend_Test_PHPUnit_ControllerTestCase implements DbTes
|
|||||||
|
|
||||||
// @codingStandardsIgnoreStart
|
// @codingStandardsIgnoreStart
|
||||||
BaseTestCase::setupDirectories();
|
BaseTestCase::setupDirectories();
|
||||||
// @codingStandardsIgnoreEnd
|
// @codingStandardsIgnoreEnd
|
||||||
|
@ -41,7 +41,7 @@ use \Icinga\Protocol\Statusdat\Reader;
|
|||||||
use \Icinga\Web\Controller\ActionController;
|
use \Icinga\Web\Controller\ActionController;
|
||||||
use \Icinga\Application\DbAdapterFactory;
|
use \Icinga\Application\DbAdapterFactory;
|
||||||
use \Icinga\Module\Monitoring\Backend\Ido;
|
use \Icinga\Module\Monitoring\Backend\Ido;
|
||||||
use \Icinga\Moudle\Monitoring\Backend\Statusdat;
|
use \Icinga\Module\Monitoring\Backend\Statusdat;
|
||||||
use \Test\Monitoring\Testlib\DataSource\TestFixture;
|
use \Test\Monitoring\Testlib\DataSource\TestFixture;
|
||||||
use \Test\Monitoring\Testlib\DataSource\DataSourceTestSetup;
|
use \Test\Monitoring\Testlib\DataSource\DataSourceTestSetup;
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@ require_once BaseTestCase::$libDir . '/Web/Url.php';
|
|||||||
require_once BaseTestCase::$appDir . '/forms/Config/Authentication/BaseBackendForm.php';
|
require_once BaseTestCase::$appDir . '/forms/Config/Authentication/BaseBackendForm.php';
|
||||||
require_once BaseTestCase::$appDir . '/forms/Config/Authentication/DbBackendForm.php';
|
require_once BaseTestCase::$appDir . '/forms/Config/Authentication/DbBackendForm.php';
|
||||||
require_once BaseTestCase::$appDir . '/forms/Config/Authentication/LdapBackendForm.php';
|
require_once BaseTestCase::$appDir . '/forms/Config/Authentication/LdapBackendForm.php';
|
||||||
|
require_once BaseTestCase::$appDir . '/forms/Config/Authentication/ReorderForm.php';
|
||||||
// @codingStandardsIgnoreEnd
|
// @codingStandardsIgnoreEnd
|
||||||
|
|
||||||
use \Zend_Config;
|
use \Zend_Config;
|
||||||
|
@ -2,24 +2,24 @@
|
|||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
/**
|
/**
|
||||||
* This file is part of Icinga 2 Web.
|
* This file is part of Icinga 2 Web.
|
||||||
*
|
*
|
||||||
* Icinga 2 Web - Head for multiple monitoring backends.
|
* Icinga 2 Web - Head for multiple monitoring backends.
|
||||||
* Copyright (C) 2013 Icinga Development Team
|
* Copyright (C) 2013 Icinga Development Team
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
* as published by the Free Software Foundation; either version 2
|
* as published by the Free Software Foundation; either version 2
|
||||||
* of the License, or (at your option) any later version.
|
* of the License, or (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||||
* @author Icinga Development Team <info@icinga.org>
|
* @author Icinga Development Team <info@icinga.org>
|
||||||
@ -227,4 +227,4 @@ class GeneralFormTest extends BaseTestCase
|
|||||||
"Asserting the db resource to be displayed when db preference is set"
|
"Asserting the db resource to be displayed when db preference is set"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ require_once 'Zend/Config.php';
|
|||||||
require_once 'Zend/Config/Ini.php';
|
require_once 'Zend/Config/Ini.php';
|
||||||
require_once BaseTestCase::$libDir . '/Web/Form.php';
|
require_once BaseTestCase::$libDir . '/Web/Form.php';
|
||||||
require_once BaseTestCase::$appDir . '/forms/Config/GeneralForm.php';
|
require_once BaseTestCase::$appDir . '/forms/Config/GeneralForm.php';
|
||||||
|
require_once BaseTestCase::$appDir . '/forms/Config/LoggingForm.php';
|
||||||
// @codingStandardsIgnoreEnd
|
// @codingStandardsIgnoreEnd
|
||||||
|
|
||||||
use \Zend_Config;
|
use \Zend_Config;
|
||||||
|
@ -30,7 +30,10 @@ namespace Tests\Icinga\Test;
|
|||||||
|
|
||||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||||
|
|
||||||
use Icinga\Test\BaseTestCase;
|
use \Icinga\Test\BaseTestCase;
|
||||||
|
|
||||||
|
require_once BaseTestCase::$appDir . '/forms/Authentication/LoginForm.php';
|
||||||
|
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Config/ConfirmRemovalForm.php';
|
||||||
|
|
||||||
class BaseTestCaseFormTest extends BaseTestCase
|
class BaseTestCaseFormTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user