Updated Drupal to 8.6. This goes with the following updates because it's possible...
[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  * @group legacy
13  */
14 class MenuTreeSerializationTitleTest extends UpdatePathTestBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   protected function setDatabaseDumpFiles() {
20     $this->databaseDumpFiles = [
21       __DIR__ . '/../../../../tests/fixtures/update/drupal-8.bare.standard.php.gz',
22     ];
23   }
24
25   /**
26    * Ensures that the system_update_8001() runs as expected.
27    */
28   public function testUpdate() {
29     $this->runUpdates();
30
31     // Ensure that some fields got dropped.
32     $database = \Drupal::database();
33     $schema = $database->schema();
34
35     if (!$schema->tableExists('menu_tree')) {
36       return;
37     }
38
39     $this->assertFalse($schema->fieldExists('menu_tree', 'title_arguments'));
40     $this->assertFalse($schema->fieldExists('menu_tree', 'title_contexts'));
41
42     // Ensure that all titles and description values can be unserialized.
43     $select = $database->select('menu_tree');
44     $result = $select->fields('menu_tree', ['id', 'title', 'description'])
45       ->execute()
46       ->fetchAllAssoc('id');
47
48     // The test coverage relies upon the fact that unserialize() would emit a
49     // warning if the value is not a valid serialized value.
50     foreach ($result as $link) {
51       $title = unserialize($link->title);
52       $description = unserialize($link->description);
53       // Verify that all the links from system module have a been updated with
54       // a TranslatableMarkup as title and description due to the rebuild.
55       if (strpos($link->id, 'system.') === 0) {
56         $this->assertTrue($title instanceof TranslatableMarkup, get_class($title));
57         if ($description) {
58           $this->assertTrue($description instanceof TranslatableMarkup, get_class($description));
59         }
60       }
61     }
62   }
63
64 }