3 namespace Drupal\system\Tests\Entity\Update;
5 use Drupal\Core\Database\Database;
6 use Drupal\system\Tests\Update\UpdatePathTestBase;
9 * Tests that the entity langcode fields have been updated to varchar_ascii.
13 class LangcodeToAsciiUpdateTest extends UpdatePathTestBase {
18 public function setDatabaseDumpFiles() {
19 $this->databaseDumpFiles = [
20 __DIR__ . '/../../../../tests/fixtures/update/drupal-8.bare.standard.php.gz',
25 * Tests that the column collation has been updated on MySQL.
27 public function testLangcodeColumnCollation() {
28 // Only testable on MySQL.
29 // @see https://www.drupal.org/node/301038
30 if (Database::getConnection()->databaseType() !== 'mysql') {
31 $this->pass('This test can only run on MySQL');
35 // Check a few different tables.
37 'node_field_data' => ['langcode'],
38 'users_field_data' => ['langcode', 'preferred_langcode', 'preferred_admin_langcode'],
40 foreach ($tables as $table => $columns) {
41 foreach ($columns as $column) {
42 $this->assertEqual('utf8mb4_general_ci', $this->getColumnCollation($table, $column), 'Found correct starting collation for ' . $table . '.' . $column);
49 foreach ($tables as $table => $columns) {
50 foreach ($columns as $column) {
51 $this->assertEqual('ascii_general_ci', $this->getColumnCollation($table, $column), 'Found correct updated collation for ' . $table . '.' . $column);
57 * Determine the column collation.
59 * @param string $table
61 * @param string $column
64 protected function getColumnCollation($table, $column) {
65 $query = Database::getConnection()->query("SHOW FULL COLUMNS FROM {" . $table . "}");
66 while ($row = $query->fetchAssoc()) {
67 if ($row['Field'] === $column) {
68 return $row['Collation'];
71 $this->fail('No collation found for ' . $table . '.' . $column);