Commit 9a504cbf authored by webchick's avatar webchick
Browse files

Issue #2263339 by damiankloip, mitrpaka, blueminds, almaudoh, mgifford, xjm,...

Issue #2263339 by damiankloip, mitrpaka, blueminds, almaudoh, mgifford, xjm, znerol, dawehner: Fix all current_user set calls
parent b3f23196
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace Drupal\system\Tests\Form; namespace Drupal\system\Tests\Form;
use Drupal\Core\Form\FormState; use Drupal\Core\Form\FormState;
use Drupal\Core\Session\AnonymousUserSession;
use Drupal\Core\Session\UserSession; use Drupal\Core\Session\UserSession;
use Drupal\simpletest\KernelTestBase; use Drupal\simpletest\KernelTestBase;
...@@ -88,7 +89,9 @@ function testCacheToken() { ...@@ -88,7 +89,9 @@ function testCacheToken() {
* Tests the form cache without a logged-in user. * Tests the form cache without a logged-in user.
*/ */
function testNoCacheToken() { 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()); $this->form_state->set('example', $this->randomMachineName());
\Drupal::formBuilder()->setCache($this->form_build_id, $this->form, $this->form_state); \Drupal::formBuilder()->setCache($this->form_build_id, $this->form, $this->form_state);
...@@ -98,6 +101,9 @@ function testNoCacheToken() { ...@@ -98,6 +101,9 @@ function testNoCacheToken() {
$this->assertEqual($this->form['#property'], $cached_form['#property']); $this->assertEqual($this->form['#property'], $cached_form['#property']);
$this->assertTrue(empty($cached_form['#cache_token']), 'Form has no cache token'); $this->assertTrue(empty($cached_form['#cache_token']), 'Form has no cache token');
$this->assertEqual($this->form_state->get('example'), $cached_form_state->get('example')); $this->assertEqual($this->form_state->get('example'), $cached_form_state->get('example'));
// Restore user account.
$account_switcher->switchBack();
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment