public function InsertTest::testInsertSelectAll in Drupal 8
Same name and namespace in other branches
- 9 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 179
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
->assertIdentical($saved_age, '30', 'Can retrieve after inserting.');
}