You are here

function DatabaseInsertTestCase::testInsertSelectAll in Drupal 7

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

File

modules/simpletest/tests/database_test.test, line 641

Class

DatabaseInsertTestCase
Test the insert builder.

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