diff --git a/core/includes/module.inc b/core/includes/module.inc index d9eab10..a772436 100644 --- a/core/includes/module.inc +++ b/core/includes/module.inc @@ -61,14 +61,29 @@ function module_load_all($bootstrap = FALSE) { * list will persist until the next call with a new $fixed_list passed in. * Primarily intended for internal use (e.g., in install.php and update.php). * Use module_list_reset() to undo the $fixed_list override. + * @param bool $reset + * (optional) Whether to reset/remove the $fixed_list. * * @return array * An associative array whose keys and values are the names of the modules in * the list. + * + * @see module_list_reset() */ -function module_list($type = 'module_enabled', array $fixed_list = NULL) { - // This static is only used for $fixed_list. - $module_list = &drupal_static(__FUNCTION__); +function module_list($type = 'module_enabled', array $fixed_list = NULL, $reset = FALSE) { + // This static is only used for $fixed_list. It must not be a drupal_static(), + // since any call to drupal_static_reset() in unit tests would cause an + // attempt to retrieve the list of modules from the database (which does not + // exist). + static $module_list; + + if ($reset) { + $module_list = NULL; + // Do nothing if no $type and no $fixed_list have been passed. + if (!isset($type) && !isset($fixed_list)) { + return; + } + } // The list that will be be returned. Separate from $module_list in order // to not duplicate the static cache of system_list(). @@ -94,7 +109,7 @@ function module_list($type = 'module_enabled', array $fixed_list = NULL) { * Subsequent calls to module_list() will no longer use a fixed list. */ function module_list_reset() { - drupal_static_reset('module_list'); + module_list(NULL, NULL, TRUE); } /** diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php index d31cf1c..00eb07f 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -796,9 +796,8 @@ protected function tearDown() { // Reset all static variables. drupal_static_reset(); - // Restore has_run state. - $has_run = &drupal_static('module_load_all'); - $has_run = TRUE; + // Reset module list. + module_list_reset(); // Restore original in-memory configuration. $conf = $this->originalConf;