function FieldBlockTest::testBlockAccessEntityAllowedFieldHasValue
Tests populated vs empty build.
@covers ::blockAccess
      
    
@covers ::build
      
    
@dataProvider providerTestBlockAccessEntityAllowedFieldHasValue
File
- 
              core/modules/ layout_builder/ tests/ src/ Kernel/ FieldBlockTest.php, line 157 
Class
- FieldBlockTest
- @coversDefaultClass \Drupal\layout_builder\Plugin\Block\FieldBlock[[api-linebreak]] @group Field
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.
