diff --git a/core/modules/layout_builder/src/Plugin/Block/TestContentBlock.php b/core/modules/layout_builder/src/Plugin/Block/TestContentBlock.php new file mode 100644 index 0000000000..2d8c431f26 --- /dev/null +++ b/core/modules/layout_builder/src/Plugin/Block/TestContentBlock.php @@ -0,0 +1,34 @@ + FALSE, + 'text' => '', + ]; + } + + /** + * {@inheritdoc} + */ + public function build() { + return ['#markup' => $this->configuration['text']]; + } + +} diff --git a/core/modules/layout_builder/tests/src/Kernel/LayoutSectionFormatterTest.php b/core/modules/layout_builder/tests/src/Kernel/LayoutSectionFormatterTest.php index fe540d0f45..c391ed92d4 100644 --- a/core/modules/layout_builder/tests/src/Kernel/LayoutSectionFormatterTest.php +++ b/core/modules/layout_builder/tests/src/Kernel/LayoutSectionFormatterTest.php @@ -80,21 +80,31 @@ protected function setUp() { * * @dataProvider providerTestLayoutSectionFormatter */ - public function testLayoutSectionFormatter($layout, $section, $expected_selector, $expected_content) { - $entity = EntityTest::create([]); - $entity->{$this->fieldName}->layout = $layout; - $entity->{$this->fieldName}->section = $section; + public function testLayoutSectionFormatter($layout_data, $expected_selector, $expected_content) { + $values = []; + $values[$this->fieldName] = $layout_data; + $entity = EntityTest::create($values); // Build and render the content. $content = $this->display->build($entity); $this->render($content); // Find the given selector. - $element = $this->cssSelect($expected_selector); - $this->assertNotEmpty($element); + if (!is_array($expected_selector)) { + $expected_selector = [$expected_selector]; + } + foreach ($expected_selector as $selector) { + $element = $this->cssSelect($selector); + $this->assertNotEmpty($element); + } // Find the given content. - $this->assertRaw($expected_content); + if (!is_array($expected_content)) { + $expected_content = [$expected_content]; + } + foreach ($expected_content as $content) { + $this->assertRaw($content); + } } /** @@ -103,17 +113,61 @@ public function testLayoutSectionFormatter($layout, $section, $expected_selector public function providerTestLayoutSectionFormatter() { $data = []; $data[] = [ - 'layout_onecol', [ - 'content' => [ - 'this_should_be_a_UUID' => [ - 'plugin_id' => 'system_powered_by_block', - ], + [ + 'layout' => 'layout_onecol', + 'section' => [ + 'content' => [ + 'baz' => [ + 'plugin_id' => 'system_powered_by_block' + ] + ] + ] ], ], '.layout--onecol', 'Powered by', ]; + $data[] = [ + [ + [ + 'layout' => 'layout_onecol', + 'section' => [ + 'content' => [ + 'baz' => [ + 'plugin_id' => 'system_powered_by_block' + ] + ] + ] + ], + [ + 'layout' => 'layout_twocol', + 'section' => [ + 'left' => [ + 'foo' => [ + 'plugin_id' => 'test_content', + 'text' => 'foo text' + ] + ], + 'right' => [ + 'bar' => [ + 'plugin_id' => 'test_content', + 'text' => 'bar text' + ] + ] + ] + ] + ], + [ + '.layout--onecol', + '.layout--twocol' + ], + [ + 'Powered by', + 'foo text', + 'bar text' + ], + ]; return $data; }