View source
<?php
namespace Drupal\Tests\views\Kernel\Handler;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Views;
class SortTest extends ViewsKernelTestBase {
public static $testViews = [
'test_view',
];
public function testNumericOrdering() {
$view = Views::getView('test_view');
$view
->setDisplay();
$view->displayHandlers
->get('default')
->overrideOption('sorts', [
'age' => [
'order' => 'ASC',
'id' => 'age',
'table' => 'views_test_data',
'field' => 'age',
'relationship' => 'none',
],
]);
$this
->executeView($view);
$this
->assertSameSize($this
->dataSet(), $view->result, 'The number of returned rows match.');
$this
->assertIdenticalResultset($view, $this
->orderResultSet($this
->dataSet(), 'age'), [
'views_test_data_name' => 'name',
'views_test_data_age' => 'age',
]);
$view
->destroy();
$view
->setDisplay();
$view->displayHandlers
->get('default')
->overrideOption('sorts', [
'age' => [
'order' => 'DESC',
'id' => 'age',
'table' => 'views_test_data',
'field' => 'age',
'relationship' => 'none',
],
]);
$this
->executeView($view);
$this
->assertSameSize($this
->dataSet(), $view->result, 'The number of returned rows match.');
$this
->assertIdenticalResultset($view, $this
->orderResultSet($this
->dataSet(), 'age', TRUE), [
'views_test_data_name' => 'name',
'views_test_data_age' => 'age',
]);
}
public function testStringOrdering() {
$view = Views::getView('test_view');
$view
->setDisplay();
$view->displayHandlers
->get('default')
->overrideOption('sorts', [
'name' => [
'order' => 'ASC',
'id' => 'name',
'table' => 'views_test_data',
'field' => 'name',
'relationship' => 'none',
],
]);
$this
->executeView($view);
$this
->assertSameSize($this
->dataSet(), $view->result, 'The number of returned rows match.');
$this
->assertIdenticalResultset($view, $this
->orderResultSet($this
->dataSet(), 'name'), [
'views_test_data_name' => 'name',
'views_test_data_age' => 'age',
]);
$view
->destroy();
$view
->setDisplay();
$view->displayHandlers
->get('default')
->overrideOption('sorts', [
'name' => [
'order' => 'DESC',
'id' => 'name',
'table' => 'views_test_data',
'field' => 'name',
'relationship' => 'none',
],
]);
$this
->executeView($view);
$this
->assertSameSize($this
->dataSet(), $view->result, 'The number of returned rows match.');
$this
->assertIdenticalResultset($view, $this
->orderResultSet($this
->dataSet(), 'name', TRUE), [
'views_test_data_name' => 'name',
'views_test_data_age' => 'age',
]);
}
}