Commit 037932df authored by alexpott's avatar alexpott

Issue #2851635 by tim.plunkett, alexpott, dawehner:...

Issue #2851635 by tim.plunkett, alexpott, dawehner: DefaultSingleLazyPluginCollection retains stale instance IDs
parent b67ccdc1
......@@ -17,7 +17,7 @@ abstract class ConfigurableActionBase extends ActionBase implements Configurable
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->configuration += $this->defaultConfiguration();
$this->setConfiguration($configuration);
}
/**
......@@ -38,7 +38,7 @@ public function getConfiguration() {
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$this->configuration = $configuration;
$this->configuration = $configuration + $this->defaultConfiguration();
}
/**
......
......@@ -52,10 +52,7 @@ class DefaultSingleLazyPluginCollection extends LazyPluginCollection {
*/
public function __construct(PluginManagerInterface $manager, $instance_id, array $configuration) {
$this->manager = $manager;
$this->instanceId = $instance_id;
// This is still needed by the parent LazyPluginCollection class.
$this->instanceIDs = array($instance_id => $instance_id);
$this->configuration = $configuration;
$this->addInstanceId($instance_id, $configuration);
}
/**
......@@ -95,6 +92,8 @@ public function setConfiguration($configuration) {
*/
public function addInstanceId($id, $configuration = NULL) {
$this->instanceId = $id;
// Reset the list of instance IDs since there can be only one.
$this->instanceIDs = [];
parent::addInstanceId($id, $configuration);
if ($configuration !== NULL) {
$this->setConfiguration($configuration);
......
......@@ -62,6 +62,9 @@ protected function setUpModerationInformation(ContentEntityInterface $entity) {
// mocked.
$container = new ContainerBuilder();
$workflow_type = $this->prophesize(WorkflowTypeInterface::class);
$workflow_type->setConfiguration(Argument::any())->will(function ($arguments) {
$this->getConfiguration()->willReturn($arguments[0]);
});
$workflow_type->decorateState(Argument::any())->willReturnArgument(0);
$workflow_type->decorateTransition(Argument::any())->willReturnArgument(0);
$workflow_manager = $this->prophesize(WorkflowTypeManager::class);
......
......@@ -23,7 +23,7 @@ abstract class ConfigurableSearchPluginBase extends SearchPluginBase implements
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->configuration = NestedArray::mergeDeep($this->defaultConfiguration(), $this->configuration);
$this->setConfiguration($configuration);
}
/**
......@@ -44,7 +44,7 @@ public function getConfiguration() {
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$this->configuration = $configuration;
$this->configuration = NestedArray::mergeDeep($this->defaultConfiguration(), $configuration);
}
/**
......
......@@ -27,6 +27,9 @@ protected function setUp() {
// mocked.
$container = new ContainerBuilder();
$workflow_type = $this->prophesize(WorkflowTypeInterface::class);
$workflow_type->setConfiguration(Argument::any())->will(function ($arguments) {
$this->getConfiguration()->willReturn($arguments[0]);
});
$workflow_type->decorateState(Argument::any())->willReturnArgument(0);
$workflow_type->decorateTransition(Argument::any())->willReturnArgument(0);
$workflow_type->deleteState(Argument::any())->willReturn(NULL);
......
......@@ -27,6 +27,9 @@ protected function setUp() {
// mocked.
$container = new ContainerBuilder();
$workflow_type = $this->prophesize(WorkflowTypeInterface::class);
$workflow_type->setConfiguration(Argument::any())->will(function ($arguments) {
$this->getConfiguration()->willReturn($arguments[0]);
});
$workflow_type->decorateState(Argument::any())->willReturnArgument(0);
$workflow_type->decorateTransition(Argument::any())->willReturnArgument(0);
$workflow_manager = $this->prophesize(WorkflowTypeManager::class);
......
......@@ -27,6 +27,9 @@ protected function setUp() {
// mocked.
$container = new ContainerBuilder();
$workflow_type = $this->prophesize(WorkflowTypeInterface::class);
$workflow_type->setConfiguration(Argument::any())->will(function ($arguments) {
$this->getConfiguration()->willReturn($arguments[0]);
});
$workflow_type->decorateState(Argument::any())->willReturnArgument(0);
$workflow_type->decorateTransition(Argument::any())->willReturnArgument(0);
$workflow_manager = $this->prophesize(WorkflowTypeManager::class);
......@@ -215,6 +218,9 @@ public function testDeleteState() {
// correctly.
$container = new ContainerBuilder();
$workflow_type = $this->prophesize(WorkflowTypeInterface::class);
$workflow_type->setConfiguration(Argument::any())->will(function ($arguments) {
$this->getConfiguration()->willReturn($arguments[0]);
});
$workflow_type->decorateState(Argument::any())->willReturnArgument(0);
$workflow_type->decorateTransition(Argument::any())->willReturnArgument(0);
$workflow_type->deleteState('draft')->shouldBeCalled();
......@@ -636,6 +642,9 @@ public function testDeleteTransition() {
// correctly.
$container = new ContainerBuilder();
$workflow_type = $this->prophesize(WorkflowTypeInterface::class);
$workflow_type->setConfiguration(Argument::any())->will(function ($arguments) {
$this->getConfiguration()->willReturn($arguments[0]);
});
$workflow_type->decorateState(Argument::any())->willReturnArgument(0);
$workflow_type->decorateTransition(Argument::any())->willReturnArgument(0);
$workflow_type->deleteTransition('publish')->shouldBeCalled();
......
......@@ -58,6 +58,17 @@ public function testAddInstanceId() {
$this->assertEquals(['id' => 'banana', 'key' => 'other_value'], $this->defaultPluginCollection->get('banana')->getConfiguration());
}
/**
* @covers ::getInstanceIds
*/
public function testGetInstanceIds() {
$this->setupPluginCollection($this->any());
$this->assertEquals(['apple' => 'apple'], $this->defaultPluginCollection->getInstanceIds());
$this->defaultPluginCollection->addInstanceId('banana', ['id' => 'banana', 'key' => 'other_value']);
$this->assertEquals(['banana' => 'banana'], $this->defaultPluginCollection->getInstanceIds());
}
}
class ConfigurablePlugin extends PluginBase implements ConfigurablePluginInterface {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment