Skip to content
Snippets Groups Projects
Verified Commit eb8cd5d6 authored by Dave Long's avatar Dave Long
Browse files

Issue #3417365 by kristiaanvandeneynde, smustgrave: Properly set current_user service in tests

parent c5e63487
No related branches found
No related tags found
No related merge requests found
...@@ -26,6 +26,7 @@ protected function setUp(): void { ...@@ -26,6 +26,7 @@ protected function setUp(): void {
parent::setUp(); parent::setUp();
$this->container->get('current_user') $this->container->get('current_user')
->getAccount()
->addRole($this->drupalCreateRole([ ->addRole($this->drupalCreateRole([
'access contextual links', 'access contextual links',
])); ]));
......
...@@ -136,6 +136,7 @@ public function testAccessUnpublished($allowed_to_view_unpublished, $expected_re ...@@ -136,6 +136,7 @@ public function testAccessUnpublished($allowed_to_view_unpublished, $expected_re
// Are we testing as a user who is allowed to view the embedded entity? // Are we testing as a user who is allowed to view the embedded entity?
if ($allowed_to_view_unpublished) { if ($allowed_to_view_unpublished) {
$this->container->get('current_user') $this->container->get('current_user')
->getAccount()
->addRole($this->drupalCreateRole(['view own unpublished media'])); ->addRole($this->drupalCreateRole(['view own unpublished media']));
} }
......
...@@ -86,7 +86,7 @@ protected function setUp(): void { ...@@ -86,7 +86,7 @@ protected function setUp(): void {
'access content', 'access content',
'view media', 'view media',
]); ]);
$this->container->set('current_user', $user); $this->container->get('current_user')->setAccount($user);
$this->image = File::create([ $this->image = File::create([
'uri' => $this->getTestFiles('image')[0]->uri, 'uri' => $this->getTestFiles('image')[0]->uri,
......
...@@ -41,7 +41,7 @@ protected function setUp(): void { ...@@ -41,7 +41,7 @@ protected function setUp(): void {
$this->user->save(); $this->user->save();
// Set current user. // Set current user.
$this->container->set('current_user', $this->user); $this->container->get('current_user')->setAccount($this->user);
// Install the router table and then rebuild. // Install the router table and then rebuild.
\Drupal::service('router.builder')->rebuild(); \Drupal::service('router.builder')->rebuild();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment