function ConfigImporterTest::testSiteUuidValidate

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

Tests verification of site UUID before importing configuration.

File

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

Class

ConfigImporterTest
Tests importing configuration from files into active configuration.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testSiteUuidValidate() : void {
    $sync = \Drupal::service('config.storage.sync');
    // Create updated configuration object.
    $config_data = $this->config('system.site')
        ->get();
    // Generate a new site UUID.
    $config_data['uuid'] = \Drupal::service('uuid')->generate();
    $sync->write('system.site', $config_data);
    $config_importer = $this->configImporter();
    try {
        $config_importer->import();
        $this->fail('ConfigImporterException not thrown, invalid import was not stopped due to mis-matching site UUID.');
    } catch (ConfigImporterException $e) {
        $actual_message = $e->getMessage();
        $actual_error_log = $config_importer->getErrors();
        $expected_error_log = [
            'Site UUID in source storage does not match the target storage.',
        ];
        $this->assertEquals($expected_error_log, $actual_error_log);
        $expected = static::FAIL_MESSAGE . PHP_EOL . 'Site UUID in source storage does not match the target storage.';
        $this->assertEquals($expected, $actual_message);
        foreach ($expected_error_log as $log_row) {
            $this->assertMatchesRegularExpression("/{$log_row}/", $actual_message);
        }
    }
}

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