Version 1
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Database / InsertLobTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Database;
4
5 /**
6  * Tests the Insert query builder with LOB fields.
7  *
8  * @group Database
9  */
10 class InsertLobTest extends DatabaseTestBase {
11
12   /**
13    * Tests that we can insert a single blob field successfully.
14    */
15   public function testInsertOneBlob() {
16     $data = "This is\000a test.";
17     $this->assertTrue(strlen($data) === 15, 'Test data contains a NULL.');
18     $id = db_insert('test_one_blob')
19       ->fields(['blob1' => $data])
20       ->execute();
21     $r = db_query('SELECT * FROM {test_one_blob} WHERE id = :id', [':id' => $id])->fetchAssoc();
22     $this->assertTrue($r['blob1'] === $data, format_string('Can insert a blob: id @id, @data.', ['@id' => $id, '@data' => serialize($r)]));
23   }
24
25   /**
26    * Tests that we can insert multiple blob fields in the same query.
27    */
28   public function testInsertMultipleBlob() {
29     $id = db_insert('test_two_blobs')
30       ->fields([
31         'blob1' => 'This is',
32         'blob2' => 'a test',
33       ])
34       ->execute();
35     $r = db_query('SELECT * FROM {test_two_blobs} WHERE id = :id', [':id' => $id])->fetchAssoc();
36     $this->assertTrue($r['blob1'] === 'This is' && $r['blob2'] === 'a test', 'Can insert multiple blobs per row.');
37   }
38
39 }