function AlterTest::testAlterChangeConditional
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Database/AlterTest.php \Drupal\KernelTests\Core\Database\AlterTest::testAlterChangeConditional()
- 8.9.x core/tests/Drupal/KernelTests/Core/Database/AlterTest.php \Drupal\KernelTests\Core\Database\AlterTest::testAlterChangeConditional()
- 11.x core/tests/Drupal/KernelTests/Core/Database/AlterTest.php \Drupal\KernelTests\Core\Database\AlterTest::testAlterChangeConditional()
Tests that we can alter a query's conditionals.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ AlterTest.php, line 56
Class
- AlterTest
- Tests the hook_query_alter capabilities of the Select builder.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testAlterChangeConditional() : void {
$query = $this->connection
->select('test_task');
$tid_field = $query->addField('test_task', 'tid');
$pid_field = $query->addField('test_task', 'pid');
$task_field = $query->addField('test_task', 'task');
$people_alias = $query->join('test', 'people', "[test_task].[pid] = [people].[id]");
$name_field = $query->addField($people_alias, 'name', 'name');
$query->condition('test_task.tid', '1');
$query->orderBy($tid_field);
$query->addTag('database_test_alter_change_conditional');
$result = $query->execute();
$records = $result->fetchAll();
$this->assertCount(1, $records, 'Returned the correct number of rows.');
$this->assertEquals('John', $records[0]->{$name_field}, 'Correct data retrieved.');
$this->assertEquals(2, $records[0]->{$tid_field}, 'Correct data retrieved.');
$this->assertEquals(1, $records[0]->{$pid_field}, 'Correct data retrieved.');
$this->assertEquals('sleep', $records[0]->{$task_field}, 'Correct data retrieved.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.