1 database_test.test DatabaseSelectOrderedTestCase::testSimpleSelectOrdered()

Test basic order by.

File

core/modules/simpletest/tests/database_test.test, line 1829
Database tests.

Class

DatabaseSelectOrderedTestCase
Test select with order by clauses.

Code

function testSimpleSelectOrdered() {
  $query = db_select('test');
  $name_field = $query->addField('test', 'name');
  $age_field = $query->addField('test', 'age', 'age');
  $query->orderBy($age_field);
  $result = $query->execute();

  $num_records = 0;
  $last_age = 0;
  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.');
}