public function QuickEditEntityFieldAccessCheckTest::testAccess in Drupal 10
Same name and namespace in other branches
- 8 core/modules/quickedit/tests/src/Unit/Access/QuickEditEntityFieldAccessCheckTest.php \Drupal\Tests\quickedit\Unit\Access\QuickEditEntityFieldAccessCheckTest::testAccess()
- 9 core/modules/quickedit/tests/src/Unit/Access/QuickEditEntityFieldAccessCheckTest.php \Drupal\Tests\quickedit\Unit\Access\QuickEditEntityFieldAccessCheckTest::testAccess()
Tests the method for checking access to routes.
@dataProvider providerTestAccess
Parameters
bool $entity_is_editable: Whether the subject entity is editable.
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
- core/
modules/ quickedit/ tests/ src/ Unit/ Access/ QuickEditEntityFieldAccessCheckTest.php, line 67
Class
- QuickEditEntityFieldAccessCheckTest
- @coversDefaultClass \Drupal\quickedit\Access\QuickEditEntityFieldAccessCheck @group Access @group quickedit
Namespace
Drupal\Tests\quickedit\Unit\AccessCode
public function testAccess($entity_is_editable, $field_storage_is_accessible, AccessResult $expected_result) {
$entity = $this
->createMockEntity();
$entity
->expects($this
->any())
->method('access')
->willReturn(AccessResult::allowedIf($entity_is_editable)
->cachePerPermissions());
$field_storage = $this
->createMock('Drupal\\field\\FieldStorageConfigInterface');
$field_storage
->expects($this
->any())
->method('access')
->willReturn(AccessResult::allowedIf($field_storage_is_accessible));
$expected_result
->cachePerPermissions();
$field_name = 'valid';
$entity_with_field = clone $entity;
$entity_with_field
->expects($this
->any())
->method('get')
->with($field_name)
->will($this
->returnValue($field_storage));
$entity_with_field
->expects($this
->once())
->method('hasTranslation')
->with(LanguageInterface::LANGCODE_NOT_SPECIFIED)
->will($this
->returnValue(TRUE));
$account = $this
->createMock('Drupal\\Core\\Session\\AccountInterface');
$access = $this->editAccessCheck
->access($entity_with_field, $field_name, LanguageInterface::LANGCODE_NOT_SPECIFIED, $account);
$this
->assertEquals($expected_result, $access);
}