4dee52d5c7fd6c50949ba8cb2ef637b8054a72af
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Database / RegressionTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Database;
4
5 /**
6  * Regression tests cases for the database layer.
7  *
8  * @group Database
9  */
10 class RegressionTest extends DatabaseTestBase {
11
12   /**
13    * Modules to enable.
14    *
15    * @var array
16    */
17   public static $modules = ['node', 'user'];
18
19   /**
20    * Ensures that non-ASCII UTF-8 data is stored in the database properly.
21    */
22   public function testRegression_310447() {
23     // That's a 255 character UTF-8 string.
24     $job = str_repeat("é", 255);
25     db_insert('test')
26       ->fields([
27         'name' => $this->randomMachineName(),
28         'age' => 20,
29         'job' => $job,
30       ])->execute();
31
32     $from_database = db_query('SELECT job FROM {test} WHERE job = :job', [':job' => $job])->fetchField();
33     $this->assertSame($job, $from_database, 'The database handles UTF-8 characters cleanly.');
34   }
35
36   /**
37    * Tests the db_table_exists() function.
38    */
39   public function testDBTableExists() {
40     $this->assertSame(TRUE, $this->connection->schema()->tableExists('test'), 'Returns true for existent table.');
41     $this->assertSame(FALSE, $this->connection->schema()->tableExists('nosuchtable'), 'Returns false for nonexistent table.');
42   }
43
44   /**
45    * Tests the db_field_exists() function.
46    */
47   public function testDBFieldExists() {
48     $this->assertSame(TRUE, db_field_exists('test', 'name'), 'Returns true for existent column.');
49     $this->assertSame(FALSE, db_field_exists('test', 'nosuchcolumn'), 'Returns false for nonexistent column.');
50   }
51
52   /**
53    * Tests the db_index_exists() function.
54    */
55   public function testDBIndexExists() {
56     $this->assertSame(TRUE, db_index_exists('test', 'ages'), 'Returns true for existent index.');
57     $this->assertSame(FALSE, db_index_exists('test', 'nosuchindex'), 'Returns false for nonexistent index.');
58   }
59
60 }