View source
<?php
namespace Drupal\Tests\config_ignore_keys\Kernel;
use Drupal\Core\Config\ConfigImporter;
use Drupal\Core\Config\StorageComparer;
use Drupal\field\Entity\FieldConfig;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\NodeType;
class ConfigIgnoreTest extends KernelTestBase {
public static $modules = [
'system',
'field',
'text',
'user',
'node',
'language',
'configuration_ignore_test',
'config_ignore_keys',
];
protected $sync;
protected $configImporter;
const NODE_TYPE_NAME = 'test_node_type';
public function setUp() {
parent::setUp();
$this
->installEntitySchema('node');
$this
->installConfig([
'field',
'node',
]);
$this->sync = $this->container
->get('config.storage.sync');
$this
->copyConfig($this->container
->get('config.storage'), $this->sync);
$storage_comparer = new StorageComparer($this->container
->get('config.storage.sync'), $this->container
->get('config.storage'), $this->container
->get('config.manager'));
$this->configImporter = new ConfigImporter($storage_comparer
->createChangelist(), $this->container
->get('event_dispatcher'), $this->container
->get('config.manager'), $this->container
->get('lock'), $this->container
->get('config.typed'), $this->container
->get('module_handler'), $this->container
->get('module_installer'), $this->container
->get('theme_handler'), $this->container
->get('string_translation'));
$this->configImporter
->reset()
->import();
$content_type = NodeType::create([
'type' => static::NODE_TYPE_NAME,
'name' => 'Test node type',
]);
$content_type
->save();
node_add_body_field($content_type);
$active = $this->container
->get('config.storage');
$this
->copyConfig($active, $this->sync);
$this->configImporter
->reset()
->import();
}
public function testConfigIgnored() {
$content_type = NodeType::load(static::NODE_TYPE_NAME);
$content_type
->set('name', 'New node type name');
$content_type
->save();
$this->configImporter
->reset();
$updates = $this->configImporter
->getUnprocessedConfiguration('update');
self::assertEquals(1, count($updates), 'There is 1 configuration item to update.');
$this->configImporter
->reset()
->import();
$content_type = NodeType::load(static::NODE_TYPE_NAME);
self::assertNotEquals($content_type
->get('name'), 'Test node type');
}
public function testConfigNotIgnored() {
$content_type = NodeType::load(static::NODE_TYPE_NAME);
$field = FieldConfig::loadByName('node', $content_type
->id(), 'body');
$field
->set('label', 'New label');
$field
->save();
$this->configImporter
->reset();
$updates = $this->configImporter
->getUnprocessedConfiguration('update');
self::assertEquals(1, count($updates), 'There is 1 configuration item to update.');
$this->configImporter
->reset()
->import();
$field = FieldConfig::loadByName('node', $content_type
->id(), 'body');
self::assertEquals($field
->get('label'), 'Body');
}
}