Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6fe9319

Browse filesBrowse files
committed
feature #21253 [TwigBridge][Worklow] Added a new workflow_has_place function (Padam87, lyrixx)
This PR was merged into the 3.3-dev branch. Discussion ---------- [TwigBridge][Worklow] Added a new workflow_has_place function | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20781 | License | MIT | Doc PR | --- This PR follow up #20781 I also increased the Coverage of the WorkflowExtension and finally I added an extra commit that is not related to clean-up 2 unused properties Commits ------- 108c89d [TwigBridge] Removed unused class property 77f820e [TwigBridge][Workflow] Added more tests on WorkflowExtension efe500d [TwigBridge][Workflow] Fixed code and tests 4d0cc68 [TwigBridge][Workflow] Added workflow_has_place twig function
2 parents bcab8b8 + 108c89d commit 6fe9319
Copy full SHA for 6fe9319

File tree

6 files changed

+91
-7
lines changed
Filter options

6 files changed

+91
-7
lines changed

‎src/Symfony/Bridge/Twig/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/CHANGELOG.md
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
CHANGELOG
22
=========
33

4+
3.3.0
5+
-----
6+
7+
* added a `workflow_has_marked_place` function
8+
49
3.2.0
510
-----
611

712
* added `AppVariable::getToken()`
813
* Deprecated the possibility to inject the Form `TwigRenderer` into the `FormExtension`.
9-
* [BC BREAK] Registering the `FormExtension` without configuring a runtime loader for the `TwigRenderer`
14+
* [BC BREAK] Registering the `FormExtension` without configuring a runtime loader for the `TwigRenderer`
1015
doesn't work anymore.
11-
16+
1217
Before:
1318

1419
```php
@@ -36,6 +41,7 @@ CHANGELOG
3641
$twig->addExtension(new FormExtension());
3742
```
3843
* Deprecated the `TwigRendererEngineInterface` interface.
44+
* added WorkflowExtension (provides `workflow_can` and `workflow_transitions`)
3945

4046
2.7.0
4147
-----

‎src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function getFunctions()
3232
return array(
3333
new \Twig_SimpleFunction('workflow_can', array($this, 'canTransition')),
3434
new \Twig_SimpleFunction('workflow_transitions', array($this, 'getEnabledTransitions')),
35+
new \Twig_SimpleFunction('workflow_has_marked_place', array($this, 'hasMarkedPlace')),
3536
);
3637
}
3738

@@ -45,6 +46,11 @@ public function getEnabledTransitions($object, $name = null)
4546
return $this->workflowRegistry->get($object, $name)->getEnabledTransitions($object);
4647
}
4748

49+
public function hasMarkedPlace($object, $place, $name = null)
50+
{
51+
return $this->workflowRegistry->get($object, $name)->getMarking($object)->has($place);
52+
}
53+
4854
public function getName()
4955
{
5056
return 'workflow';

‎src/Symfony/Bridge/Twig/Tests/Extension/CodeExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/Extension/CodeExtensionTest.php
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
class CodeExtensionTest extends \PHPUnit_Framework_TestCase
1818
{
19-
protected $helper;
20-
2119
public function testFormatFile()
2220
{
2321
$expected = sprintf('<a href="proto://foobar%s#&amp;line=25" title="Click to open this file" class="file_link">%s at line 25</a>', substr(__FILE__, 5), __FILE__);

‎src/Symfony/Bridge/Twig/Tests/Extension/ExpressionExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/Extension/ExpressionExtensionTest.php
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
class ExpressionExtensionTest extends \PHPUnit_Framework_TestCase
1717
{
18-
protected $helper;
19-
2018
public function testExpressionCreation()
2119
{
2220
$template = "{{ expression('1 == 1') }}";
+76Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Twig\Tests\Extension;
13+
14+
use Symfony\Bridge\Twig\Extension\WorkflowExtension;
15+
use Symfony\Component\Workflow\Definition;
16+
use Symfony\Component\Workflow\Marking;
17+
use Symfony\Component\Workflow\Registry;
18+
use Symfony\Component\Workflow\Transition;
19+
use Symfony\Component\Workflow\Workflow;
20+
21+
class WorkflowExtensionTest extends \PHPUnit_Framework_TestCase
22+
{
23+
private $extension;
24+
25+
protected function setUp()
26+
{
27+
if (!class_exists(Workflow::class)) {
28+
$this->markTestSkipped('The Workflow component is needed to run tests for this extension.');
29+
}
30+
31+
$places = array('ordered', 'waiting_for_payment', 'processed');
32+
$transitions = array(
33+
new Transition('t1', 'ordered', 'waiting_for_payment'),
34+
new Transition('t2', 'waiting_for_payment', 'processed'),
35+
);
36+
$definition = new Definition($places, $transitions);
37+
$workflow = new Workflow($definition);
38+
39+
$registry = new Registry();
40+
$registry->add($workflow, \stdClass::class);
41+
42+
$this->extension = new WorkflowExtension($registry);
43+
}
44+
45+
public function testCanTransition()
46+
{
47+
$subject = new \stdClass();
48+
$subject->marking = array();
49+
50+
$this->assertTrue($this->extension->canTransition($subject, 't1'));
51+
$this->assertFalse($this->extension->canTransition($subject, 't2'));
52+
}
53+
54+
public function testGetEnabledTransitions()
55+
{
56+
$subject = new \stdClass();
57+
$subject->marking = array();
58+
59+
$transitions = $this->extension->getEnabledTransitions($subject);
60+
61+
$this->assertCount(1, $transitions);
62+
$this->assertInstanceOf(Transition::class, $transitions[0]);
63+
$this->assertSame('t1', $transitions[0]->getName());
64+
}
65+
66+
public function testHasMarkedPlace()
67+
{
68+
$subject = new \stdClass();
69+
$subject->marking = array();
70+
$subject->marking = array('ordered' => 1, 'waiting_for_payment' => 1);
71+
72+
$this->assertTrue($this->extension->hasMarkedPlace($subject, 'ordered'));
73+
$this->assertTrue($this->extension->hasMarkedPlace($subject, 'waiting_for_payment'));
74+
$this->assertFalse($this->extension->hasMarkedPlace($subject, 'processed'));
75+
}
76+
}

‎src/Symfony/Component/Workflow/Marking.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/Marking.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Marking
2121
private $places = array();
2222

2323
/**
24-
* @param string[] $representation Keys are the place name and values should be 1
24+
* @param int[] $representation Keys are the place name and values should be 1
2525
*/
2626
public function __construct(array $representation = array())
2727
{

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.