diff --git a/core/modules/system/src/Tests/Form/ElementsLabelsTest.php b/core/modules/system/src/Tests/Form/ElementsLabelsTest.php index 766386a..98721bf 100644 --- a/core/modules/system/src/Tests/Form/ElementsLabelsTest.php +++ b/core/modules/system/src/Tests/Form/ElementsLabelsTest.php @@ -96,7 +96,7 @@ function testFormLabels() { } /** - * Test description of form elements with different placement options. + * Tests different display options for form element descriptions. */ function testFormDescriptions() { $test = $this->drupalGet('form_test/form-descriptions'); @@ -113,10 +113,13 @@ function testFormDescriptions() { $elements = $this->xpath('//input[@id="' . $field_id . '" and @aria-describedby="' . $description_id . '"]/preceding-sibling::div[@id="' . $description_id . '"]'); $this->assertTrue(isset($elements[0]), t('Properly places the #description element before the form item.')); - // Check #description placement with #description_display='invisible'. + // 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'; $elements = $this->xpath('//input[@id="' . $field_id . '" and @aria-describedby="' . $description_id . '"]/following-sibling::div[contains(@class, "visually-hidden")]'); $this->assertTrue(isset($elements[0]), t('Properly renders the #description element visually-hidden.')); } + } diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestDescriptionForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestDescriptionForm.php index 65df1e6..1b500bb 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestDescriptionForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestDescriptionForm.php @@ -12,7 +12,9 @@ use Symfony\Component\HttpFoundation\JsonResponse; /** - * Form for testing the different positions of the description in an element. + * Defines a form for testing form element description display options. + * + * @see \Drupal\system\Tests\Form\ElementsLabelsTest::testFormDescriptions() */ class FormTestDescriptionForm extends FormBase { @@ -27,35 +29,35 @@ public function getFormId() { * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { - $form['form_textfield_test_description_before'] = array( - '#type' =>'textfield', - '#title' => 'Textfield test for description before element', - '#description' => 'Textfield test for description before element', - '#description_display' => 'before', - ); - - $form['form_textfield_test_description_after'] = array( - '#type' =>'textfield', - '#title' => 'Textfield test for description after element', - '#description' => 'Textfield test for description after element', - '#description_display' => 'after', - ); - - $form['form_textfield_test_description_invisible'] = array( - '#type' =>'textfield', - '#title' => 'Textfield test for visually-hidden description', - '#description' => 'Textfield test for visually-hidden description', - '#description_display' => 'invisible', - ); - - return $form; + $form['form_textfield_test_description_before'] = array( + '#type' => 'textfield', + '#title' => 'Textfield test for description before element', + '#description' => 'Textfield test for description before element', + '#description_display' => 'before', + ); + + $form['form_textfield_test_description_after'] = array( + '#type' => 'textfield', + '#title' => 'Textfield test for description after element', + '#description' => 'Textfield test for description after element', + '#description_display' => 'after', + ); + + $form['form_textfield_test_description_invisible'] = array( + '#type' => 'textfield', + '#title' => 'Textfield test for visually-hidden description', + '#description' => 'Textfield test for visually-hidden description', + '#description_display' => 'invisible', + ); + + return $form; } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - + // The test that uses this form does not submit the form so this is empty. } }