- <?php
-
- * @file
- * Definition of ViewsHandlerSortRandomTest.
- */
-
- require_once BACKDROP_ROOT . '/core/modules/views/tests/views_query.test';
-
- * Tests for core views_handler_sort_random handler.
- */
- class ViewsHandlerSortRandomTest extends ViewsSqlTest {
-
- * Add more items to the test set, to make the order tests more robust.
- */
- protected function dataSet() {
- $data = parent::dataSet();
- for ($i = 0; $i < 50; $i++) {
- $data[] = array(
- 'name' => 'name_' . $i,
- 'age' => $i,
- 'job' => 'job_' . $i,
- 'created' => rand(0, time()),
- );
- }
- return $data;
- }
-
-
- * Return a basic view with random ordering.
- */
- protected function getBasicRandomView() {
- $view = $this->getBasicView();
-
-
- $view->display['default']->handler->override_option('sorts', array(
- 'random' => array(
- 'id' => 'random',
- 'field' => 'random',
- 'table' => 'views',
- ),
- ));
-
- return $view;
- }
-
-
- * Tests random ordering of the result set.
- *
- * @see DatabaseSelectTestCase::testRandomOrder()
- */
- public function testRandomOrdering() {
-
- $view = $this->getBasicView();
- $this->executeView($view);
-
-
- $this->assertEqual(count($this->dataSet()), count($view->result), t('The number of returned rows match.'));
- $this->assertIdenticalResultset($view, $this->dataSet(), array(
- 'views_test_name' => 'name',
- 'views_test_age' => 'age',
- ));
-
-
- $view_random = $this->getBasicRandomView();
- $this->executeView($view_random);
- $this->assertEqual(count($this->dataSet()), count($view_random->result), t('The number of returned rows match.'));
- $this->assertNotIdenticalResultset($view_random, $view->result, array(
- 'views_test_name' => 'views_test_name',
- 'views_test_age' => 'views_test_name',
- ));
-
-
- $view_random_2 = $this->getBasicRandomView();
- $this->executeView($view_random_2);
- $this->assertEqual(count($this->dataSet()), count($view_random_2->result), t('The number of returned rows match.'));
- $this->assertNotIdenticalResultset($view_random, $view->result, array(
- 'views_test_name' => 'views_test_name',
- 'views_test_age' => 'views_test_name',
- ));
- }
- }