public function UpdateTest::testExpressionUpdate in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/KernelTests/Core/Database/UpdateTest.php \Drupal\KernelTests\Core\Database\UpdateTest::testExpressionUpdate()
Tests updating with expressions.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Database/ UpdateTest.php, line 101
Class
- UpdateTest
- Tests the update query builder.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testExpressionUpdate() {
// Ensure that expressions are handled properly. This should set every
// record's age to a square of itself.
$num_rows = $this->connection
->update('test')
->expression('age', 'age * age')
->execute();
$this
->assertIdentical($num_rows, 4, 'Updated 4 records.');
$saved_name = $this->connection
->query('SELECT name FROM {test} WHERE age = :age', [
':age' => pow(26, 2),
])
->fetchField();
$this
->assertIdentical($saved_name, 'Paul', 'Successfully updated values using an algebraic expression.');
}