function DatabaseUpdateComplexTestCase::testUpdateOnlyExpression

7.x database_test.test DatabaseUpdateComplexTestCase::testUpdateOnlyExpression()

Test update with only expression values.

File

drupal/modules/simpletest/tests/database_test.test, line 981

Class

DatabaseUpdateComplexTestCase
Tests for more complex update statements.

Code

function testUpdateOnlyExpression() {
  $before_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'))->fetchField();
  $num_updated = db_update('test')->condition('name', 'Ringo')->expression('age', 'age + :age', array(':age' => 4))->execute();
  $this->assertIdentical($num_updated, 1, 'Updated 1 record.');

  $after_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'))->fetchField();
  $this->assertEqual($before_age + 4, $after_age, 'Age updated correctly');
}