You are here

public function SortTest::testStringOrdering in Views (for Drupal 7) 8.3

Tests string ordering of the result set.

File

lib/Drupal/views/Tests/Handler/SortTest.php, line 83
Definition of Drupal\views\Tests\Handler\SortTest.

Class

SortTest
Tests for core Drupal\views\Plugin\views\sort\SortPluginBase handler.

Namespace

Drupal\views\Tests\Handler

Code

public function testStringOrdering() {
  $view = $this
    ->getView();

  // Change the ordering
  $view->displayHandlers['default']
    ->overrideOption('sorts', array(
    'name' => array(
      'order' => 'ASC',
      'id' => 'name',
      'table' => 'views_test_data',
      'field' => 'name',
      'relationship' => 'none',
    ),
  ));

  // Execute the view.
  $this
    ->executeView($view);

  // Verify the result.
  $this
    ->assertEqual(count($this
    ->dataSet()), count($view->result), t('The number of returned rows match.'));
  $this
    ->assertIdenticalResultset($view, $this
    ->orderResultSet($this
    ->dataSet(), 'name'), array(
    'views_test_data_name' => 'name',
    'views_test_data_age' => 'age',
  ));
  $view = $this
    ->getView();

  // Reverse the ordering
  $view->displayHandlers['default']
    ->overrideOption('sorts', array(
    'name' => array(
      'order' => 'DESC',
      'id' => 'name',
      'table' => 'views_test_data',
      'field' => 'name',
      'relationship' => 'none',
    ),
  ));

  // Execute the view.
  $this
    ->executeView($view);

  // Verify the result.
  $this
    ->assertEqual(count($this
    ->dataSet()), count($view->result), t('The number of returned rows match.'));
  $this
    ->assertIdenticalResultset($view, $this
    ->orderResultSet($this
    ->dataSet(), 'name', TRUE), array(
    'views_test_data_name' => 'name',
    'views_test_data_age' => 'age',
  ));
}