function TableSortExampleTest::testTableSortExampleBasic

Same name and namespace in other branches
  1. 3.x modules/tablesort_example/tests/src/Functional/TableSortExampleTest.php \Drupal\Tests\tablesort_example\Functional\TableSortExampleTest::testTableSortExampleBasic()

Verify the functionality of the sortable table.

File

modules/tablesort_example/tests/src/Functional/TableSortExampleTest.php, line 41

Class

TableSortExampleTest
Verify the tablesort functionality.

Namespace

Drupal\Tests\tablesort_example\Functional

Code

public function testTableSortExampleBasic() {
  $assert = $this->assertSession();
  // No need to log in for this test.
  $this->drupalGet('/examples/tablesort-example', [
    'query' => [
      'sort' => 'desc',
      'order' => 'Numbers',
    ],
  ]);
  $assert->statusCodeEquals(200);
  // Ordered by Number, descending.
  $item = $this->getSession()
    ->getPage()
    ->find('xpath', '//tbody/tr/td[1]');
  $this->assertEquals(7, $item->getText(), 'Ordered by Number, descending.');
  $this->drupalGet('/examples/tablesort-example', [
    'query' => [
      'sort' => 'asc',
      'order' => 'Numbers',
    ],
  ]);
  $assert->statusCodeEquals(200);
  // Ordered by Number, ascending.
  $item = $this->getSession()
    ->getPage()
    ->find('xpath', '//tbody/tr/td[1]');
  $this->assertEquals(1, $item->getText(), 'Ordered by Number, ascending.');
  // Sort by Letters.
  $this->drupalGet('/examples/tablesort-example', [
    'query' => [
      'sort' => 'desc',
      'order' => 'Letters',
    ],
  ]);
  $assert->statusCodeEquals(200);
  // Ordered by Letters, descending.
  $item = $this->getSession()
    ->getPage()
    ->find('xpath', '//tbody/tr/td[2]');
  $this->assertEquals('w', $item->getText(), 'Ordered by Letters, descending.');
  $this->drupalGet('/examples/tablesort-example', [
    'query' => [
      'sort' => 'asc',
      'order' => 'Letters',
    ],
  ]);
  $assert->statusCodeEquals(200);
  // Ordered by Letters, ascending.
  $item = $this->getSession()
    ->getPage()
    ->find('xpath', '//tbody/tr/td[2]');
  $this->assertEquals('a', $item->getText(), 'Ordered by Letters, ascending.');
  // Sort by Mixture.
  $this->drupalGet('/examples/tablesort-example', [
    'query' => [
      'sort' => 'desc',
      'order' => 'Mixture',
    ],
  ]);
  $assert->statusCodeEquals(200);
  // Ordered by Mixture, descending.
  $item = $this->getSession()
    ->getPage()
    ->find('xpath', '//tbody/tr/td[3]');
  // cspell:disable-next-line
  $this->assertEquals('t982hkv', $item->getText(), 'Ordered by Mixture, descending.');
  $this->drupalGet('/examples/tablesort-example', [
    'query' => [
      'sort' => 'asc',
      'order' => 'Mixture',
    ],
  ]);
  $assert->statusCodeEquals(200);
  // Ordered by Mixture, ascending.
  $item = $this->getSession()
    ->getPage()
    ->find('xpath', '//tbody/tr/td[3]');
  // cspell:disable-next-line
  $this->assertEquals('0kuykuh', $item->getText(), 'Ordered by Mixture, ascending.');
}