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