Pull merge.
[yaffs-website] / web / core / modules / layout_builder / tests / src / Kernel / LayoutBuilderFieldLayoutCompatibilityTest.php
1 <?php
2
3 namespace Drupal\Tests\layout_builder\Kernel;
4
5 use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage;
6 use Drupal\layout_builder\Section;
7
8 /**
9  * Ensures that Layout Builder and Field Layout are compatible with each other.
10  *
11  * @group layout_builder
12  */
13 class LayoutBuilderFieldLayoutCompatibilityTest extends LayoutBuilderCompatibilityTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = [
19     'field_layout',
20   ];
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function setUp() {
26     parent::setUp();
27
28     $this->display
29       ->setLayoutId('layout_twocol')
30       ->save();
31   }
32
33   /**
34    * Tests the compatibility of Layout Builder and Field Layout.
35    */
36   public function testCompatibility() {
37     // Ensure that the configurable field is shown in the correct region and
38     // that the non-configurable field is shown outside the layout.
39     $expected_fields = [
40       'field field--name-name field--type-string field--label-hidden field__item',
41       'field field--name-test-field-display-configurable field--type-boolean field--label-above',
42       'clearfix text-formatted field field--name-test-display-configurable field--type-text field--label-above',
43       'clearfix text-formatted field field--name-test-display-non-configurable field--type-text field--label-above',
44       'clearfix text-formatted field field--name-test-display-multiple field--type-text field--label-above',
45     ];
46     $this->assertFieldAttributes($this->entity, $expected_fields);
47     $this->assertNotEmpty($this->cssSelect('.layout__region--first .field--name-test-display-configurable'));
48     $this->assertNotEmpty($this->cssSelect('.layout__region--first .field--name-test-field-display-configurable'));
49     $this->assertNotEmpty($this->cssSelect('.field--name-test-display-non-configurable'));
50     $this->assertEmpty($this->cssSelect('.layout__region .field--name-test-display-non-configurable'));
51
52     $this->installLayoutBuilder();
53
54     // Without using Layout Builder for an override, the result has not changed.
55     $this->assertFieldAttributes($this->entity, $expected_fields);
56
57     // Add a layout override.
58     $this->enableOverrides();
59     /** @var \Drupal\layout_builder\SectionStorageInterface $field_list */
60     $field_list = $this->entity->get(OverridesSectionStorage::FIELD_NAME);
61     $field_list->appendSection(new Section('layout_onecol'));
62     $this->entity->save();
63
64     // The rendered entity has now changed. The non-configurable field is shown
65     // outside the layout, the configurable field is not shown at all, and the
66     // layout itself is rendered (but empty).
67     $new_expected_fields = [
68       'field field--name-name field--type-string field--label-hidden field__item',
69       'clearfix text-formatted field field--name-test-display-non-configurable field--type-text field--label-above',
70       'clearfix text-formatted field field--name-test-display-multiple field--type-text field--label-above',
71     ];
72     $this->assertFieldAttributes($this->entity, $new_expected_fields);
73     $this->assertNotEmpty($this->cssSelect('.layout--onecol'));
74
75     // Removing the layout restores the original rendering of the entity.
76     $field_list->removeSection(0);
77     $this->entity->save();
78     $this->assertFieldAttributes($this->entity, $expected_fields);
79   }
80
81 }