public function InsertTest::testInsertSelectAll in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Database/InsertTest.php \Drupal\KernelTests\Core\Database\InsertTest::testInsertSelectAll()
Tests that the INSERT INTO ... SELECT * ... syntax works.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Database/ InsertTest.php, line 181
Class
- InsertTest
- Tests the insert builder.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testInsertSelectAll() {
$query = $this->connection
->select('test_people', 'tp')
->fields('tp')
->condition('tp.name', 'Meredith');
// The resulting query should be equivalent to:
// INSERT INTO test_people_copy
// SELECT *
// FROM test_people tp
// WHERE tp.name = 'Meredith'
$this->connection
->insert('test_people_copy')
->from($query)
->execute();
$saved_age = $this->connection
->query('SELECT [age] FROM {test_people_copy} WHERE [name] = :name', [
':name' => 'Meredith',
])
->fetchField();
$this
->assertSame('30', $saved_age, 'Can retrieve after inserting.');
}