summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-11-21 14:35:05 +0000
committerDries Buytaert <dries@buytaert.net>2009-11-21 14:35:05 +0000
commitff88ee0f565ed9d3ebc0bba662987b0f0aacf9dc (patch)
treea6bf998a6a295b638c1185536187c892ad6f0ce2 /modules
parent63f39bedf6a7b3a8c8d4a9427d332a67bba2acdf (diff)
downloadbrdo-ff88ee0f565ed9d3ebc0bba662987b0f0aacf9dc.tar.gz
brdo-ff88ee0f565ed9d3ebc0bba662987b0f0aacf9dc.tar.bz2
- Patch #601584 by effulgentsia, boombatower, yched: setUp() function for unit and web test cases should reset all resettable statics.
Diffstat (limited to 'modules')
-rw-r--r--modules/field/tests/field.test1
-rw-r--r--modules/simpletest/drupal_web_test_case.php6
-rw-r--r--modules/simpletest/tests/bootstrap.test5
-rw-r--r--modules/simpletest/tests/common.test19
4 files changed, 11 insertions, 20 deletions
diff --git a/modules/field/tests/field.test b/modules/field/tests/field.test
index 8de70bfe5..8d2a55e50 100644
--- a/modules/field/tests/field.test
+++ b/modules/field/tests/field.test
@@ -2495,6 +2495,7 @@ class FieldTranslationsTestCase extends FieldTestCase {
$this->assertTrue(count($obj_info['translation']), t('Nodes are translatable.'));
// Prepare the field translations.
+ field_test_entity_info_translatable('test_entity', TRUE);
$eid = $evid = 1;
$obj_type = 'test_entity';
$object = field_test_create_stub_entity($eid, $evid, $this->instance['bundle']);
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index 998716926..5fd4a18d4 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -539,6 +539,9 @@ class DrupalUnitTestCase extends DrupalTestCase {
$this->originalPrefix = $db_prefix;
$this->originalFileDirectory = file_directory_path();
+ // Reset all statics so that test is performed with a clean environment.
+ drupal_static_reset();
+
// Generate temporary prefixed database to ensure that tests have a clean starting point.
$db_prefix = Database::getConnection()->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}');
$conf['file_public_path'] = $this->originalFileDirectory . '/' . $db_prefix;
@@ -1053,6 +1056,9 @@ class DrupalWebTestCase extends DrupalTestCase {
ini_set('log_errors', 1);
ini_set('error_log', $directory . '/error.log');
+ // Reset all statics so that test is performed with a clean environment.
+ drupal_static_reset();
+
include_once DRUPAL_ROOT . '/includes/install.inc';
drupal_install_system();
diff --git a/modules/simpletest/tests/bootstrap.test b/modules/simpletest/tests/bootstrap.test
index e4ef2d717..ff71a167a 100644
--- a/modules/simpletest/tests/bootstrap.test
+++ b/modules/simpletest/tests/bootstrap.test
@@ -405,16 +405,11 @@ class BootstrapResettableStaticTestCase extends DrupalUnitTestCase {
$var = 'bar';
drupal_static_reset($name);
$this->assertEqual($var, 'foo', t('Variable was reset after second invocation of name-specific reset.'));
-
- // Ensure that batch processing doesn't get reset.
- $batch = &batch_get();
- $batch_saved = $batch;
$var = 'bar';
drupal_static_reset();
$this->assertEqual($var, 'foo', t('Variable was reset after first invocation of global reset.'));
$var = 'bar';
drupal_static_reset();
$this->assertEqual($var, 'foo', t('Variable was reset after second invocation of global reset.'));
- $batch = $batch_saved;
}
}
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index aa43a62eb..76c4d4dfc 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -56,8 +56,11 @@ class DrupalAlterTestCase extends DrupalWebTestCase {
/**
* Tests for URL generation functions.
+ *
+ * url() calls module_implements(), which may issue a db query, which requires
+ * inheriting from a web test case rather than a unit test case.
*/
-class CommonURLUnitTest extends DrupalUnitTestCase {
+class CommonURLUnitTest extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'URL generation tests',
@@ -70,23 +73,9 @@ class CommonURLUnitTest extends DrupalUnitTestCase {
* Confirm that invalid text given as $path is filtered.
*/
function testLXSS() {
- global $conf;
$text = $this->randomName();
$path = "<SCRIPT>alert('XSS')</SCRIPT>";
- // Regardless of whether there is a theme override of theme_link() or not,
- // unless the 'theme_link' configuration variable is FALSE, l() will
- // attempt to initialize the theme system in order to determine if
- // the link needs to be themed. However, drupal_theme_initialize() requires
- // a database query, which doesn't work in the context of unit tests,
- // because simpletest sets up a table prefix, but doesn't generate the
- // corresponding prefixed tables. We need to either circumvent theme system
- // initialization, or make CommonURLUnitTest inherit from DrupalWebTestCase.
- // Since our goal in this unit test is specifically to test the default
- // implementation, we choose the former.
- $theme_link_saved = isset($conf['theme_link']) ? $conf['theme_link'] : NULL;
- $conf['theme_link'] = FALSE;
$link = l($text, $path);
- $conf['theme_link'] = $theme_link_saved;
$sanitized_path = check_url(url($path));
$this->assertTrue(strpos($link, $sanitized_path) !== FALSE, t('XSS attack @path was filtered', array('@path' => $path)));
}