@@ -302,14 +302,84 @@ public function testWorkflowMultipleTransitionsWithSameName()
302302
303303 $ this ->assertCount (5 , $ transitions );
304304
305- $ this ->assertSame ('request_review ' , $ transitions [0 ]->getArgument (0 ));
306- $ this ->assertSame ('journalist_approval ' , $ transitions [1 ]->getArgument (0 ));
307- $ this ->assertSame ('spellchecker_approval ' , $ transitions [2 ]->getArgument (0 ));
308- $ this ->assertSame ('publish ' , $ transitions [3 ]->getArgument (0 ));
309- $ this ->assertSame ('publish ' , $ transitions [4 ]->getArgument (0 ));
310-
311- $ this ->assertSame (array ('approved_by_journalist ' , 'approved_by_spellchecker ' ), $ transitions [3 ]->getArgument (1 ));
312- $ this ->assertSame (array ('draft ' ), $ transitions [4 ]->getArgument (1 ));
305+ $ this ->assertSame ('workflow.article.transition.0 ' , (string ) $ transitions [0 ]);
306+ $ this ->assertSame (array (
307+ 'request_review ' ,
308+ array (
309+ 'draft ' ,
310+ ),
311+ array (
312+ 'wait_for_journalist ' , 'wait_for_spellchecker ' ,
313+ ),
314+ ), $ container ->getDefinition ($ transitions [0 ])->getArguments ());
315+
316+ $ this ->assertSame ('workflow.article.transition.1 ' , (string ) $ transitions [1 ]);
317+ $ this ->assertSame (array (
318+ 'journalist_approval ' ,
319+ array (
320+ 'wait_for_journalist ' ,
321+ ),
322+ array (
323+ 'approved_by_journalist ' ,
324+ ),
325+ ), $ container ->getDefinition ($ transitions [1 ])->getArguments ());
326+
327+ $ this ->assertSame ('workflow.article.transition.2 ' , (string ) $ transitions [2 ]);
328+ $ this ->assertSame (array (
329+ 'spellchecker_approval ' ,
330+ array (
331+ 'wait_for_spellchecker ' ,
332+ ),
333+ array (
334+ 'approved_by_spellchecker ' ,
335+ ),
336+ ), $ container ->getDefinition ($ transitions [2 ])->getArguments ());
337+
338+ $ this ->assertSame ('workflow.article.transition.3 ' , (string ) $ transitions [3 ]);
339+ $ this ->assertSame (array (
340+ 'publish ' ,
341+ array (
342+ 'approved_by_journalist ' ,
343+ 'approved_by_spellchecker ' ,
344+ ),
345+ array (
346+ 'published ' ,
347+ ),
348+ ), $ container ->getDefinition ($ transitions [3 ])->getArguments ());
349+
350+ $ this ->assertSame ('workflow.article.transition.4 ' , (string ) $ transitions [4 ]);
351+ $ this ->assertSame (array (
352+ 'publish ' ,
353+ array (
354+ 'draft ' ,
355+ ),
356+ array (
357+ 'published ' ,
358+ ),
359+ ), $ container ->getDefinition ($ transitions [4 ])->getArguments ());
360+ }
361+
362+ public function testGuardExpressions ()
363+ {
364+ $ container = $ this ->createContainerFromFile ('workflow_with_guard_expression ' );
365+
366+ $ this ->assertTrue ($ container ->hasDefinition ('workflow.article.listener.guard ' ), 'Workflow guard listener is registered as a service ' );
367+ $ this ->assertTrue ($ container ->hasParameter ('workflow.has_guard_listeners ' ), 'Workflow guard listeners parameter exists ' );
368+ $ this ->assertTrue (true === $ container ->getParameter ('workflow.has_guard_listeners ' ), 'Workflow guard listeners parameter is enabled ' );
369+ $ guardDefinition = $ container ->getDefinition ('workflow.article.listener.guard ' );
370+ $ this ->assertSame (array (
371+ array (
372+ 'event ' => 'workflow.article.guard.publish ' ,
373+ 'method ' => 'onTransition ' ,
374+ ),
375+ ), $ guardDefinition ->getTag ('kernel.event_listener ' ));
376+ $ guardsConfiguration = $ guardDefinition ->getArgument (0 );
377+ $ this ->assertTrue (1 === \count ($ guardsConfiguration ), 'Workflow guard configuration contains one element per transition name ' );
378+ $ transitionGuardExpressions = $ guardsConfiguration ['workflow.article.guard.publish ' ];
379+ $ this ->assertSame ('workflow.article.transition.3 ' , (string ) $ transitionGuardExpressions [0 ]->getArgument (0 ));
380+ $ this ->assertSame ('!!true ' , $ transitionGuardExpressions [0 ]->getArgument (1 ));
381+ $ this ->assertSame ('workflow.article.transition.4 ' , (string ) $ transitionGuardExpressions [1 ]->getArgument (0 ));
382+ $ this ->assertSame ('!!false ' , $ transitionGuardExpressions [1 ]->getArgument (1 ));
313383 }
314384
315385 public function testWorkflowServicesCanBeEnabled ()
0 commit comments