From 017fd56bd85de2cf5c544f202743e90785ef4608 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 5 Oct 2018 09:14:48 +0200 Subject: [PATCH] deal with explicitly enabled workflow nodes --- .../DependencyInjection/Configuration.php | 15 ++++++++++++++- .../php/workflows_explicitly_enabled.php | 19 +++++++++++++++++++ ...ows_explicitly_enabled_named_workflows.php | 19 +++++++++++++++++++ .../xml/workflows_explicitly_enabled.xml | 19 +++++++++++++++++++ ...ows_explicitly_enabled_named_workflows.xml | 19 +++++++++++++++++++ .../yml/workflows_explicitly_enabled.yml | 16 ++++++++++++++++ ...ows_explicitly_enabled_named_workflows.yml | 15 +++++++++++++++ .../FrameworkExtensionTest.php | 14 ++++++++++++++ 8 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled_named_workflows.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_explicitly_enabled.xml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_explicitly_enabled_named_workflows.xml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled.yml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled_named_workflows.yml diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 7f47411d0ba7..ee76f128cbe4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -18,6 +18,7 @@ use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; +use Symfony\Component\DependencyInjection\Exception\LogicException; use Symfony\Component\Form\Form; use Symfony\Component\Lock\Lock; use Symfony\Component\Lock\Store\SemaphoreStore; @@ -266,10 +267,22 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode) $workflows = $v; unset($workflows['enabled']); - if (1 === \count($workflows) && isset($workflows[0]['enabled'])) { + if (1 === \count($workflows) && isset($workflows[0]['enabled']) && 1 === \count($workflows[0])) { $workflows = array(); } + if (1 === \count($workflows) && isset($workflows['workflows']) && array_keys($workflows['workflows']) !== range(0, \count($workflows) - 1) && !empty(array_diff(array_keys($workflows['workflows']), array('audit_trail', 'type', 'marking_store', 'supports', 'support_strategy', 'initial_place', 'places', 'transitions')))) { + $workflows = $workflows['workflows']; + } + + foreach ($workflows as $key => $workflow) { + if (isset($workflow['enabled']) && false === $workflow['enabled']) { + throw new LogicException(sprintf('Cannot disable a single workflow. Remove the configuration for the workflow "%s" instead.', $workflow['name'])); + } + + unset($workflows[$key]['enabled']); + } + $v = array( 'enabled' => true, 'workflows' => $workflows, diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled.php new file mode 100644 index 000000000000..16009b588fff --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled.php @@ -0,0 +1,19 @@ +loadFromExtension('framework', array( + 'workflows' => array( + 'enabled' => true, + 'foo' => array( + 'type' => 'workflow', + 'supports' => array('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest'), + 'initial_place' => 'bar', + 'places' => array('bar', 'baz'), + 'transitions' => array( + 'bar_baz' => array( + 'from' => array('foo'), + 'to' => array('bar'), + ), + ), + ), + ), +)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled_named_workflows.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled_named_workflows.php new file mode 100644 index 000000000000..bd36d87fa257 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled_named_workflows.php @@ -0,0 +1,19 @@ +loadFromExtension('framework', array( + 'workflows' => array( + 'enabled' => true, + 'workflows' => array( + 'type' => 'workflow', + 'supports' => array('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest'), + 'initial_place' => 'bar', + 'places' => array('bar', 'baz'), + 'transitions' => array( + 'bar_baz' => array( + 'from' => array('foo'), + 'to' => array('bar'), + ), + ), + ), + ), +)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_explicitly_enabled.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_explicitly_enabled.xml new file mode 100644 index 000000000000..a73b553c4956 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_explicitly_enabled.xml @@ -0,0 +1,19 @@ + + + + + + Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest + bar + baz + + bar + baz + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_explicitly_enabled_named_workflows.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_explicitly_enabled_named_workflows.xml new file mode 100644 index 000000000000..4b430d9115b3 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_explicitly_enabled_named_workflows.xml @@ -0,0 +1,19 @@ + + + + + + Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest + bar + baz + + bar + baz + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled.yml new file mode 100644 index 000000000000..21abbf03055a --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled.yml @@ -0,0 +1,16 @@ +framework: + workflows: + enabled: true + workflows: + foo: + type: workflow + supports: + - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest + initial_place: bar + places: + - bar + - baz + transitions: + bar_baz: + from: [foo] + to: [bar] diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled_named_workflows.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled_named_workflows.yml new file mode 100644 index 000000000000..a6c03de95d1b --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled_named_workflows.yml @@ -0,0 +1,15 @@ +framework: + workflows: + enabled: true + workflows: + type: workflow + supports: + - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest + initial_place: bar + places: + - bar + - baz + transitions: + bar_baz: + from: [foo] + to: [bar] diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 06e709c5ca3a..07fc026397d7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -320,6 +320,20 @@ public function testWorkflowServicesCanBeEnabled() $this->assertTrue($container->hasDefinition('console.command.workflow_dump')); } + public function testExplicitlyEnabledWorkflows() + { + $container = $this->createContainerFromFile('workflows_explicitly_enabled'); + + $this->assertTrue($container->hasDefinition('workflow.foo.definition')); + } + + public function testExplicitlyEnabledWorkflowNamedWorkflows() + { + $container = $this->createContainerFromFile('workflows_explicitly_enabled_named_workflows'); + + $this->assertTrue($container->hasDefinition('workflow.workflows.definition')); + } + public function testEnabledPhpErrorsConfig() { $container = $this->createContainerFromFile('php_errors_enabled');