1010use Drupal \Tests \UnitTestCase ;
1111use Drupal \workflow_type_test \Plugin \WorkflowType \TestType ;
1212use Drupal \workflows \Entity \Workflow ;
13+ use Drupal \workflows \State ;
1314use Drupal \workflows \WorkflowTypeManager ;
1415use Prophecy \Argument ;
1516
1920 */
2021class StateTransitionValidationTest extends UnitTestCase {
2122
23+ /**
24+ * A test workflow.
25+ *
26+ * @var \Drupal\workflows\WorkflowInterface
27+ */
28+ protected $ workflow ;
29+
30+ /**
31+ * {@inheritdoc}
32+ */
33+ protected function setUp () {
34+ parent ::setUp ();
35+
36+ // Create a container so that the plugin manager and workflow type can be
37+ // mocked.
38+ $ container = new ContainerBuilder ();
39+ $ workflow_manager = $ this ->prophesize (WorkflowTypeManager::class);
40+ $ workflow_manager ->createInstance ('content_moderation ' , Argument::any ())->willReturn (new TestType ([], '' , []));
41+ $ container ->set ('plugin.manager.workflows.type ' , $ workflow_manager ->reveal ());
42+ \Drupal::setContainer ($ container );
43+
44+ $ this ->workflow = new Workflow (['id ' => 'process ' , 'type ' => 'content_moderation ' ], 'workflow ' );
45+ $ this ->workflow
46+ ->getTypePlugin ()
47+ ->addState ('draft ' , 'draft ' )
48+ ->addState ('needs_review ' , 'needs_review ' )
49+ ->addState ('published ' , 'published ' )
50+ ->addTransition ('draft ' , 'draft ' , ['draft ' ], 'draft ' )
51+ ->addTransition ('review ' , 'review ' , ['draft ' ], 'needs_review ' )
52+ ->addTransition ('publish ' , 'publish ' , ['needs_review ' , 'published ' ], 'published ' );
53+ }
54+
2255 /**
2356 * Verifies user-aware transition validation.
2457 *
@@ -47,7 +80,10 @@ public function testUserSensitiveValidTransitions($from_id, $to_id, $permission,
4780 $ entity ->moderation_state = new \stdClass ();
4881 $ entity ->moderation_state ->value = $ from_id ;
4982
50- $ validator = new StateTransitionValidation ($ this ->setUpModerationInformation ($ entity ));
83+ $ moderation_info = $ this ->prophesize (ModerationInformationInterface::class);
84+ $ moderation_info ->getWorkflowForEntity ($ entity )->willReturn ($ this ->workflow );
85+
86+ $ validator = new StateTransitionValidation ($ moderation_info ->reveal ());
5187 $ has_transition = FALSE ;
5288 foreach ($ validator ->getValidTransitions ($ entity , $ user ->reveal ()) as $ transition ) {
5389 if ($ transition ->to ()->id () === $ to_id ) {
@@ -58,27 +94,17 @@ public function testUserSensitiveValidTransitions($from_id, $to_id, $permission,
5894 $ this ->assertSame ($ result , $ has_transition );
5995 }
6096
61- protected function setUpModerationInformation (ContentEntityInterface $ entity ) {
62- // Create a container so that the plugin manager and workflow type can be
63- // mocked.
64- $ container = new ContainerBuilder ();
65- $ workflow_manager = $ this ->prophesize (WorkflowTypeManager::class);
66- $ workflow_manager ->createInstance ('content_moderation ' , Argument::any ())->willReturn (new TestType ([], '' , []));
67- $ container ->set ('plugin.manager.workflows.type ' , $ workflow_manager ->reveal ());
68- \Drupal::setContainer ($ container );
69-
70- $ workflow = new Workflow (['id ' => 'process ' , 'type ' => 'content_moderation ' ], 'workflow ' );
71- $ workflow
72- ->getTypePlugin ()
73- ->addState ('draft ' , 'draft ' )
74- ->addState ('needs_review ' , 'needs_review ' )
75- ->addState ('published ' , 'published ' )
76- ->addTransition ('draft ' , 'draft ' , ['draft ' ], 'draft ' )
77- ->addTransition ('review ' , 'review ' , ['draft ' ], 'needs_review ' )
78- ->addTransition ('publish ' , 'publish ' , ['needs_review ' , 'published ' ], 'published ' );
97+ /**
98+ * @expectedDeprecation Omitting the $entity parameter from Drupal\content_moderation\StateTransitionValidation::isTransitionValid is deprecated and will be required in Drupal 9.0.0.
99+ * @group legacy
100+ */
101+ public function testDeprecatedEntityParameter () {
79102 $ moderation_info = $ this ->prophesize (ModerationInformationInterface::class);
80- $ moderation_info ->getWorkflowForEntity ($ entity )->willReturn ($ workflow );
81- return $ moderation_info ->reveal ();
103+ $ state = new State ($ this ->workflow ->getTypePlugin (), 'draft ' , 'draft ' );
104+ $ user = $ this ->prophesize (AccountInterface::class);
105+
106+ $ validator = new StateTransitionValidation ($ moderation_info ->reveal ());
107+ $ validator ->isTransitionValid ($ this ->workflow , $ state , $ state , $ user ->reveal ());
82108 }
83109
84110 /**
0 commit comments