Commit c999c2d4 authored by catch's avatar catch

Issue #2227731 by webflo, mtift: Fixed Normalize configuration data during config writes.

parent 5e154f01
......@@ -250,10 +250,7 @@ protected function doSave($id, EntityInterface $entity) {
}
// Retrieve the desired properties and set them in config.
$record = $this->mapToStorageRecord($entity);
foreach ($record as $key => $value) {
$config->set($key, $value);
}
$config->setData($this->mapToStorageRecord($entity));
$config->save();
return $is_new ? SAVED_NEW : SAVED_UPDATED;
......
<?php
namespace Drupal\config\Tests;
use Drupal\simpletest\KernelTestBase;
/**
* Tests the listing of configuration entities.
*
* @group config
*/
class ConfigEntityNormalizeTest extends KernelTestBase {
public static $modules = array('config_test');
protected function setUp() {
parent::setUp();
$this->installConfig(static::$modules);
}
public function testNormalize() {
$config_entity = entity_create('config_test', array('id' => 'system', 'label' => 'foobar', 'weight' => 1));
$config_entity->save();
// Modify stored config entity, this is comparable with a schema change.
$config = \Drupal::config('config_test.dynamic.system');
$data = array(
'label' => 'foobar',
'additional_key' => TRUE
) + $config->getRawData();
$config->setData($data)->save();
$this->assertNotIdentical($config_entity->toArray(), $config->getRawData(), 'Stored config entity is not is equivalent to config schema.');
$config_entity = entity_load('config_test', 'system', TRUE);
$config_entity->save();
$config = \Drupal::config('config_test.dynamic.system');
$this->assertIdentical($config_entity->toArray(), $config->getRawData(), 'Stored config entity is equivalent to config schema.');
}
}
......@@ -235,8 +235,8 @@ public function testSaveInsert(EntityInterface $entity) {
$config_object->expects($this->atLeastOnce())
->method('isNew')
->will($this->returnValue(TRUE));
$config_object->expects($this->exactly(3))
->method('set');
$config_object->expects($this->exactly(1))
->method('setData');
$config_object->expects($this->once())
->method('save');
......@@ -294,8 +294,8 @@ public function testSaveUpdate(EntityInterface $entity) {
$config_object->expects($this->atLeastOnce())
->method('isNew')
->will($this->returnValue(FALSE));
$config_object->expects($this->exactly(3))
->method('set');
$config_object->expects($this->exactly(1))
->method('setData');
$config_object->expects($this->once())
->method('save');
......@@ -354,8 +354,8 @@ public function testSaveRename(ConfigEntityInterface $entity) {
$config_object->expects($this->atLeastOnce())
->method('isNew')
->will($this->returnValue(FALSE));
$config_object->expects($this->exactly(3))
->method('set');
$config_object->expects($this->exactly(1))
->method('setData');
$config_object->expects($this->once())
->method('save');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment