You are here

public function ConfigSingleImportExportTest::testImportSimpleConfiguration in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/config/tests/src/Functional/ConfigSingleImportExportTest.php \Drupal\Tests\config\Functional\ConfigSingleImportExportTest::testImportSimpleConfiguration()

Tests importing a simple configuration file.

File

core/modules/config/tests/src/Functional/ConfigSingleImportExportTest.php, line 210

Class

ConfigSingleImportExportTest
Tests the user interface for importing/exporting a single configuration.

Namespace

Drupal\Tests\config\Functional

Code

public function testImportSimpleConfiguration() {
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'import configuration',
  ]));
  $config = $this
    ->config('system.site')
    ->set('name', 'Test simple import');

  // Place branding block with site name into header region.
  $this
    ->drupalPlaceBlock('system_branding_block', [
    'region' => 'header',
  ]);
  $edit = [
    'config_type' => 'system.simple',
    'config_name' => $config
      ->getName(),
    'import' => Yaml::encode($config
      ->get()),
  ];
  $this
    ->drupalGet('admin/config/development/configuration/single/import');
  $this
    ->submitForm($edit, 'Import');
  $this
    ->assertSession()
    ->pageTextContains('Are you sure you want to update the ' . $config
    ->getName() . ' simple configuration?');
  $this
    ->submitForm([], 'Confirm');
  $this
    ->drupalGet('');
  $this
    ->assertSession()
    ->pageTextContains('Test simple import');

  // Ensure that ConfigImporter validation is running when importing simple
  // configuration.
  $config_data = $this
    ->config('core.extension')
    ->get();

  // Simulate uninstalling the Config module.
  unset($config_data['module']['config']);
  $edit = [
    'config_type' => 'system.simple',
    'config_name' => 'core.extension',
    'import' => Yaml::encode($config_data),
  ];
  $this
    ->drupalGet('admin/config/development/configuration/single/import');
  $this
    ->submitForm($edit, 'Import');
  $this
    ->assertSession()
    ->pageTextContains('Can not uninstall the Configuration module as part of a configuration synchronization through the user interface.');

  // Try to import without any values.
  $this
    ->drupalGet('admin/config/development/configuration/single/import');
  $this
    ->submitForm([], 'Import');
  $this
    ->assertSession()
    ->pageTextContains('Configuration type field is required.');
  $this
    ->assertSession()
    ->pageTextContains('Paste your configuration here field is required.');
}