function TableSortExampleTest::testTableSortExampleBasic

Same name in other branches
  1. 4.0.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 login for this test.
    $this->drupalGet('/examples/tablesort-example', [
        'query' => [
            'sort' => 'desc',
            'order' => 'Numbers',
        ],
    ]);
    $assert->statusCodeEquals(200);
    // Ordered by number decending.
    $item = $this->getSession()
        ->getPage()
        ->find('xpath', '//tbody/tr/td[1]');
    $this->assertEquals(7, $item->getText(), 'Ordered by number decending.');
    $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 decending.
    $item = $this->getSession()
        ->getPage()
        ->find('xpath', '//tbody/tr/td[2]');
    $this->assertEquals('w', $item->getText(), 'Ordered by Letters decending.');
    $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 decending.
    $item = $this->getSession()
        ->getPage()
        ->find('xpath', '//tbody/tr/td[3]');
    $this->assertEquals('t982hkv', $item->getText(), 'Ordered by Mixture decending.');
    $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]');
    $this->assertEquals('0kuykuh', $item->getText(), 'Ordered by Mixture ascending.');
}