You are here

function UpdateTest::testWhereAndConditionUpdate 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::testWhereAndConditionUpdate()

Confirms that we can stack condition and where calls.

File

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

Class

UpdateTest
Tests the update query builder.

Namespace

Drupal\system\Tests\Database

Code

function testWhereAndConditionUpdate() {
  $update = db_update('test')
    ->fields(array(
    'job' => 'Musician',
  ))
    ->where('age > :age', array(
    ':age' => 26,
  ))
    ->condition('name', 'Ringo');
  $num_updated = $update
    ->execute();
  $this
    ->assertIdentical($num_updated, 1, 'Updated 1 record.');
  $num_matches = db_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(
    ':job' => 'Musician',
  ))
    ->fetchField();
  $this
    ->assertIdentical($num_matches, '1', 'Updated fields successfully.');
}