You are here

public function GroupAccessControlHandlerTest::testUpdateOrDeleteAccess in Group 2.0.x

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

Tests the behavior of update or delete access for groups.

@covers ::checkAccess @dataProvider updateOrDeleteAccessProvider

Parameters

string $operation: The operation to test.

string $permission: The permission name for the operation.

File

tests/src/Kernel/GroupAccessControlHandlerTest.php, line 48

Class

GroupAccessControlHandlerTest
Tests the general access behavior of group entities.

Namespace

Drupal\Tests\group\Kernel

Code

public function testUpdateOrDeleteAccess($operation, $permission) {
  $access_control_handler = $this->entityTypeManager
    ->getAccessControlHandler('group');
  $this
    ->assertFalse($this->group
    ->access($operation), 'An outsider without the right permission has no access');
  $access_control_handler
    ->resetCache();
  $this->group
    ->addMember($this
    ->getCurrentUser());
  $this
    ->assertFalse($this->group
    ->access($operation), 'A member without the right permission has no access');
  $access_control_handler
    ->resetCache();
  $this->groupType
    ->getMemberRole()
    ->grantPermission($permission)
    ->save();
  $this
    ->assertTrue($this->group
    ->access($operation), 'A member with the right permission has access');
  $access_control_handler
    ->resetCache();
  $this->group
    ->set('status', FALSE)
    ->save();
  $this
    ->assertTrue($this->group
    ->access($operation), 'Unpublishing the group does not change access');
  $access_control_handler
    ->resetCache();
  $this->group
    ->removeMember($this
    ->getCurrentUser());
  $this
    ->assertFalse($this->group
    ->access($operation), 'Leaving the group does change access');
}