function SelectComplexTest::testDefaultJoin

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

Tests simple JOIN statements.

File

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

Class

SelectComplexTest
Tests the Select query builder with more complex queries.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testDefaultJoin() {
    $query = $this->connection
        ->select('test_task', 't');
    $people_alias = $query->join('test', 'p', 't.pid = p.id');
    $name_field = $query->addField($people_alias, 'name', 'name');
    $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, 'Results returned in correct order.');
        $this->assertNotEqual($record->{$name_field}, 'Ringo', 'Taskless person not selected.');
        $last_priority = $record->{$priority_field};
    }
    $this->assertEqual($num_records, 7, 'Returned the correct number of rows.');
}

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