You are here

function DatabaseFetchTestCase::testQueryFetchDefault in SimpleTest 7

Confirm that we can fetch a record properly in default object mode.

File

tests/database_test.test, line 266

Class

DatabaseFetchTestCase
Test fetch actions, part 1.

Code

function testQueryFetchDefault() {
  $records = array();
  $result = db_query('SELECT name FROM {test} WHERE age = :age', array(
    ':age' => 25,
  ));
  $this
    ->assertTrue($result instanceof DatabaseStatementInterface, t('Result set is a Drupal statement object.'));
  foreach ($result as $record) {
    $records[] = $record;
    $this
      ->assertTrue(is_object($record), t('Record is an object.'));
    $this
      ->assertIdentical($record->name, 'John', t('25 year old is John.'));
  }
  $this
    ->assertIdentical(count($records), 1, t('There is only one record.'));
}