6eb51a2a5123a6e2911e25b73c3d09a8a2ff3890
[yaffs-website] / web / core / modules / system / tests / src / Functional / Update / RecalculatedDependencyTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Update;
4
5 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
6
7 /**
8  * Tests system_post_update_recalculate_dependencies_for_installed_config_entities().
9  *
10  * @group Update
11  */
12 class RecalculatedDependencyTest extends UpdatePathTestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   protected function setDatabaseDumpFiles() {
18     $this->databaseDumpFiles = [
19       __DIR__ . '/../../../../tests/fixtures/update/drupal-8.bare.standard.php.gz',
20     ];
21   }
22
23   /**
24    * Ensures that the entities are resaved so they have the new dependency.
25    */
26   public function testUpdate() {
27     // Test the configuration pre update.
28     $data = \Drupal::config('field.field.node.article.field_tags')->get();
29     $this->assertEqual(['entity_reference'], $data['dependencies']['module']);
30     $this->assertEqual([
31       'field.storage.node.field_tags',
32       'node.type.article',
33     ], $data['dependencies']['config']);
34
35     $data = \Drupal::config('field.field.user.user.user_picture')->get();
36     $this->assertFalse(isset($data['dependencies']['module']));
37
38     $data = \Drupal::config('field.storage.node.field_image')->get();
39     $this->assertEqual(['node', 'image'], $data['dependencies']['module']);
40
41     // Explicitly break an optional configuration dependencies to ensure it is
42     // recalculated. Use active configuration storage directly so that no events
43     // are fired.
44     $config_storage = \Drupal::service('config.storage');
45     $data = $config_storage->read('search.page.node_search');
46     unset($data['dependencies']);
47     $config_storage->write('search.page.node_search', $data);
48     // Ensure the update is successful.
49     $data = \Drupal::config('search.page.node_search')->get();
50     $this->assertFalse(isset($data['dependencies']['module']));
51
52     // Run the updates.
53     $this->runUpdates();
54
55     // Test the configuration post update.
56     $data = \Drupal::config('field.field.node.article.field_tags')->get();
57     $this->assertFalse(isset($data['dependencies']['module']));
58     $this->assertEqual([
59       'field.storage.node.field_tags',
60       'node.type.article',
61       'taxonomy.vocabulary.tags'
62     ], $data['dependencies']['config']);
63
64     $data = \Drupal::config('field.field.user.user.user_picture')->get();
65     $this->assertEqual(['image', 'user'], $data['dependencies']['module']);
66
67     $data = \Drupal::config('field.storage.node.field_image')->get();
68     $this->assertEqual(['file', 'image', 'node'], $data['dependencies']['module']);
69
70     $data = \Drupal::config('search.page.node_search')->get();
71     $this->assertEqual(['node'], $data['dependencies']['module']);
72   }
73
74 }