You are here

public function LangcodeToAsciiUpdateTest::testLangcodeColumnCollation in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Entity/Update/LangcodeToAsciiUpdateTest.php \Drupal\system\Tests\Entity\Update\LangcodeToAsciiUpdateTest::testLangcodeColumnCollation()

Tests that the column collation has been updated on MySQL.

File

core/modules/system/src/Tests/Entity/Update/LangcodeToAsciiUpdateTest.php, line 32
Contains \Drupal\system\Tests\Entity\Update\LangcodeToAsciiUpdateTest.

Class

LangcodeToAsciiUpdateTest
Tests that the entity langcode fields have been updated to varchar_ascii.

Namespace

Drupal\system\Tests\Entity\Update

Code

public function testLangcodeColumnCollation() {

  // Only testable on MySQL.
  // @see https://www.drupal.org/node/301038
  if (Database::getConnection()
    ->databaseType() !== 'mysql') {
    $this
      ->pass('This test can only run on MySQL');
    return;
  }

  // Check a few different tables.
  $tables = [
    'node_field_data' => [
      'langcode',
    ],
    'users_field_data' => [
      'langcode',
      'preferred_langcode',
      'preferred_admin_langcode',
    ],
  ];
  foreach ($tables as $table => $columns) {
    foreach ($columns as $column) {
      $this
        ->assertEqual('utf8mb4_general_ci', $this
        ->getColumnCollation($table, $column), 'Found correct starting collation for ' . $table . '.' . $column);
    }
  }

  // Apply updates.
  $this
    ->runUpdates();
  foreach ($tables as $table => $columns) {
    foreach ($columns as $column) {
      $this
        ->assertEqual('ascii_general_ci', $this
        ->getColumnCollation($table, $column), 'Found correct updated collation for ' . $table . '.' . $column);
    }
  }
}