->
orderBy('id'
) ->
execute() ->
fetchCol();
$this->
assertEquals($expected_ids,
$ordered_ids, 'A query without random ordering returns IDs in the correct order.'
);
// Now perform the same query, but instead choose a random ordering. We
// expect this to contain a differently ordered version of the original
// result.
$randomized_ids =
$this->connection->
select('test', 't'
) ->
fields('t',
['id'
]) ->
range(0,
$number_of_items) ->
orderRandom() ->
execute() ->
fetchCol();
$this->
assertNotEquals($ordered_ids,
$randomized_ids, 'A query with random ordering returns an unordered set of IDs.'
);
$sorted_ids =
$randomized_ids;
sort($sorted_ids);
$this->
assertEquals($ordered_ids,
$sorted_ids, 'After sorting the random list, the result matches the original query.'
);
// Now perform the exact same query again, and make sure the order is
// different.
$randomized_ids_second_set =
$this->connection->
select('test', 't'
) ->
fields('t',
['id'
])