You are here

function DatabaseSelectComplexTestCase::testCountQueryFieldRemovals in Drupal 7

Test that countQuery properly removes fields and expressions.

File

modules/simpletest/tests/database_test.test, line 2235

Class

DatabaseSelectComplexTestCase
Test more complex select statements.

Code

function testCountQueryFieldRemovals() {

  // countQuery should remove all fields and expressions, so this can be
  // tested by adding a non-existent field and expression: if it ends
  // up in the query, an error will be thrown. If not, it will return the
  // number of records, which in this case happens to be 4 (there are four
  // records in the {test} table).
  $query = db_select('test');
  $query
    ->fields('test', array(
    'fail',
  ));
  $this
    ->assertEqual(4, $query
    ->countQuery()
    ->execute()
    ->fetchField(), 'Count Query removed fields');
  $query = db_select('test');
  $query
    ->addExpression('fail');
  $this
    ->assertEqual(4, $query
    ->countQuery()
    ->execute()
    ->fetchField(), 'Count Query removed expressions');
}