public function SelectComplexTest::testDefaultJoin in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php \Drupal\KernelTests\Core\Database\SelectComplexTest::testDefaultJoin()
- 9 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\DatabaseCode
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;
// Verify that the results are returned in the correct order.
foreach ($result as $record) {
$num_records++;
$this
->assertGreaterThanOrEqual($last_priority, $record->{$priority_field});
$this
->assertNotSame('Ringo', $record->{$name_field}, 'Taskless person not selected.');
$last_priority = $record->{$priority_field};
}
$this
->assertEquals(7, $num_records, 'Returned the correct number of rows.');
}