function AlterTest::testAlterWithJoin
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Database/AlterTest.php \Drupal\KernelTests\Core\Database\AlterTest::testAlterWithJoin()
- 8.9.x core/tests/Drupal/KernelTests/Core/Database/AlterTest.php \Drupal\KernelTests\Core\Database\AlterTest::testAlterWithJoin()
- 10 core/tests/Drupal/KernelTests/Core/Database/AlterTest.php \Drupal\KernelTests\Core\Database\AlterTest::testAlterWithJoin()
Tests that we can alter the joins on a query.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ AlterTest.php, line 32
Class
- AlterTest
- Tests the hook_query_alter capabilities of the Select builder.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testAlterWithJoin() : void {
$query = $this->connection
->select('test_task');
$tid_field = $query->addField('test_task', 'tid');
$task_field = $query->addField('test_task', 'task');
$query->orderBy($task_field);
$query->addTag('database_test_alter_add_join');
$result = $query->execute();
$records = $result->fetchAll();
$this->assertCount(2, $records, 'Returned the correct number of rows.');
$this->assertEquals('George', $records[0]->name, 'Correct data retrieved.');
$this->assertEquals(4, $records[0]->{$tid_field}, 'Correct data retrieved.');
$this->assertEquals('sing', $records[0]->{$task_field}, 'Correct data retrieved.');
$this->assertEquals('George', $records[1]->name, 'Correct data retrieved.');
$this->assertEquals(5, $records[1]->{$tid_field}, 'Correct data retrieved.');
$this->assertEquals('sleep', $records[1]->{$task_field}, 'Correct data retrieved.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.