1 database_test.test DatabaseSelectComplexTestCase::testCountQuery()

Test that we can generate a count query from a built query.

File

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

Class

DatabaseSelectComplexTestCase
Test more complex select statements.

Code

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

  $count = $query->countQuery()->execute()->fetchField();

  $this->assertEqual($count, 4, 'Counted the correct number of records.');

  // Now make sure we didn't break the original query!  We should still have
  // all of the fields we asked for.
  $record = $query->execute()->fetch();
  $this->assertEqual($record->$name_field, 'George', 'Correct data retrieved.');
  $this->assertEqual($record->$age_field, 27, 'Correct data retrieved.');
}