View source
<?php
namespace Drupal\Tests\layout_builder\Kernel;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage;
use Drupal\layout_builder\Section;
class LayoutBuilderInstallTest extends LayoutBuilderCompatibilityTestBase {
public function testCompatibility() {
$expected_fields = [
'field field--name-name field--type-string field--label-hidden field__item',
'field field--name-test-field-display-configurable field--type-boolean field--label-above',
'clearfix text-formatted field field--name-test-display-configurable field--type-text field--label-above',
'clearfix text-formatted field field--name-test-display-non-configurable field--type-text field--label-above',
'clearfix text-formatted field field--name-test-display-multiple field--type-text field--label-above',
];
$this
->assertFieldAttributes($this->entity, $expected_fields);
$this
->installLayoutBuilder();
$this
->assertFieldAttributes($this->entity, $expected_fields);
$this
->enableOverrides();
$this->entity = $this
->reloadEntity($this->entity);
$this->entity
->get(OverridesSectionStorage::FIELD_NAME)
->appendSection(new Section('layout_onecol'));
$this->entity
->save();
$new_expected_fields = [
'field field--name-name field--type-string field--label-hidden field__item',
'clearfix text-formatted field field--name-test-display-non-configurable field--type-text field--label-above',
'clearfix text-formatted field field--name-test-display-multiple field--type-text field--label-above',
];
$this
->assertFieldAttributes($this->entity, $new_expected_fields);
$this
->assertNotEmpty($this
->cssSelect('.layout--onecol'));
$this->entity
->get(OverridesSectionStorage::FIELD_NAME)
->removeAllSections();
$this->entity
->save();
$this
->assertFieldAttributes($this->entity, $expected_fields);
$field_storage = FieldStorageConfig::create([
'entity_type' => 'entity_test_base_field_display',
'field_name' => 'test_field_display_post_install',
'type' => 'text',
]);
$field_storage
->save();
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'entity_test_base_field_display',
'label' => 'FieldConfig with configurable display',
])
->save();
$this->entity = $this
->reloadEntity($this->entity);
$this->entity->test_field_display_post_install = 'Test string';
$this->entity
->save();
$this->display = $this
->reloadEntity($this->display);
$this->display
->setComponent('test_field_display_post_install', [
'weight' => 50,
])
->save();
$new_expected_fields = [
'field field--name-name field--type-string field--label-hidden field__item',
'field field--name-test-field-display-configurable field--type-boolean field--label-above',
'clearfix text-formatted field field--name-test-display-configurable field--type-text field--label-above',
'clearfix text-formatted field field--name-test-field-display-post-install field--type-text field--label-above',
'clearfix text-formatted field field--name-test-display-non-configurable field--type-text field--label-above',
'clearfix text-formatted field field--name-test-display-multiple field--type-text field--label-above',
];
$this
->assertFieldAttributes($this->entity, $new_expected_fields);
$this
->assertNotEmpty($this
->cssSelect('.layout--onecol'));
$this
->assertText('Test string');
}
}