function FieldBlockTest::testBuild

Same name and namespace in other branches
  1. 9 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()
  3. 11.x 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 <a href="/api/drupal/core%21modules%21layout_builder%21src%21Plugin%21Block%21FieldBlock.php/class/FieldBlock/8.9.x" title="Provides a block that renders a field from an entity." class="local">\Drupal\layout_builder\Plugin\Block\FieldBlock</a> @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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.