You are here

public function GroupQueryAccessHandlerTest::testOnlyGroupUpdateAccess in Group 8

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

Tests the conditions for people with update access in just the group scope.

@covers ::getConditions

File

tests/src/Kernel/GroupQueryAccessHandlerTest.php, line 192

Class

GroupQueryAccessHandlerTest
Tests the behavior of group query access handler.

Namespace

Drupal\Tests\group\Kernel

Code

public function testOnlyGroupUpdateAccess() {
  $user = $this
    ->getCurrentUser();
  $group = $this
    ->createGroup();
  $group
    ->addMember($user);

  // Remove the 'view group' permission from the default group type's outsider
  // role so the user only has the permission for the groups they are in.
  $this->entityTypeManager
    ->getStorage('group_role')
    ->load('default-outsider')
    ->revokePermission('view group')
    ->save();

  // Make sure members have access.
  $this->entityTypeManager
    ->getStorage('group_role')
    ->load('default-member')
    ->grantPermission('edit group')
    ->revokePermission('view group')
    ->save();
  $conditions = $this->handler
    ->getConditions('update', $user);
  $expected_conditions = [
    new Condition('id', [
      $group
        ->id(),
    ]),
  ];
  $this
    ->assertEquals(1, $conditions
    ->count());
  $this
    ->assertEquals($expected_conditions, $conditions
    ->getConditions());
  $this
    ->assertEquals([
    'user.group_permissions',
    'user.permissions',
  ], $conditions
    ->getCacheContexts());
  $this
    ->assertFalse($conditions
    ->isAlwaysFalse());
  foreach ([
    'view',
    'delete',
  ] as $operation) {
    $conditions = $this->handler
      ->getConditions($operation, $user);
    $this
      ->assertEquals(0, $conditions
      ->count());
    $this
      ->assertEquals([
      'user.group_permissions',
      'user.permissions',
    ], $conditions
      ->getCacheContexts());
    $this
      ->assertTrue($conditions
      ->isAlwaysFalse());
  }
}