You are here

public function GroupContentQueryAccessHandlerTest::testAdminAccess in Group 8

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

Tests the conditions for admin access.

@covers ::getConditions

File

tests/src/Kernel/GroupContentQueryAccessHandlerTest.php, line 279

Class

GroupContentQueryAccessHandlerTest
Tests the behavior of group content query access handler.

Namespace

Drupal\Tests\group\Kernel

Code

public function testAdminAccess() {
  $user = $this
    ->createUser();
  $group = $this
    ->createGroup([
    'type' => $this->groupType
      ->id(),
  ]);
  $group
    ->addMember($user);

  // Allow members to administer all content.
  $group_role = $this->groupType
    ->getMemberRole();
  $group_role
    ->grantPermission('administer user_as_content')
    ->save();
  foreach ([
    'view',
    'update',
    'delete',
  ] as $operation) {
    $conditions = $this->handler
      ->getConditions($operation, $user);
    $expected_conditions = [
      new Condition('gid', [
        $group
          ->id(),
      ]),
    ];
    $this
      ->assertEquals(1, $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());
  }
}