Issue #1786990 by effulgentsia, tim.plunkett, andypost, sun: Fixed [Module]Bundle is registered too late in WebTestBase::setUp().

8.0.x
webchick 2012-10-11 08:42:27 -07:00
parent 1fc2ac33ca
commit 44898fe980
2 changed files with 32 additions and 16 deletions

View File

@ -9,6 +9,7 @@ namespace Drupal\simpletest;
use Drupal\Core\Database\Database;
use Drupal\Core\Database\ConnectionNotDefinedException;
use Drupal\Core\DrupalKernel;
use ReflectionMethod;
use ReflectionObject;
use Exception;
@ -828,6 +829,35 @@ abstract class TestBase {
$this->setupEnvironment = TRUE;
}
/**
* Rebuild drupal_container().
*
* @todo Fix http://drupal.org/node/1708692 so that module enable/disable
* changes are immediately reflected in drupal_container(). Until then,
* tests can invoke this workaround when requiring services from newly
* enabled modules to be immediately available in the same request.
*/
protected function rebuildContainer() {
// DrupalKernel expects to merge a fresh bootstrap container, not remerge
// what is left over from a prior container build.
drupal_container(NULL, TRUE);
// Create a new DrupalKernel for testing purposes, now that all required
// modules have been enabled. This also stores a new dependency injection
// container in drupal_container(). Drupal\simpletest\TestBase::tearDown()
// restores the original container.
// @see Drupal\Core\DrupalKernel::initializeContainer()
$this->kernel = new DrupalKernel('testing', FALSE);
// Booting the kernel is necessary to initialize the new DIC. While
// normally the kernel gets booted on demand in
// Symfony\Component\HttpKernel\handle(), this kernel needs manual booting
// as it is not used to handle a request.
$this->kernel->boot();
// The DrupalKernel does not update the container in drupal_container(), but
// replaces it with a new object. We therefore need to replace the minimal
// boostrap container that has been set up by TestBase::prepareEnvironment().
$this->container = drupal_container();
}
/**
* Deletes created files, database tables, and reverts all environment changes.
*

View File

@ -684,6 +684,7 @@ abstract class WebTestBase extends TestBase {
// Execute the non-interactive installer.
require_once DRUPAL_ROOT . '/core/includes/install.core.inc';
install_drupal($settings);
$this->rebuildContainer();
// Restore the original Simpletest batch.
$batch = &batch_get();
@ -716,24 +717,9 @@ abstract class WebTestBase extends TestBase {
if ($modules) {
$success = module_enable($modules, TRUE);
$this->assertTrue($success, t('Enabled modules: %modules', array('%modules' => implode(', ', $modules))));
$this->rebuildContainer();
}
// Create a new DrupalKernel for testing purposes, now that all required
// modules have been enabled. This also stores a new dependency injection
// container in drupal_container(). Drupal\simpletest\TestBase::tearDown()
// restores the original container.
// @see Drupal\Core\DrupalKernel::initializeContainer()
$this->kernel = new DrupalKernel('testing', FALSE);
// Booting the kernel is necessary to initialize the new DIC. While
// normally the kernel gets booted on demand in
// Symfony\Component\HttpKernel\handle(), this kernel needs manual booting
// as it is not used to handle a request.
$this->kernel->boot();
// The DrupalKernel does not update the container in drupal_container(), but
// replaces it with a new object. We therefore need to replace the minimal
// boostrap container that has been set up by TestBase::prepareEnvironment().
$this->container = drupal_container();
// Reset/rebuild all data structures after enabling the modules.
$this->resetAll();