You are here

public function EntityQueryAlterComplexTest::testMemberAdminAccess in Group 2.0.x

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

Tests the admin access for members.

File

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

Class

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

Namespace

Drupal\Tests\group\Kernel

Code

public function testMemberAdminAccess() {
  $account = $this
    ->createUser();
  $node_1 = $this
    ->createNode([
    'type' => 'page',
  ]);
  $node_2 = $this
    ->createNode([
    'type' => 'page',
    'status' => 0,
  ]);
  $node_3 = $this
    ->createNode([
    'type' => 'page',
  ]);
  $node_4 = $this
    ->createNode([
    'type' => 'page',
    'status' => 0,
  ]);
  $node_5 = $this
    ->createNode([
    'type' => 'page',
    'uid' => $account
      ->id(),
  ]);
  $node_6 = $this
    ->createNode([
    'type' => 'page',
    'status' => 0,
    'uid' => $account
      ->id(),
  ]);
  $this->groupTypeA
    ->getMemberRole()
    ->grantPermission('administer node_as_content:page')
    ->save();
  $this->groupTypeB
    ->getMemberRole()
    ->grantPermission('administer node_as_content:page')
    ->save();
  $group_a = $this
    ->createGroup([
    'type' => $this->groupTypeA
      ->id(),
  ]);
  $group_a
    ->addContent($node_3, 'node_as_content:page');
  $group_a
    ->addContent($node_4, 'node_as_content:page');
  $group_a
    ->addMember($this
    ->getCurrentUser());
  $group_b = $this
    ->createGroup([
    'type' => $this->groupTypeB
      ->id(),
  ]);
  $group_b
    ->addContent($node_5, 'node_as_content:page');
  $group_b
    ->addContent($node_6, 'node_as_content:page');
  $group_b
    ->addMember($this
    ->getCurrentUser());
  $expected = [
    $node_1
      ->id(),
    $node_2
      ->id(),
    $node_3
      ->id(),
    $node_4
      ->id(),
    $node_5
      ->id(),
    $node_6
      ->id(),
  ];
  $this
    ->assertQueryAccessResult($expected, 'Admin member can see anything regardless of owner or published status.');
}