Verified Commit 3cdeded2 authored by Dave Long's avatar Dave Long
Browse files

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

(cherry picked from commit eb8cd5d6)
parent 660b30a0
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ protected function setUp(): void {
    parent::setUp();

    $this->container->get('current_user')
      ->getAccount()
      ->addRole($this->drupalCreateRole([
        'access contextual links',
      ]));
+1 −0
Original line number Diff line number Diff line
@@ -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?
    if ($allowed_to_view_unpublished) {
      $this->container->get('current_user')
        ->getAccount()
        ->addRole($this->drupalCreateRole(['view own unpublished media']));
    }

+1 −1
Original line number Diff line number Diff line
@@ -86,7 +86,7 @@ protected function setUp(): void {
      'access content',
      'view media',
    ]);
    $this->container->set('current_user', $user);
    $this->container->get('current_user')->setAccount($user);

    $this->image = File::create([
      'uri' => $this->getTestFiles('image')[0]->uri,
+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ protected function setUp(): void {
    $this->user->save();

    // 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.
    \Drupal::service('router.builder')->rebuild();
  }