You are here

function UpdateTest::testExpressionUpdate in Zircon Profile 8

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

Tests updating with expressions.

File

core/modules/system/src/Tests/Database/UpdateTest.php, line 106
Contains \Drupal\system\Tests\Database\UpdateTest.

Class

UpdateTest
Tests the update query builder.

Namespace

Drupal\system\Tests\Database

Code

function testExpressionUpdate() {

  // Ensure that expressions are handled properly. This should set every
  // record's age to a square of itself.
  $num_rows = db_update('test')
    ->expression('age', 'age * age')
    ->execute();
  $this
    ->assertIdentical($num_rows, 4, 'Updated 4 records.');
  $saved_name = db_query('SELECT name FROM {test} WHERE age = :age', array(
    ':age' => pow(26, 2),
  ))
    ->fetchField();
  $this
    ->assertIdentical($saved_name, 'Paul', 'Successfully updated values using an algebraic expression.');
}