RegressionTest.php 1.72 KB
Newer Older
1 2
<?php

3
namespace Drupal\KernelTests\Core\Database;
4 5

/**
6 7 8
 * Regression tests cases for the database layer.
 *
 * @group Database
9 10 11
 */
class RegressionTest extends DatabaseTestBase {

12 13 14 15 16
  /**
   * Modules to enable.
   *
   * @var array
   */
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 41
    $this->assertSame(TRUE, db_table_exists('test'), 'Returns true for existent table.');
    $this->assertSame(FALSE, db_table_exists('nosuchtable'), 'Returns false for nonexistent table.');
42 43 44
  }

  /**
45
   * Tests the db_field_exists() function.
46
   */
47
  public function testDBFieldExists() {
48 49
    $this->assertSame(TRUE, db_field_exists('test', 'name'), 'Returns true for existent column.');
    $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 57
    $this->assertSame(TRUE, db_index_exists('test', 'ages'), 'Returns true for existent index.');
    $this->assertSame(FALSE, db_index_exists('test', 'nosuchindex'), 'Returns false for nonexistent index.');
58
  }
59

60
}