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()
  2. 10 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 173

Class

FormGroupingElementsTest
Tests for form grouping elements.

Namespace

Drupal\FunctionalJavascriptTests\Core\Form

Code

public function testDetailsContainsRequiredTextfield() : void {
  $this->drupalGet('form_test/details-contains-required-fields');
  $details = $this->assertSession()
    ->elementExists('css', 'details[data-drupal-selector="edit-meta"]');
  $details2 = $this->assertSession()
    ->elementExists('css', 'details[data-drupal-selector="edit-meta2"]');
  $details3 = $this->assertSession()
    ->elementExists('css', 'details[data-drupal-selector="edit-meta3"]');
  // Make sure details element is not open at the beginning.
  $this->assertFalse($details->hasAttribute('open'));
  $this->assertFalse($details2->hasAttribute('open'));
  $this->assertFalse($details3->hasAttribute('open'));
  $textfield = $this->assertSession()
    ->elementExists('css', 'input[name="required_textfield_in_details"]');
  $textarea = $this->assertSession()
    ->elementExists('css', 'textarea[name="required_textarea_in_details"]');
  $select = $this->assertSession()
    ->elementExists('css', 'select[name="required_select_in_details"]');
  // The fields inside the details elements are not visible too.
  $this->assertFalse($textfield->isVisible(), 'Text field is not visible');
  $this->assertFalse($textarea->isVisible(), 'Text area field is not visible');
  $this->assertFalse($select->isVisible(), 'Select 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 fields are visible.
  $this->assertTrue($textfield->isVisible(), 'Text field is visible');
  $this->assertTrue($textarea->isVisible(), 'Text area field is visible');
  $this->assertTrue($select->isVisible(), 'Select field is visible');
}

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