You are here

public function EntityQueryAlterComplexTest::testMemberViewAnyPublishedAccess in Group 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Kernel/EntityQueryAlterComplexTest.php \Drupal\Tests\group\Kernel\EntityQueryAlterComplexTest::testMemberViewAnyPublishedAccess()

Tests the viewing of any published entities for members.

File

tests/src/Kernel/EntityQueryAlterComplexTest.php, line 156

Class

EntityQueryAlterComplexTest
Tests that Group properly checks access for "complex" grouped entities.

Namespace

Drupal\Tests\group\Kernel

Code

public function testMemberViewAnyPublishedAccess() {
  $account = $this
    ->createUser();
  $node_1 = $this
    ->createNode([
    'type' => 'page',
  ]);
  $node_2 = $this
    ->createNode([
    'type' => 'page',
  ]);
  $node_3 = $this
    ->createNode([
    'type' => 'page',
    'uid' => $account
      ->id(),
  ]);
  $this->groupTypeA
    ->getMemberRole()
    ->grantPermission('view any node_as_content:page entity')
    ->save();
  $this->groupTypeB
    ->getMemberRole()
    ->grantPermission('view any node_as_content:page entity')
    ->save();
  $group_a = $this
    ->createGroup([
    'type' => $this->groupTypeA
      ->id(),
  ]);
  $group_a
    ->addContent($node_1, 'node_as_content:page');
  $group_a
    ->addMember($this
    ->getCurrentUser());
  $group_a
    ->addMember($account);
  $group_b = $this
    ->createGroup([
    'type' => $this->groupTypeB
      ->id(),
  ]);
  $group_b
    ->addContent($node_3, 'node_as_content:page');
  $group_b
    ->addMember($this
    ->getCurrentUser());
  $group_b
    ->addMember($account);
  $this
    ->assertQueryAccessResult([
    $node_1
      ->id(),
    $node_2
      ->id(),
    $node_3
      ->id(),
  ], 'Members can see any published nodes.');
  $this
    ->setCurrentUser($account);
  $this
    ->assertQueryAccessResult([
    $node_1
      ->id(),
    $node_2
      ->id(),
    $node_3
      ->id(),
  ], 'Members can see any published nodes.');
  $this
    ->setCurrentUser($this
    ->createUser());
  $this
    ->assertQueryAccessResult([
    $node_2
      ->id(),
  ], 'Only the ungrouped published node shows up.');
}