function SortTest::testStringOrdering

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Kernel/Handler/SortTest.php \Drupal\Tests\views\Kernel\Handler\SortTest::testStringOrdering()
  2. 10 core/modules/views/tests/src/Kernel/Handler/SortTest.php \Drupal\Tests\views\Kernel\Handler\SortTest::testStringOrdering()
  3. 11.x core/modules/views/tests/src/Kernel/Handler/SortTest.php \Drupal\Tests\views\Kernel\Handler\SortTest::testStringOrdering()

Tests string ordering of the result set.

File

core/modules/views/tests/src/Kernel/Handler/SortTest.php, line 78

Class

SortTest
Tests for core <a href="/api/drupal/core%21modules%21views%21src%21Plugin%21views%21sort%21SortPluginBase.php/class/SortPluginBase/8.9.x" title="Base sort handler that has no options and performs a simple sort." class="local">Drupal\views\Plugin\views\sort\SortPluginBase</a> handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testStringOrdering() {
    $view = Views::getView('test_view');
    $view->setDisplay();
    // Change the ordering
    $view->displayHandlers
        ->get('default')
        ->overrideOption('sorts', [
        'name' => [
            '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), '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();
    // Reverse the ordering
    $view->displayHandlers
        ->get('default')
        ->overrideOption('sorts', [
        'name' => [
            '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), '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',
    ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.