function LayoutBuilderDefaultValuesTest::setUp

Same name in other branches
  1. 10 core/modules/layout_builder/tests/src/Functional/LayoutBuilderDefaultValuesTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderDefaultValuesTest::setUp()
  2. 11.x core/modules/layout_builder/tests/src/Functional/LayoutBuilderDefaultValuesTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderDefaultValuesTest::setUp()

Overrides BrowserTestBase::setUp

File

core/modules/layout_builder/tests/src/Functional/LayoutBuilderDefaultValuesTest.php, line 46

Class

LayoutBuilderDefaultValuesTest
Tests rendering default field values in Layout Builder.

Namespace

Drupal\Tests\layout_builder\Functional

Code

protected function setUp() : void {
    parent::setUp();
    $this->createContentType([
        'type' => 'test_node_type',
        'name' => 'Test Node Type',
    ]);
    $this->addTextFields();
    $this->addImageFields();
    // Create node 1 with specific values.
    $this->createNode([
        'type' => 'test_node_type',
        'title' => 'Test Node 1 Has Values',
        'field_string_no_default' => 'No default, no problem.',
        'field_string_with_default' => 'It is ok to be different',
        'field_string_with_callback' => 'Not from a callback',
        'field_string_late_default' => 'I am way ahead of you.',
        'field_image_with_default' => [
            'target_id' => 2,
            'alt' => 'My different alt text',
        ],
        'field_image_no_default' => [
            'target_id' => 3,
            'alt' => 'My third alt text',
        ],
    ]);
    // Create node 2 relying on defaults.
    $this->createNode([
        'type' => 'test_node_type',
        'title' => 'Test Node 2 Uses Defaults',
    ]);
    // Add default value to field_string_late_default.
    $field = FieldConfig::loadByName('node', 'test_node_type', 'field_string_late_default');
    $field->setDefaultValue('Too late!');
    $field->save();
}

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