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 testAutoInsertSTATUS() { $this->specify('autoInsert Status : insert the model in provided workflow', function () { $o = new Item00(); $o->attachBehavior('workflow', ['class' => SimpleWorkflowBehavior::className(), 'autoInsert' => 'Item05Workflow', 'defaultWorkflowId' => 'Item04Workflow']); expect('model as status', $o->hasWorkflowStatus())->true(); expect('model status is Item05Workflow/new', $o->getWorkflowStatus()->getId())->equals('Item05Workflow/new'); expect('model status is initial status', $o->statusEquals($o->getWorkflow()->getInitialStatusId()))->true(); }); $this->specify('autoInsert Status : no update if status already set', function () { $o = new Item00(); $o->status = 'Item05Workflow/new'; $o->attachBehavior('workflow', ['class' => SimpleWorkflowBehavior::className(), 'autoInsert' => 'Item04Workflow', 'defaultWorkflowId' => 'Item04Workflow']); expect('model as status', $o->hasWorkflowStatus())->true(); expect('model status is NOT Item04Workflow/A', $o->getWorkflowStatus()->getId())->notEquals('Item04Workflow/A'); expect('model status is Item05Workflow/new', $o->getWorkflowStatus()->getId())->equals('Item05Workflow/new'); expect('model status is initial status', $o->statusEquals($o->getWorkflow()->getInitialStatusId()))->true(); }); }
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"); }