[TwigBridge][Workflow] Fixed code and tests
This commit is contained in:
parent
4d0cc6836f
commit
efe500da84
@ -1,14 +1,19 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
3.3.0
|
||||
-----
|
||||
|
||||
* added a `workflow_has_marked_place` function
|
||||
|
||||
3.2.0
|
||||
-----
|
||||
|
||||
* added `AppVariable::getToken()`
|
||||
* Deprecated the possibility to inject the Form `TwigRenderer` into the `FormExtension`.
|
||||
* [BC BREAK] Registering the `FormExtension` without configuring a runtime loader for the `TwigRenderer`
|
||||
* [BC BREAK] Registering the `FormExtension` without configuring a runtime loader for the `TwigRenderer`
|
||||
doesn't work anymore.
|
||||
|
||||
|
||||
Before:
|
||||
|
||||
```php
|
||||
@ -36,6 +41,7 @@ CHANGELOG
|
||||
$twig->addExtension(new FormExtension());
|
||||
```
|
||||
* Deprecated the `TwigRendererEngineInterface` interface.
|
||||
* added WorkflownExtension (provides `workflow_can` and `workflow_transitions`)
|
||||
|
||||
2.7.0
|
||||
-----
|
||||
|
@ -32,7 +32,7 @@ class WorkflowExtension extends \Twig_Extension
|
||||
return array(
|
||||
new \Twig_SimpleFunction('workflow_can', array($this, 'canTransition')),
|
||||
new \Twig_SimpleFunction('workflow_transitions', array($this, 'getEnabledTransitions')),
|
||||
new \Twig_SimpleFunction('workflow_has_place', array($this, 'hasPlace')),
|
||||
new \Twig_SimpleFunction('workflow_has_marked_place', array($this, 'hasMarkedPlace')),
|
||||
);
|
||||
}
|
||||
|
||||
@ -46,12 +46,9 @@ class WorkflowExtension extends \Twig_Extension
|
||||
return $this->workflowRegistry->get($object, $name)->getEnabledTransitions($object);
|
||||
}
|
||||
|
||||
public function hasPlace($object, $state, $name = null)
|
||||
public function hasMarkedPlace($object, $place, $name = null)
|
||||
{
|
||||
$workflow = $this->workflowRegistry->get($object, $name);
|
||||
$marking = $workflow->getMarking($object);
|
||||
|
||||
return $marking->has($state);
|
||||
return $this->workflowRegistry->get($object, $name)->getMarking($object)->has($place);
|
||||
}
|
||||
|
||||
public function getName()
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Bridge\Twig\Tests\Extension;
|
||||
|
||||
use Symfony\Bridge\Twig\Extension\WorkflowExtension;
|
||||
use Symfony\Component\Workflow\Definition;
|
||||
use Symfony\Component\Workflow\Marking;
|
||||
use Symfony\Component\Workflow\Registry;
|
||||
use Symfony\Component\Workflow\Workflow;
|
||||
@ -20,35 +21,26 @@ class WorkflowExtensionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!class_exists('Symfony\Component\Workflow\Workflow')) {
|
||||
if (!class_exists(Workflow::class)) {
|
||||
$this->markTestSkipped('The Workflow component is needed to run tests for this extension.');
|
||||
}
|
||||
}
|
||||
|
||||
public function testHasPlace()
|
||||
public function testHasMarkedPlace()
|
||||
{
|
||||
$subject = new \stdClass();
|
||||
$definition = new Definition(['ordered', 'waiting_for_payment', 'processed'], []);
|
||||
$workflow = new Workflow($definition);
|
||||
|
||||
$marking = new Marking(array('ordered' => true, 'waiting_for_payment' => true));
|
||||
|
||||
$workflow = $this->getMock(Workflow::class, array(), array(), '', false);
|
||||
$workflow->expects($this->exactly(3))
|
||||
->method('getMarking')
|
||||
->with($subject)
|
||||
->will($this->returnValue($marking));
|
||||
|
||||
$registry = $this->getMock(Registry::class);
|
||||
$registry->expects($this->exactly(3))
|
||||
->method('get')
|
||||
->with($subject)
|
||||
->will($this->returnValue($workflow));
|
||||
$registry = new Registry();
|
||||
$registry->add($workflow, \stdClass::class);
|
||||
|
||||
$extension = new WorkflowExtension($registry);
|
||||
|
||||
$this->assertTrue($extension->hasPlace($subject, 'ordered'));
|
||||
$this->assertTrue($extension->hasPlace($subject, 'waiting_for_payment'));
|
||||
$this->assertFalse($extension->hasPlace($subject, 'processed'));
|
||||
$subject = new \stdClass();
|
||||
$subject->marking = array('ordered' => 1, 'waiting_for_payment' => 1);
|
||||
|
||||
$this->assertTrue($extension->hasMarkedPlace($subject, 'ordered'));
|
||||
$this->assertTrue($extension->hasMarkedPlace($subject, 'waiting_for_payment'));
|
||||
$this->assertFalse($extension->hasMarkedPlace($subject, 'processed'));
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ class Marking
|
||||
private $places = array();
|
||||
|
||||
/**
|
||||
* @param string[] $representation Keys are the place name and values should be 1
|
||||
* @param int[] $representation Keys are the place name and values should be 1
|
||||
*/
|
||||
public function __construct(array $representation = array())
|
||||
{
|
||||
|
Reference in New Issue
Block a user