You are here

function UpdateTest::testMultiUpdate in Zircon Profile 8

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

Confirms that we can update multiple records successfully.

File

core/modules/system/src/Tests/Database/UpdateTest.php, line 49
Contains \Drupal\system\Tests\Database\UpdateTest.

Class

UpdateTest
Tests the update query builder.

Namespace

Drupal\system\Tests\Database

Code

function testMultiUpdate() {
  $num_updated = db_update('test')
    ->fields(array(
    'job' => 'Musician',
  ))
    ->condition('job', 'Singer')
    ->execute();
  $this
    ->assertIdentical($num_updated, 2, 'Updated 2 records.');
  $num_matches = db_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(
    ':job' => 'Musician',
  ))
    ->fetchField();
  $this
    ->assertIdentical($num_matches, '2', 'Updated fields successfully.');
}