Loading core/modules/workflows/src/Plugin/WorkflowTypeBase.php +10 −2 Original line number Diff line number Diff line Loading @@ -178,7 +178,11 @@ public function setStateLabel($state_id, $label) { */ public function setStateWeight($state_id, $weight) { if (!$this->hasState($state_id)) { throw new \InvalidArgumentException("The state '$state_id' does not exist in workflow.'"); throw new \InvalidArgumentException("The state '$state_id' does not exist in workflow."); } if (!is_numeric($weight)) { $label = $this->getState($state_id)->label(); throw new \InvalidArgumentException("The weight '$weight' must be numeric for state '$label'."); } $this->configuration['states'][$state_id]['weight'] = $weight; return $this; Loading Loading @@ -390,7 +394,11 @@ public function setTransitionLabel($transition_id, $label) { */ public function setTransitionWeight($transition_id, $weight) { if (!$this->hasTransition($transition_id)) { throw new \InvalidArgumentException("The transition '$transition_id' does not exist in workflow.'"); throw new \InvalidArgumentException("The transition '$transition_id' does not exist in workflow."); } if (!is_numeric($weight)) { $label = $this->getTransition($transition_id)->label(); throw new \InvalidArgumentException("The weight '$weight' must be numeric for transition '$label'."); } $this->configuration['transitions'][$transition_id]['weight'] = $weight; return $this; Loading core/modules/workflows/tests/src/Unit/WorkflowTest.php +21 −0 Original line number Diff line number Diff line Loading @@ -225,6 +225,16 @@ public function testSetStateWeightException() { $workflow->getTypePlugin()->setStateWeight('draft', 10); } /** * @covers ::setStateWeight */ public function testSetStateWeightNonNumericException() { $this->setExpectedException(\InvalidArgumentException::class, "The weight 'foo' must be numeric for state 'Published'."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow->getTypePlugin()->addState('published', 'Published'); $workflow->getTypePlugin()->setStateWeight('published', 'foo'); } /** * @covers ::deleteState */ Loading Loading @@ -556,6 +566,17 @@ public function testSetTransitionWeightException() { $workflow->getTypePlugin()->setTransitionWeight('draft-published', 10); } /** * @covers ::setTransitionWeight */ public function testSetTransitionWeightNonNumericException() { $this->setExpectedException(\InvalidArgumentException::class, "The weight 'foo' must be numeric for transition 'Publish'."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow->getTypePlugin()->addState('published', 'Published'); $workflow->getTypePlugin()->addTransition('publish', 'Publish', [], 'published'); $workflow->getTypePlugin()->setTransitionWeight('publish', 'foo'); } /** * @covers ::setTransitionFromStates */ Loading Loading
core/modules/workflows/src/Plugin/WorkflowTypeBase.php +10 −2 Original line number Diff line number Diff line Loading @@ -178,7 +178,11 @@ public function setStateLabel($state_id, $label) { */ public function setStateWeight($state_id, $weight) { if (!$this->hasState($state_id)) { throw new \InvalidArgumentException("The state '$state_id' does not exist in workflow.'"); throw new \InvalidArgumentException("The state '$state_id' does not exist in workflow."); } if (!is_numeric($weight)) { $label = $this->getState($state_id)->label(); throw new \InvalidArgumentException("The weight '$weight' must be numeric for state '$label'."); } $this->configuration['states'][$state_id]['weight'] = $weight; return $this; Loading Loading @@ -390,7 +394,11 @@ public function setTransitionLabel($transition_id, $label) { */ public function setTransitionWeight($transition_id, $weight) { if (!$this->hasTransition($transition_id)) { throw new \InvalidArgumentException("The transition '$transition_id' does not exist in workflow.'"); throw new \InvalidArgumentException("The transition '$transition_id' does not exist in workflow."); } if (!is_numeric($weight)) { $label = $this->getTransition($transition_id)->label(); throw new \InvalidArgumentException("The weight '$weight' must be numeric for transition '$label'."); } $this->configuration['transitions'][$transition_id]['weight'] = $weight; return $this; Loading
core/modules/workflows/tests/src/Unit/WorkflowTest.php +21 −0 Original line number Diff line number Diff line Loading @@ -225,6 +225,16 @@ public function testSetStateWeightException() { $workflow->getTypePlugin()->setStateWeight('draft', 10); } /** * @covers ::setStateWeight */ public function testSetStateWeightNonNumericException() { $this->setExpectedException(\InvalidArgumentException::class, "The weight 'foo' must be numeric for state 'Published'."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow->getTypePlugin()->addState('published', 'Published'); $workflow->getTypePlugin()->setStateWeight('published', 'foo'); } /** * @covers ::deleteState */ Loading Loading @@ -556,6 +566,17 @@ public function testSetTransitionWeightException() { $workflow->getTypePlugin()->setTransitionWeight('draft-published', 10); } /** * @covers ::setTransitionWeight */ public function testSetTransitionWeightNonNumericException() { $this->setExpectedException(\InvalidArgumentException::class, "The weight 'foo' must be numeric for transition 'Publish'."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow->getTypePlugin()->addState('published', 'Published'); $workflow->getTypePlugin()->addTransition('publish', 'Publish', [], 'published'); $workflow->getTypePlugin()->setTransitionWeight('publish', 'foo'); } /** * @covers ::setTransitionFromStates */ Loading