You are here

function ConfigImporterTest::testSiteUuidValidate in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/config/src/Tests/ConfigImporterTest.php \Drupal\config\Tests\ConfigImporterTest::testSiteUuidValidate()

Tests verification of site UUID before importing configuration.

File

core/modules/config/src/Tests/ConfigImporterTest.php, line 100
Contains \Drupal\config\Tests\ConfigImporterTest.

Class

ConfigImporterTest
Tests importing configuration from files into active configuration.

Namespace

Drupal\config\Tests

Code

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) {
    $this
      ->assertEqual($e
      ->getMessage(), 'There were errors validating the config synchronization.');
    $error_log = $this->configImporter
      ->getErrors();
    $expected = array(
      'Site UUID in source storage does not match the target storage.',
    );
    $this
      ->assertEqual($expected, $error_log);
  }
}