public function FieldPermissionsServiceTest::providerTestGetFieldAccess in Field Permissions 8
Same name and namespace in other branches
- 8.2 tests/src/Unit/FieldPermissionsServiceTest.php \Drupal\Tests\field_permissions\Unit\FieldPermissionsServiceTest::providerTestGetFieldAccess()
Data provider for ::testGetFieldAccess.
File
- tests/
src/ Unit/ FieldPermissionsServiceTest.php, line 77
Class
- FieldPermissionsServiceTest
- Tests the field permissions service.
Namespace
Drupal\Tests\field_permissions\UnitCode
public function providerTestGetFieldAccess() {
$cases = [];
$field_item_list = $this
->prophesize(FieldItemListInterface::class)
->reveal();
// Administrator role.
$account = $this
->prophesize(AccountInterface::class);
$account
->getRoles()
->willReturn([
'administrator',
]);
$field_definition = $this
->prophesize(FieldDefinitionInterface::class);
$storage = $this
->prophesize(FieldStorageConfigInterface::class);
$storage
->getThirdPartySetting('field_permissions', 'permission_type', FieldPermissionTypeInterface::ACCESS_PUBLIC)
->willReturn('foo');
$field_definition
->getFieldStorageDefinition()
->willReturn($storage
->reveal());
$cases[] = [
'view',
$field_item_list,
$account
->reveal(),
$field_definition
->reveal(),
TRUE,
];
// No admin roles, but public access.
$account = $this
->prophesize(AccountInterface::class);
$account
->getRoles()
->willReturn([
'blah',
]);
$field_definition = $this
->prophesize(FieldDefinitionInterface::class);
$storage = $this
->prophesize(FieldStorageConfigInterface::class);
$storage
->getThirdPartySetting('field_permissions', 'permission_type', FieldPermissionTypeInterface::ACCESS_PUBLIC)
->willReturn(FieldPermissionTypeInterface::ACCESS_PUBLIC);
$field_definition
->getFieldStorageDefinition()
->willReturn($storage
->reveal());
$cases[] = [
'view',
$field_item_list,
$account
->reveal(),
$field_definition
->reveal(),
TRUE,
];
return $cases;
}