public function testUnsubscribeContactFromListUsingWorkflowAction()
 {
     $this->assertEquals(1, static::$marketingList->marketingListMembers->count());
     $this->assertEquals(1, MarketingListMember::getCount());
     //Try to unsubscribe the contact, this doesn't do anything useful as contact is already unsubscribed
     $action = new ActionForWorkflowForm('Contact', Workflow::TYPE_ON_SAVE);
     $action->type = ActionForWorkflowForm::TYPE_UNSUBSCRIBE_FROM_LIST;
     $attributes = array('marketingList' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => static::$marketingList->id));
     $action->setAttributes(array(ActionForWorkflowForm::ACTION_ATTRIBUTES => $attributes));
     $helper = new WorkflowActionProcessingHelper(88, 'some name', $action, static::$contact, Yii::app()->user->userModel);
     $helper->processNonUpdateSelfAction();
     $marketingListId = static::$marketingList->id;
     static::$marketingList->forget();
     static::$marketingList = MarketingList::getById($marketingListId);
     $this->assertEquals(1, static::$marketingList->marketingListMembers->count());
     $this->assertEquals(1, static::$marketingList->marketingListMembers[0]->unsubscribed);
     $this->assertEquals(1, MarketingListMember::getCount());
 }
 /**
  * @depends testCreateRelatedHasOnesInferredNonOwned
  * Similar to a meeting updating its related contacts
  */
 public function testCreateRelatedInferredsHasOneNonOwned()
 {
     $action = new ActionForWorkflowForm('WorkflowModelTestItem5', Workflow::TYPE_ON_SAVE);
     $action->type = ActionForWorkflowForm::TYPE_CREATE_RELATED;
     $action->relation = 'WorkflowModelTestItem__workflowItems__Inferred';
     $action->relatedModelRelation = 'hasOne';
     $attributes = array('name' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'some new model 2'));
     $action->setAttributes(array(ActionForWorkflowForm::ACTION_ATTRIBUTES => $attributes));
     $model = new WorkflowModelTestItem5();
     $relatedModel = new WorkflowModelTestItem();
     $relatedModel->lastName = 'lastName';
     $relatedModel->string = 'string';
     $saved = $relatedModel->save();
     $this->assertTrue($saved);
     $model->workflowItems->add($relatedModel);
     $saved = $model->save();
     $this->assertTrue($saved);
     $this->assertTrue($model->workflowItems[0]->hasOne->id < 0);
     $helper = new WorkflowActionProcessingHelper(88, 'some name', $action, $model, Yii::app()->user->userModel);
     $helper->processNonUpdateSelfAction();
     $this->assertTrue($model->workflowItems[0]->hasOne->id > 0);
     $this->assertEquals('some new model 2', $model->workflowItems[0]->hasOne->name);
 }
 /**
  * Process any workflow actions that are updates to the passed in model during the processing of any
  * ByTimeWorkflowQueue models. @see ByTimeWorkflowInQueueJob.
  * @param Workflow $workflow
  * @param RedBeanModel $model
  * @param User $triggeredByUser
  * @throws FailedToSaveModelException
  */
 public static function processOnByTimeWorkflowInQueueJob(Workflow $workflow, RedBeanModel $model, User $triggeredByUser)
 {
     foreach ($workflow->getActions() as $action) {
         try {
             $helper = new WorkflowActionProcessingHelper((int) $workflow->getId(), $workflow->getName(), $action, $model, $triggeredByUser, false);
             $helper->processUpdateSelfAction();
             $helper->processNonUpdateSelfAction();
         } catch (Exception $e) {
             WorkflowUtil::handleProcessingException($e, 'application.modules.workflows.utils.WorkflowActionsUtil.processOnByTimeWorkflowInQueueJob');
         }
     }
 }