You are here

public function ConfigImporterTest::testDeleted in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php \Drupal\KernelTests\Core\Config\ConfigImporterTest::testDeleted()

Tests deletion of configuration during import.

File

core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php, line 124

Class

ConfigImporterTest
Tests importing configuration from files into active configuration.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testDeleted() {
  $dynamic_name = 'config_test.dynamic.dotted.default';
  $storage = $this->container
    ->get('config.storage');
  $sync = $this->container
    ->get('config.storage.sync');

  // Verify the default configuration values exist.
  $config = $this
    ->config($dynamic_name);
  $this
    ->assertSame('dotted.default', $config
    ->get('id'));

  // Delete the file from the sync directory.
  $sync
    ->delete($dynamic_name);

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

  // Verify the file has been removed.
  $this
    ->assertFalse($storage
    ->read($dynamic_name));
  $config = $this
    ->config($dynamic_name);
  $this
    ->assertNull($config
    ->get('id'));

  // Verify that appropriate module API hooks have been invoked.
  $this
    ->assertTrue(isset($GLOBALS['hook_config_test']['load']));
  $this
    ->assertFalse(isset($GLOBALS['hook_config_test']['presave']));
  $this
    ->assertFalse(isset($GLOBALS['hook_config_test']['insert']));
  $this
    ->assertFalse(isset($GLOBALS['hook_config_test']['update']));
  $this
    ->assertTrue(isset($GLOBALS['hook_config_test']['predelete']));
  $this
    ->assertTrue(isset($GLOBALS['hook_config_test']['delete']));
  $this
    ->assertFalse($this->configImporter
    ->hasUnprocessedConfigurationChanges());
  $logs = $this->configImporter
    ->getErrors();
  $this
    ->assertCount(0, $logs);
}