X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fsystem%2Ftests%2Fsrc%2FFunctional%2FEntity%2FUpdate%2FLangcodeToAsciiUpdateTest.php;fp=web%2Fcore%2Fmodules%2Fsystem%2Ftests%2Fsrc%2FFunctional%2FEntity%2FUpdate%2FLangcodeToAsciiUpdateTest.php;h=d1a3cabb06ed2aa2f33bf8528193365c29349e8b;hp=0000000000000000000000000000000000000000;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/modules/system/tests/src/Functional/Entity/Update/LangcodeToAsciiUpdateTest.php b/web/core/modules/system/tests/src/Functional/Entity/Update/LangcodeToAsciiUpdateTest.php new file mode 100644 index 000000000..d1a3cabb0 --- /dev/null +++ b/web/core/modules/system/tests/src/Functional/Entity/Update/LangcodeToAsciiUpdateTest.php @@ -0,0 +1,74 @@ +databaseDumpFiles = [ + __DIR__ . '/../../../../fixtures/update/drupal-8.bare.standard.php.gz', + ]; + } + + /** + * Tests that the column collation has been updated on MySQL. + */ + 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); + } + } + } + + /** + * Determine the column collation. + * + * @param string $table + * The table name. + * @param string $column + * The column name. + */ + 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); + } + +}