You are here

public function FormTest::testRequiredAttribute in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/Form/FormTest.php \Drupal\Tests\system\Functional\Form\FormTest::testRequiredAttribute()

Tests required attribute.

File

core/modules/system/tests/src/Functional/Form/FormTest.php, line 890

Class

FormTest
Tests various form element validation mechanisms.

Namespace

Drupal\Tests\system\Functional\Form

Code

public function testRequiredAttribute() {
  $this
    ->drupalGet('form-test/required-attribute');
  foreach ([
    'textfield',
    'password',
    'textarea',
  ] as $type) {
    $field = $this
      ->assertSession()
      ->fieldExists("edit-{$type}");
    $this
      ->assertSame('required', $field
      ->getAttribute('required'), "The {$type} has the proper required attribute.");
  }
}