You are here

function DatabaseUpdateTestCase::testWhereAndConditionUpdate in Drupal 7

Confirm that we can stack condition and where calls.

File

modules/simpletest/tests/database_test.test, line 848

Class

DatabaseUpdateTestCase
Update builder tests.

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.');
}