function ConfigSingleImportExportTest::testImportSimpleConfiguration

Same name in other branches
  1. 9 core/modules/config/tests/src/Functional/ConfigSingleImportExportTest.php \Drupal\Tests\config\Functional\ConfigSingleImportExportTest::testImportSimpleConfiguration()
  2. 8.9.x core/modules/config/tests/src/Functional/ConfigSingleImportExportTest.php \Drupal\Tests\config\Functional\ConfigSingleImportExportTest::testImportSimpleConfiguration()
  3. 11.x 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 201

Class

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

Namespace

Drupal\Tests\config\Functional

Code

public function testImportSimpleConfiguration() : void {
    $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.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.