public function GroupContentAccessControlHandlerTest::testRelationCreateAccess in Group 8
Tests the relation create access.
@covers ::relationCreateAccess @dataProvider relationCreateAccessProvider
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 relation create permission.
File
- tests/
src/ Unit/ GroupContentAccessControlHandlerTest.php, line 225
Class
- GroupContentAccessControlHandlerTest
- Tests the default GroupContentEnabler access handler.
Namespace
Drupal\Tests\group\UnitCode
public function testRelationCreateAccess(\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
->getRelationCreatePermission()
->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
->relationCreateAccess($group
->reveal(), $account, TRUE);
$this
->assertEquals($expected(), $result);
}