You are here

public function EntityQueryAlterTest::testNewGroupContent in Group 2.0.x

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

Tests that adding new group content clears caches.

File

tests/src/Kernel/EntityQueryAlterTest.php, line 256

Class

EntityQueryAlterTest
Tests that Group properly checks access for grouped entities.

Namespace

Drupal\Tests\group\Kernel

Code

public function testNewGroupContent() {
  $entity_1 = $this
    ->createTestEntity();
  $entity_2 = $this
    ->createTestEntity();
  $this->groupTypeA
    ->getMemberRole()
    ->grantPermission('view any entity_test_as_content entity')
    ->save();
  $group = $this
    ->createGroup([
    'type' => $this->groupTypeA
      ->id(),
  ]);
  $this
    ->assertQueryAccessResult([
    $entity_1
      ->id(),
    $entity_2
      ->id(),
  ], 'Outsiders can see ungrouped test entities');

  // This should clear the cache.
  $group
    ->addContent($entity_1, 'entity_test_as_content');
  $this
    ->assertQueryAccessResult([
    $entity_2
      ->id(),
  ], 'Outsiders can see ungrouped test entities');
}