You are here

public function UpdateTest::testSimpleUpdate in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Database/UpdateTest.php \Drupal\KernelTests\Core\Database\UpdateTest::testSimpleUpdate()

Confirms that we can update a single record successfully.

File

core/tests/Drupal/KernelTests/Core/Database/UpdateTest.php, line 15

Class

UpdateTest
Tests the update query builder.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testSimpleUpdate() {
  $num_updated = $this->connection
    ->update('test')
    ->fields([
    'name' => 'Tiffany',
  ])
    ->condition('id', 1)
    ->execute();
  $this
    ->assertIdentical($num_updated, 1, 'Updated 1 record.');
  $saved_name = $this->connection
    ->query('SELECT name FROM {test} WHERE id = :id', [
    ':id' => 1,
  ])
    ->fetchField();
  $this
    ->assertIdentical($saved_name, 'Tiffany', 'Updated name successfully.');
}