public function ConfigActionsSourceTest::testArray in Config Actions 8
@covers \Drupal\config_actions\Plugin\ConfigActionsSource\ConfigActionsArray
File
- tests/
src/ Kernel/ ConfigActionsSourceTest.php, line 68
Class
- ConfigActionsSourceTest
- test the ConfigActionsSource plugins
Namespace
Drupal\Tests\config_actions\KernelCode
public function testArray() {
$source = [
'mykey' => 'test value',
];
$options = [
'source' => $source,
];
/** @var \Drupal\config_actions\ConfigActionsSourceInterface $plugin */
$plugin = $this->sourceManager
->createInstance('array', $options);
$this
->assertTrue($plugin
->detect($source), 'Source detected');
$this
->assertEquals($source, $plugin
->load(), 'Loading plugin data');
// First test merging new data
$new_data = [
'newkey' => 'new value',
];
$source = array_merge($source, $new_data);
$this
->assertTrue($plugin
->save($new_data), 'Saving data to plugin');
$this
->assertEquals($source, $plugin
->load());
// Next, test replacing existing data
$new_data = [
'mykey' => 'new value2',
'newkey' => 'new value2',
];
$source = $new_data;
$this
->assertTrue($plugin
->save($new_data), 'Saving data to plugin');
$this
->assertEquals($source, $plugin
->load());
// Next, test without merge
$new_data = [
'newkey' => 'new value2',
];
$source = $new_data;
$plugin
->setMerge(FALSE);
$this
->assertTrue($plugin
->save($new_data), 'Saving data to plugin');
$this
->assertEquals($source, $plugin
->load());
}