You are here

function SelectComplexTest::testLeftOuterJoin in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/system/src/Tests/Database/SelectComplexTest.php \Drupal\system\Tests\Database\SelectComplexTest::testLeftOuterJoin()

Tests LEFT OUTER joins.

File

core/modules/system/src/Tests/Database/SelectComplexTest.php, line 55
Contains \Drupal\system\Tests\Database\SelectComplexTest.

Class

SelectComplexTest
Tests the Select query builder with more complex queries.

Namespace

Drupal\system\Tests\Database

Code

function testLeftOuterJoin() {
  $query = db_select('test', 'p');
  $people_alias = $query
    ->leftJoin('test_task', 't', 't.pid = p.id');
  $name_field = $query
    ->addField('p', 'name', 'name');
  $query
    ->addField($people_alias, 'task', 'task');
  $query
    ->addField($people_alias, 'priority', 'priority');
  $query
    ->orderBy($name_field);
  $result = $query
    ->execute();
  $num_records = 0;
  $last_name = 0;
  foreach ($result as $record) {
    $num_records++;
    $this
      ->assertTrue(strcmp($record->{$name_field}, $last_name) >= 0, 'Results returned in correct order.');
  }
  $this
    ->assertEqual($num_records, 8, 'Returned the correct number of rows.');
}