diff --git a/core/modules/system/src/Tests/Form/ElementsDetailsTest.php b/core/modules/system/src/Tests/Form/ElementsDetailsTest.php new file mode 100644 index 0000000..c7df48f --- /dev/null +++ b/core/modules/system/src/Tests/Form/ElementsDetailsTest.php @@ -0,0 +1,58 @@ +drupalGet('form-test/group-details'); + + // Check #description default placement. + $field_id = 'edit-details'; + $description_id = $field_id . '--description'; + $elements = $this->xpath('//details[@id="' . $field_id . '" and @aria-describedby="' . $description_id . '"]//details[@id="edit-meta"]/preceding-sibling::div[@id="' . $description_id . '"]'); + $this->assertTrue(isset($elements[0]), t('Properly places by default the #description element before the form item within details group.')); + + // Check #description placement with #description_display='before'. + $field_id = 'edit-details-before'; + $description_id = $field_id . '--description'; + $elements = $this->xpath('//details[@id="' . $field_id . '" and @aria-describedby="' . $description_id . '"]//div[@id="edit-meta-before"]/preceding-sibling::div[@id="' . $description_id . '"]'); + $this->assertTrue(isset($elements[0]), t('Properly places the #description element before the form item within details group.')); + + // Check #description placement with #description_display='after'. + $field_id = 'edit-details-after'; + $description_id = $field_id . '--description'; + $elements = $this->xpath('//details[@id="' . $field_id . '" and @aria-describedby="' . $description_id . '"]//div[@id="edit-meta-after"]/following-sibling::div[@id="' . $description_id . '"]'); + $this->assertTrue(isset($elements[0]), t('Properly places the #description element after the form item within details group.')); + + // Check if the class is 'visually-hidden' on the form details description + // for the option with #description_display='invisible' and also check that + // the description is placed after the form element. + $field_id = 'edit-details-invisible'; + $description_id = $field_id . '--description'; + $elements = $this->xpath('//details[@id="' . $field_id . '" and @aria-describedby="' . $description_id . '"]//div[@id="edit-meta-invisible"]/following-sibling::div[contains(@class, "visually-hidden")]'); + $this->assertTrue(isset($elements[0]), t('Properly renders the #description element visually-hidden within details group.')); + } +} diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestGroupDetailsForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestGroupDetailsForm.php index d8f5925..fc0ad84 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestGroupDetailsForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestGroupDetailsForm.php @@ -29,6 +29,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $form['details'] = array( '#type' => 'details', '#title' => 'Root element', + '#description' => 'Details test for default description position.', '#open' => TRUE, ); $form['meta'] = array( @@ -41,6 +42,54 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'textfield', '#title' => 'Nest in details element', ); + + $form['details_before'] = array( + '#type' => 'details', + '#title' => 'Details test for description before element', + '#description' => 'Details test for description before element.', + '#description_display' => 'before', + ); + $form['meta_before'] = array( + '#type' => 'container', + '#title' => 'Group element', + '#group' => 'details_before', + ); + $form['meta_before']['element'] = array( + '#type' => 'textfield', + '#title' => 'Nest in container element', + ); + + $form['details_after'] = array( + '#type' => 'details', + '#title' => 'Details test for description after element', + '#description' => 'Details test for description after element.', + '#description_display' => 'after', + ); + $form['meta_after'] = array( + '#type' => 'container', + '#title' => 'Group element', + '#group' => 'details_after', + ); + $form['meta_after']['element'] = array( + '#type' => 'textfield', + '#title' => 'Nest in container element', + ); + + $form['details_invisible'] = array( + '#type' => 'details', + '#title' => 'Details test for visually-hidden description', + '#description' => 'Details test for visually-hidden description.', + '#description_display' => 'invisible', + ); + $form['meta_invisible'] = array( + '#type' => 'container', + '#title' => 'Group element', + '#group' => 'details_invisible', + ); + $form['meta_invisible']['element'] = array( + '#type' => 'textfield', + '#title' => 'Nest in container element', + ); return $form; }