You are here

public function LinkOwnershipAccessTest::doGlobalFlagOwnershipAccessTest in Flag 8.4

1 call to LinkOwnershipAccessTest::doGlobalFlagOwnershipAccessTest()
LinkOwnershipAccessTest::testFlagOwnershipAccess in tests/src/Functional/LinkOwnershipAccessTest.php
Test ownership access.

File

tests/src/Functional/LinkOwnershipAccessTest.php, line 65

Class

LinkOwnershipAccessTest
Tests the current user sees links for their own flaggings, or global ones.

Namespace

Drupal\Tests\flag\Functional

Code

public function doGlobalFlagOwnershipAccessTest() {

  // Create a global flag.
  $flag = $this
    ->createGlobalFlag();

  // Grant the flag permissions to the authenticated role, so that both
  // users have the same roles and share the render cache.
  $this
    ->grantFlagPermissions($flag);

  // Create and login a new user.
  $user_1 = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($user_1);

  // Flag the node with user 1.
  $this
    ->drupalGet($this->node
    ->toUrl());
  $this
    ->clickLink($flag
    ->getShortText('flag'));
  $this
    ->assertResponse(200);
  $this
    ->assertLink($flag
    ->getShortText('unflag'));

  // Switch to user 2. They should see the unflag link too.
  $user_2 = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($user_2);
  $this
    ->drupalGet($this->node
    ->toUrl());
  $this
    ->assertLink($flag
    ->getShortText('unflag'), 0, "The unflag link is found on the page for user 2.");
}