function SortRandomTest::dataSet

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

Add more items to the test set, to make the order tests more robust.

In total we have then 60 entries, which makes a probability of a collision of 1/60!, which is around 1/1E80, which is higher than the estimated amount of protons / electrons in the observable universe, also called the eddington number.

Overrides ViewsKernelTestBase::dataSet

See also

http://wikipedia.org/wiki/Eddington_number

1 call to SortRandomTest::dataSet()
SortRandomTest::testRandomOrdering in core/modules/views/tests/src/Kernel/Handler/SortRandomTest.php
Tests random ordering of the result set.

File

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

Class

SortRandomTest
Tests for core <a href="/api/drupal/core%21modules%21views%21src%21Plugin%21views%21sort%21Random.php/class/Random/11.x" title="Handle a random sort." class="local">Drupal\views\Plugin\views\sort\Random</a> handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

protected function dataSet() {
    $data = parent::dataSet();
    for ($i = 0; $i < 55; $i++) {
        $data[] = [
            'name' => 'name_' . $i,
            'age' => $i,
            'job' => 'job_' . $i,
            'created' => rand(0, time()),
            'status' => 1,
        ];
    }
    return $data;
}

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