You are here

public function ConfigActionsPluginTest::testSource in Config Actions 8

Test "source" option that is used in many plugins.

File

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

Class

ConfigActionsPluginTest
test the ConfigActions plugins

Namespace

Drupal\Tests\config_actions\Kernel

Code

public function testSource() {
  $source = [
    'mykey' => 'myvalue',
    'label' => 'This is a @test@',
  ];
  $dest = 'core.date_format.long';
  $replace = [
    'label' => [
      'with' => 'mylabel',
      // We only want to replace the 'value' option, not the 'path'.
      'in' => [
        'value',
      ],
    ],
    '@test@' => 'new',
  ];
  $value = 'My @test@ label';
  $action = [
    'plugin' => 'change',
    'source' => $source,
    'dest' => $dest,
    'path' => [
      'label',
    ],
    'value' => $value,
    'replace' => $replace,
  ];
  $orig_config = $this
    ->getConfig($dest);
  $tree = $this->configActions
    ->processAction($action);
  $new_config = $this
    ->getConfig($dest);
  $source['label'] = 'My new mylabel';

  // First, test the raw return value
  self::assertEquals($source, $tree);

  // Now test what was actually stored in the config because of the schema
  // where you can't just add the 'newkey'
  $orig_config['label'] = 'My new mylabel';
  self::assertEquals($orig_config, $new_config);
  self::assertArrayNotHasKey('mykey', $new_config);
}