function FormTest::testRequiredAttribute

Tests required attribute.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php, line 637
Definition of Drupal\system\Tests\Form\FormTest.

Class

FormTest

Namespace

Drupal\system\Tests\Form

Code

function testRequiredAttribute() {
  $this
    ->drupalGet('form-test/required-attribute');
  $expected = 'required';

  // Test to make sure the elements have the proper required attribute.
  foreach (array(
    'textfield',
    'password',
  ) as $type) {
    $element = $this
      ->xpath('//input[@id=:id and @required=:expected]', array(
      ':id' => 'edit-' . $type,
      ':expected' => $expected,
    ));
    $this
      ->assertTrue(!empty($element), format_string('The @type has the proper required attribute.', array(
      '@type' => $type,
    )));
  }

  // Test to make sure textarea has the proper required attribute.
  $element = $this
    ->xpath('//textarea[@id=:id and @required=:expected]', array(
    ':id' => 'edit-textarea',
    ':expected' => $expected,
  ));
  $this
    ->assertTrue(!empty($element), 'The textarea has the proper required attribute.');
}