You are here

function DatabaseSelectComplexTestCase::testDefaultJoin in SimpleTest 7

Test simple JOIN statements.

File

tests/database_test.test, line 1663

Class

DatabaseSelectComplexTestCase
Test more complex select statements.

Code

function testDefaultJoin() {
  $query = db_select('test_task', 't');
  $people_alias = $query
    ->join('test', 'p', 't.pid = p.id');
  $name_field = $query
    ->addField($people_alias, 'name', 'name');
  $task_field = $query
    ->addField('t', 'task', 'task');
  $priority_field = $query
    ->addField('t', 'priority', 'priority');
  $query
    ->orderBy($priority_field);
  $result = $query
    ->execute();
  $num_records = 0;
  $last_priority = 0;
  foreach ($result as $record) {
    $num_records++;
    $this
      ->assertTrue($record->{$priority_field} >= $last_priority, t('Results returned in correct order.'));
    $this
      ->assertNotEqual($record->{$name_field}, 'Ringo', t('Taskless person not selected.'));
    $last_priority = $record->{$priority_field};
  }
  $this
    ->assertEqual($num_records, 7, t('Returned the correct number of rows.'));
}