function MergeTest::testMergeBlob
Tests a native merge into blob fields.
File
-
core/
modules/ pgsql/ tests/ src/ Kernel/ pgsql/ MergeTest.php, line 148
Class
- MergeTest
- Tests the native MERGE implementation of the PostgreSQL driver.
Namespace
Drupal\Tests\pgsql\Kernel\pgsqlCode
public function testMergeBlob() : void {
$this->connection
->schema()
->createTable('test_blob_merge', [
'fields' => [
'name' => [
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
],
'data' => [
'type' => 'blob',
'size' => 'big',
],
],
'primary key' => [
'name',
],
]);
$fetch_blob = function () {
$data = $this->connection
->query('SELECT [data] FROM {test_blob_merge} WHERE [name] = :name', [
':name' => 'trademark',
])
->fetchField();
return is_resource($data) ? stream_get_contents($data) : $data;
};
$binary = "Drupal \x00 The \x01 dries \xff his \xcc\xdd tears";
$result = $this->connection
->merge('test_blob_merge')
->key('name', 'trademark')
->fields([
'data' => $binary,
])
->execute();
$this->assertSame(Merge::STATUS_INSERT, $result);
$this->assertSame($binary, $fetch_blob());
$binary = "The \x00 quick \xcc brown \xff fox";
$result = $this->connection
->merge('test_blob_merge')
->key('name', 'trademark')
->fields([
'data' => $binary,
])
->execute();
$this->assertSame(Merge::STATUS_UPDATE, $result);
$this->assertSame($binary, $fetch_blob());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.