public function FieldAccessCheckTest::testAccess in FileField Sources 8
Tests the FileFieldAccessCheck.
This check is pretty straightforward if the user is not allowed to edit the field value then is not allowed then the access check is not allowed either.
This is used for instance in the reference FilefieldSource if the user cannot use the field then the route for the autocomplete is now allowed either.
@dataProvider providerTestAccess
Parameters
bool $field_storage_is_accessible: Whether the user has access to the field storage entity.
\Drupal\Core\Access\AccessResult $expected_result: The expected result of the access call.
File
- tests/
src/ Unit/ FieldAccessCheckTest.php, line 80
Class
- FieldAccessCheckTest
- @coversDefaultClass \Drupal\filefield_sources\Access\FieldAccessCheck @group Access
Namespace
Drupal\Tests\filefield_sources\UnitCode
public function testAccess(bool $field_storage_is_accessible, AccessResult $expected_result) {
$access_result = AccessResult::forbidden();
if ($field_storage_is_accessible) {
$access_result = AccessResult::allowed();
}
$access_control = $this
->createMock(EntityAccessControlHandlerInterface::class);
$access_control
->expects($this
->any())
->method('fieldAccess')
->willReturn($access_result);
$this->entityTypeManager
->expects($this
->any())
->method('getAccessControlHandler')
->willReturn($access_control);
$editAccessCheck = new FieldAccessCheck($this->entityTypeManager);
$account = $this
->createMock('Drupal\\Core\\Session\\AccountInterface');
$access = $editAccessCheck
->access('edit', 'bundle', 'field', $account);
$this
->assertEquals($expected_result, $access);
}