function SelectComplexTest::testCountQueryFieldRemovals

Tests that countQuery properly removes fields and expressions.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Database/SelectComplexTest.php, line 252
Definition of Drupal\system\Tests\Database\SelectComplexTest.

Class

SelectComplexTest
Tests more complex select statements.

Namespace

Drupal\system\Tests\Database

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');
}