summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2012-08-21 23:34:31 (GMT)
committerwebchick2012-08-21 23:34:31 (GMT)
commit7a95a78eb2049c93b11c3be65b2392d17264cc02 (patch)
tree62f2499c03f41a24ea24606be39b4bcc129f79f6
parent6cdb69e106dade4f8917f60606f2e661226728e3 (diff)
Issue #1727538 by katbailey, chx, alexpott: WebTest tests should have access to the correct DIC.
-rw-r--r--core/includes/bootstrap.inc2
-rw-r--r--core/includes/path.inc2
-rw-r--r--core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php22
-rw-r--r--core/modules/system/lib/Drupal/system/Tests/Bundle/BundleTest.php7
-rw-r--r--core/modules/system/system.module2
-rw-r--r--core/modules/system/tests/modules/bundle_test/bundle_test.module25
6 files changed, 26 insertions, 34 deletions
diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index eadcba9..e173a95 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 36556a0..07aeee5 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 2cbc243..25139e6 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;
@@ -144,6 +145,11 @@ abstract class WebTestBase extends TestBase {
protected $redirect_count;
/**
+ * The kernel used in this test.
+ */
+ protected $kernel;
+
+ /**
* Constructor for Drupal\simpletest\WebTestBase.
*/
function __construct($test_id = NULL) {
@@ -659,6 +665,18 @@ abstract class WebTestBase extends TestBase {
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 @@ abstract class WebTestBase extends TestBase {
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 4aeea00..3177687 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 @@ class BundleTest extends WebTestBase {
* 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 523c433..de7241f 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 5f30b8f..b3d9bbc 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 @@
<?php
-
-/**
- * Implements hook_menu().
- */
-function bundle_test_menu() {
- $items['bundle_test'] = array(
- 'type' => 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');
-}
-