function UpdateTest::testWhereUpdate

Confirms that we can update multiple records with a where call.

File

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

Class

UpdateTest
Tests the update query builder.

Namespace

Drupal\system\Tests\Database

Code

function testWhereUpdate() {
  $num_updated = db_update('test')
    ->fields(array(
    'job' => 'Musician',
  ))
    ->where('age > :age', array(
    ':age' => 26,
  ))
    ->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.');
}