diff --git a/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php index 54a4fe7..1926b96 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php @@ -63,7 +63,9 @@ protected function setUp() { $conf = array(); drupal_static_reset(); - // Collect and set fixed module list. + // Ensure that the module list is initially empty. + $this->moduleList = array(); + // Collect and set a fixed module list. $class = get_class($this); $modules = array(); while ($class) { @@ -72,13 +74,9 @@ protected function setUp() { } $class = get_parent_class($class); } - foreach ($modules as $module) { - $this->moduleList[$module] = drupal_get_path('module', $module); - } - module_list(NULL, $this->moduleList); - module_load_all(); + $this->enableModules($modules, FALSE); - // Provide a minimal environment for unit tests. + // Provide a minimal, partially mocked environment for unit tests. $conf['file_public_path'] = $this->public_files_directory; $conf['lock_backend'] = 'Drupal\Core\Lock\NullLockBackend'; $conf['cache_classes'] = array('cache' => 'Drupal\Core\Cache\NullBackend'); @@ -118,25 +116,40 @@ protected function installSchema($module, $table) { /** * Enables modules for this test. * - * The {system} table is required for using this method. Install it via: + * Callbacks invoked by module_enable() may need to access information + * provided by info hooks of the new modules already. However, module_enable() + * enables the new modules in {system} only, but that has no effect, since we + * are operating with a fixed module list. + * + * The {system} table is required to install new modules. Install it via: * @code - * $this->installSchema('system', 'system'); + * $this->installSchema('system', 'system'); * @endcode * * @param array $modules * A list of modules to enable. + * @param bool $install + * (optional) Whether to install the list of modules via module_enable(). + * Defaults to TRUE. Requires the {system} table to exist. If FALSE, the new + * modules are only added to the fixed module list and loaded. + * + * @todo Remove this method as soon as there is an Extensions service + * implementation that is able to manage a fixed module list. */ - protected function enableModules(array $modules) { - // Add the new modules to the fixed module_list() first, since callbacks - // invoked by module_enable() may need to access information provided by - // info hooks of the new modules already. module_enable() enables the new - // modules in {system}, but that has no effect, since we are operating with - // a fixed module list. + protected function enableModules(array $modules, $install = TRUE) { + // Set the modules in the fixed module_list(). foreach ($modules as $module) { $this->moduleList[$module] = drupal_get_path('module', $module); } module_list(NULL, $this->moduleList); - module_enable($modules); + // Call module_enable() to enable (install) the new modules. + if ($install) { + module_enable($modules); + } + // Otherwise, only ensure that the new modules are loaded. + else { + module_load_all(FALSE, TRUE); + } } }