You are here

function UpdateComplexTest::testUpdateOnlyExpression in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Database/UpdateComplexTest.php \Drupal\system\Tests\Database\UpdateComplexTest::testUpdateOnlyExpression()

Tests UPDATE with only expression values.

File

core/modules/system/src/Tests/Database/UpdateComplexTest.php, line 118
Contains \Drupal\system\Tests\Database\UpdateComplexTest.

Class

UpdateComplexTest
Tests the Update query builder, complex queries.

Namespace

Drupal\system\Tests\Database

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