diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index e6339cc..3f38249 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2478,7 +2478,8 @@ function drupal_container(Container $new_container = NULL, $rebuild = FALSE) { // Register the KeyValueStore factory. $container - ->register('keyvalue', 'Drupal\Core\KeyValueStore\KeyValueFactory'); + ->register('keyvalue', 'Drupal\Core\KeyValueStore\KeyValueFactory') + ->addArgument('Drupal\Core\KeyValueStore\DatabaseStorage'); } return $container; } diff --git a/core/includes/module.inc b/core/includes/module.inc index 5a17873..bc5112d 100644 --- a/core/includes/module.inc +++ b/core/includes/module.inc @@ -182,7 +182,7 @@ function system_list($type) { // Drupal installations, which might have modules installed in different // locations in the file system. The ordering here must also be // consistent with the one used in module_implements(). - $enabled_modules = config('system.module')->get('enabled'); + $enabled_modules = (array) config('system.module')->get('enabled'); $module_files = state()->get('system.module.files'); foreach ($enabled_modules as $name => $weight) { // Build a list of all enabled modules. @@ -196,7 +196,7 @@ function system_list($type) { } // Build a list of themes. - $enabled_themes = config('system.theme')->get('enabled'); + $enabled_themes = (array) config('system.theme')->get('enabled'); // @todo Themes include all themes, including disabled/uninstalled. This // system.theme.data state will go away entirely as soon as themes have // a proper installation status. diff --git a/core/lib/Drupal/Core/KeyValueStore/KeyValueFactory.php b/core/lib/Drupal/Core/KeyValueStore/KeyValueFactory.php index 7edb754..a1aaa60 100644 --- a/core/lib/Drupal/Core/KeyValueStore/KeyValueFactory.php +++ b/core/lib/Drupal/Core/KeyValueStore/KeyValueFactory.php @@ -12,6 +12,8 @@ */ class KeyValueFactory { + protected $backend; + /** * Instantiated stores, keyed by collection name. * @@ -20,6 +22,17 @@ class KeyValueFactory { protected $stores = array(); /** + * Constructs the key/value store factory. + * + * @param string $backend + * The fully-qualified class name of backend implementing + * KeyValueStoreInterface. + */ + function __construct($backend) { + $this->backend = $backend; + } + + /** * Constructs a new key/value store for a given collection name. * * @param string $collection @@ -30,7 +43,7 @@ class KeyValueFactory { */ public function get($collection) { if (!isset($this->stores[$collection])) { - $this->stores[$collection] = new DatabaseStorage($collection); + $this->stores[$collection] = new $this->backend($collection); } return $this->stores[$collection]; } diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigInstallTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigInstallTest.php index 5efecd0..b549119 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigInstallTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigInstallTest.php @@ -23,7 +23,6 @@ public static function getInfo() { function setUp() { parent::setUp(); - $this->installSchema('system', 'system'); // Ensure the global variable being asserted by this test does not exist; // a previous test executed in this request/process might have set it. diff --git a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php index 116bb05..4935038 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php @@ -22,10 +22,6 @@ * * @see DrupalUnitTestBase::$modules * @see DrupalUnitTestBase::enableModules() - * - * By installing the {system} schema, modules may be fully installed, too. - * - * @see DrupalUnitTestBase::installSchema() */ abstract class DrupalUnitTestBase extends UnitTestBase { @@ -37,6 +33,13 @@ * this property. The values of all properties in all classes in the hierarchy * are merged. * + * Unlike UnitTestBase::setUp(), any modules specified in the $modules + * property are automatically loaded and set as the fixed module list. + * + * Unlike WebTestBase::setUp(), the specified modules are loaded only, but not + * automatically installed. Modules need to be installed manually, if needed. + * + * @see DrupalUnitTestBase::enableModules() * @see DrupalUnitTestBase::setUp() * * @var array @@ -55,25 +58,41 @@ */ private $moduleList = array(); + private $moduleFiles; + private $themeFiles; + private $themeData; + /** * Sets up Drupal unit test environment. * - * Unlike UnitTestBase::setUp(), any modules specified in the $modules - * property are automatically loaded and set as the fixed module list. - * * @see DrupalUnitTestBase::$modules * @see DrupalUnitTestBase */ protected function setUp() { global $conf; + // Copy/prime extension file lists once to avoid filesystem scans. + if (!isset($this->moduleFiles)) { + $this->moduleFiles = state()->get('system.module.files') ?: array(); + $this->themeFiles = state()->get('system.theme.files') ?: array(); + $this->themeData = state()->get('system.theme.data') ?: array(); + } + parent::setUp(); // Provide a minimal, partially mocked environment for unit tests. $conf['lock_backend'] = 'Drupal\Core\Lock\NullLockBackend'; - $conf['cache_classes'] = array('cache' => 'Drupal\Core\Cache\NullBackend'); - $this->container->register('config.storage', 'Drupal\Core\Config\FileStorage') + $conf['cache_classes'] = array('cache' => 'Drupal\Core\Cache\MemoryBackend'); + $this->container + ->register('config.storage', 'Drupal\Core\Config\FileStorage') ->addArgument($this->configDirectories[CONFIG_ACTIVE_DIRECTORY]); + $this->container + ->register('keyvalue', 'Drupal\Core\KeyValueStore\KeyValueFactory') + ->addArgument('Drupal\Core\KeyValueStore\MemoryStorage'); + + state()->set('system.module.files', $this->moduleFiles); + state()->set('system.theme.files', $this->themeFiles); + state()->set('system.theme.data', $this->themeData); // Ensure that the module list is initially empty. $this->moduleList = array(); @@ -109,20 +128,15 @@ protected function installSchema($module, $table) { * * 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'); - * @endcode + * enables the new modules in the system.module configuration only, but that + * has no effect, since we are operating with a fixed module list. * * @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. + * Defaults to TRUE. 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. @@ -130,7 +144,7 @@ protected function installSchema($module, $table) { 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); + $this->moduleList[$module]['filename'] = drupal_get_filename('module', $module); } module_list(NULL, $this->moduleList); diff --git a/core/modules/system/system.module b/core/modules/system/system.module index bb3f2b4..1cc16c3 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -2821,8 +2821,8 @@ function system_rebuild_module_data() { $files = array(); ksort($modules); // Add name, status, weight, and schema version. - $enabled_modules = config('system.module')->get('enabled'); - $disabled_modules = config('system.module.disabled')->get(); + $enabled_modules = (array) config('system.module')->get('enabled'); + $disabled_modules = (array) config('system.module.disabled')->get(); $all_modules = $enabled_modules + $disabled_modules; foreach ($modules as $module => $record) { $record->name = $module; @@ -2994,7 +2994,7 @@ function system_rebuild_theme_data() { // based on the current config. Remove this code when themes have a proper // installation status. // @see http://drupal.org/node/1067408 - $enabled_themes = config('system.theme')->get('enabled'); + $enabled_themes = (array) config('system.theme')->get('enabled'); $files = array(); foreach ($themes as $name => $theme) { $theme->status = (int) isset($enabled_themes[$name]);