You are here

function DatabaseSelectTestCase::testSimpleSelectMultipleFields in SimpleTest 7

Test adding multiple fields to a select statement at the same time.

File

tests/database_test.test, line 1285

Class

DatabaseSelectTestCase
Test the SELECT builder.

Code

function testSimpleSelectMultipleFields() {
  $record = db_select('test')
    ->fields('test', array(
    'id',
    'name',
    'age',
    'job',
  ))
    ->condition('age', 27)
    ->execute()
    ->fetchObject();

  // Check that all fields we asked for are present.
  $this
    ->assertNotNull($record->id, t('ID field is present.'));
  $this
    ->assertNotNull($record->name, t('Name field is present.'));
  $this
    ->assertNotNull($record->age, t('Age field is present.'));
  $this
    ->assertNotNull($record->job, t('Job field is present.'));

  // Ensure that we got the right record.
  // Check that all fields we asked for are present.
  $this
    ->assertEqual($record->id, 2, t('ID field has the correct value.'));
  $this
    ->assertEqual($record->name, 'George', t('Name field has the correct value.'));
  $this
    ->assertEqual($record->age, 27, t('Age field has the correct value.'));
  $this
    ->assertEqual($record->job, 'Singer', t('Job field has the correct value.'));
}