ConfigSnapshotTest.php in Drupal 10
File
core/tests/Drupal/KernelTests/Core/Config/ConfigSnapshotTest.php
View source
<?php
namespace Drupal\KernelTests\Core\Config;
use Drupal\Core\Config\StorageComparer;
use Drupal\KernelTests\KernelTestBase;
class ConfigSnapshotTest extends KernelTestBase {
protected static $modules = [
'config_test',
'system',
];
protected function setUp() : void {
parent::setUp();
$this
->installConfig([
'system',
]);
\Drupal::service('config.manager')
->createSnapshot(\Drupal::service('config.storage'), \Drupal::service('config.storage.snapshot'));
$this
->copyConfig($this->container
->get('config.storage'), $this->container
->get('config.storage.sync'));
}
public function testSnapshot() {
$active = $this->container
->get('config.storage');
$sync = $this->container
->get('config.storage.sync');
$snapshot = $this->container
->get('config.storage.snapshot');
$config_name = 'config_test.system';
$config_key = 'foo';
$new_data = 'foobar';
$active_snapshot_comparer = new StorageComparer($active, $snapshot);
$sync_snapshot_comparer = new StorageComparer($sync, $snapshot);
$this
->assertFalse($active_snapshot_comparer
->createChangelist()
->hasChanges());
$this
->installConfig([
'config_test',
]);
$this
->assertTrue($active_snapshot_comparer
->reset()
->hasChanges());
\Drupal::service('config.manager')
->createSnapshot($active, $snapshot);
$this
->assertFalse($active_snapshot_comparer
->reset()
->hasChanges());
$sync_data = $this
->config($config_name)
->get();
$sync_data[$config_key] = $new_data;
$sync
->write($config_name, $sync_data);
$this
->assertFalse($active_snapshot_comparer
->reset()
->hasChanges());
$this
->assertTrue($sync_snapshot_comparer
->createChangelist()
->hasChanges());
$this
->configImporter()
->import();
\Drupal::configFactory()
->reset($config_name);
$this
->assertSame($new_data, $this
->config($config_name)
->get($config_key));
$this
->assertFalse($active_snapshot_comparer
->reset()
->hasChanges());
}
}