You are here

public function InsertLobTest::testInsertOneBlob in Drupal 8

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

Tests that we can insert a single blob field successfully.

File

core/tests/Drupal/KernelTests/Core/Database/InsertLobTest.php, line 17

Class

InsertLobTest
Tests the Insert query builder with LOB fields.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testInsertOneBlob() {
  $data = "This is\0a test.";
  $this
    ->assertTrue(strlen($data) === 15, 'Test data contains a NULL.');
  $id = $this->connection
    ->insert('test_one_blob')
    ->fields([
    'blob1' => $data,
  ])
    ->execute();
  $r = $this->connection
    ->query('SELECT * FROM {test_one_blob} WHERE id = :id', [
    ':id' => $id,
  ])
    ->fetchAssoc();
  $this
    ->assertTrue($r['blob1'] === $data, new FormattableMarkup('Can insert a blob: id @id, @data.', [
    '@id' => $id,
    '@data' => serialize($r),
  ]));
}