View source
<?php
namespace Drupal\Tests\config_ignore\Functional;
use Drupal\config_ignore\Plugin\ConfigFilter\IgnoreFilter;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class ConfigIgnoreTest extends ConfigIgnoreBrowserTestBase {
use StringTranslationTrait;
public function testSyncTableUpdate() {
$this
->config('system.site')
->set('name', 'Test import')
->save();
$this
->config('system.date')
->set('first_day', '0')
->save();
$this
->config('config_ignore.settings')
->set('ignored_config_entities', [
'system.site',
])
->save();
$this
->doExport();
$this
->drupalLogin($this
->drupalCreateUser([
'synchronize configuration',
]));
$this
->config('system.site')
->set('name', 'Test import with changed title')
->save();
$this
->config('system.date')
->set('first_day', '1')
->save();
$this
->drupalGet('admin/config/development/configuration');
$this
->assertSession()
->linkExists('Config Ignore Settings');
$table_content = $this
->xpath('//table[@id="edit-ignored"]//td');
$table_values = [];
foreach ($table_content as $item) {
$table_values[] = $item
->getHtml();
}
$this
->assertTrue(in_array('system.site', $table_values));
$this
->assertFalse(in_array('system.date', $table_values));
}
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, $this
->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.' . IgnoreFilter::INCLUDE_SUFFIX,
])
->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 = [
IgnoreFilter::FORCE_EXCLUSION_PREFIX . '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.' . IgnoreFilter::INCLUDE_SUFFIX,
IgnoreFilter::FORCE_EXCLUSION_PREFIX . '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'));
}
}