You are here

public function GroupContentQueryAccessHandlerTest::testOwnerGroupTypeAccess in Group 8

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

Tests the conditions for owner access in the group type scope.

@covers ::getConditions

File

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

Class

GroupContentQueryAccessHandlerTest
Tests the behavior of group content query access handler.

Namespace

Drupal\Tests\group\Kernel

Code

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

  // Allow outsiders to edit their own content.
  $group_role = $this->groupType
    ->getOutsiderRole();
  $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('type', [
      $this->groupContentType
        ->id(),
    ])
      ->addCondition('gid', [
      $group
        ->id(),
    ], 'NOT IN'),
  ];
  $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());
  }
}