You are here

function DatabaseSelectOrderedTestCase::testSimpleSelectOrderedDesc in SimpleTest 7

Test order by descending.

File

tests/database_test.test, line 1628

Class

DatabaseSelectOrderedTestCase
Test select with order by clauses.

Code

function testSimpleSelectOrderedDesc() {
  $query = db_select('test');
  $name_field = $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, t('Results returned in correct order.'));
    $last_age = $record->age;
  }
  $this
    ->assertEqual($num_records, 4, t('Returned the correct number of rows.'));
}