commit 775127eae0890f744a015653fdb59950f7773e8d Author: Joel Pittet Date: Sat Jan 4 01:44:08 2014 -0800 add in onces deemed safe diff --git a/core/includes/common.inc b/core/includes/common.inc index e926ac5..50ea821 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -3187,8 +3187,8 @@ function drupal_cron_run() { // Force the current user to anonymous to ensure consistent permissions on // cron runs. - $original_user = $GLOBALS['user']; - $GLOBALS['user'] = drupal_anonymous_user(); + $original_user = \Drupal::currentUser(); + \Drupal::getContainer()->set('current_user', drupal_anonymous_user()); // Try to allocate enough time to run all the hook_cron implementations. drupal_set_time_limit(240); @@ -3246,7 +3246,7 @@ function drupal_cron_run() { } } // Restore the user. - $GLOBALS['user'] = $original_user; + \Drupal::getContainer()->set('current_user', $original_user); drupal_save_session($original_session_saving); return $return; diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php index a93300e..85159b5 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php @@ -120,7 +120,7 @@ public function testSort() { // Test as a non-admin. $normal_user = $this->drupalCreateUser(array('access content')); - $GLOBALS['user'] = $normal_user; + $this->container->set('current_user', $normal_user); $handler = $this->container->get('plugin.manager.entity_reference.selection')->getSelectionHandler($instance); diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php index 2f794b2..ecce74c 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -898,7 +898,8 @@ protected function changeDatabasePrefix() { * @see TestBase::tearDown() */ protected function prepareEnvironment() { - global $user, $conf; + global $conf; + $user = \Drupal::currentUser(); $language_interface = language(Language::TYPE_INTERFACE); // When running the test runner within a test, back up the original database @@ -931,9 +932,6 @@ protected function prepareEnvironment() { // Ensure that the current session is not changed by the new environment. require_once DRUPAL_ROOT . '/' . settings()->get('session_inc', 'core/includes/session.inc'); drupal_save_session(FALSE); - // Run all tests as a anonymous user by default, web tests will replace that - // during the test set up. - $user = drupal_anonymous_user(); // Save and clean the shutdown callbacks array because it is static cached // and will be changed by the test run. Otherwise it will contain callbacks @@ -976,7 +974,10 @@ protected function prepareEnvironment() { $request = Request::create('/'); $this->container->set('request', $request); - $this->container->set('current_user', $GLOBALS['user']); + + // Run all tests as a anonymous user by default, web tests will replace that + // during the test set up. + $this->container->set('current_user', drupal_anonymous_user()); \Drupal::setContainer($this->container); @@ -1048,9 +1049,9 @@ protected function rebuildContainer() { // DrupalKernel replaces the container in \Drupal::getContainer() with a // different object, so we need to replace the instance on this test class. $this->container = \Drupal::getContainer(); - // The global $user is set in TestBase::prepareEnvironment(). + // The current user is set in TestBase::prepareEnvironment(). $this->container->set('request', $request); - $this->container->set('current_user', $GLOBALS['user']); + $this->container->set('current_user', \Drupal::currentUser()); } /** @@ -1065,7 +1066,7 @@ protected function rebuildContainer() { * @see TestBase::prepareEnvironment() */ protected function tearDown() { - global $user, $conf; + global $conf; // Reset all static variables. // Unsetting static variables will potentially invoke destruct methods, @@ -1143,7 +1144,7 @@ protected function tearDown() { $callbacks = $this->originalShutdownCallbacks; // Restore original user session. - $user = $this->originalUser; + $this->container->set('current_user', $this->originalUser); drupal_save_session(TRUE); } diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 518d563..6c955b4 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -277,7 +277,7 @@ protected function drupalCreateNode(array $settings = array()) { $settings['uid'] = $this->loggedInUser->id(); } else { - $user = \Drupal::currentUser() ?: $GLOBALS['user']; + $user = \Drupal::currentUser() ?: drupal_anonymous_user(); $settings['uid'] = $user->id(); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceTest.php b/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceTest.php index 4344801..edad64a 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceTest.php @@ -32,7 +32,6 @@ function testTokenReplacement() { $account = $this->drupalCreateUser(); $node = $this->drupalCreateNode(array('uid' => $account->id())); $node->title = 'Blinking Text'; - global $user; $language_interface = language(Language::TYPE_INTERFACE); $source = '[node:title]'; // Title of the node we passed in @@ -46,7 +45,7 @@ function testTokenReplacement() { $target = check_plain($node->getTitle()); $target .= check_plain($account->getUsername()); $target .= format_interval(REQUEST_TIME - $node->getCreatedTime(), 2, $language_interface->id); - $target .= check_plain($user->getUsername()); + $target .= check_plain(\Drupal::currentUser()->getUsername()); $target .= format_date(REQUEST_TIME, 'short', '', NULL, $language_interface->id); // Test that the clear parameter cleans out non-existent tokens.