public function ConfigImporterTest::testNew in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php \Drupal\KernelTests\Core\Config\ConfigImporterTest::testNew()
- 10 core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php \Drupal\KernelTests\Core\Config\ConfigImporterTest::testNew()
Tests creation of configuration during import.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Config/ ConfigImporterTest.php, line 161
Class
- ConfigImporterTest
- Tests importing configuration from files into active configuration.
Namespace
Drupal\KernelTests\Core\ConfigCode
public function testNew() {
$dynamic_name = 'config_test.dynamic.new';
$storage = $this->container
->get('config.storage');
$sync = $this->container
->get('config.storage.sync');
// Verify the configuration to create does not exist yet.
$this
->assertFalse($storage
->exists($dynamic_name), $dynamic_name . ' not found.');
// Create new config entity.
$original_dynamic_data = [
'uuid' => '30df59bd-7b03-4cf7-bb35-d42fc49f0651',
'langcode' => \Drupal::languageManager()
->getDefaultLanguage()
->getId(),
'status' => TRUE,
'dependencies' => [],
'id' => 'new',
'label' => 'New',
'weight' => 0,
'style' => '',
'size' => '',
'size_value' => '',
'protected_property' => '',
];
$sync
->write($dynamic_name, $original_dynamic_data);
$this
->assertTrue($sync
->exists($dynamic_name), $dynamic_name . ' found.');
// Import.
$this->configImporter
->reset()
->import();
// Verify the values appeared.
$config = $this
->config($dynamic_name);
$this
->assertSame($original_dynamic_data['label'], $config
->get('label'));
// Verify that appropriate module API hooks have been invoked.
$this
->assertFalse(isset($GLOBALS['hook_config_test']['load']));
$this
->assertTrue(isset($GLOBALS['hook_config_test']['presave']));
$this
->assertTrue(isset($GLOBALS['hook_config_test']['insert']));
$this
->assertFalse(isset($GLOBALS['hook_config_test']['update']));
$this
->assertFalse(isset($GLOBALS['hook_config_test']['predelete']));
$this
->assertFalse(isset($GLOBALS['hook_config_test']['delete']));
// Verify that hook_config_import_steps_alter() can add steps to
// configuration synchronization.
$this
->assertTrue(isset($GLOBALS['hook_config_test']['config_import_steps_alter']));
// Verify that there is nothing more to import.
$this
->assertFalse($this->configImporter
->hasUnprocessedConfigurationChanges());
$logs = $this->configImporter
->getErrors();
$this
->assertCount(0, $logs);
}