You are here

public function EntityQueryAlterComplexTest::testNonMemberGroupAccessWithoutPermission in Group 2.0.x

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

Tests that grouped nodes are properly hidden for non-members.

File

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

Class

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

Namespace

Drupal\Tests\group\Kernel

Code

public function testNonMemberGroupAccessWithoutPermission() {
  $node_1 = $this
    ->createNode([
    'type' => 'page',
  ]);
  $node_2 = $this
    ->createNode([
    'type' => 'page',
  ]);
  $group = $this
    ->createGroup([
    'type' => $this->groupTypeA
      ->id(),
  ]);
  $group
    ->addContent($node_1, 'node_as_content:page');
  $this
    ->assertQueryAccessResult([
    $node_2
      ->id(),
  ], 'Only the ungrouped node shows up.');

  // Extra hardening: Re-confirm result when another group type does grant
  // access but does not contain the node.
  $this->groupTypeB
    ->getOutsiderRole()
    ->grantPermission('view any node_as_content:page entity')
    ->save();
  $this
    ->createGroup([
    'type' => $this->groupTypeB
      ->id(),
  ]);
  $this
    ->assertQueryAccessResult([
    $node_2
      ->id(),
  ], 'Only the ungrouped node shows up.');
}