1.20.x database_test.test DatabaseSelectTestCase::testSimpleSelectExpressionMultiple()

Test SELECT statements with multiple expressions.

File

modules/simpletest/tests/database_test.test, line 1431
Database tests.

Class

DatabaseSelectTestCase
Test the SELECT builder.

Code

function testSimpleSelectExpressionMultiple() {
  $query = db_select('test');
  $name_field = $query->addField('test', 'name');
  $age_double_field = $query->addExpression("age*2");
  $age_triple_field = $query->addExpression("age*3");
  $query->condition('age', 27);
  $result = $query->execute();

  // Check that the aliases are being created the way we want.
  $this->assertEqual($age_double_field, 'expression', 'Double age field alias is correct.');
  $this->assertEqual($age_triple_field, 'expression_2', 'Triple age field alias is correct.');

  // Ensure that we got the right record.
  $record = $result->fetch();
  $this->assertEqual($record->$name_field, 'George', 'Fetched name is correct.');
  $this->assertEqual($record->$age_double_field, 27 * 2, 'Fetched double age expression is correct.');
  $this->assertEqual($record->$age_triple_field, 27 * 3, 'Fetched triple age expression is correct.');
}