You are here

public function UpsertTest::testUpsertNullBlob in Drupal 9

Tests that we can upsert a null into blob field.

File

core/tests/Drupal/KernelTests/Core/Database/UpsertTest.php, line 128

Class

UpsertTest
Tests the Upsert query builder.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testUpsertNullBlob() {
  $id = $this->connection
    ->insert('test_one_blob')
    ->fields([
    'blob1' => 'test',
  ])
    ->execute();
  $r = $this->connection
    ->query('SELECT * FROM {test_one_blob} WHERE [id] = :id', [
    ':id' => $id,
  ])
    ->fetchAssoc();
  $this
    ->assertSame('test', $r['blob1']);
  $this->connection
    ->upsert('test_one_blob')
    ->key('id')
    ->fields([
    'id',
    'blob1',
  ])
    ->values([
    'id' => $id,
    'blob1' => NULL,
  ])
    ->values([
    'id' => $id + 1,
    'blob1' => NULL,
  ])
    ->execute();
  $r = $this->connection
    ->query('SELECT * FROM {test_one_blob} WHERE [id] = :id', [
    ':id' => $id,
  ])
    ->fetchAssoc();
  $this
    ->assertNull($r['blob1']);
  $r = $this->connection
    ->query('SELECT * FROM {test_one_blob} WHERE [id] = :id', [
    ':id' => $id + 1,
  ])
    ->fetchAssoc();
  $this
    ->assertNull($r['blob1']);
}