From 9a504cbf79b1b39784cc0446bd43c41a9e386ec2 Mon Sep 17 00:00:00 2001
From: webchick <drupal@webchick.net>
Date: Mon, 5 Jan 2015 10:45:30 -0800
Subject: [PATCH] Issue #2263339 by damiankloip, mitrpaka, blueminds, almaudoh,
 mgifford, xjm, znerol, dawehner: Fix all current_user set calls

---
 core/modules/system/src/Tests/Form/FormCacheTest.php | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/core/modules/system/src/Tests/Form/FormCacheTest.php b/core/modules/system/src/Tests/Form/FormCacheTest.php
index 906a1292e7b3..fbbb0f4cb843 100644
--- a/core/modules/system/src/Tests/Form/FormCacheTest.php
+++ b/core/modules/system/src/Tests/Form/FormCacheTest.php
@@ -8,6 +8,7 @@
 namespace Drupal\system\Tests\Form;
 
 use Drupal\Core\Form\FormState;
+use Drupal\Core\Session\AnonymousUserSession;
 use Drupal\Core\Session\UserSession;
 use Drupal\simpletest\KernelTestBase;
 
@@ -88,7 +89,9 @@ function testCacheToken() {
    * Tests the form cache without a logged-in user.
    */
   function testNoCacheToken() {
-    $this->container->set('current_user', new UserSession(array('uid' => 0)));
+    // Switch to a anonymous user account.
+    $account_switcher = \Drupal::service('account_switcher');
+    $account_switcher->switchTo(new AnonymousUserSession());
 
     $this->form_state->set('example', $this->randomMachineName());
     \Drupal::formBuilder()->setCache($this->form_build_id, $this->form, $this->form_state);
@@ -98,6 +101,9 @@ function testNoCacheToken() {
     $this->assertEqual($this->form['#property'], $cached_form['#property']);
     $this->assertTrue(empty($cached_form['#cache_token']), 'Form has no cache token');
     $this->assertEqual($this->form_state->get('example'), $cached_form_state->get('example'));
+
+    // Restore user account.
+    $account_switcher->switchBack();
   }
 
 }
-- 
GitLab