Commit 8bfede4d authored by catch's avatar catch
Browse files

Issue #3396197 by alexpott, BramDriesen, borisson_: Config saved during import...

Issue #3396197 by alexpott, BramDriesen, borisson_: Config saved during import does not have correct initial values set

(cherry picked from commit b07fdfae)
(cherry picked from commit d5d7549f)
parent 78b55658
Loading
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -996,6 +996,9 @@ protected function importConfig($collection, $op, $name) {
      $config->delete();
    }
    else {
      if ($old_data = $this->storageComparer->getTargetStorage($collection)->read($name)) {
        $config->initWithData($old_data);
      }
      $data = $this->storageComparer->getSourceStorage($collection)->read($name);
      $config->setData($data ? $data : []);
      $config->save();
+22 −1
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

use Drupal\Component\Utility\Html;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Config\ConfigEvents;
use Drupal\Core\Config\ConfigImporter;
use Drupal\Core\Config\ConfigImporterException;
use Drupal\KernelTests\KernelTestBase;
@@ -25,7 +26,7 @@ class ConfigImporterTest extends KernelTestBase {
   *
   * @var array
   */
  protected static $modules = ['config_test', 'system', 'config_import_test'];
  protected static $modules = ['config_test', 'system', 'config_import_test', 'config_events_test'];

  /**
   * {@inheritdoc}
@@ -899,6 +900,26 @@ public function testUninstallThemeIncrementsCount(): void {
    $this->assertEquals(0, $this->config($cronName)->get('logging'));
  }

  /**
   * Tests config events during config import.
   */
  public function testConfigEvents(): void {
    $this->installConfig(['config_events_test']);
    $this->config('config_events_test.test')->set('key', 'bar')->save();
    $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));
    $this->config('config_events_test.test')->set('key', 'foo')->save();
    \Drupal::state()->set('config_events_test.event', []);

    // Import the configuration. This results in a save event with the value
    // changing from foo to bar.
    $this->configImporter()->import();
    $event = \Drupal::state()->get('config_events_test.event', []);
    $this->assertSame(ConfigEvents::SAVE, $event['event_name']);
    $this->assertSame(['key' => 'bar'], $event['current_config_data']);
    $this->assertSame(['key' => 'bar'], $event['raw_config_data']);
    $this->assertSame(['key' => 'foo'], $event['original_config_data']);
  }

  /**
   * Helper method to test custom config installer steps.
   *