function AlterTest::testAlterChangeFields
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Database/AlterTest.php \Drupal\KernelTests\Core\Database\AlterTest::testAlterChangeFields()
- 8.9.x core/tests/Drupal/KernelTests/Core/Database/AlterTest.php \Drupal\KernelTests\Core\Database\AlterTest::testAlterChangeFields()
- 11.x core/tests/Drupal/KernelTests/Core/Database/AlterTest.php \Drupal\KernelTests\Core\Database\AlterTest::testAlterChangeFields()
Tests that we can alter the fields of a query.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ AlterTest.php, line 81
Class
- AlterTest
- Tests the hook_query_alter capabilities of the Select builder.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testAlterChangeFields() : void {
$query = $this->connection
->select('test');
$name_field = $query->addField('test', 'name');
$age_field = $query->addField('test', 'age', 'age');
$query->orderBy('name');
$query->addTag('database_test_alter_change_fields');
$record = $query->execute()
->fetch();
$this->assertEquals('George', $record->{$name_field}, 'Correct data retrieved.');
$this->assertFalse(isset($record->{$age_field}), 'Age field not found, as intended.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.