function DatabaseUpdateComplexTestCase::testUpdateOnlyExpression in Drupal 7
Test update with only expression values.
File
- modules/
simpletest/ tests/ database_test.test, line 1009
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');
}