You are here

public function ConfigImporterTest::testSiteUuidValidate in Drupal 9

Same name and namespace in other branches
  1. 8 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 95

Class

ConfigImporterTest
Tests importing configuration from files into active configuration.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testSiteUuidValidate() {
  $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);
  try {
    $this->configImporter
      ->reset()
      ->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 = $this->configImporter
      ->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);
    }
  }
}