Upgraded drupal core with security updates
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Database / UpdateLobTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Database;
4
5 /**
6  * Tests the Update query builder with LOB fields.
7  *
8  * @group Database
9  */
10 class UpdateLobTest extends DatabaseTestBase {
11
12   /**
13    * Confirms that we can update a blob column.
14    */
15   public function testUpdateOneBlob() {
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
22     $data .= $data;
23     db_update('test_one_blob')
24       ->condition('id', $id)
25       ->fields(['blob1' => $data])
26       ->execute();
27
28     $r = db_query('SELECT * FROM {test_one_blob} WHERE id = :id', [':id' => $id])->fetchAssoc();
29     $this->assertTrue($r['blob1'] === $data, format_string('Can update a blob: id @id, @data.', ['@id' => $id, '@data' => serialize($r)]));
30   }
31
32   /**
33    * Confirms that we can update two blob columns in the same table.
34    */
35   public function testUpdateMultipleBlob() {
36     $id = db_insert('test_two_blobs')
37       ->fields([
38         'blob1' => 'This is',
39         'blob2' => 'a test',
40       ])
41       ->execute();
42
43     db_update('test_two_blobs')
44       ->condition('id', $id)
45       ->fields(['blob1' => 'and so', 'blob2' => 'is this'])
46       ->execute();
47
48     $r = db_query('SELECT * FROM {test_two_blobs} WHERE id = :id', [':id' => $id])->fetchAssoc();
49     $this->assertTrue($r['blob1'] === 'and so' && $r['blob2'] === 'is this', 'Can update multiple blobs per row.');
50   }
51
52 }