function DatabaseUpdateTestCase::testPrimaryKeyUpdate

7.x database_test.test DatabaseUpdateTestCase::testPrimaryKeyUpdate()

Confirm that we can update the primary key of a record successfully.

File

drupal-7.x/modules/simpletest/tests/database_test.test, line 877

Class

DatabaseUpdateTestCase
Update builder tests.

Code

function testPrimaryKeyUpdate() {
  $num_updated = db_update('test')
    ->fields(array('id' => 42, 'name' => 'John'))
    ->condition('id', 1)
    ->execute();
  $this->assertIdentical($num_updated, 1, 'Updated 1 record.');

  $saved_name = db_query('SELECT name FROM {test} WHERE id = :id', array(':id' => 42))->fetchField();
  $this->assertIdentical($saved_name, 'John', 'Updated primary key successfully.');
}