diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php index 9671787..031fe2e 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -8,6 +8,7 @@ namespace Drupal\simpletest; use Drupal\Component\Utility\Random; +use Drupal\Core\Authentication\AuthenticationManager; use Drupal\Core\Database\Database; use Drupal\Component\Utility\String; use Drupal\Core\Config\ConfigImporter; @@ -1089,10 +1090,14 @@ private function prepareEnvironment() { $request = Request::create('/'); $this->container->set('request', $request); + $account_proxy = new AccountProxy(new AuthenticationManager(), $request); + // Run all tests as a anonymous user by default, web tests will replace that // during the test set up. - $current_user = $this->container->get('current_user'); - $current_user->setAccount(new AnonymousUserSession()); + $account_proxy->setAccount(new AnonymousUserSession()); + + $this->container->set('current_user', $account_proxy); + \Drupal::setContainer($this->container);