You are here

public function EntityQueryAlterTest::testNonMemberViewAnyAccess in Group 8

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

Tests the viewing of any entities for non-members.

File

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

Class

EntityQueryAlterTest
Tests that Group properly checks access for grouped entities.

Namespace

Drupal\Tests\group\Kernel

Code

public function testNonMemberViewAnyAccess() {
  $account = $this
    ->createUser([], [
    'administer entity_test_with_owner content',
  ]);
  $entity_1 = $this
    ->createTestEntity();
  $entity_2 = $this
    ->createTestEntity();
  $entity_3 = $this
    ->createTestEntity();
  $this->groupTypeA
    ->getOutsiderRole()
    ->grantPermission('view any entity_test_as_content entity')
    ->save();
  $this->groupTypeB
    ->getOutsiderRole()
    ->grantPermission('view any entity_test_as_content entity')
    ->save();
  $group_a = $this
    ->createGroup([
    'type' => $this->groupTypeA
      ->id(),
  ]);
  $group_a
    ->addContent($entity_1, 'entity_test_as_content');
  $group_a
    ->addMember($account);
  $group_b = $this
    ->createGroup([
    'type' => $this->groupTypeB
      ->id(),
  ]);
  $group_b
    ->addContent($entity_3, 'entity_test_as_content');
  $group_b
    ->addMember($account);
  $this
    ->assertQueryAccessResult([
    $entity_1
      ->id(),
    $entity_2
      ->id(),
    $entity_3
      ->id(),
  ], 'Non-members can see any test entities.');
  $this
    ->setCurrentUser($this
    ->createUser([], [
    'administer entity_test_with_owner content',
  ]));
  $this
    ->assertQueryAccessResult([
    $entity_1
      ->id(),
    $entity_2
      ->id(),
    $entity_3
      ->id(),
  ], 'Non-members can see any test entities.');
  $this
    ->setCurrentUser($account);
  $this
    ->assertQueryAccessResult([
    $entity_2
      ->id(),
  ], 'Only the ungrouped test entity shows up.');
}