function SelectComplexTest::testLeftOuterJoin

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php \Drupal\KernelTests\Core\Database\SelectComplexTest::testLeftOuterJoin()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php \Drupal\KernelTests\Core\Database\SelectComplexTest::testLeftOuterJoin()
  3. 11.x core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php \Drupal\KernelTests\Core\Database\SelectComplexTest::testLeftOuterJoin()

Tests LEFT OUTER joins.

File

core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php, line 53

Class

SelectComplexTest
Tests the Select query builder with more complex queries.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testLeftOuterJoin() : void {
    $query = $this->connection
        ->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';
    // Verify that the results are returned in the correct order.
    foreach ($result as $record) {
        $num_records++;
        $this->assertGreaterThanOrEqual(0, strcmp($record->{$name_field}, $last_name));
    }
    $this->assertEquals(8, $num_records, 'Returned the correct number of rows.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.