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
|
||||
* @param array $requestData Request data for the form
|
||||
* If the form has CSRF protection enabled, creates the form's token element and adds the generated token to the
|
||||
* 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
|
||||
* @throws RuntimeException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function createForm($formClass, array $requestData = array())
|
||||
{
|
||||
$this->requireFormLibraries();
|
||||
|
||||
$classParts = explode('\\', $formClass);
|
||||
$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 = new $formClass;
|
||||
// If the form has CSRF protection enabled, add the token to the request data, else all calls to
|
||||
// isSubmittedAndValid will fail
|
||||
$form->initCsrfToken();
|
||||
|
||||
$token = $form->getValue($form->getTokenElementName());
|
||||
if ($token !== null) {
|
||||
$requestData[$form->getTokenElementName()] = $token;
|
||||
@ -338,14 +319,12 @@ class BaseTestCase extends Zend_Test_PHPUnit_ControllerTestCase implements DbTes
|
||||
$request = $this->getRequest();
|
||||
$request->setMethod('POST');
|
||||
$request->setPost($requestData);
|
||||
|
||||
$form->setRequest($request);
|
||||
$form->setUserPreferences(
|
||||
new Preferences(
|
||||
array()
|
||||
)
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ use \Icinga\Protocol\Statusdat\Reader;
|
||||
use \Icinga\Web\Controller\ActionController;
|
||||
use \Icinga\Application\DbAdapterFactory;
|
||||
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\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/DbBackendForm.php';
|
||||
require_once BaseTestCase::$appDir . '/forms/Config/Authentication/LdapBackendForm.php';
|
||||
require_once BaseTestCase::$appDir . '/forms/Config/Authentication/ReorderForm.php';
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use \Zend_Config;
|
||||
|
@ -39,6 +39,7 @@ require_once 'Zend/Config.php';
|
||||
require_once 'Zend/Config/Ini.php';
|
||||
require_once BaseTestCase::$libDir . '/Web/Form.php';
|
||||
require_once BaseTestCase::$appDir . '/forms/Config/GeneralForm.php';
|
||||
require_once BaseTestCase::$appDir . '/forms/Config/LoggingForm.php';
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use \Zend_Config;
|
||||
|
@ -30,7 +30,10 @@ namespace Tests\Icinga\Test;
|
||||
|
||||
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
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user