function FormGroupingElementsTest::testDetailsContainsRequiredTextfield

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/FunctionalJavascriptTests/Core/Form/FormGroupingElementsTest.php \Drupal\FunctionalJavascriptTests\Core\Form\FormGroupingElementsTest::testDetailsContainsRequiredTextfield()

Tests form submit with a required field in closed details element.

File

core/tests/Drupal/FunctionalJavascriptTests/Core/Form/FormGroupingElementsTest.php, line 171

Class

FormGroupingElementsTest
Tests for form grouping elements.

Namespace

Drupal\FunctionalJavascriptTests\Core\Form

Code

public function testDetailsContainsRequiredTextfield() : void {
  $this->drupalGet('form_test/details-contains-required-textfield');
  $details = $this->assertSession()
    ->elementExists('css', 'details[data-drupal-selector="edit-meta"]');
  // Make sure details element is not open at the beginning.
  $this->assertFalse($details->hasAttribute('open'));
  $textfield = $this->assertSession()
    ->elementExists('css', 'input[name="required_textfield_in_details"]');
  // The text field inside the details element is not visible too.
  $this->assertFalse($textfield->isVisible(), 'Text field is not visible');
  // Submit the form with invalid data in the required fields.
  $this->assertSession()
    ->elementExists('css', 'input[data-drupal-selector="edit-submit"]')
    ->click();
  // Confirm the required field is visible.
  $this->assertTrue($textfield->isVisible(), 'Text field is visible');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.