You are here

public function ConfigActionsPluginTest::testDelete in Config Actions 8

@covers \Drupal\config_actions\Plugin\ConfigActions\ConfigActionsDelete

File

tests/src/Kernel/ConfigActionsPluginTest.php, line 196

Class

ConfigActionsPluginTest
test the ConfigActions plugins

Namespace

Drupal\Tests\config_actions\Kernel

Code

public function testDelete() {
  $source = 'core.date_format.long';
  $action = [
    'plugin' => 'delete',
    'source' => $source,
    'path' => [
      'label',
    ],
  ];
  $orig_config = $this
    ->getConfig($source);
  $this->configActions
    ->processAction($action);
  $new_config = $this
    ->getConfig($source);
  $orig_config['label'] = '';
  self::assertEquals($orig_config, $new_config);

  // Test pruning the data
  $source = 'core.date_format.long';
  $action = [
    'plugin' => 'delete',
    'source' => $source,
    'path' => [
      'label',
    ],
    'prune' => TRUE,
  ];
  $orig_config = $this
    ->getConfig($source);
  $new_config = $this->configActions
    ->processAction($action);

  // Cannot use getConfig to test because Drupal won't actually delete the key
  unset($orig_config['label']);
  self::assertEquals($orig_config, $new_config);

  // Test deleting entire config entity
  $source = 'core.date_format.long';
  $action = [
    'plugin' => 'delete',
    'source' => $source,
  ];
  $this->configActions
    ->processAction($action);
  $new_config = $this
    ->getConfig($source);
  self::assertEmpty($new_config);
}