function UpdateTest::testUpdateAffectedRows

Tests return value on update.

File

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

Class

UpdateTest
Tests the update query builder.

Namespace

Drupal\system\Tests\Database

Code

function testUpdateAffectedRows() {

  // At 5am in the morning, all band members but those with a priority 1 task
  // are sleeping. So we set their tasks to 'sleep'. 5 records match the
  // condition and therefore are affected by the query, even though two of
  // them actually don't have to be changed because their value was already
  // 'sleep'. Still, execute() should return 5 affected rows, not only 3,
  // because that's cross-db expected behaviour.
  $num_rows = db_update('test_task')
    ->condition('priority', 1, '<>')
    ->fields(array(
    'task' => 'sleep',
  ))
    ->execute();
  $this
    ->assertIdentical($num_rows, 5, 'Correctly returned 5 affected rows.');
}