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 / UpdateEntityDisplayTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Update;
4
5 use Drupal\Core\Entity\Entity\EntityFormDisplay;
6 use Drupal\Core\Entity\Entity\EntityViewDisplay;
7 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
8
9 /**
10  * Tests updates for entity displays.
11  *
12  * @group Update
13  * @group legacy
14  */
15 class UpdateEntityDisplayTest extends UpdatePathTestBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   protected function setDatabaseDumpFiles() {
21     $this->databaseDumpFiles = [
22       __DIR__ . '/../../../../tests/fixtures/update/drupal-8.bare.standard.php.gz',
23     ];
24   }
25
26   /**
27    * Tests that entity displays are updated with regions for their fields.
28    *
29    * @see system_post_update_add_region_to_entity_displays()
30    */
31   public function testRegionUpdate() {
32     // No region key appears pre-update.
33     $entity_form_display = EntityFormDisplay::load('node.article.default');
34     $options = $entity_form_display->getComponent('body');
35     $this->assertFalse(array_key_exists('region', $options));
36
37     $entity_view_display = EntityViewDisplay::load('node.article.default');
38     $options = $entity_view_display->getComponent('body');
39     $this->assertFalse(array_key_exists('region', $options));
40
41     $this->runUpdates();
42
43     // The region key has been populated with 'content'.
44     $entity_form_display = EntityFormDisplay::load('node.article.default');
45     $options = $entity_form_display->getComponent('body');
46     $this->assertIdentical('content', $options['region']);
47
48     $entity_view_display = EntityViewDisplay::load('node.article.default');
49     $options = $entity_view_display->getComponent('body');
50     $this->assertIdentical('content', $options['region']);
51   }
52
53   /**
54    * Tests that entity displays are updated to properly store extra fields.
55    *
56    * @see system_post_update_extra_fields()
57    */
58   public function testExtraFieldsUpdate() {
59     $assertion = function ($expected_keys) {
60       $entity_view_display = EntityViewDisplay::load('node.article.default');
61       $this->assertEquals($expected_keys, array_keys($entity_view_display->getComponent('links')));
62     };
63
64     // Before the update extra fields are missing additional configuration.
65     $assertion(['weight', 'region']);
66     $this->runUpdates();
67     // After the update the additional configuration is present.
68     $assertion(['weight', 'region', 'settings', 'third_party_settings']);
69   }
70
71 }