function ElementsTableSelectTest::testAjax

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/FunctionalJavascript/Form/ElementsTableSelectTest.php \Drupal\Tests\system\FunctionalJavascript\Form\ElementsTableSelectTest::testAjax()
  2. 8.9.x core/modules/system/tests/src/FunctionalJavascript/Form/ElementsTableSelectTest.php \Drupal\Tests\system\FunctionalJavascript\Form\ElementsTableSelectTest::testAjax()
  3. 11.x core/modules/system/tests/src/FunctionalJavascript/Form/ElementsTableSelectTest.php \Drupal\Tests\system\FunctionalJavascript\Form\ElementsTableSelectTest::testAjax()

Tests the presence of ajax functionality for all options.

File

core/modules/system/tests/src/FunctionalJavascript/Form/ElementsTableSelectTest.php, line 29

Class

ElementsTableSelectTest
Tests the tableselect form element for expected behavior.

Namespace

Drupal\Tests\system\FunctionalJavascript\Form

Code

public function testAjax() : void {
  // Test checkboxes (#multiple == TRUE).
  $this->drupalGet('form_test/tableselect/multiple-true');
  $session = $this->getSession();
  $page = $session->getPage();
  for ($i = 1; $i <= 3; $i++) {
    $row = 'row' . $i;
    $page->hasUncheckedField($row);
    $page->checkField($row);
    $this->assertSession()
      ->assertWaitOnAjaxRequest();
    // Check current row and previous rows are checked.
    for ($j = 1; $j <= $i; $j++) {
      $other_row = 'row' . $j;
      $page->hasCheckedField($other_row);
    }
  }
  // Test radios (#multiple == FALSE).
  $this->drupalGet('form_test/tableselect/multiple-false');
  for ($i = 1; $i <= 3; $i++) {
    $row = 'input[value="row' . $i . '"]';
    $page->hasUncheckedField($row);
    $this->click($row);
    $this->assertSession()
      ->assertWaitOnAjaxRequest();
    $page->hasCheckedField($row);
    // Check other rows are not checked
    for ($j = 1; $j <= 3; $j++) {
      if ($j == $i) {
        continue;
      }
      $other_row = 'edit-tableselect-row' . $j;
      $page->hasUncheckedField($other_row);
    }
  }
}

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