You are here

public function GroupContentQueryAccessHandlerTest::testGroupAccess in Group 2.0.x

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

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

@covers ::getConditions

File

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

Class

GroupContentQueryAccessHandlerTest
Tests the behavior of group content query access handler.

Namespace

Drupal\Tests\group\Kernel

Code

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

  // Allow members to update any content.
  $group_role = $this->groupType
    ->getMemberRole();
  $group_role
    ->grantPermission('update any user_as_content relation')
    ->save();
  $conditions = $this->handler
    ->getConditions('update', $user);
  $expected_conditions = [
    new Condition('gid', [
      $group
        ->id(),
    ]),
  ];
  $this
    ->assertEquals(1, $conditions
    ->count());
  $this
    ->assertEquals($expected_conditions, $conditions
    ->getConditions());
  $this
    ->assertEqualsCanonicalizing([
    '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
      ->assertEqualsCanonicalizing([
      'user.group_permissions',
      'user.permissions',
    ], $conditions
      ->getCacheContexts());
    $this
      ->assertTrue($conditions
      ->isAlwaysFalse());
  }
}