function DatabaseSelectTestCase::testSimpleSelectConditional in SimpleTest 7
Test basic conditionals on SELECT statements.
File
- tests/
database_test.test, line 1223
Class
- DatabaseSelectTestCase
- Test the SELECT builder.
Code
function testSimpleSelectConditional() {
$query = db_select('test');
$name_field = $query
->addField('test', 'name');
$age_field = $query
->addField('test', 'age', 'age');
$query
->condition('age', 27);
$result = $query
->execute();
// Check that the aliases are being created the way we want.
$this
->assertEqual($name_field, 'name', t('Name field alias is correct.'));
$this
->assertEqual($age_field, 'age', t('Age field alias is correct.'));
// Ensure that we got the right record.
$record = $result
->fetch();
$this
->assertEqual($record->{$name_field}, 'George', t('Fetched name is correct.'));
$this
->assertEqual($record->{$age_field}, 27, t('Fetched age is correct.'));
}