public function FieldWebTest::testClickSorting in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/views/src/Tests/Handler/FieldWebTest.php \Drupal\views\Tests\Handler\FieldWebTest::testClickSorting()
Tests the click sorting functionality.
File
- core/
modules/ views/ src/ Tests/ Handler/ FieldWebTest.php, line 67 - Contains \Drupal\views\Tests\Handler\FieldWebTest.
Class
- FieldWebTest
- Tests fields from within a UI.
Namespace
Drupal\views\Tests\HandlerCode
public function testClickSorting() {
$this
->drupalGet('test_click_sort');
$this
->assertResponse(200);
// Only the id and name should be click sortable, but not the name.
$this
->assertLinkByHref(\Drupal::url('<none>', [], [
'query' => [
'order' => 'id',
'sort' => 'asc',
],
]));
$this
->assertLinkByHref(\Drupal::url('<none>', [], [
'query' => [
'order' => 'name',
'sort' => 'desc',
],
]));
$this
->assertNoLinkByHref(\Drupal::url('<none>', [], [
'query' => [
'order' => 'created',
],
]));
// 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(t('ID'));
$this
->assertLinkByHref(\Drupal::url('<none>', [], [
'query' => [
'order' => 'id',
'sort' => 'desc',
],
]));
// Check that the output has the expected order (asc).
$ids = $this
->clickSortLoadIdsFromOutput();
$this
->assertEqual($ids, range(1, 5));
$this
->clickLink(t('ID Sort descending'));
// Check that the output has the expected order (desc).
$ids = $this
->clickSortLoadIdsFromOutput();
$this
->assertEqual($ids, range(5, 1, -1));
}