Namespace
Drupal\Tests\tablesort_example\Functional
File
-
modules/tablesort_example/tests/src/Functional/TableSortExampleTest.php
View source
<?php
namespace Drupal\Tests\tablesort_example\Functional;
use Drupal\Tests\examples\Functional\ExamplesBrowserTestBase;
use Drupal\Core\Url;
class TableSortExampleTest extends ExamplesBrowserTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'tablesort_example',
'toolbar',
];
protected $profile = 'minimal';
public function testTableSortExampleBasic() {
$assert = $this->assertSession();
$this->drupalGet('/examples/tablesort-example', [
'query' => [
'sort' => 'desc',
'order' => 'Numbers',
],
]);
$assert->statusCodeEquals(200);
$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);
$item = $this->getSession()
->getPage()
->find('xpath', '//tbody/tr/td[1]');
$this->assertEquals(1, $item->getText(), 'Ordered by Number ascending.');
$this->drupalGet('/examples/tablesort-example', [
'query' => [
'sort' => 'desc',
'order' => 'Letters',
],
]);
$assert->statusCodeEquals(200);
$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);
$item = $this->getSession()
->getPage()
->find('xpath', '//tbody/tr/td[2]');
$this->assertEquals('a', $item->getText(), 'Ordered by Letters ascending.');
$this->drupalGet('/examples/tablesort-example', [
'query' => [
'sort' => 'desc',
'order' => 'Mixture',
],
]);
$assert->statusCodeEquals(200);
$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);
$item = $this->getSession()
->getPage()
->find('xpath', '//tbody/tr/td[3]');
$this->assertEquals('0kuykuh', $item->getText(), 'Ordered by Mixture ascending.');
}
public function testTableSortExampleLink() {
$assert = $this->assertSession();
$this->drupalLogin($this->createUser([
'access content',
'access toolbar',
]));
$links = [
'' => Url::fromRoute('tablesort_example.description'),
];
foreach ($links as $page => $url) {
$this->drupalGet($page);
$assert->linkByHrefExists($url->getInternalPath());
}
foreach ($links as $url) {
$this->drupalGet($url);
$assert->statusCodeEquals(200);
}
}
}
Classes