public function testAttachFails3() { $this->specify('the status attribute must exist in the owner model', function () { $model = new Item01(); $model->detachBehavior('workflow'); $model->attachBehavior('workflow', ['class' => SimpleWorkflowBehavior::className(), 'statusAttribute' => 'not_found']); }, ['throws' => 'yii\\base\\InvalidConfigException']); }
public function testConfiguredWorkflowId() { $this->specify('use the configured workflow Id', function () { $model = new Item01(); $model->attachBehavior('workflow', ['class' => SimpleWorkflowBehavior::className(), 'defaultWorkflowId' => 'myWorkflow']); expect('model should have workflow id set to "myWorkflow"', $model->getDefaultWorkflowId() == 'myWorkflow')->true(); }); }
protected function setup() { parent::setUp(); $this->eventsBefore = []; $this->eventsAfter = []; Yii::$app->set('workflowSource', ['class' => 'raoul2000\\workflow\\source\\file\\WorkflowFileSource', 'definitionLoader' => ['class' => 'raoul2000\\workflow\\source\\file\\PhpClassLoader', 'namespace' => 'tests\\codeception\\unit\\models']]); Yii::$app->set('eventSequence', ['class' => 'raoul2000\\workflow\\events\\ReducedEventSequence']); $this->model = new Item04(); $this->model->attachBehavior('workflow', ['class' => SimpleWorkflowBehavior::className()]); }
public function testGetNextStatusFails() { $item = new Item04(); $item->detachBehavior('workflow'); $item->attachBehavior('workflowForTest', ['class' => SimpleWorkflowBehavior::className(), 'defaultWorkflowId' => 'INVALID_ID']); $this->specify('getNextStatus throws exception if default workflow Id is invalid', function () use($item) { $this->setExpectedException('raoul2000\\workflow\\base\\WorkflowException', "Invalid workflow Id : 'INVALID_ID'"); $item->getNextStatuses(); }); }
public function testConvertionOnLeaveWorkflow() { $item = new Item04(); $item->attachBehavior('workflow', ['class' => SimpleWorkflowBehavior::className(), 'statusConverter' => 'converter']); $this->assertEquals(null, $item->status); $this->assertEquals('Item04Workflow/B', $item->getWorkflowStatus()->getId()); $this->specify('convertion is done when leaving workflow', function () use($item) { $item->sendToStatus(null); expect('item to not be in a workflow', $item->getWorkflow())->equals(null); expect('item to not have status', $item->hasWorkflowStatus())->false(); expect('status attribut to be converted into 55', $item->status)->equals(55); }); }
public function testNoPropagateErrorToModel() { // prepare item instance $item = new Item00(); $item->attachBehavior('workflow', ['class' => SimpleWorkflowBehavior::className(), 'defaultWorkflowId' => 'Item04Workflow', 'propagateErrorsToModel' => false]); $item->on(WorkflowEvent::beforeEnterStatus('Item04Workflow/B'), [$this, 'invalidateEvent']); $item->sendToStatus('Item04Workflow/A'); verify('item is in status A', $item->getWorkflowStatus()->getId())->equals('Item04Workflow/A'); verify('item has no error', $item->hasErrors())->false(); // send to B $item->sendToStatus('B'); expect('status is still A', $item->getWorkflowStatus()->getId())->equals('Item04Workflow/A'); expect('item has no error', $item->hasErrors())->false(); }
public function testInitStatusAfterFindSuccess() { $this->specify('status initialisation when reading model from db (after find)', function () { $model = new Item01(); $model->detachBehavior('workflow'); $model->id = 1; $model->name = 'name'; $model->status = 'Workflow1/B'; $model->save(false); $model = Item01::findOne(1); $model->attachBehavior('workflow', ['class' => SimpleWorkflowBehavior::className(), 'defaultWorkflowId' => 'Workflow1']); verify('current model status is "B"', $model->getWorkflowStatus()->getId())->equals('Workflow1/B'); }); }
public function testDefaultEventNotFired2() { // Default event is NOT fired when fireDefaultEvent is FALSE $this->model = new Item04(); $this->model->attachBehavior('workflow', ['class' => SimpleWorkflowBehavior::className(), 'eventSequence' => null, 'fireDefaultEvent' => false]); $this->model->on(SimpleWorkflowBehavior::EVENT_BEFORE_CHANGE_STATUS, function ($event) { $this->eventsBefore[] = $event; }); $this->model->on(SimpleWorkflowBehavior::EVENT_AFTER_CHANGE_STATUS, function ($event) { $this->eventsAfter[] = $event; }); $this->model->enterWorkflow(); verify('current status is set', $this->model->hasWorkflowStatus())->true(); expect('event handlers have NOT been called (before)', count($this->eventsBefore))->equals(0); expect('event handlers have NOT been called (after)', count($this->eventsAfter))->equals(0); }
public function testStopOnFirstInvalidEventFalse() { // prepare item instance $item = new Item00(); $item->attachBehavior('workflowBehavior', ['class' => SimpleWorkflowBehavior::className(), 'defaultWorkflowId' => 'Item04Workflow', 'propagateErrorsToModel' => true, 'stopOnFirstInvalidEvent' => false]); $item->on(WorkflowEvent::beforeLeaveStatus('Item04Workflow/A'), [$this, 'invalidateEvent1']); $item->on(WorkflowEvent::beforeEnterStatus('Item04Workflow/B'), [$this, 'invalidateEvent2']); verify('stopOnFirstInvalidEvent is true', $item->stopOnFirstInvalidEvent)->false(); $item->sendToStatus('Item04Workflow/A'); verify('item is in status A', $item->getWorkflowStatus()->getId())->equals('Item04Workflow/A'); verify('item has no error', $item->hasErrors())->false(); // send to B $item->sendToStatus('B'); expect('status is still A', $item->getWorkflowStatus()->getId())->equals('Item04Workflow/A'); expect('item has error', $item->hasErrors())->true(); expect('1 error message is set for attribute "status"', count($item->getErrors('status')))->equals(2); $errorMessages = $item->getErrors('status'); expect('First error message is "err_message_1" ', $errorMessages[0])->equals("err_message_1"); expect('Second error message is "err_message_2" ', $errorMessages[1])->equals("err_message_2"); }
public function behaviors() { return ['workflow' => ['class' => SimpleWorkflowBehavior::className()]]; }
/** * (non-PHPdoc) * @see \yii\base\Component::behaviors() */ public function behaviors() { return ['w1' => ['class' => \raoul2000\workflow\base\SimpleWorkflowBehavior::className(), 'defaultWorkflowId' => 'Item08Workflow1'], 'w2' => ['class' => \raoul2000\workflow\base\SimpleWorkflowBehavior::className(), 'statusAttribute' => 'status_ex', 'defaultWorkflowId' => 'Item08Workflow2']]; }
/** * @expectedException raoul2000\workflow\base\WorkflowException * @expectedExceptionMessage failed to load workflow definition : Class tests\codeception\unit\models\NOTFOUND does not exist */ public function testAutoInsertFails2() { $o = new Item00(); $o->attachBehavior('workflow', ['class' => SimpleWorkflowBehavior::className(), 'autoInsert' => 'NOTFOUND', 'defaultWorkflowId' => 'Item04Workflow']); }
public function behaviors() { return ['workflow' => ['class' => SimpleWorkflowBehavior::className(), 'statusAttribute' => 'statusAlias', 'statusAccessor' => 'status_accessor']]; }