public function FieldWebTest::testClickSorting in Drupal 9
Same name and namespace in other branches
- 8 core/modules/views/tests/src/Functional/Handler/FieldWebTest.php \Drupal\Tests\views\Functional\Handler\FieldWebTest::testClickSorting()
Tests the click sorting functionality.
File
- core/
modules/ views/ tests/ src/ Functional/ Handler/ FieldWebTest.php, line 69
Class
- FieldWebTest
- Tests fields from within a UI.
Namespace
Drupal\Tests\views\Functional\HandlerCode
public function testClickSorting() {
$this
->drupalGet('test_click_sort');
$this
->assertSession()
->statusCodeEquals(200);
// Only the id and name should be click sortable, but not the name.
$this
->assertSession()
->linkByHrefExists(Url::fromRoute('<none>', [], [
'query' => [
'order' => 'id',
'sort' => 'asc',
],
])
->toString());
$this
->assertSession()
->linkByHrefExists(Url::fromRoute('<none>', [], [
'query' => [
'order' => 'name',
'sort' => 'desc',
],
])
->toString());
$this
->assertSession()
->linkByHrefNotExists(Url::fromRoute('<none>', [], [
'query' => [
'order' => 'created',
],
])
->toString());
// Check that the view returns the click sorting cache contexts.
$expected_contexts = [
'languages:language_interface',
'theme',
'url.query_args',
];
$this
->assertCacheContexts($expected_contexts);
// Clicking a click sort should change the order.
$this
->clickLink('ID');
$href = Url::fromRoute('<none>', [], [
'query' => [
'order' => 'id',
'sort' => 'desc',
],
])
->toString();
$this
->assertSession()
->linkByHrefExists($href);
// Check that the output has the expected order (asc).
$ids = $this
->clickSortLoadIdsFromOutput();
$this
->assertEquals(range(1, 5), $ids);
// Check that the rel attribute has the correct value.
$this
->assertSession()
->elementAttributeContains('xpath', "//a[@href='{$href}']", 'rel', 'nofollow');
$this
->clickLink('ID Sort descending');
// Check that the output has the expected order (desc).
$ids = $this
->clickSortLoadIdsFromOutput();
$this
->assertEquals(range(5, 1, -1), $ids);
}