You are here

public function ConfigIgnoreTest::testValidateForceImporting in Config Ignore 8

Verify Force Import syntax is working.

This test makes sure we avoid regression issues.

File

src/Tests/ConfigIgnoreTest.php, line 133

Class

ConfigIgnoreTest
Class ConfigIgnoreTest.

Namespace

Drupal\config_ignore\Tests

Code

public function testValidateForceImporting() {

  // Login with a user that has permission to import config.
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'import configuration',
  ]));

  // Set the site name to a known value that we later will try and overwrite.
  $this
    ->config('system.site')
    ->set('name', 'Test import')
    ->save();

  // Set the system.site:name to be (force-) imported upon config import.
  $settings = [
    ConfigImporterIgnore::FORCE_EXCLUSION_PREFIX . 'system.site',
  ];
  $this
    ->config('config_ignore.settings')
    ->set('ignored_config_entities', $settings)
    ->save();

  // Assemble a change that will try and override the current value.
  $config = $this
    ->config('system.site')
    ->set('name', 'Import has changed title');
  $edit = [
    'config_type' => 'system.simple',
    'config_name' => $config
      ->getName(),
    'import' => Yaml::encode($config
      ->get()),
  ];

  // Submit a new single item config, with the changes.
  $this
    ->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import'));
  $this
    ->drupalPostForm(NULL, [], t('Confirm'));

  // Validate if the title from the imported config was imported.
  $this
    ->assertText('Import has changed title');

  // Validate that the user does NOT get the message about configuration
  // been ignored.
  $this
    ->assertNoText('The following config entity was ignored');
}