1 form.test public FormsElementsDescriptionsTestCase::testFormDescriptions()

Test Form Descriptions.

File

core/modules/simpletest/tests/form.test, line 1029
Unit tests for the Backdrop Form API.

Class

FormsElementsDescriptionsTestCase
Test form element labels, required markers and associated output.

Code

public function testFormDescriptions() {
  $this->backdropGet('form_test/form-descriptions');

  // Check #description placement with #description_display='after'.
  $field_id = 'edit-form-textfield-test-description-after';
  $elements = $this->xpath('//input[@id="' . $field_id . '"]/following-sibling::div[contains(@class, "description")]');
  $this->assertTrue(isset($elements[0]), t('Properly places the #description element after the form item.'));

  // Check #description placement with #description_display='before'.
  $field_id = 'edit-form-textfield-test-description-before';
  $elements = $this->xpath('//input[@id="' . $field_id . '"]/preceding-sibling::div[contains(@class, "description")]');
  $this->assertTrue(isset($elements[0]), t('Properly places the #description element before the form item.'));

  // 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';
  $elements = $this->xpath('//input[@id="' . $field_id . '"]/following-sibling::div[contains(@class, "element-invisible")]');
  $this->assertTrue(isset($elements[0]), t('Properly renders the #description element invisible.'));

  // Check #description placement with #description_display='before'.
  $field_id = 'edit-form-checkboxes-test-description-before';
  $elements = $this->xpath('//div[@id="' . $field_id . '"]/preceding-sibling::div[contains(@class, "description")]');
  $this->assertTrue(isset($elements[0]), t('Properly places the #description element before the form item.'));

  // Check #description placement with #description_display='before'.
  $field_id = 'edit-form-radios-test-description-before';
  $elements = $this->xpath('//div[@id="' . $field_id . '"]/preceding-sibling::div[contains(@class, "description")]');
  $this->assertTrue(isset($elements[0]), t('Properly places the #description element before the form item.'));

  // Check #description placement with #description_display='before'.
  $field_id = 'edit-form-textarea-test-description-before';
  $elements = $this->xpath('//label[@for="' . $field_id . '"]/following-sibling::div[contains(@class, "description")]');
  $this->assertTrue(isset($elements[0]), t('Properly places the #description element before the form item.'));

  // Check #description placement with #description_display='after'.
  $field_id = 'edit-form-checkboxes-test-description-after';
  $elements = $this->xpath('//div[@id="' . $field_id . '"]/following-sibling::div[contains(@class, "description")]');
  $this->assertTrue(isset($elements[0]), t('Properly places the #description element after the form item.'));

  // Check #description placement with #description_display='after'.
  $field_id = 'edit-form-radios-test-description-after';
  $elements = $this->xpath('//div[@id="' . $field_id . '"]/following-sibling::div[contains(@class, "description")]');
  $this->assertTrue(isset($elements[0]), t('Properly places the #description element after the form item.'));

  // Check #description placement with #description_display='after'.
  $field_id = 'edit-form-textarea-test-description-after';
  $elements = $this->xpath('//textarea[@id="' . $field_id . '"]/parent::div/following-sibling::div[contains(@class, "description")]');
  $this->assertTrue(isset($elements[0]), t('Properly places the #description element after the form item.'));
}