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