public function SortTest::testNumericOrdering

Tests numeric ordering of the result set.

File

drupal/core/modules/views/lib/Drupal/views/Tests/Handler/SortTest.php, line 35
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 testNumericOrdering() {
  $view = views_get_view('test_view');
  $view
    ->setDisplay();

  // Change the ordering
  $view->displayHandlers['default']
    ->overrideOption('sorts', array(
    'age' => array(
      'order' => 'ASC',
      'id' => 'age',
      'table' => 'views_test_data',
      'field' => 'age',
      '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(), 'age'), array(
    'views_test_data_name' => 'name',
    'views_test_data_age' => 'age',
  ));
  $view
    ->destroy();
  $view
    ->setDisplay();

  // Reverse the ordering
  $view->displayHandlers['default']
    ->overrideOption('sorts', array(
    'age' => array(
      'order' => 'DESC',
      'id' => 'age',
      'table' => 'views_test_data',
      'field' => 'age',
      '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(), 'age', TRUE), array(
    'views_test_data_name' => 'name',
    'views_test_data_age' => 'age',
  ));
}