function SortRandomTest::testRandomOrdering

Same name in other branches
  1. 8.9.x core/modules/views/tests/src/Kernel/Handler/SortRandomTest.php \Drupal\Tests\views\Kernel\Handler\SortRandomTest::testRandomOrdering()
  2. 10 core/modules/views/tests/src/Kernel/Handler/SortRandomTest.php \Drupal\Tests\views\Kernel\Handler\SortRandomTest::testRandomOrdering()
  3. 11.x core/modules/views/tests/src/Kernel/Handler/SortRandomTest.php \Drupal\Tests\views\Kernel\Handler\SortRandomTest::testRandomOrdering()

Tests random ordering of the result set.

See also

DatabaseSelectTestCase::testRandomOrder()

File

core/modules/views/tests/src/Kernel/Handler/SortRandomTest.php, line 72

Class

SortRandomTest
Tests for core Drupal\views\Plugin\views\sort\Random handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testRandomOrdering() {
    // Execute a basic view first.
    $view = Views::getView('test_view');
    $this->executeView($view);
    // Verify the result.
    $this->assertSameSize($this->dataSet(), $view->result, 'The number of returned rows match.');
    $this->assertIdenticalResultset($view, $this->dataSet(), [
        'views_test_data_name' => 'name',
        'views_test_data_age' => 'age',
    ]);
    // Execute a random view, we expect the result set to be different.
    $view_random = $this->getBasicRandomView();
    $this->executeView($view_random);
    $this->assertSameSize($this->dataSet(), $view_random->result, 'The number of returned rows match.');
    $this->assertNotIdenticalResultset($view_random, $view->result, [
        'views_test_data_name' => 'views_test_data_name',
        'views_test_data_age' => 'views_test_data_name',
    ]);
    // Execute a second random view, we expect the result set to be different again.
    $view_random_2 = $this->getBasicRandomView();
    $this->executeView($view_random_2);
    $this->assertSameSize($this->dataSet(), $view_random_2->result, 'The number of returned rows match.');
    $this->assertNotIdenticalResultset($view_random, $view->result, [
        'views_test_data_name' => 'views_test_data_name',
        'views_test_data_age' => 'views_test_data_name',
    ]);
}

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