View source
<?php
namespace Drupal\Tests\config_actions\Unit;
use Drupal\config_actions\ConfigActionsPluginBase;
use Drupal\config_actions\ConfigActionsServiceInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\Core\DependencyInjection\ContainerBuilder;
class ConfigActionsPluginBaseTest extends UnitTestCase {
protected $configActions;
protected $definition;
public function setUp() {
parent::setUp();
$container = new ContainerBuilder();
$this->configActions = $this
->createMock(ConfigActionsServiceInterface::class);
$container
->set('config_actions', $this->configActions);
\Drupal::setContainer($container);
$this->definition = [
'options' => [],
'replace_in' => [],
'data' => [],
];
}
public function testGetOption() {
$options = [
'source' => 'my source',
];
$plugin = new ConfigActionsPluginBase($options, 'test', $this->definition, $this->configActions);
$plugin
->setOptions($options);
$this
->assertEquals('my source', $plugin
->getOption('source'));
}
public function testSetOptions() {
$options = [
'source' => 'node.type.@bundle@',
'replace' => [
'@bundle@' => 'article',
],
];
$this->definition['replace_in'] = [
'source',
];
$plugin = new ConfigActionsPluginBase($options, 'test', $this->definition, $this->configActions);
$plugin
->setOptions($options);
$this
->assertEquals('node.type.article', $plugin
->getOption('source'));
}
public function testParseOptions() {
$options = [
'id' => 'testid',
'source' => '@id@',
];
$plugin = new ConfigActionsPluginBase($options, 'test', $this->definition, $this->configActions);
$new_options = $plugin
->parseOptions($options);
$this
->assertEquals('testid', $new_options['source']);
}
public function testSimpleOptions() {
$options = [
'source' => 'node.type.@bundle@',
'@bundle@' => 'article',
];
$this->definition['replace_in'] = [
'source',
];
$plugin = new ConfigActionsPluginBase($options, 'test', $this->definition, $this->configActions);
$plugin
->setOptions($options);
$this
->assertEquals('node.type.article', $plugin
->getOption('source'));
}
}