You are here

public function ConfigIgnoreTest::setUp in Config Ignore Keys 8

Overrides KernelTestBase::setUp

File

tests/src/Kernel/ConfigIgnoreTest.php, line 56

Class

ConfigIgnoreTest
Class ConfigIgnoreTest.

Namespace

Drupal\Tests\config_ignore_keys\Kernel

Code

public function setUp() {
  parent::setUp();
  $this
    ->installEntitySchema('node');
  $this
    ->installConfig([
    'field',
    'node',
  ]);

  // Load sync configuration.
  $this->sync = $this->container
    ->get('config.storage.sync');
  $this
    ->copyConfig($this->container
    ->get('config.storage'), $this->sync);

  // Set up the ConfigImporter object for testing.
  $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'));

  // Import.
  $this->configImporter
    ->reset()
    ->import();

  // Create a new content type.
  $content_type = NodeType::create([
    'type' => static::NODE_TYPE_NAME,
    'name' => 'Test node type',
  ]);
  $content_type
    ->save();

  // Add a body field.
  node_add_body_field($content_type);

  // Copy the current config over the sync config set.
  $active = $this->container
    ->get('config.storage');
  $this
    ->copyConfig($active, $this->sync);
  $this->configImporter
    ->reset()
    ->import();
}