View source
<?php
namespace Drupal\Tests\config_ignore\Functional;
use Drupal\config_test\ConfigTestInterface;
class ConfigIgnoreTest extends ConfigIgnoreBrowserTestBase {
protected static $modules = [
'config',
'config_test',
];
public function testSettingsForm() {
$this
->drupalLogin($this
->drupalCreateUser([
'import configuration',
]));
$edit = [
'ignored_config_entities' => 'config.test_01' . "\r\n" . 'config.test_02',
];
$this
->drupalGet('admin/config/development/configuration/ignore');
$this
->submitForm($edit, t('Save configuration'));
$settings = $this
->config('config_ignore.settings')
->get('ignored_config_entities');
$this
->assertEquals([
'config.test_01',
'config.test_02',
], $settings);
}
public function testValidateIgnoring() {
$this
->config('system.site')
->set('name', 'Test import')
->save();
$this
->config('config_ignore.settings')
->set('ignored_config_entities', [
'system.site',
])
->save();
$this
->doExport();
$this
->config('system.site')
->set('name', 'Changed title')
->save();
$this
->doImport();
$this
->assertEquals('Changed title', $this
->config('system.site')
->get('name'));
}
public function testValidateIgnoringWithWildcard() {
$this
->config('system.site')
->set('name', 'Test import')
->save();
$this
->config('config_ignore.settings')
->set('ignored_config_entities', [
'system.*',
])
->save();
$this
->doExport();
$this
->config('system.site')
->set('name', 'Changed title')
->save();
$this
->doImport();
$this
->assertEquals('Changed title', $this
->config('system.site')
->get('name'));
}
public function testValidateForceImporting() {
$this
->config('system.site')
->set('name', 'Test import')
->save();
$settings = [
'~system.site',
];
$this
->config('config_ignore.settings')
->set('ignored_config_entities', $settings)
->save();
$this
->doExport();
$this
->config('system.site')
->set('name', 'Changed title')
->save();
$this
->doImport();
$this
->assertEquals('Test import', $this
->config('system.site')
->get('name'));
}
public function testValidateForceImportingWithWildcard() {
$this
->config('system.site')
->set('name', 'Test import')
->save();
$settings = [
'system.*',
'~system.site',
];
$this
->config('config_ignore.settings')
->set('ignored_config_entities', $settings)
->save();
$this
->doExport();
$this
->config('system.site')
->set('name', 'Changed title')
->save();
$this
->doImport();
$this
->assertEquals('Test import', $this
->config('system.site')
->get('name'));
}
public function testValidateImportingWithIgnoredSubKeys() {
$this
->config('system.site')
->set('name', 'Test name')
->set('slogan', 'Test slogan')
->set('page.front', '/ignore')
->save();
$settings = [
'system.site:name',
'system.site:page.front',
];
$this
->config('config_ignore.settings')
->set('ignored_config_entities', $settings)
->save();
$this
->doExport();
$this
->config('system.site')
->set('name', 'Changed title')
->set('slogan', 'Changed slogan')
->set('page.front', '/new-ignore')
->save();
$this
->doImport();
$this
->assertEquals('Changed title', $this
->config('system.site')
->get('name'));
$this
->assertEquals('Test slogan', $this
->config('system.site')
->get('slogan'));
$this
->assertEquals('/new-ignore', $this
->config('system.site')
->get('page.front'));
}
public function testImportMissingConfig() {
$this
->config('config_ignore.settings')
->set('ignored_config_entities', [
'config_test.*',
])
->save();
$this
->doExport();
$config_test_storage = $this->container
->get('entity_type.manager')
->getStorage('config_test');
$entity = $config_test_storage
->create([
'id' => 'foo',
'label' => 'Foo',
]);
$entity
->save();
$this
->doImport();
$loaded_entity = $config_test_storage
->load($entity
->id());
$this
->assertInstanceOf(ConfigTestInterface::class, $loaded_entity);
}
}