RegressionTest.php 1.91 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
  protected 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 26
    $this->connection
      ->insert('test')
27
      ->fields([
28
        'name' => $this->randomMachineName(),
29
        'age' => 20,
30
        'job' => $job,
31
      ])->execute();
32

33
    $from_database = $this->connection->query('SELECT [job] FROM {test} WHERE [job] = :job', [':job' => $job])->fetchField();
34
    $this->assertSame($job, $from_database, 'The database handles UTF-8 characters cleanly.');
35 36 37
  }

  /**
38
   * Tests the Schema::tableExists() method.
39
   */
40
  public function testDBTableExists() {
41 42
    $this->assertTrue($this->connection->schema()->tableExists('test'), 'Returns true for existent table.');
    $this->assertFalse($this->connection->schema()->tableExists('nosuchtable'), 'Returns false for nonexistent table.');
43 44 45
  }

  /**
46
   * Tests the \Drupal\Core\Database\Schema::fieldExists() method.
47
   */
48
  public function testDBFieldExists() {
49
    $schema = $this->connection->schema();
50 51
    $this->assertTrue($schema->fieldExists('test', 'name'), 'Returns true for existent column.');
    $this->assertFalse($schema->fieldExists('test', 'nosuchcolumn'), 'Returns false for nonexistent column.');
52 53 54
  }

  /**
55
   * Tests the Schema::indexExists() method.
56
   */
57
  public function testDBIndexExists() {
58 59
    $this->assertTrue($this->connection->schema()->indexExists('test', 'ages'), 'Returns true for existent index.');
    $this->assertFalse($this->connection->schema()->indexExists('test', 'nosuchindex'), 'Returns false for nonexistent index.');
60
  }
61

62
}