You are here

public function EntityQueryAlterComplexTest::testNonMemberViewOwnUnpublishedAccess in Group 2.0.x

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

Tests the viewing of own unpublished entities for non-members.

File

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

Class

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

Namespace

Drupal\Tests\group\Kernel

Code

public function testNonMemberViewOwnUnpublishedAccess() {
  $account = $this
    ->createUser();
  $node_1 = $this
    ->createNode([
    'type' => 'page',
    'status' => 0,
  ]);
  $node_2 = $this
    ->createNode([
    'type' => 'page',
    'status' => 0,
  ]);
  $node_3 = $this
    ->createNode([
    'type' => 'page',
    'status' => 0,
    'uid' => $account
      ->id(),
  ]);
  $this->groupTypeA
    ->getOutsiderRole()
    ->grantPermission('view own unpublished node_as_content:page entity')
    ->save();
  $this->groupTypeB
    ->getOutsiderRole()
    ->grantPermission('view own unpublished 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($account);
  $group_b = $this
    ->createGroup([
    'type' => $this->groupTypeB
      ->id(),
  ]);
  $group_b
    ->addContent($node_3, 'node_as_content:page');
  $group_b
    ->addMember($account);
  $this
    ->assertQueryAccessResult([
    $node_1
      ->id(),
    $node_2
      ->id(),
  ], 'Non-members can see their own unpublished nodes.');
  $this
    ->setCurrentUser($this
    ->createUser());
  $this
    ->assertQueryAccessResult([
    $node_2
      ->id(),
  ], 'Only the ungrouped unpublished node shows up.');

  // This is actually a core issue, but for now unpublished nodes show up in
  // entity queries when there are no node grants defining modules.
  $this
    ->setCurrentUser($account);
  $this
    ->assertQueryAccessResult([
    $node_2
      ->id(),
  ], 'Only the ungrouped unpublished node shows up.');
}