bug #28769 [FrameworkBundle] deal with explicitly enabled workflow nodes (xabbuh)

This PR was merged into the 3.4 branch.

Discussion
----------

[FrameworkBundle] deal with explicitly enabled workflow nodes

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | not yet
| Fixed tickets | #28662
| License       | MIT
| Doc PR        |

Commits
-------

017fd56bd8 deal with explicitly enabled workflow nodes
This commit is contained in:
Grégoire Pineau 2018-11-19 10:38:20 +01:00
commit b74a086ec2
8 changed files with 135 additions and 1 deletions

View File

@ -18,6 +18,7 @@ use Symfony\Component\Asset\Package;
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;
@ -267,10 +268,22 @@ class Configuration implements ConfigurationInterface
$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,

View File

@ -0,0 +1,19 @@
<?php
$container->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'),
),
),
),
),
));

View File

@ -0,0 +1,19 @@
<?php
$container->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'),
),
),
),
),
));

View File

@ -0,0 +1,19 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
<framework:config>
<framework:workflow enabled="true" name="foo" type="workflow" initial-place="bar">
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
<framework:place>bar</framework:place>
<framework:place>baz</framework:place>
<framework:transition name="bar_baz">
<framework:from>bar</framework:from>
<framework:to>baz</framework:to>
</framework:transition>
</framework:workflow>
</framework:config>
</container>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
<framework:config>
<framework:workflow enabled="true" name="workflows" type="workflow" initial-place="bar">
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
<framework:place>bar</framework:place>
<framework:place>baz</framework:place>
<framework:transition name="bar_baz">
<framework:from>bar</framework:from>
<framework:to>baz</framework:to>
</framework:transition>
</framework:workflow>
</framework:config>
</container>

View File

@ -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]

View File

@ -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]

View File

@ -390,6 +390,20 @@ abstract class FrameworkExtensionTest extends TestCase
$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');