3 namespace Drupal\Tests\views\Kernel\Handler;
5 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
6 use Drupal\views\Views;
9 * Tests for core Drupal\views\Plugin\views\sort\SortPluginBase handler.
13 class SortTest extends ViewsKernelTestBase {
16 * Views used by this test.
20 public static $testViews = ['test_view'];
23 * Tests numeric ordering of the result set.
25 public function testNumericOrdering() {
26 $view = Views::getView('test_view');
29 // Change the ordering
30 $view->displayHandlers->get('default')->overrideOption('sorts', [
34 'table' => 'views_test_data',
36 'relationship' => 'none',
41 $this->executeView($view);
44 $this->assertEqual(count($this->dataSet()), count($view->result), 'The number of returned rows match.');
45 $this->assertIdenticalResultset($view, $this->orderResultSet($this->dataSet(), 'age'), [
46 'views_test_data_name' => 'name',
47 'views_test_data_age' => 'age',
53 // Reverse the ordering
54 $view->displayHandlers->get('default')->overrideOption('sorts', [
58 'table' => 'views_test_data',
60 'relationship' => 'none',
65 $this->executeView($view);
68 $this->assertEqual(count($this->dataSet()), count($view->result), 'The number of returned rows match.');
69 $this->assertIdenticalResultset($view, $this->orderResultSet($this->dataSet(), 'age', TRUE), [
70 'views_test_data_name' => 'name',
71 'views_test_data_age' => 'age',
76 * Tests string ordering of the result set.
78 public function testStringOrdering() {
79 $view = Views::getView('test_view');
82 // Change the ordering
83 $view->displayHandlers->get('default')->overrideOption('sorts', [
87 'table' => 'views_test_data',
89 'relationship' => 'none',
94 $this->executeView($view);
97 $this->assertEqual(count($this->dataSet()), count($view->result), 'The number of returned rows match.');
98 $this->assertIdenticalResultset($view, $this->orderResultSet($this->dataSet(), 'name'), [
99 'views_test_data_name' => 'name',
100 'views_test_data_age' => 'age',
106 // Reverse the ordering
107 $view->displayHandlers->get('default')->overrideOption('sorts', [
111 'table' => 'views_test_data',
113 'relationship' => 'none',
118 $this->executeView($view);
120 // Verify the result.
121 $this->assertEqual(count($this->dataSet()), count($view->result), 'The number of returned rows match.');
122 $this->assertIdenticalResultset($view, $this->orderResultSet($this->dataSet(), 'name', TRUE), [
123 'views_test_data_name' => 'name',
124 'views_test_data_age' => 'age',