Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / system / tests / src / Functional / Update / MenuTreeSerializationTitleTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Update;
4
5 use Drupal\Core\StringTranslation\TranslatableMarkup;
6 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
7
8 /**
9  * Tests system_update_8001().
10  *
11  * @group Update
12  */
13 class MenuTreeSerializationTitleTest extends UpdatePathTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   protected function setDatabaseDumpFiles() {
19     $this->databaseDumpFiles = [
20       __DIR__ . '/../../../../tests/fixtures/update/drupal-8.bare.standard.php.gz',
21     ];
22   }
23
24   /**
25    * Ensures that the system_update_8001() runs as expected.
26    */
27   public function testUpdate() {
28     $this->runUpdates();
29
30     // Ensure that some fields got dropped.
31     $database = \Drupal::database();
32     $schema = $database->schema();
33
34     if (!$schema->tableExists('menu_tree')) {
35       return;
36     }
37
38     $this->assertFalse($schema->fieldExists('menu_tree', 'title_arguments'));
39     $this->assertFalse($schema->fieldExists('menu_tree', 'title_contexts'));
40
41     // Ensure that all titles and description values can be unserialized.
42     $select = $database->select('menu_tree');
43     $result = $select->fields('menu_tree', ['id', 'title', 'description'])
44       ->execute()
45       ->fetchAllAssoc('id');
46
47     // The test coverage relies upon the fact that unserialize() would emit a
48     // warning if the value is not a valid serialized value.
49     foreach ($result as $link) {
50       $title = unserialize($link->title);
51       $description = unserialize($link->description);
52       // Verify that all the links from system module have a been updated with
53       // a TranslatableMarkup as title and description due to the rebuild.
54       if (strpos($link->id, 'system.') === 0) {
55         $this->assertTrue($title instanceof TranslatableMarkup, get_class($title));
56         if ($description) {
57           $this->assertTrue($description instanceof TranslatableMarkup, get_class($description));
58         }
59       }
60     }
61   }
62
63 }