You are here

public function GroupContentAccessControlHandlerTest::testEntityCreateAccess in Group 8

Tests the entity create access.

@covers ::entityCreateAccess @dataProvider entityCreateAccessProvider

Parameters

\Closure $expected: A closure returning the expected access result.

string $plugin_id: The plugin ID.

array $definition: The plugin definition.

bool $has_admin_permission: Whether the account has the admin permission.

bool $has_permission: Whether the account has the required permission.

string|false $permission: The entity create permission.

File

tests/src/Unit/GroupContentAccessControlHandlerTest.php, line 540

Class

GroupContentAccessControlHandlerTest
Tests the default GroupContentEnabler access handler.

Namespace

Drupal\Tests\group\Unit

Code

public function testEntityCreateAccess(\Closure $expected, $plugin_id, array $definition, $has_admin_permission, $has_permission, $permission) {
  $permission_provider = $this
    ->prophesize(GroupContentPermissionProviderInterface::class);
  $permission_provider
    ->getAdminPermission()
    ->willReturn($definition['admin_permission']);
  $permission_provider
    ->getEntityCreatePermission()
    ->willReturn($permission);
  $manager = $this
    ->prophesize(GroupContentEnablerManagerInterface::class);
  $manager
    ->hasHandler($plugin_id, 'permission_provider')
    ->willReturn(TRUE);
  $manager
    ->getPermissionProvider($plugin_id)
    ->willReturn($permission_provider
    ->reveal());
  $this->container
    ->get('plugin.manager.group_content_enabler')
    ->willReturn($manager
    ->reveal());
  $access_control_handler = GroupContentAccessControlHandler::createInstance($this->container
    ->reveal(), $plugin_id, $definition);
  $group = $this
    ->prophesize(GroupInterface::class);
  $account = $this
    ->prophesize(AccountInterface::class)
    ->reveal();
  if ($definition['admin_permission']) {
    $group
      ->hasPermission($definition['admin_permission'], $account)
      ->willReturn($has_admin_permission);
  }
  else {
    $group
      ->hasPermission($definition['admin_permission'], $account)
      ->shouldNotBeCalled();
  }
  if ($permission) {
    $group
      ->hasPermission($permission, $account)
      ->willReturn($has_permission);
  }
  else {
    $group
      ->hasPermission($permission, $account)
      ->shouldNotBeCalled();
  }
  $result = $access_control_handler
    ->entityCreateAccess($group
    ->reveal(), $account, TRUE);
  $this
    ->assertEquals($expected(), $result);
}