Security update for Core, with self-updated composer
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Config / ConfigSnapshotTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Config;
4
5 use Drupal\Core\Config\StorageComparer;
6 use Drupal\KernelTests\KernelTestBase;
7
8 /**
9  * Tests config snapshot creation and updating.
10  *
11  * @group config
12  */
13 class ConfigSnapshotTest extends KernelTestBase {
14
15   /**
16    * Modules to enable.
17    *
18    * @var array
19    */
20   public static $modules = ['config_test', 'system'];
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function setUp() {
26     parent::setUp();
27     // Update the config snapshot. This allows the parent::setUp() to write
28     // configuration files.
29     \Drupal::service('config.manager')->createSnapshot(\Drupal::service('config.storage'), \Drupal::service('config.storage.snapshot'));
30     $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));
31   }
32
33   /**
34    * Tests config snapshot creation and updating.
35    */
36   public function testSnapshot() {
37     $active = $this->container->get('config.storage');
38     $sync = $this->container->get('config.storage.sync');
39     $snapshot = $this->container->get('config.storage.snapshot');
40     $config_manager = $this->container->get('config.manager');
41     $config_name = 'config_test.system';
42     $config_key = 'foo';
43     $new_data = 'foobar';
44
45     $active_snapshot_comparer = new StorageComparer($active, $snapshot, $config_manager);
46     $sync_snapshot_comparer = new StorageComparer($sync, $snapshot, $config_manager);
47
48     // Verify that we have an initial snapshot that matches the active
49     // configuration. This has to be true as no config should be installed.
50     $this->assertFalse($active_snapshot_comparer->createChangelist()->hasChanges());
51
52     // Install the default config.
53     $this->installConfig(['config_test']);
54     // Although we have imported config this has not affected the snapshot.
55     $this->assertTrue($active_snapshot_comparer->reset()->hasChanges());
56
57     // Update the config snapshot.
58     \Drupal::service('config.manager')->createSnapshot($active, $snapshot);
59
60     // The snapshot and active config should now contain the same config
61     // objects.
62     $this->assertFalse($active_snapshot_comparer->reset()->hasChanges());
63
64     // Change a configuration value in sync.
65     $sync_data = $this->config($config_name)->get();
66     $sync_data[$config_key] = $new_data;
67     $sync->write($config_name, $sync_data);
68
69     // Verify that active and snapshot match, and that sync doesn't match
70     // active.
71     $this->assertFalse($active_snapshot_comparer->reset()->hasChanges());
72     $this->assertTrue($sync_snapshot_comparer->createChangelist()->hasChanges());
73
74     // Import changed data from sync to active.
75     $this->configImporter()->import();
76
77     // Verify changed config was properly imported.
78     \Drupal::configFactory()->reset($config_name);
79     $this->assertIdentical($this->config($config_name)->get($config_key), $new_data);
80
81     // Verify that a new snapshot was created which and that it matches
82     // the active config.
83     $this->assertFalse($active_snapshot_comparer->reset()->hasChanges());
84   }
85
86 }