public function ElementsLabelsTest::testFormDescriptions in Drupal 10
Same name and namespace in other branches
- 8 core/modules/system/tests/src/Functional/Form/ElementsLabelsTest.php \Drupal\Tests\system\Functional\Form\ElementsLabelsTest::testFormDescriptions()
- 9 core/modules/system/tests/src/Functional/Form/ElementsLabelsTest.php \Drupal\Tests\system\Functional\Form\ElementsLabelsTest::testFormDescriptions()
Tests different display options for form element descriptions.
File
- core/
modules/ system/ tests/ src/ Functional/ Form/ ElementsLabelsTest.php, line 111
Class
- ElementsLabelsTest
- Tests form element labels, required markers and associated output.
Namespace
Drupal\Tests\system\Functional\FormCode
public function testFormDescriptions() {
$this
->drupalGet('form_test/form-descriptions');
// Check #description placement with #description_display='after'.
$field_id = 'edit-form-textfield-test-description-after';
$description_id = $field_id . '--description';
// Verify the #description element is placed after the form item.
$this
->assertSession()
->elementExists('xpath', '//input[@id="' . $field_id . '" and @aria-describedby="' . $description_id . '"]/following-sibling::div[@id="' . $description_id . '"]');
// Check #description placement with #description_display='before'.
$field_id = 'edit-form-textfield-test-description-before';
$description_id = $field_id . '--description';
// Verify the #description element is placed before the form item.
$this
->assertSession()
->elementExists('xpath', '//input[@id="' . $field_id . '" and @aria-describedby="' . $description_id . '"]/preceding-sibling::div[@id="' . $description_id . '"]');
// Check if the class is 'visually-hidden' on the form element description
// for the option with #description_display='invisible' and also check that
// the description is placed after the form element.
$field_id = 'edit-form-textfield-test-description-invisible';
$description_id = $field_id . '--description';
// Verify that the #description element is visually-hidden.
$this
->assertSession()
->elementExists('xpath', '//input[@id="' . $field_id . '" and @aria-describedby="' . $description_id . '"]/following-sibling::div[contains(@class, "visually-hidden")]');
}