You are here

public function EntityQueryAlterTest::testNewPermission in Group 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Kernel/EntityQueryAlterTest.php \Drupal\Tests\group\Kernel\EntityQueryAlterTest::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 test entity.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/EntityQueryAlterTest.php, line 282

Class

EntityQueryAlterTest
Tests that Group properly checks access for grouped entities.

Namespace

Drupal\Tests\group\Kernel

Code

public function testNewPermission() {
  $entity_1 = $this
    ->createTestEntity();
  $entity_2 = $this
    ->createTestEntity();
  $group = $this
    ->createGroup([
    'type' => $this->groupTypeA
      ->id(),
  ]);
  $group
    ->addContent($entity_1, 'entity_test_as_content');
  $group
    ->addMember($this
    ->getCurrentUser());
  $this
    ->assertQueryAccessResult([
    $entity_2
      ->id(),
  ], 'Members can only see ungrouped test entities');

  // This should trigger a different set of conditions.
  $this->groupTypeA
    ->getMemberRole()
    ->grantPermission('view any entity_test_as_content entity')
    ->save();
  $this
    ->assertQueryAccessResult([
    $entity_1
      ->id(),
    $entity_2
      ->id(),
  ], 'Outsiders can see grouped test entities');
}