function UpdateTest::testPrimaryKeyUpdate

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

File

drupal/core/modules/system/lib/Drupal/system/Tests/Database/UpdateTest.php, line 144
Definition of Drupal\system\Tests\Database\UpdateTest.

Class

UpdateTest
Tests the update query builder.

Namespace

Drupal\system\Tests\Database

Code

function testPrimaryKeyUpdate() {
  $num_updated = db_update('test')
    ->fields(array(
    'id' => 42,
    'name' => 'John',
  ))
    ->condition('id', 1)
    ->execute();
  $this
    ->assertIdentical($num_updated, 1, t('Updated 1 record.'));
  $saved_name = db_query('SELECT name FROM {test} WHERE id = :id', array(
    ':id' => 42,
  ))
    ->fetchField();
  $this
    ->assertIdentical($saved_name, 'John', t('Updated primary key successfully.'));
}