View source
<?php
namespace Drupal\Tests\ds\Functional;
class FieldTemplateLayoutBuilderTest extends TestBase {
public static $modules = [
'node',
'user',
'field_ui',
'rdf',
'quickedit',
'taxonomy',
'block',
'ds',
'ds_extras',
'ds_test',
'ds_switch_view_mode',
'layout_discovery',
'layout_builder',
];
protected function setup() {
parent::setup();
\Drupal::configFactory()
->getEditable('ds.settings')
->set('field_template', TRUE)
->set('ft-layout-builder', TRUE)
->save();
$this
->drupalPlaceBlock('local_tasks_block');
$this
->createContentType([
'type' => 'bundle_with_section_field',
'name' => 'Bundle with section field',
]);
$this
->createNode([
'type' => 'bundle_with_section_field',
'title' => 'The first node title',
'body' => [
[
'value' => 'The first node body',
],
],
]);
}
public function testDsLbFieldTemplate() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
'administer node fields',
]));
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
$selector_prefix = 'settings[formatter][third_party_settings][ds][ft]';
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$this
->clickLink('Manage layout');
$this
->clickLink('Add block');
$this
->clickLink('Title');
$page
->selectFieldOption($selector_prefix . '[id]', 'expert');
$page
->pressButton('Add block');
$title_blocks = $this
->cssSelect('.block-field-blocknodebundle-with-section-fieldtitle');
$title_block = reset($title_blocks);
$block_id = $title_block
->getAttribute('data-layout-block-uuid');
$this
->drupalGet('layout_builder/update/block/defaults/node.bundle_with_section_field.default/0/content/' . $block_id);
$page
->checkField($selector_prefix . '[settings][ow]');
$page
->fillField($selector_prefix . '[settings][ow-cl]', 'ds-wrapper');
$page
->checkField($selector_prefix . '[settings][fis]');
$page
->fillField($selector_prefix . '[settings][fis-cl]', 'ds-field-items');
$page
->fillField($selector_prefix . '[settings][lb]', 'This is the label');
$page
->pressButton('Update');
drupal_flush_all_caches();
$this
->drupalGet($this
->getUrl());
$assert_session
->pageTextContains('This is the label');
$assert_session
->elementExists('css', '.ds-wrapper');
$assert_session
->elementExists('css', '.ds-field-items');
$page
->pressButton('Save layout');
$this
->drupalGet('node/1');
$assert_session
->pageTextContains('The first node title');
$assert_session
->pageTextContains('This is the label');
$assert_session
->elementExists('css', '.ds-wrapper');
$assert_session
->elementExists('css', '.ds-field-items');
}
}