You are here

function SelectOrderedTest::testSimpleSelectOrderedDesc in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Database/SelectOrderedTest.php \Drupal\system\Tests\Database\SelectOrderedTest::testSimpleSelectOrderedDesc()

Tests ORDER BY descending.

File

core/modules/system/src/Tests/Database/SelectOrderedTest.php, line 72
Contains \Drupal\system\Tests\Database\SelectOrderedTest.

Class

SelectOrderedTest
Tests the Select query builder.

Namespace

Drupal\system\Tests\Database

Code

function testSimpleSelectOrderedDesc() {
  $query = db_select('test');
  $query
    ->addField('test', 'name');
  $age_field = $query
    ->addField('test', 'age', 'age');
  $query
    ->orderBy($age_field, 'DESC');
  $result = $query
    ->execute();
  $num_records = 0;
  $last_age = 100000000;
  foreach ($result as $record) {
    $num_records++;
    $this
      ->assertTrue($record->age <= $last_age, 'Results returned in correct order.');
    $last_age = $record->age;
  }
  $this
    ->assertEqual($num_records, 4, 'Returned the correct number of rows.');
}