You are here

public function EntityQueryAlterComplexTest::testNewPermission in Group 2.0.x

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

Tests that adding new permissions clears caches.

This is actually tested in the permission calculator, but added here also for additional hardening. It does not really clear the cached conditions, but rather return a different set as your user.group_permissions cache context value changes.

We will not test any further scenarios that trigger a change in your group permissions as those are -as mentioned above- tested elsewhere. It just seemed like a good idea to at least test one scenario here.

File

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

Class

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

Namespace

Drupal\Tests\group\Kernel

Code

public function testNewPermission() {
  $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');
  $group
    ->addMember($this
    ->getCurrentUser());
  $this
    ->assertQueryAccessResult([
    $node_2
      ->id(),
  ], 'Members can only see ungrouped nodes');

  // This should trigger a different set of conditions.
  $this->groupTypeA
    ->getMemberRole()
    ->grantPermission('view any node_as_content:page entity')
    ->save();
  $this
    ->assertQueryAccessResult([
    $node_1
      ->id(),
    $node_2
      ->id(),
  ], 'Outsiders can see grouped nodes');
}