function LayoutTest::testRenderLayout
Same name in other branches
- 9 core/modules/layout_discovery/tests/src/Kernel/LayoutTest.php \Drupal\Tests\layout_discovery\Kernel\LayoutTest::testRenderLayout()
- 8.9.x core/modules/layout_discovery/tests/src/Kernel/LayoutTest.php \Drupal\Tests\layout_discovery\Kernel\LayoutTest::testRenderLayout()
- 11.x core/modules/layout_discovery/tests/src/Kernel/LayoutTest.php \Drupal\Tests\layout_discovery\Kernel\LayoutTest::testRenderLayout()
Tests rendering a layout.
@dataProvider renderLayoutData
File
-
core/
modules/ layout_discovery/ tests/ src/ Kernel/ LayoutTest.php, line 55
Class
- LayoutTest
- Tests Layout functionality.
Namespace
Drupal\Tests\layout_discovery\KernelCode
public function testRenderLayout($layout_id, $config, $regions, array $html) : void {
$layout = $this->layoutPluginManager
->createInstance($layout_id, $config);
$built['layout'] = $layout->build($regions);
$built['layout']['#prefix'] = 'Test prefix' . "\n";
$built['layout']['#suffix'] = 'Test suffix' . "\n";
// Assume each layout is contained by a form, in order to ensure the
// building of the layout does not interfere with form processing.
$form_state = new FormState();
$form_builder = $this->container
->get('form_builder');
$form_builder->prepareForm('the_form_id', $built, $form_state);
$form_builder->processForm('the_form_id', $built, $form_state);
$this->render($built);
// Add in the wrapping form elements and prefix/suffix.
array_unshift($html, 'Test prefix');
array_unshift($html, '<form data-drupal-selector="the-form-id" action="/" method="post" id="the-form-id" accept-charset="UTF-8">');
// Retrieve the build ID from the rendered HTML since the string is random.
$build_id_input = $this->cssSelect('input[name="form_build_id"]')[0]
->asXML();
$form_id_input = '<input data-drupal-selector="edit-the-form-id" type="hidden" name="form_id" value="the_form_id"/>';
$html[] = 'Test suffix';
$html[] = $build_id_input . "\n" . $form_id_input . "\n" . '</form>';
// Match the HTML to the full form element.
$this->assertSame(implode("\n", $html), $this->cssSelect('#the-form-id')[0]
->asXML());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.