public function ConfigActionsSourceTest::testList in Config Actions 8
@covers \Drupal\config_actions\Plugin\ConfigActionsSource\ConfigActionsList
File
- tests/
src/ Kernel/ ConfigActionsSourceTest.php, line 195
Class
- ConfigActionsSourceTest
- test the ConfigActionsSource plugins
Namespace
Drupal\Tests\config_actions\KernelCode
public function testList() {
$source = [
'field.field.node.image.yml',
'core.date_format.long',
];
$options = [
'source' => $source,
'base' => DRUPAL_ROOT . '/' . drupal_get_path('module', 'test_config_actions'),
];
// First, test that the File is loaded first
/** @var \Drupal\config_actions\ConfigActionsSourceInterface $plugin */
$plugin = $this->sourceManager
->createInstance('list', $options);
$this
->assertTrue($plugin
->detect($source), 'Source detected');
$data = $plugin
->load();
$this
->assertEquals('node.@bundle@.@field_name@', $data['id']);
// Next, test that when the file doesn't exist, the ID is loaded.
$source = [
'field.field.node.image.DOESNOTEXIST.yml',
'core.date_format.long',
];
$options = [
'source' => $source,
'base' => DRUPAL_ROOT . '/' . drupal_get_path('module', 'test_config_actions'),
];
/** @var \Drupal\config_actions\ConfigActionsSourceInterface $plugin */
$plugin = $this->sourceManager
->createInstance('list', $options);
$this
->assertTrue($plugin
->detect($source), 'Source detected');
$data = $plugin
->load();
$this
->assertEquals('long', $data['id']);
// Next, test that the ID is loaded first.
$source = [
'core.date_format.long',
'field.field.node.image.yml',
];
$options = [
'source' => $source,
'base' => DRUPAL_ROOT . '/' . drupal_get_path('module', 'test_config_actions'),
];
/** @var \Drupal\config_actions\ConfigActionsSourceInterface $plugin */
$plugin = $this->sourceManager
->createInstance('list', $options);
$this
->assertTrue($plugin
->detect($source), 'Source detected');
$data = $plugin
->load();
$this
->assertEquals('long', $data['id']);
// Finally, test that the File is loaded if the ID doesn't exist.
$source = [
'core.date_format.MYFORMAT',
'field.field.node.image.yml',
];
$options = [
'source' => $source,
'base' => DRUPAL_ROOT . '/' . drupal_get_path('module', 'test_config_actions'),
];
/** @var \Drupal\config_actions\ConfigActionsSourceInterface $plugin */
$plugin = $this->sourceManager
->createInstance('list', $options);
$this
->assertTrue($plugin
->detect($source), 'Source detected');
$data = $plugin
->load();
$this
->assertEquals('node.@bundle@.@field_name@', $data['id']);
}