Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Database/InsertTest.php \Drupal\KernelTests\Core\Database\InsertTest::testInsertSelectAll()
  2. 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 183

Class

InsertTest
Tests the insert builder.

Namespace

Drupal\KernelTests\Core\Database

Code

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.');
}