Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / system / tests / src / Functional / Entity / Update / LangcodeToAsciiUpdateTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Entity\Update;
4
5 use Drupal\Core\Database\Database;
6 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
7
8 /**
9  * Tests that the entity langcode fields have been updated to varchar_ascii.
10  *
11  * @group Entity
12  */
13 class LangcodeToAsciiUpdateTest extends UpdatePathTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public function setDatabaseDumpFiles() {
19     $this->databaseDumpFiles = [
20       __DIR__ . '/../../../../fixtures/update/drupal-8.bare.standard.php.gz',
21     ];
22   }
23
24   /**
25    * Tests that the column collation has been updated on MySQL.
26    */
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');
32       return;
33     }
34
35     // Check a few different tables.
36     $tables = [
37       'node_field_data' => ['langcode'],
38       'users_field_data' => ['langcode', 'preferred_langcode', 'preferred_admin_langcode'],
39     ];
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);
43       }
44     }
45
46     // Apply updates.
47     $this->runUpdates();
48
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);
52       }
53     }
54   }
55
56   /**
57    * Determine the column collation.
58    *
59    * @param string $table
60    *   The table name.
61    * @param string $column
62    *   The column name.
63    */
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'];
69       }
70     }
71     $this->fail('No collation found for ' . $table . '.' . $column);
72   }
73
74 }