function FieldBlockTest::testBlockAccessEntityAllowedFieldNotAllowed
Tests field access.
@legacy-covers ::blockAccess
Attributes
#[DataProvider('providerTestBlockAccessNotAllowed')]
File
-
core/
modules/ layout_builder/ tests/ src/ Kernel/ FieldBlockTest.php, line 138
Class
Namespace
Drupal\Tests\layout_builder\KernelCode
public function testBlockAccessEntityAllowedFieldNotAllowed($expected, $field_access) : void {
$entity = $this->prophesize(FieldableEntityInterface::class);
$block = $this->getTestBlock($entity);
$account = $this->prophesize(AccountInterface::class);
$entity->access('view', $account->reveal(), TRUE)
->willReturn(AccessResult::allowed());
$entity->hasField('the_field_name')
->willReturn(TRUE);
$field = $this->prophesize(FieldItemListInterface::class);
$entity->get('the_field_name')
->willReturn($field->reveal());
$field->access('view', $account->reveal(), TRUE)
->willReturn($field_access);
$field->isEmpty()
->shouldNotBeCalled();
$access = $block->access($account->reveal(), TRUE);
$this->assertSame($expected, $access->isAllowed());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.