function FormGroupingElementsTest::testDetailsContainsRequiredTextfieldAjaxForm

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

Tests required field in closed details element with ajax form.

File

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

Class

FormGroupingElementsTest
Tests for form grouping elements.

Namespace

Drupal\FunctionalJavascriptTests\Core\Form

Code

public function testDetailsContainsRequiredTextfieldAjaxForm() : void {
  $this->drupalGet('form_test/details-contains-required-fields/true');
  $assert_session = $this->assertSession();
  $textfield = $assert_session->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"]');
  // Submit the ajax form to open the details element at the first time.
  $assert_session->elementExists('css', 'input[value="Submit Ajax"]')
    ->click();
  $assert_session->waitForElementVisible('css', 'input[name="required_textfield_in_details"]');
  $assert_session->waitForElementVisible('css', 'textarea[name="required_textarea_in_details"]');
  $assert_session->waitForElementVisible('css', 'select[name="required_select_in_details"]');
  // 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');
  // Close the details elements.
  $this->assertSession()
    ->elementExists('css', 'details[data-drupal-selector="edit-meta"] summary')
    ->click();
  $this->assertSession()
    ->elementExists('css', 'details[data-drupal-selector="edit-meta2"] summary')
    ->click();
  $this->assertSession()
    ->elementExists('css', 'details[data-drupal-selector="edit-meta3"] summary')
    ->click();
  // 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 without ajax.
  $assert_session->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.