You are here

public function GroupContentQueryAccessHandlerTest::testGroupTypeAccess in Group 8

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

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

@covers ::getConditions

File

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

Class

GroupContentQueryAccessHandlerTest
Tests the behavior of group content query access handler.

Namespace

Drupal\Tests\group\Kernel

Code

public function testGroupTypeAccess() {
  $user = $this
    ->createUser();

  // Allow outsiders to view any content.
  $group_role = $this->groupType
    ->getOutsiderRole();
  $group_role
    ->grantPermission('view user_as_content content')
    ->save();

  // Allow members to update any content.
  $group_role = $this->groupType
    ->getMemberRole();
  $group_role
    ->grantPermission('update any user_as_content content')
    ->save();
  $conditions = $this->handler
    ->getConditions('view', $user);
  $expected_conditions = [
    new Condition('type', [
      $this->groupContentType
        ->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 ([
    'update',
    '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());
  }
}