function DatabaseSelectTestCase::testSimpleComment in Drupal 7
Test rudimentary SELECT statement with a COMMENT.
File
- modules/
simpletest/ tests/ database_test.test, line 1390
Class
- DatabaseSelectTestCase
- Test the SELECT builder.
Code
function testSimpleComment() {
$query = db_select('test')
->comment('Testing query comments');
$name_field = $query
->addField('test', 'name');
$age_field = $query
->addField('test', 'age', 'age');
$result = $query
->execute();
$num_records = 0;
foreach ($result as $record) {
$num_records++;
}
$query = (string) $query;
$expected = "/* Testing query comments */ SELECT test.name AS name, test.age AS age\nFROM \n{test} test";
$this
->assertEqual($num_records, 4, 'Returned the correct number of rows.');
$this
->assertEqual($query, $expected, 'The flattened query contains the comment string.');
}