function FormElementsRenderTest::assertRenderedElement

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Kernel/Common/FormElementsRenderTest.php \Drupal\Tests\system\Kernel\Common\FormElementsRenderTest::assertRenderedElement()
  2. 10 core/modules/system/tests/src/Kernel/Common/FormElementsRenderTest.php \Drupal\Tests\system\Kernel\Common\FormElementsRenderTest::assertRenderedElement()
  3. 11.x core/modules/system/tests/src/Kernel/Common/FormElementsRenderTest.php \Drupal\Tests\system\Kernel\Common\FormElementsRenderTest::assertRenderedElement()

Tests that elements are rendered properly.

1 call to FormElementsRenderTest::assertRenderedElement()
FormElementsRenderTest::testDrupalRenderFormElements in core/modules/system/tests/src/Kernel/Common/FormElementsRenderTest.php
Tests rendering form elements without passing through \Drupal::formBuilder()->doBuildForm().

File

core/modules/system/tests/src/Kernel/Common/FormElementsRenderTest.php, line 143

Class

FormElementsRenderTest
Performs integration tests on <a href="/api/drupal/core%21includes%21common.inc/function/drupal_render/8.9.x" title="Renders HTML given a structured array tree." class="local">drupal_render</a>().

Namespace

Drupal\Tests\system\Kernel\Common

Code

protected function assertRenderedElement(array $element, $xpath, array $xpath_args = []) {
    $this->render($element);
    // @see \Drupal\simpletest\WebTestBase::xpath()
    $xpath = $this->buildXPathQuery($xpath, $xpath_args);
    $element += [
        '#value' => NULL,
    ];
    $this->assertFieldByXPath($xpath, $element['#value'], new FormattableMarkup('#type @type was properly rendered.', [
        '@type' => var_export($element['#type'], TRUE),
    ]));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.