1 database_test.test | DatabaseSelectComplexTestCase::testCountQueryFieldRemovals() |
Test that countQuery properly removes fields and expressions.
File
- core/
modules/ simpletest/ tests/ database_test.test, line 2205 - Database tests.
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');
}