InsertLobTest.php in Drupal 8
File
core/tests/Drupal/KernelTests/Core/Database/InsertLobTest.php
View source
<?php
namespace Drupal\KernelTests\Core\Database;
use Drupal\Component\Render\FormattableMarkup;
class InsertLobTest extends DatabaseTestBase {
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),
]));
}
public function testInsertMultipleBlob() {
$id = $this->connection
->insert('test_two_blobs')
->fields([
'blob1' => 'This is',
'blob2' => 'a test',
])
->execute();
$r = $this->connection
->query('SELECT * FROM {test_two_blobs} WHERE id = :id', [
':id' => $id,
])
->fetchAssoc();
$this
->assertTrue($r['blob1'] === 'This is' && $r['blob2'] === 'a test', 'Can insert multiple blobs per row.');
}
}