protected function UpdateModeTest::setUp in Configuration Synchronizer 8.2
Overrides KernelTestBase::setUp
File
- tests/
src/ Kernel/ UpdateModeTest.php, line 83
Class
- UpdateModeTest
- Tests importing configuration entities using various import modes.
Namespace
Drupal\Tests\config_sync\KernelCode
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('node');
$this
->installEntitySchema('config_snapshot');
$this
->installConfig([
'system',
'user',
'field',
'filter',
'text',
'node',
'config_sync_test',
]);
// Refresh the extension snapshot, since this won't have been done on
// module install.
$this->container
->get('config_sync.snapshotter')
->refreshExtensionSnapshot('module', [
'config_sync_test',
], ConfigSyncSnapshotterInterface::SNAPSHOT_MODE_INSTALL);
// Load and customize the node type provided by config_sync_test_1 module.
$content_type_1 = NodeType::load($this->nodeTypeNames[1]);
$content_type_1
->set('name', 'Custom name')
->set('description', 'Prior description')
->set('help', 'Custom help')
->save();
// Load the configuration snapshot for the test module.
$test_module_snapshot = ConfigSnapshot::load(ConfigSyncSnapshotterInterface::CONFIG_SNAPSHOT_SET . '.module.config_sync_test');
// Load and customize the node type snapshot, simulating a prior install
// state.
$this->configNames[1] = $content_type_1
->getEntityType()
->getConfigPrefix() . '.' . $content_type_1
->id();
$content_type_1_snapshot = $test_module_snapshot
->getItem(StorageInterface::DEFAULT_COLLECTION, $this->configNames[1]);
$content_type_1_snapshot['name'] = 'Prior name';
$content_type_1_snapshot['description'] = 'Prior description';
$test_module_snapshot
->setItem(StorageInterface::DEFAULT_COLLECTION, $this->configNames[1], $content_type_1_snapshot)
->save();
// Remove the second node type from both the snapshot and the active
// configuration. This simulates an item that is newly provided.
$content_type_2 = NodeType::load($this->nodeTypeNames[2]);
$this->configNames[2] = $content_type_2
->getEntityType()
->getConfigPrefix() . '.' . $content_type_2
->id();
$test_module_snapshot
->clearItem(StorageInterface::DEFAULT_COLLECTION, $this->configNames[2])
->save();
$content_type_2
->delete();
// Delete the third node type. This covers an item installed and
// later deleted.
$content_type_3 = NodeType::load($this->nodeTypeNames[3]);
$this->configNames[3] = $content_type_3
->getEntityType()
->getConfigPrefix() . '.' . $content_type_3
->id();
$content_type_3
->delete($this->nodeTypeNames[3]);
// Modify the fourth node. This covers an item that has been customized and
// for which no update is available.
$content_type_4 = NodeType::load($this->nodeTypeNames[4]);
$this->configNames[4] = $content_type_4
->getEntityType()
->getConfigPrefix() . '.' . $content_type_4
->id();
$content_type_4
->set('name', 'Custom name')
->save();
$this->testSnapshotStorage = $this
->getConfigSnapshotStorage(ConfigSyncSnapshotterInterface::CONFIG_SNAPSHOT_SET, 'module', 'config_sync_test');
// We deleted the snapshot for config_sync_test_2.
$expected_snapshot_items = $this->configNames;
unset($expected_snapshot_items[2]);
$expected_snapshot_items = array_values($expected_snapshot_items);
$snapshot_items = $this->testSnapshotStorage
->listAll();
$this
->assertSame($snapshot_items, $expected_snapshot_items, 'Snapshot items match those expected.');
}