function FieldBlockTest::testBlockAccessEntityAllowedFieldHasValue
Tests populated vs empty build.
@legacy-covers ::blockAccess @legacy-covers ::build
Attributes
#[DataProvider('providerTestBlockAccessEntityAllowedFieldHasValue')]
File
-
core/
modules/ layout_builder/ tests/ src/ Kernel/ FieldBlockTest.php, line 162
Class
Namespace
Drupal\Tests\layout_builder\KernelCode
public function testBlockAccessEntityAllowedFieldHasValue($expected, $is_empty, $default_value) : 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);
$field_definition = $this->prophesize(FieldDefinitionInterface::class);
$field->getFieldDefinition()
->willReturn($field_definition->reveal());
$field_definition->getDefaultValue($entity->reveal())
->willReturn($default_value);
$field_definition->getType()
->willReturn('not_an_image');
$entity->get('the_field_name')
->willReturn($field->reveal());
$field->access('view', $account->reveal(), TRUE)
->willReturn(AccessResult::allowed());
$field->isEmpty()
->willReturn($is_empty)
->shouldBeCalled();
$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.