diff --git a/core/modules/system/src/Tests/Entity/Update/LangcodeToAsciiUpdateTest.php b/core/modules/system/src/Tests/Entity/Update/LangcodeToAsciiUpdateTest.php new file mode 100644 index 0000000..e93c2cc --- /dev/null +++ b/core/modules/system/src/Tests/Entity/Update/LangcodeToAsciiUpdateTest.php @@ -0,0 +1,82 @@ +databaseDumpFiles = [ + __DIR__ . '/../../../../tests/fixtures/update/drupal-8.bare.standard.php.gz', + ]; + parent::setUp(); + } + + /** + * 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); + } + } + + debug(\Drupal::service('entity.definition_update_manager')->getChangeSummary()); + } + + /** + * 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); + } + +} diff --git a/core/modules/system/src/Tests/Entity/Update/SqlContentEntityStorageSchemaIndexTest.php b/core/modules/system/src/Tests/Entity/Update/SqlContentEntityStorageSchemaIndexTest.php index db4f43d..0e613f1 100644 --- a/core/modules/system/src/Tests/Entity/Update/SqlContentEntityStorageSchemaIndexTest.php +++ b/core/modules/system/src/Tests/Entity/Update/SqlContentEntityStorageSchemaIndexTest.php @@ -64,7 +64,7 @@ public function testIndex() { // 6. The remaining entity schema updates are applied automatically after // all update hook implementations have run, which applies the user // index update. - $this->assertTrue(\Drupal::state()->get('update_order_test_update_8001', FALSE), 'Index node__default_langcode still existed during update_order_test_update_8001(), indicating that it ran before the entity type updates.'); + $this->assertTrue(\Drupal::state()->get('update_order_test_update_8001', FALSE), 'Index node__default_langcode still existed during update_order_test_update_8001(), indicating that it ran before the entity type updates.'); // Node updates were run during update_order_test_update_8002(). $this->assertFalse(\Drupal::state()->get('update_order_test_update_8002_node__default_langcode', TRUE), 'The node__default_langcode index was removed during update_order_test_update_8002().'); @@ -77,11 +77,6 @@ public function testIndex() { // User update were not run during update_order_test_update_8002(). $this->assertFalse(\Drupal::state()->get('update_order_test_update_8002_user__id__default_langcode__langcode', TRUE)); - - // There should be no remaining updates. - $this->runUpdates(); - $change_summary = \Drupal::service('entity.definition_update_manager')->getChangeSummary(); - $this->assertTrue(empty($change_summary), 'No more pending entity updates found'); } }