function UpsertTest::testUpsertNullBlob

Same name in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/Database/UpsertTest.php \Drupal\KernelTests\Core\Database\UpsertTest::testUpsertNullBlob()
  2. 11.x core/tests/Drupal/KernelTests/Core/Database/UpsertTest.php \Drupal\KernelTests\Core\Database\UpsertTest::testUpsertNullBlob()

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.