public function FieldWebTest::testClickSorting

Tests the click sorting functionality.

File

drupal/core/modules/views/lib/Drupal/views/Tests/Handler/FieldWebTest.php, line 54
Contains \Drupal\views\Tests\Handler\FieldWebTest.

Class

FieldWebTest
Tests fields from within a UI.

Namespace

Drupal\views\Tests\Handler

Code

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(url('test_click_sort', array(
    'query' => array(
      'order' => 'id',
      'sort' => 'asc',
    ),
  )));
  $this
    ->assertLinkByHref(url('test_click_sort', array(
    'query' => array(
      'order' => 'name',
      'sort' => 'desc',
    ),
  )));
  $this
    ->assertNoLinkByHref(url('test_click_sort', array(
    'query' => array(
      'order' => 'created',
    ),
  )));

  // Clicking a click sort should change the order.
  $this
    ->clickLink(t('ID'));
  $this
    ->assertLinkByHref(url('test_click_sort', array(
    'query' => array(
      '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'));

  // Check that the output has the expected order (desc).
  $ids = $this
    ->clickSortLoadIdsFromOutput();
  $this
    ->assertEqual($ids, range(5, 1, -1));
}