function ConfigImporterTest::testInstallProfileMisMatch

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php \Drupal\KernelTests\Core\Config\ConfigImporterTest::testInstallProfileMisMatch()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php \Drupal\KernelTests\Core\Config\ConfigImporterTest::testInstallProfileMisMatch()
  3. 10 core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php \Drupal\KernelTests\Core\Config\ConfigImporterTest::testInstallProfileMisMatch()

Tests install profile validation during configuration import.

See also

\Drupal\Core\EventSubscriber\ConfigImportSubscriber

File

core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php, line 756

Class

ConfigImporterTest
Tests importing configuration from files into active configuration.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testInstallProfileMisMatch() : void {
    // Install profiles can not be changed. They can only be uninstalled. We
    // need to set an install profile prior to testing because KernelTestBase
    // tests do not use one.
    $this->setInstallProfile('minimal');
    $sync = $this->container
        ->get('config.storage.sync');
    $extensions = $sync->read('core.extension');
    // Change the install profile.
    $extensions['profile'] = 'this_will_not_work';
    $sync->write('core.extension', $extensions);
    $config_importer = $this->configImporter();
    try {
        $config_importer->import();
        $this->fail('ConfigImporterException not thrown; an invalid import was not stopped due to missing dependencies.');
    } catch (ConfigImporterException $e) {
        $expected = static::FAIL_MESSAGE . PHP_EOL . 'Cannot change the install profile from <em class="placeholder">minimal</em> to <em class="placeholder">this_will_not_work</em> once Drupal is installed.';
        $this->assertEquals($expected, $e->getMessage(), 'There were errors validating the config synchronization.');
        $error_log = $config_importer->getErrors();
        $this->assertEquals([
            'Cannot change the install profile from minimal to this_will_not_work once Drupal is installed.',
        ], $error_log);
    }
}

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