public function ConfigActionsPluginTest::testReplace in Config Actions 8
Test string replacement.
File
- tests/
src/ Kernel/ ConfigActionsPluginTest.php, line 68
Class
- ConfigActionsPluginTest
- test the ConfigActions plugins
Namespace
Drupal\Tests\config_actions\KernelCode
public function testReplace() {
// Config data taken from core.date_format.long.yml
// Additional keys added to test the string and key replacement system
$source = [
'langcode' => 'en',
'status' => true,
'dependencies' => [],
'id' => '@format@',
'label' => 'Default long date',
'locked' => false,
'pattern' => 'l, F j, Y - H:i',
'@key@' => 'date',
];
// $vars get replaced everywhere (options AND source data values and keys)
$replace = [
// Test replacement in 'value' option.
'@test@' => 'new',
// Test replacement in loaded data value (id).
'@format@' => 'long',
// Test replacement in loaded data key.
'@key@' => 'date',
//
'date' => [
'with' => 'datetime',
'type' => 'value',
// Only change loaded data values, so does not replace in 'value' option
'in' => [
'load',
],
],
'label' => [
'with' => 'mylabel',
// Only change loaded key values, so does not replace in 'path' option
'type' => 'key',
],
];
$value = 'My @test@ date';
$action = [
'plugin' => 'change',
'source' => $source,
// Original 'label' key was changed to 'mylabel'
// But path is not replaced with 'mymylabel' because only keys were replaced.
'path' => [
'mylabel',
],
'value' => $value,
'replace' => $replace,
'replace_in' => [
'value',
'load',
'path',
],
];
$new_config = $this->configActions
->processAction($action);
$source['mylabel'] = 'My new date';
$source['id'] = 'long';
unset($source['label']);
$source['date'] = 'datetime';
unset($source['@key@']);
self::assertEquals($source, $new_config);
}