diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index eadcba91fd4bc08ec6b270a076b56f6329136293..e173a958e4f314f3ab6c4e23936e0f0663ef82c3 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2632,7 +2632,7 @@ function language($type, $reset = FALSE) { // Reset the language manager's cache and our own. if ($reset) { - if (drupal_container()->has('language_manager')) { + if (drupal_container()->isScopeActive('request')) { drupal_container()->get('language_manager')->reset($type); } if (!isset($type)) { diff --git a/core/includes/path.inc b/core/includes/path.inc index 36556a02f20f3eb20e9bad76dbad5cce1cda4514..07aeee5fbe25dd08eabecc2518727863a55e5839 100644 --- a/core/includes/path.inc +++ b/core/includes/path.inc @@ -370,7 +370,7 @@ function current_path() { // @todo Remove the check for whether the request service exists and the // fallback code below, once the path alias logic has been figured out in // http://drupal.org/node/1269742. - if (drupal_container()->has('request')) { + if (drupal_container()->isScopeActive('request')) { return drupal_container()->get('request')->attributes->get('system_path'); } // If we are outside the request scope, fall back to using the path stored in diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 2cbc2439629eb9eae96c850d16d9171f270acb3e..25139e67f1a387779b13f5c742225f3c6e913de5 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -7,6 +7,7 @@ namespace Drupal\simpletest; +use Drupal\Core\DrupalKernel; use Drupal\Core\Database\Database; use Drupal\Core\Database\ConnectionNotDefinedException; use PDO; @@ -143,6 +144,11 @@ abstract class WebTestBase extends TestBase { */ protected $redirect_count; + /** + * The kernel used in this test. + */ + protected $kernel; + /** * Constructor for Drupal\simpletest\WebTestBase. */ @@ -659,6 +665,18 @@ protected function setUp() { module_enable(array($this->profile), FALSE); } + // 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(); + // Reset/rebuild all data structures after enabling the modules. $this->resetAll(); @@ -769,6 +787,10 @@ protected function tearDown() { if (!$this->setupDatabasePrefix) { return FALSE; } + // Destroy the testing kernel. + if (isset($this->kernel)) { + $this->kernel->shutdown(); + } // Remove all prefixed tables. $connection_info = Database::getConnectionInfo('default'); $tables = db_find_tables($connection_info['default']['prefix']['default'] . '%'); diff --git a/core/modules/system/lib/Drupal/system/Tests/Bundle/BundleTest.php b/core/modules/system/lib/Drupal/system/Tests/Bundle/BundleTest.php index 4aeea00e9dc6ec7b7b7c9593d69056333e94ab7c..3177687c088117e0d65af2cc1524fd831c9810e5 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Bundle/BundleTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Bundle/BundleTest.php @@ -33,12 +33,7 @@ public static function getInfo() { * Test that services provided by module bundles get registered to the DIC. */ function testBundleRegistration() { - // The page callback at /bundle_test checks - // drupal_container()->has('bundle_test_class') - // and if this returns TRUE it outputs a message to this effect. We just - // need to check that the message appears on the page. - $this->drupalGet('bundle_test'); - $this->assertText(t('The service with id bundle_test_class is available in the DIC'), t('The bundle_test_class service has been registered to the DIC')); + $this->assertTrue(drupal_container()->has('bundle_test_class'), t('The bundle_test_class service has been registered to the DIC')); // The event subscriber method in the test class calls drupal_set_message with // a message saying it has fired. This will fire on every page request so it // should show up on the front page. diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 523c43331c2e89d130b9b0a9fcc09a352ad33944..de7241fcbefc414e50bd3e2328b60f85a28c71bd 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -2205,7 +2205,7 @@ function system_add_module_assets() { * Implements hook_custom_theme(). */ function system_custom_theme() { - if (drupal_container()->has('request')) { + if (drupal_container()->isScopeActive('request')) { $request = drupal_container()->get('request'); $path = $request->attributes->get('system_path'); if (user_access('view the administration theme') && path_is_admin($path)) { diff --git a/core/modules/system/tests/modules/bundle_test/bundle_test.module b/core/modules/system/tests/modules/bundle_test/bundle_test.module index 5f30b8f45f9ef1ee9c1924ac173f74e7f2191c2d..b3d9bbc7f3711e882119cd6b3af051245d859d04 100644 --- a/core/modules/system/tests/modules/bundle_test/bundle_test.module +++ b/core/modules/system/tests/modules/bundle_test/bundle_test.module @@ -1,26 +1 @@ MENU_CALLBACK, - 'title' => t('Bundle test callback'), - 'page callback' => 'bundle_test_callback', - 'access callback' => TRUE, - ); - return $items; -} - -/** - * Simple callback for testing that the bundle_test_class service exists in the - * DIC. - */ -function bundle_test_callback() { - if (drupal_container()->has('bundle_test_class')) { - return t('The service with id bundle_test_class is available in the DIC'); - } - return t('Service not found'); -} -