View source
<?php
namespace Drupal\Tests\layout_builder\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class LayoutBuilderNestedFormUiTest extends WebDriverTestBase {
const FORM_BLOCK_LABELS = [
'Layout Builder form block test form api form block',
'Layout Builder form block test inline template form block',
'Test Block View: Exposed form block',
];
protected static $modules = [
'block',
'field_ui',
'node',
'layout_builder',
'layout_builder_form_block_test',
'views',
'layout_builder_views_test',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this
->drupalPlaceBlock('local_tasks_block');
$this
->createContentType([
'type' => 'bundle_with_section_field',
'name' => 'Bundle with section field',
]);
for ($i = 1; $i <= count(static::FORM_BLOCK_LABELS); $i++) {
$this
->createNode([
'type' => 'bundle_with_section_field',
'title' => "Node {$i} title",
]);
}
}
public function testAddingFormBlocksToDefaults() {
$this
->markTestSkipped();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$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');
$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');
$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);
$entity_view_display = $entity_view_display_storage
->updateFromStorageRecord($entity_view_display, $original_display_config_data);
$entity_view_display
->save();
}
}
public function testAddingFormBlocksToOverrides() {
$this
->markTestSkipped();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$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');
$expected_save_message = 'The layout override has been saved.';
$nid = 1;
foreach (static::FORM_BLOCK_LABELS as $label) {
$this
->addFormBlock($label, "node/{$nid}", $expected_save_message);
$nid++;
}
}
protected function addFormBlock($label, $path, $expected_save_message) {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalGet($path . '/layout');
$assert_session
->linkExists('Add block');
$this
->clickLink('Add block');
$assert_session
->waitForElementVisible('named', [
'link',
$label,
]);
$assert_session
->linkExists($label);
$this
->clickLink($label);
$assert_session
->waitForElementVisible('named', [
'button',
'Add block',
]);
$page
->pressButton('Add block');
$assert_session
->assertWaitOnAjaxRequest();
$assert_session
->pageTextContains($label);
$assert_session
->addressEquals($path . '/layout');
$page
->pressButton('Save layout');
$assert_session
->pageTextContains($expected_save_message);
$assert_session
->addressEquals($path);
$this
->drupalGet($path . '/layout');
$page
->pressButton('Save layout');
$assert_session
->pageTextContains($expected_save_message);
$assert_session
->addressEquals($path);
}
}