You are here

public function FieldBlockTest::testBuild in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/tests/src/Kernel/FieldBlockTest.php \Drupal\Tests\layout_builder\Kernel\FieldBlockTest::testBuild()
  2. 10 core/modules/layout_builder/tests/src/Kernel/FieldBlockTest.php \Drupal\Tests\layout_builder\Kernel\FieldBlockTest::testBuild()

@covers ::build @dataProvider providerTestBuild

1 call to FieldBlockTest::testBuild()
FieldBlockTest::testBuildException in core/modules/layout_builder/tests/src/Kernel/FieldBlockTest.php
@covers ::build

File

core/modules/layout_builder/tests/src/Kernel/FieldBlockTest.php, line 238

Class

FieldBlockTest
@coversDefaultClass \Drupal\layout_builder\Plugin\Block\FieldBlock @group Field

Namespace

Drupal\Tests\layout_builder\Kernel

Code

public function testBuild(PromiseInterface $promise, $expected_markup, $log_message = '', $log_arguments = []) {
  $entity = $this
    ->prophesize(FieldableEntityInterface::class);
  $field = $this
    ->prophesize(FieldItemListInterface::class);
  $entity
    ->get('the_field_name')
    ->willReturn($field
    ->reveal());
  $field
    ->view(Argument::type('array'))
    ->will($promise);
  $field_definition = $this
    ->prophesize(FieldDefinitionInterface::class);
  $field_definition
    ->getLabel()
    ->willReturn('The Field Label');
  $this->entityFieldManager
    ->getFieldDefinitions('entity_test', 'entity_test')
    ->willReturn([
    'the_field_name' => $field_definition,
  ]);
  if ($log_message) {
    $this->logger
      ->warning($log_message, $log_arguments)
      ->shouldBeCalled();
  }
  else {
    $this->logger
      ->warning(Argument::cetera())
      ->shouldNotBeCalled();
  }
  $block = $this
    ->getTestBlock($entity);
  $expected = [
    '#cache' => [
      'contexts' => [],
      'tags' => [],
      'max-age' => 0,
    ],
  ];
  if ($expected_markup) {
    $expected['content']['#markup'] = $expected_markup;
  }
  $actual = $block
    ->build();
  $this
    ->assertEquals($expected, $actual);
}