This method can be use for instance, by a model that holds the definition of the workflow it is
using.
If a workflow with same id already exist in this source, it is overwritten if the last parameter is set to TRUE.
If a workflow with same id already exist in this source, it is overwritten if the last parameter is set to TRUE.
public addWorkflowDefinition ( string $workflowId, array $definition, boolean $overwrite = false ) : boolean | ||
$workflowId | string | Id of the workflow |
$definition | array | array containing the workflow definition to process |
$overwrite | boolean | When set to TRUE, the operation will fail if a workflow definition already exists for this ID. Otherwise the existing definition is overwritten. |
Результат | boolean | TRUE if the workflow definition could be added, FALSE otherwise |
public function testLoadWorkflowSuccess2() { $src = new WorkflowFileSource(); $src->addWorkflowDefinition('wid', ['initialStatusId' => 'A', 'status' => ['A' => ['label' => 'Entry', 'transition' => 'A,B'], 'B' => ['label' => 'Published', 'transition' => ' A , B ']]]); verify($src->getStatus('wid/A'))->notNull(); verify($src->getStatus('wid/B'))->notNull(); verify(count($src->getTransitions('wid/A')))->equals(2); }
/** * @expectedException raoul2000\workflow\base\WorkflowValidationException * @expectedExceptionMessageRegExp #No status definition found# */ public function testStatusNotFoundSuccess() { $src = new WorkflowFileSource(); $src->addWorkflowDefinition('wid', ['initialStatusId' => 'A', 'status' => null]); $this->specify('status is not found', function () use($src) { $status = $src->getStatus('wid/A'); verify('a Workflow instance is returned', $status)->equals(null); }); }
public function testLoadMinimalWorkflowSuccess() { $src = new WorkflowFileSource(); $src->addWorkflowDefinition('wid', ['initialStatusId' => 'A', 'status' => ['A']]); $this->specify('can load workflow', function () use($src) { $w = $src->getWorkflow('wid'); verify('a Workflow instance is returned', get_class($w))->equals('raoul2000\\workflow\\base\\Workflow'); verify('workflow id is consistent', $w->getId())->equals('wid'); }); }
public function testWorkflowAccessorSuccess() { $src = new WorkflowFileSource(); $src->addWorkflowDefinition('wid', ['initialStatusId' => 'A', 'status' => ['A' => ['label' => 'label A', 'transition' => ['B', 'C']], 'B' => [], 'C' => []]]); $w = $src->getWorkflow('wid'); verify_that($w != null); $this->specify('initial status can be obtained through workflow', function () use($w) { expect_that($w->getInitialStatus() instanceof StatusInterface); expect_that($w->getInitialStatus()->getId() == $w->getInitialStatusId()); }); }