diff --git a/core/modules/simpletest/lib/Drupal/simpletest/ConfigMemoryStorage.php b/core/modules/simpletest/lib/Drupal/simpletest/ConfigMemoryStorage.php new file mode 100644 index 0000000..096ad55 --- /dev/null +++ b/core/modules/simpletest/lib/Drupal/simpletest/ConfigMemoryStorage.php @@ -0,0 +1,95 @@ +moduleList; + } + + } + + /** + * {@inheritdoc} + */ + public function write($name, array $data) + { + + } + + /** + * {@inheritdoc} + */ + public function delete($name) + { + + } + + /** + * {@inheritdoc} + */ + public function rename($name, $new_name) + { + + } + + /** + * {@inheritdoc} + */ + public function encode($data) + { + + } + + /** + * {@inheritdoc} + */ + public function decode($raw) + { + + } + + /** + * {@inheritdoc} + */ + public function listAll($prefix = '') + { + + } + + /** + * {@inheritdoc} + */ + public function deleteAll($prefix = '') + { + + } + + /** + * Sets the module list that will be returned to the module handler. + * + * @param $module_list + */ + public function setModuleList($module_list) { + $this->moduleList = $module_list; + } + +} \ No newline at end of file diff --git a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php index b2a35b1..a8bcd4e 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php @@ -13,6 +13,8 @@ use Symfony\Component\DependencyInjection\Reference; use Drupal\Core\Database\Database; use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Core\Config\BootstrapConfigStorageFactory; +use Drupal\Component\Utility\Settings; /** * Base test case class for Drupal unit tests. @@ -62,6 +64,8 @@ */ protected $keyValueFactory; + protected $bootstrapConfig; + /** * Overrides \Drupal\simpletest\UnitTestBase::__construct(). */ @@ -77,6 +81,7 @@ function __construct($test_id = NULL) { * @see DrupalUnitTestBase */ protected function setUp() { + $this->bootstrapConfig = new ConfigMemoryStorage(); // Copy/prime extension file lists once to avoid filesystem scans. if (!isset($this->moduleFiles)) { $this->moduleFiles = \Drupal::state()->get('system.module.files') ?: array(); @@ -95,7 +100,11 @@ protected function setUp() { \Drupal::state()->set('system.module.files', $this->moduleFiles); \Drupal::state()->set('system.theme.files', $this->themeFiles); \Drupal::state()->set('system.theme.data', $this->themeData); - + $settings = settings()->getAll(); + $settings['drupal_bootstrap_config_storage'] = array($this, 'getBootstrapConfig'); + // Calling the constructor will update the instance that gets returned for all + // future calls to Settings::getSingleton(). + $settings_object = new Settings($settings); // Bootstrap the kernel. // No need to dump it; this test runs in-memory. $this->kernel = new DrupalKernel('unit_testing', TRUE, drupal_classloader(), FALSE); @@ -124,6 +133,10 @@ protected function setUp() { config('system.theme')->set('default', 'stark'); } + public function getBootstrapConfig() { + return $this->bootstrapConfig; + } + protected function tearDown() { $this->kernel->shutdown(); parent::tearDown(); @@ -263,6 +276,13 @@ protected function enableModules(array $modules) { } $module_handler->setModuleList($module_filenames); $module_handler->resetImplementations(); + $module_config = array('enabled' => array()); + $weight = 0; + foreach ($module_filenames as $module => $filename) { + $module_config['enabled'][$module] = $weight++; + } + $this->bootstrapConfig->setModuleList($module_config); + // Update the kernel to make their services available. \Drupal::service('event_dispatcher')->dispatch('drupal.update_modules'); @@ -295,6 +315,12 @@ protected function disableModules(array $modules) { } $module_handler->setModuleList($module_filenames); $module_handler->resetImplementations(); + $module_config = array('enabled' => array()); + $weight = 0; + foreach ($module_filenames as $module => $filename) { + $module_config['enabled'][$module] = $weight++; + } + $this->bootstrapConfig->setModuleList($module_config); // Update the kernel to remove their services. Drupal::service('event_dispatcher')->dispatch('drupal.update_modules');