You are here

public function ConfigTest::testDelete in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Config/ConfigTest.php \Drupal\Tests\Core\Config\ConfigTest::testDelete()
  2. 10 core/tests/Drupal/Tests/Core/Config/ConfigTest.php \Drupal\Tests\Core\Config\ConfigTest::testDelete()

@covers ::delete @dataProvider overrideDataProvider

File

core/tests/Drupal/Tests/Core/Config/ConfigTest.php, line 340

Class

ConfigTest
Tests the Config.

Namespace

Drupal\Tests\Core\Config

Code

public function testDelete($data, $module_data) {
  $this->cacheTagsInvalidator
    ->expects($this
    ->once())
    ->method('invalidateTags')
    ->with([
    'config:config.test',
  ]);

  // Set initial data.
  foreach ($data as $key => $value) {
    $this->config
      ->set($key, $value);
  }

  // Set overrides.
  $this->config
    ->setModuleOverride($module_data);

  // Save.
  $this->config
    ->save();

  // Check that original data is still correct.
  $this
    ->assertOriginalConfigDataEquals($data, FALSE);

  // Check overrides have been set.
  $this
    ->assertConfigDataEquals($module_data);
  $this
    ->assertOriginalConfigDataEquals($module_data, TRUE);

  // Check that config is new.
  $this
    ->assertFalse($this->config
    ->isNew());

  // Delete.
  $this->config
    ->delete();

  // Check object properties have been reset.
  $this
    ->assertTrue($this->config
    ->isNew());
  foreach ($data as $key => $value) {
    $this
      ->assertEmpty($this->config
      ->getOriginal($key, FALSE));
  }

  // Check that overrides have persisted.
  foreach ($module_data as $key => $value) {
    $this
      ->assertConfigDataEquals($module_data);
    $this
      ->assertOriginalConfigDataEquals($module_data, TRUE);
  }
}