function FieldLayoutBuilderTest::testBuildFormEmpty

Same name in other branches
  1. 8.9.x core/modules/field_layout/tests/src/Unit/FieldLayoutBuilderTest.php \Drupal\Tests\field_layout\Unit\FieldLayoutBuilderTest::testBuildFormEmpty()
  2. 10 core/modules/field_layout/tests/src/Unit/FieldLayoutBuilderTest.php \Drupal\Tests\field_layout\Unit\FieldLayoutBuilderTest::testBuildFormEmpty()
  3. 11.x core/modules/field_layout/tests/src/Unit/FieldLayoutBuilderTest.php \Drupal\Tests\field_layout\Unit\FieldLayoutBuilderTest::testBuildFormEmpty()

@covers ::buildForm

File

core/modules/field_layout/tests/src/Unit/FieldLayoutBuilderTest.php, line 268

Class

FieldLayoutBuilderTest
@coversDefaultClass \Drupal\field_layout\FieldLayoutBuilder @group field_layout

Namespace

Drupal\Tests\field_layout\Unit

Code

public function testBuildFormEmpty() {
    $definitions = [];
    $non_configurable_field_definition = $this->prophesize(FieldDefinitionInterface::class);
    $non_configurable_field_definition->isDisplayConfigurable('form')
        ->willReturn(FALSE);
    $definitions['non_configurable_field'] = $non_configurable_field_definition->reveal();
    $this->entityFieldManager
        ->getFieldDefinitions('the_entity_type_id', 'the_entity_type_bundle')
        ->willReturn($definitions);
    $this->entityFieldManager
        ->getExtraFields('the_entity_type_id', 'the_entity_type_bundle')
        ->willReturn([]);
    $build = [
        'non_configurable_field' => [
            '#markup' => 'Non-configurable',
        ],
    ];
    $display = $this->prophesize(EntityDisplayWithLayoutInterface::class);
    $display->getTargetEntityTypeId()
        ->willReturn('the_entity_type_id');
    $display->getTargetBundle()
        ->willReturn('the_entity_type_bundle');
    $display->getLayout()
        ->willReturn($this->layoutPlugin);
    $display->getLayoutId()
        ->willReturn('two_column');
    $display->getLayoutSettings()
        ->willReturn([]);
    $display->getComponents()
        ->willReturn([
        'test1' => [
            'region' => 'right',
        ],
        'non_configurable_field' => [
            'region' => 'left',
        ],
    ]);
    $expected = [
        'non_configurable_field' => [
            '#markup' => 'Non-configurable',
        ],
    ];
    $this->fieldLayoutBuilder
        ->buildForm($build, $display->reveal());
    $this->assertSame($expected, $build);
}

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