You are here

function InsertTest::testInsertSelectAll in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Database/InsertTest.php \Drupal\system\Tests\Database\InsertTest::testInsertSelectAll()

Tests that the INSERT INTO ... SELECT * ... syntax works.

File

core/modules/system/src/Tests/Database/InsertTest.php, line 167
Contains \Drupal\system\Tests\Database\InsertTest.

Class

InsertTest
Tests the insert builder.

Namespace

Drupal\system\Tests\Database

Code

function testInsertSelectAll() {
  $query = db_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'
  db_insert('test_people_copy')
    ->from($query)
    ->execute();
  $saved_age = db_query('SELECT age FROM {test_people_copy} WHERE name = :name', array(
    ':name' => 'Meredith',
  ))
    ->fetchField();
  $this
    ->assertIdentical($saved_age, '30', 'Can retrieve after inserting.');
}