You are here

public function GroupContentQueryAccessHandlerTest::testOwnerGroupAccess in Group 8

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

Tests the conditions for owner access in the group scope.

@covers ::getConditions

File

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

Class

GroupContentQueryAccessHandlerTest
Tests the behavior of group content query access handler.

Namespace

Drupal\Tests\group\Kernel

Code

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

  // Allow members to edit their own content.
  $group_role = $this->groupType
    ->getMemberRole();
  $group_role
    ->grantPermission('update own user_as_content content')
    ->save();
  $conditions = $this->handler
    ->getConditions('update', $user);
  $expected_sub_condition = new ConditionGroup();
  $expected_conditions = [
    $expected_sub_condition
      ->addCondition('uid', $user
      ->id())
      ->addCondition('gid', [
      $group
        ->id(),
    ]),
  ];
  $this
    ->assertEquals(1, $conditions
    ->count());
  $this
    ->assertEquals('OR', $conditions
    ->getConjunction());
  $this
    ->assertEquals($expected_conditions, $conditions
    ->getConditions());
  $this
    ->assertEquals([
    'user',
    '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());
  }
}