The task of loading the workflow definition file, and turns it content into a normalized array, is delegated
to a WorkflowDefinitionLoader instance. The definition loader can be initialized through the [[definitionLoader]]
attribute.
public function testConstructSuccess() { $this->specify('Workflow source construct default', function () { $src = new WorkflowFileSource(); expect($src->getClassMapByType(WorkflowFileSource::TYPE_WORKFLOW))->equals('raoul2000\\workflow\\base\\Workflow'); expect($src->getClassMapByType(WorkflowFileSource::TYPE_STATUS))->equals('raoul2000\\workflow\\base\\Status'); expect($src->getClassMapByType(WorkflowFileSource::TYPE_TRANSITION))->equals('raoul2000\\workflow\\base\\Transition'); expect($src->getDefinitionCache())->equals(null); expect($src->getDefinitionLoader())->notNull(); }); $this->specify('Workflow source construct with class map', function () { $src = new WorkflowFileSource(['classMap' => [WorkflowFileSource::TYPE_WORKFLOW => 'my\\namespace\\Workflow', WorkflowFileSource::TYPE_STATUS => 'my\\namespace\\Status', WorkflowFileSource::TYPE_TRANSITION => 'my\\namespace\\Transition']]); expect($src->getClassMapByType(WorkflowFileSource::TYPE_WORKFLOW))->equals('my\\namespace\\Workflow'); expect($src->getClassMapByType(WorkflowFileSource::TYPE_STATUS))->equals('my\\namespace\\Status'); expect($src->getClassMapByType(WorkflowFileSource::TYPE_TRANSITION))->equals('my\\namespace\\Transition'); }); $this->specify('Workflow source construct with cache', function () { // initialized by array $src = new WorkflowFileSource(['definitionCache' => ['class' => 'yii\\caching\\FileCache']]); expect_that($src->getDefinitionCache() instanceof yii\caching\FileCache); // initialized by component ID Yii::$app->set('myCache', ['class' => 'yii\\caching\\FileCache']); $src = new WorkflowFileSource(['definitionCache' => 'myCache']); expect_that($src->getDefinitionCache() instanceof yii\caching\FileCache); // initialized by object $cache = Yii::$app->get('myCache'); Yii::$app->set('myCache', ['class' => 'yii\\caching\\FileCache']); $src = new WorkflowFileSource(['definitionCache' => $cache]); expect_that($src->getDefinitionCache() instanceof yii\caching\FileCache); }); }
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 testClassMapStatus() { $this->specify('Replace default status class with custom one', function () { $src = new WorkflowFileSource(['definitionLoader' => ['class' => 'raoul2000\\workflow\\source\\file\\PhpClassLoader', 'namespace' => 'tests\\codeception\\unit\\models'], 'classMap' => [WorkflowFileSource::TYPE_STATUS => 'tests\\codeception\\unit\\models\\MyStatus']]); verify($src->getClassMapByType(WorkflowFileSource::TYPE_WORKFLOW))->equals('raoul2000\\workflow\\base\\Workflow'); verify($src->getClassMapByType(WorkflowFileSource::TYPE_STATUS))->equals('tests\\codeception\\unit\\models\\MyStatus'); verify($src->getClassMapByType(WorkflowFileSource::TYPE_TRANSITION))->equals('raoul2000\\workflow\\base\\Transition'); $status = $src->getStatus('Item04Workflow/A'); expect(get_class($status))->equals('tests\\codeception\\unit\\models\\MyStatus'); }); }
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()); }); }
public function testCreateWithSourceSuccess() { $this->specify('create a status instance with source component', function () { $src = Yii::createObject(['class' => WorkflowFileSource::className()]); $start = new Status(['id' => 'draft', 'workflowId' => 'workflow1', 'source' => $src]); verify('a source component is available', $start->getSource())->notNull(); }); }