LangcodeToAsciiUpdateTest.php in Drupal 8
File
core/modules/system/tests/src/Functional/Entity/Update/LangcodeToAsciiUpdateTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\Entity\Update;
use Drupal\Core\Database\Database;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
class LangcodeToAsciiUpdateTest extends UpdatePathTestBase {
public function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../fixtures/update/drupal-8.bare.standard.php.gz',
];
}
public function testLangcodeColumnCollation() {
if (Database::getConnection()
->databaseType() !== 'mysql') {
$this
->pass('This test can only run on MySQL');
return;
}
$tables = [
'node_field_data' => [
'langcode',
],
'users_field_data' => [
'langcode',
'preferred_langcode',
'preferred_admin_langcode',
],
];
foreach ($tables as $table => $columns) {
foreach ($columns as $column) {
$this
->assertContains($this
->getColumnCollation($table, $column), [
'utf8mb4_0900_ai_ci',
'utf8mb4_general_ci',
], 'Found correct starting collation for ' . $table . '.' . $column);
}
}
$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);
}
}
}
protected function getColumnCollation($table, $column) {
$query = Database::getConnection()
->query("SHOW FULL COLUMNS FROM {" . $table . "}");
while ($row = $query
->fetchAssoc()) {
if ($row['Field'] === $column) {
return $row['Collation'];
}
}
$this
->fail('No collation found for ' . $table . '.' . $column);
}
}