public function ConfigActionsPluginTest::testInclude in Config Actions 8
@covers \Drupal\config_actions\Plugin\ConfigActions\ConfigActionsInclude
File
- tests/
src/ Kernel/ ConfigActionsPluginTest.php, line 555
Class
- ConfigActionsPluginTest
- test the ConfigActions plugins
Namespace
Drupal\Tests\config_actions\KernelCode
public function testInclude() {
// First, just call the field_storage action to test a simple include.
$replace = [
'@field_name@' => 'myimage',
'@cardinality@' => 1,
];
$action = [
'plugin' => 'include',
'module' => 'test_config_actions',
'action' => 'field_storage',
'replace' => $replace,
];
$path = drupal_get_path('module', 'test_config_actions') . '/config/templates';
$source = $path . '/field.storage.node.image.yml';
$orig_config = Yaml::decode(file_get_contents($source));
$orig_config = ConfigActionsTransform::replace($orig_config, $replace);
$this->configActions
->processAction($action);
$new_config = $this
->getConfig('field.storage.node.myimage');
self::assertEquals($orig_config, $new_config);
self::assertTrue(is_int($new_config['cardinality']), 'Cardinality test should set config as integer value');
// Next, call the field_instance action which has two sub-actions that have
// their own bundles defined.
$replace = [
'@field_name@' => 'myimage',
// This bundle is ignored because sub-actions have their own bundle replace.
'@bundle@' => 'mypage',
];
$replace_article = [
'@field_name@' => 'myimage',
'@bundle@' => 'article',
];
$replace_page = [
'@field_name@' => 'myimage',
'@bundle@' => 'page',
];
$action = [
'plugin' => 'include',
'module' => 'test_config_actions',
'action' => 'field_instance',
'replace' => $replace,
];
$path = drupal_get_path('module', 'test_config_actions') . '/config/templates';
$source = $path . '/field.field.node.image.yml';
$orig_config = Yaml::decode(file_get_contents($source));
$orig_config_article = ConfigActionsTransform::replace($orig_config, $replace_article);
$orig_config_page = ConfigActionsTransform::replace($orig_config, $replace_page);
$this->configActions
->processAction($action);
$new_config_article = $this
->getConfig('field.field.node.article.myimage');
$new_config_page = $this
->getConfig('field.field.node.page.myimage');
self::assertEquals($orig_config_article, $new_config_article);
self::assertEquals($orig_config_page, $new_config_page);
$this
->deleteConfig('field.field.node.article.myimage');
$this
->deleteConfig('field.field.node.page.myimage');
// Next, call one of the sub-actions directly.
// Now we can override the bundle in the sub-action.
$action = [
'plugin' => 'include',
'module' => 'test_config_actions',
'action' => 'field_instance:article',
'replace' => $replace,
];
$orig_config = Yaml::decode(file_get_contents($source));
$orig_config = ConfigActionsTransform::replace($orig_config, $replace);
$this->configActions
->processAction($action);
$new_config = $this
->getConfig('field.field.node.mypage.myimage');
$new_config_article = $this
->getConfig('field.field.node.article.myimage');
$new_config_page = $this
->getConfig('field.field.node.page.myimage');
self::assertEquals($orig_config, $new_config);
self::assertEmpty($new_config_article);
self::assertEmpty($new_config_page);
// Next, run actions in a single file.
$config_id = 'core.date_format.short';
$action = [
'plugin' => 'include',
'module' => 'test_config_actions',
'file' => $config_id,
];
$this->configActions
->processAction($action);
$new_config = $this
->getConfig($config_id);
self::assertEquals('Test short date', $new_config['label']);
// Test allowing .yml in the file name.
$config_id = 'core.date_format.short';
$label = 'New short date';
$action = [
'plugin' => 'include',
'module' => 'test_config_actions',
'file' => $config_id . '.yml',
'@label@' => $label,
];
$this->configActions
->processAction($action);
$new_config = $this
->getConfig($config_id);
self::assertEquals($label, $new_config['label']);
}