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:
Eric Lippmann 2013-09-03 11:17:28 +02:00 committed by Jannis Moßhammer
parent 092c5780ea
commit 74b9731df5
6 changed files with 25 additions and 41 deletions

View File

@ -293,9 +293,13 @@ 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
* 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
@ -303,33 +307,10 @@ class BaseTestCase extends Zend_Test_PHPUnit_ControllerTestCase implements DbTes
*/
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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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
{