RegressionTest.php 1.7 KB

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