You are here

function DatabaseAlter2TestCase::testAlterExpression in SimpleTest 7

Test that we can alter expressions in the query.

File

tests/database_test.test, line 2240

Class

DatabaseAlter2TestCase
Select alter tests, part 2.

Code

function testAlterExpression() {
  $query = db_select('test');
  $name_field = $query
    ->addField('test', 'name');
  $age_field = $query
    ->addExpression("age*2", 'double_age');
  $query
    ->condition('age', 27);
  $query
    ->addTag('database_test_alter_change_expressions');
  $result = $query
    ->execute();

  // 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 * 3, t('Fetched age expression is correct.'));
}