function LayoutBuilderNestedFormUiTest::testAddingFormBlocksToDefaults

Same name in other branches
  1. 8.9.x core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderNestedFormUiTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\LayoutBuilderNestedFormUiTest::testAddingFormBlocksToDefaults()
  2. 10 core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderNestedFormUiTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\LayoutBuilderNestedFormUiTest::testAddingFormBlocksToDefaults()
  3. 11.x core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderNestedFormUiTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\LayoutBuilderNestedFormUiTest::testAddingFormBlocksToDefaults()

Tests blocks containing forms can be successfully saved editing defaults.

File

core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderNestedFormUiTest.php, line 68

Class

LayoutBuilderNestedFormUiTest
Tests placing blocks containing forms in theLayout Builder UI.

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

public function testAddingFormBlocksToDefaults() {
    $this->drupalLogin($this->drupalCreateUser([
        'configure any layout',
        'administer node display',
    ]));
    // From the manage display page, enable Layout Builder.
    $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
    $this->drupalGet("{$field_ui_prefix}/display/default");
    $this->submitForm([
        'layout[enabled]' => TRUE,
    ], 'Save');
    $this->submitForm([
        'layout[allow_custom]' => TRUE,
    ], 'Save');
    // Save the entity view display so that it can be reverted to later.
    
    /** @var \Drupal\Core\Config\StorageInterface $active_config_storage */
    $active_config_storage = $this->container
        ->get('config.storage');
    $original_display_config_data = $active_config_storage->read('core.entity_view_display.node.bundle_with_section_field.default');
    
    /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $entity_view_display_storage */
    $entity_view_display_storage = $this->container
        ->get('entity_type.manager')
        ->getStorage('entity_view_display');
    $entity_view_display = $entity_view_display_storage->load('node.bundle_with_section_field.default');
    $expected_save_message = 'The layout has been saved.';
    foreach (static::FORM_BLOCK_LABELS as $label) {
        $this->addFormBlock($label, "{$field_ui_prefix}/display/default", $expected_save_message);
        // Revert the entity view display back to remove the previously added form
        // block.
        $entity_view_display = $entity_view_display_storage->updateFromStorageRecord($entity_view_display, $original_display_config_data);
        $entity_view_display->save();
    }
}

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