You are here

public function ElementsTableSelectTest::testTableSelectColSpan in Drupal 10

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

Tests the display when #colspan is set.

File

core/modules/system/tests/src/Functional/Form/ElementsTableSelectTest.php, line 65

Class

ElementsTableSelectTest
Tests the tableselect form element for expected behavior.

Namespace

Drupal\Tests\system\Functional\Form

Code

public function testTableSelectColSpan() {
  $this
    ->drupalGet('form_test/tableselect/colspan');

  // Verify presence of column three and absence of column four.
  $this
    ->assertSession()
    ->pageTextContains('Three');
  $this
    ->assertSession()
    ->pageTextNotContains('Four');

  // There should be three labeled column headers and 1 for the input.
  $table_head = $this
    ->xpath('//thead/tr/th');
  $this
    ->assertCount(4, $table_head, 'There are four column headers');

  // The first two body rows should each have 5 table cells: One for the
  // radio, one cell in the first column, one cell in the second column,
  // and two cells in the third column which has colspan 2.
  for ($i = 0; $i <= 1; $i++) {
    $this
      ->assertCount(5, $this
      ->xpath('//tbody/tr[' . ($i + 1) . ']/td'), 'There are five cells in row ' . $i);
  }

  // The third row should have 3 cells, one for the radio, one spanning the
  // first and second column, and a third in column 3 (which has colspan 3).
  $this
    ->assertCount(3, $this
    ->xpath('//tbody/tr[3]/td'), 'There are three cells in row 3.');
}