You are here

public function GroupQueryAccessHandlerTest::testCombinedDeleteAccess in Group 8

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

Tests the conditions for people with delete access in both scopes.

@covers ::getConditions

File

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

Class

GroupQueryAccessHandlerTest
Tests the behavior of group query access handler.

Namespace

Drupal\Tests\group\Kernel

Code

public function testCombinedDeleteAccess() {
  $user = $this
    ->getCurrentUser();
  $group = $this
    ->createGroup();
  $group
    ->addMember($user);
  $this->entityTypeManager
    ->getStorage('group_role')
    ->load('default-member')
    ->grantPermission('delete group')
    ->revokePermission('view group')
    ->save();
  $this->entityTypeManager
    ->getStorage('group_role')
    ->load('default-outsider')
    ->grantPermission('delete group')
    ->revokePermission('view group')
    ->save();
  $conditions = $this->handler
    ->getConditions('delete', $user);
  $expected_conditions = [
    (new ConditionGroup())
      ->addCondition('type', [
      'default',
    ])
      ->addCondition('id', [
      $group
        ->id(),
    ], 'NOT IN'),
    new Condition('id', [
      $group
        ->id(),
    ]),
  ];
  $this
    ->assertEquals(2, $conditions
    ->count());
  $this
    ->assertEquals('OR', $conditions
    ->getConjunction());
  $this
    ->assertEquals($expected_conditions, $conditions
    ->getConditions());
  $this
    ->assertEquals([
    'user.group_permissions',
    'user.permissions',
  ], $conditions
    ->getCacheContexts());
  $this
    ->assertFalse($conditions
    ->isAlwaysFalse());
  foreach ([
    'view',
    'update',
  ] 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());
  }
}