function DatabaseUpdateComplexTestCase::testUpdateOnlyExpression in SimpleTest 7
Test update with only expression values.
File
- tests/
database_test.test, line 858
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, t('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, t('Age updated correctly'));
}