function SelectComplexTest::testCountQueryFieldRemovals in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/Database/SelectComplexTest.php \Drupal\system\Tests\Database\SelectComplexTest::testCountQueryFieldRemovals()
Tests that countQuery properly removes fields and expressions.
File
- core/
modules/ system/ src/ Tests/ Database/ SelectComplexTest.php, line 241 - Contains \Drupal\system\Tests\Database\SelectComplexTest.
Class
- SelectComplexTest
- Tests the Select query builder with more complex queries.
Namespace
Drupal\system\Tests\DatabaseCode
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');
}