/** * Utilized during @see ByTimeWorkflowQueueJob to process workflows that are by-time * @param Workflow $workflow * @param RedBeanModel $model * @return bool * @throws NotSupportedException */ public static function areTriggersTrueOnByTimeWorkflowQueueJob(Workflow $workflow, RedBeanModel $model) { if ($workflow->getType() == Workflow::TYPE_BY_TIME) { if (self::resolveTimeTriggerIsTrueBeforeSave($workflow, $model)) { return self::resolveTriggersAreTrueBeforeSave($workflow, $model); } return false; } else { throw new NotSupportedException(); } }
/** * @param Workflow $workflow * @return ByTimeWorkflowStepsAndProgressBarForWizardView| * OnSaveWorkflowStepsAndProgressBarForWizardView * @throws NotSupportedException */ public static function makeStepsAndProgressBarViewFromWorkflow(Workflow $workflow) { $type = $workflow->getType(); if ($type == Workflow::TYPE_BY_TIME) { return new ByTimeWorkflowStepsAndProgressBarForWizardView(); } elseif ($type == Workflow::TYPE_ON_SAVE) { return new OnSaveWorkflowStepsAndProgressBarForWizardView(); } else { throw new NotSupportedException(); } }
/** * @param WorkflowWizardForm $formModel */ protected function setCommonAttributes(WorkflowWizardForm $formModel) { $formModel->id = $this->workflow->getId(); $formModel->isActive = $this->workflow->getIsActive(); $formModel->description = $this->workflow->getDescription(); $formModel->moduleClassName = $this->workflow->getModuleClassName(); $formModel->name = $this->workflow->getName(); $formModel->triggerOn = $this->workflow->getTriggerOn(); $formModel->type = $this->workflow->getType(); $formModel->triggersStructure = $this->workflow->getTriggersStructure(); $formModel->timeTriggerAttribute = $this->workflow->getTimeTriggerAttribute(); if ($this->workflow->isNew()) { $formModel->setIsNew(); } $formModel->timeTrigger = $this->workflow->getTimeTrigger(); $formModel->triggers = $this->workflow->getTriggers(); $formModel->actions = $this->workflow->getActions(); $formModel->emailMessages = $this->workflow->getEmailMessages(); }
/** * @param WorkflowMessageInQueue $workflowMessageInQueue * @param Workflow $workflow * @return EmailMessageForWorkflowForm */ public static function makeEmailMessageForWorkflowFormByQueueModelAndWorkflow(WorkflowMessageInQueue $workflowMessageInQueue, Workflow $workflow) { $moduleClassName = $workflow->getModuleClassName(); $emailMessageForWorkflowForm = new EmailMessageForWorkflowForm($moduleClassName::getPrimaryModelName(), $workflow->getType(), 0); $unserializedData = unserialize($workflowMessageInQueue->serializedData); $emailMessageForWorkflowForm->setAttributes(reset($unserializedData)); return $emailMessageForWorkflowForm; }
/** * @param string $moduleClassName * @param string $modelClassName * @return ModelRelationsAndAttributesToWorkflowAdapter based object */ protected function makeModelRelationsAndAttributesToWorkflowAdapter($moduleClassName, $modelClassName) { assert('is_string($moduleClassName)'); assert('is_string($modelClassName)'); return ModelRelationsAndAttributesToWorkflowAdapter::make($moduleClassName, $modelClassName, $this->workflow->getType()); }
public static function makeOnSaveWorkflowAndTimeTriggerForDateOrDateTime($attributeIndexOrDerivedType, $valueType, $value, $durationInterval = 0, $moduleClassName = 'WorkflowsTestModule', $modelClassName = 'WorkflowModelTestItem', $secondValue = null, $durationSign = TimeDurationUtil::DURATION_SIGN_POSITIVE, $durationType = TimeDurationUtil::DURATION_TYPE_DAY) { assert('is_string($attributeIndexOrDerivedType)'); // Not Coding Standard assert('is_string($valueType)'); // Not Coding Standard assert('is_int($durationInterval)'); // Not Coding Standard assert('is_string($moduleClassName)'); // Not Coding Standard assert('is_string($modelClassName)'); // Not Coding Standard assert('is_string($durationSign)'); // Not Coding Standard assert('is_string($durationType)'); // Not Coding Standard $workflow = new Workflow(); $workflow->setType(Workflow::TYPE_BY_TIME); $workflow->setTriggersStructure('1'); $trigger = new TimeTriggerForWorkflowForm($moduleClassName, $modelClassName, $workflow->getType()); $trigger->attributeIndexOrDerivedType = $attributeIndexOrDerivedType; $trigger->valueType = $valueType; $trigger->value = $value; $trigger->secondValue = $secondValue; $trigger->durationInterval = $durationInterval; $trigger->durationSign = $durationSign; $trigger->durationType = $durationType; $workflow->setTimeTrigger($trigger); return $workflow; }
/** * No need to sanitize for Date and DateTime since those attributes utilize integers for time-based triggers * @param array $data * @param Workflow $workflow */ public static function resolveTimeTrigger($data, Workflow $workflow) { assert('is_array($data)'); if ($workflow->getType() != Workflow::TYPE_BY_TIME) { return; } $workflow->removeTimeTrigger(); $moduleClassName = $workflow->getModuleClassName(); $timeTrigger = new TimeTriggerForWorkflowForm($moduleClassName, $moduleClassName::getPrimaryModelName(), $workflow->getType()); if (null != ($timeTriggerData = ArrayUtil::getArrayValue($data, ComponentForWorkflowForm::TYPE_TIME_TRIGGER))) { $timeTrigger->setAttributes($timeTriggerData); } $workflow->setTimeTrigger($timeTrigger); }
/** * @depends testGetWorkflowSupportedModulesClassNamesCurrentUserHasAccessTo */ public function testSetAndGetWorkflow() { $timeTrigger = new TimeTriggerForWorkflowForm('WorkflowsTestModule', 'WorkflowModelTestItem', Workflow::TYPE_ON_SAVE); $action = new ActionForWorkflowForm('WorkflowModelTestItem', Workflow::TYPE_ON_SAVE); $emailMessage = new EmailMessageForWorkflowForm('WorkflowModelTestItem', Workflow::TYPE_ON_SAVE); $trigger = new TriggerForWorkflowForm('WorkflowsTestModule', 'WorkflowModelTestItem', Workflow::TYPE_ON_SAVE); $workflow = new Workflow(); $workflow->setModuleClassName('SomeModule'); $workflow->setDescription('a description'); $workflow->setTriggersStructure('1 AND 2'); $workflow->setTimeTriggerAttribute('something'); $workflow->setId(5); $workflow->setIsActive(true); $workflow->setOrder(6); $workflow->setName('my workflow rule'); $workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW); $workflow->setType(Workflow::TYPE_ON_SAVE); $workflow->setTimeTrigger($timeTrigger); $workflow->addTrigger($trigger); $workflow->addAction($action); $workflow->addEmailMessage($emailMessage); $this->assertEquals('SomeModule', $workflow->getModuleClassName()); $this->assertEquals('a description', $workflow->getDescription()); $this->assertEquals('1 AND 2', $workflow->getTriggersStructure()); $this->assertEquals('something', $workflow->getTimeTriggerAttribute()); $this->assertEquals(5, $workflow->getId()); $this->assertTrue($workflow->getIsActive()); $this->assertEquals(6, $workflow->getOrder()); $this->assertEquals('my workflow rule', $workflow->getName()); $this->assertEquals(Workflow::TRIGGER_ON_NEW, $workflow->getTriggerOn()); $this->assertEquals(Workflow::TYPE_ON_SAVE, $workflow->getType()); $this->assertEquals($timeTrigger, $workflow->getTimeTrigger()); $actions = $workflow->getActions(); $this->assertEquals($action, $actions[0]); $this->assertCount(1, $actions); $emailMessages = $workflow->getEmailMessages(); $this->assertEquals($emailMessage, $emailMessages[0]); $this->assertCount(1, $emailMessages); $triggers = $workflow->getTriggers(); $this->assertEquals($trigger, $triggers[0]); $this->assertCount(1, $triggers); $workflow->removeAllActions(); $actions = $workflow->getActions(); $this->assertCount(0, $actions); $workflow->removeAllEmailMessages(); $emailMessages = $workflow->getEmailMessages(); $this->assertCount(0, $emailMessages); $workflow->removeAllTriggers(); $triggers = $workflow->getTriggers(); $this->assertCount(0, $triggers); $workflow->removeTimeTrigger(); $this->assertNull($workflow->getTimeTrigger()); }
/** * A test to show that the modifiedByUser works ok as a trigger with 'equals' on a newly created model. * @see testProcessBeforeSaveOnCreatedByUserEquals */ public function testProcessBeforeSaveOnModifiedByUserEquals() { Yii::app()->user->userModel = User::getByUsername('super'); //Create workflow $workflow = new Workflow(); $workflow->setDescription('aDescription'); $workflow->setIsActive(true); $workflow->setOrder(5); $workflow->setModuleClassName('AccountsModule'); $workflow->setName('myFirstWorkflow'); $workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW_AND_EXISTING); $workflow->setType(Workflow::TYPE_ON_SAVE); $workflow->setTriggersStructure('1'); //Add trigger $trigger = new TriggerForWorkflowForm('AccountsTestModule', 'Account', $workflow->getType()); $trigger->attributeIndexOrDerivedType = 'modifiedByUser'; $trigger->value = Yii::app()->user->userModel->id; $trigger->operator = 'equals'; $workflow->addTrigger($trigger); //Add action $action = new ActionForWorkflowForm('Account', Workflow::TYPE_ON_SAVE); $action->type = ActionForWorkflowForm::TYPE_UPDATE_SELF; $attributes = array('name' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'jason')); $action->setAttributes(array(ActionForWorkflowForm::ACTION_ATTRIBUTES => $attributes)); $workflow->addAction($action); //Create the saved Workflow $savedWorkflow = new SavedWorkflow(); SavedWorkflowToWorkflowAdapter::resolveWorkflowToSavedWorkflow($workflow, $savedWorkflow); $saved = $savedWorkflow->save(); $this->assertTrue($saved); //Confirm that the workflow processes and the attribute gets updated $model = new Account(); $model->name = 'aValue'; $this->assertTrue($model->save()); $this->assertEquals('jason', $model->name); }
/** * @param array $componentFormsData * @param Workflow $workflow */ protected static function makeEmailMessageForWorkflowFormAndPopulateWorkflowFromData($componentFormsData, Workflow $workflow) { assert('is_array($componentFormsData)'); $moduleClassName = $workflow->getModuleClassName(); $rowKey = 0; foreach ($componentFormsData as $componentFormData) { $component = new EmailMessageForWorkflowForm($moduleClassName::getPrimaryModelName(), $workflow->getType(), $rowKey); $component->setAttributes($componentFormData); $workflow->addEmailMessage($component); $rowKey++; } }
/** * @depends testResolveAfterSaveByModel */ public function testResolveAfterSaveByModelForByTime() { //Create workflow $workflow = new Workflow(); $workflow->setDescription('aDescription'); $workflow->setIsActive(true); $workflow->setOrder(5); $workflow->setModuleClassName('WorkflowsTestModule'); $workflow->setName('myFirstWorkflow'); $workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW_AND_EXISTING); $workflow->setType(Workflow::TYPE_BY_TIME); $workflow->setTriggersStructure('1'); $workflow->setIsActive(true); //Add time trigger $trigger = new TimeTriggerForWorkflowForm('WorkflowsTestModule', 'WorkflowModelTestItem', $workflow->getType()); $trigger->attributeIndexOrDerivedType = 'date'; $trigger->durationSeconds = '500'; $trigger->valueType = 'Is Time For'; $workflow->setTimeTrigger($trigger); //Create the saved Workflow $savedWorkflow = new SavedWorkflow(); SavedWorkflowToWorkflowAdapter::resolveWorkflowToSavedWorkflow($workflow, $savedWorkflow); $saved = $savedWorkflow->save(); $this->assertTrue($saved); $workflow->setId($savedWorkflow->id); //set Id back. $model = new WorkflowModelTestItem(); $model->lastName = 'something'; $model->string = 'aValue'; $model->date = '2013-03-03'; $saved = $model->save(); $this->assertTrue($saved); $model->addWorkflowToProcessAfterSave($workflow); $this->assertEquals(0, count(ByTimeWorkflowInQueue::getAll())); SavedWorkflowsUtil::resolveAfterSaveByModel($model, Yii::app()->user->userModel); $this->assertEquals(1, count(ByTimeWorkflowInQueue::getAll())); }
/** * @depends testProcessBeforeSave */ public function testProcessAfterSave() { //Save everyone group $group = Group::getByName(Group::EVERYONE_GROUP_NAME); $this->assertTrue($group->save()); //Create workflow $workflow = new Workflow(); $workflow->setDescription('aDescription'); $workflow->setIsActive(true); $workflow->setOrder(5); $workflow->setModuleClassName('WorkflowsTestModule'); $workflow->setName('myFirstWorkflow'); $workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW_AND_EXISTING); $workflow->setType(Workflow::TYPE_ON_SAVE); $workflow->setTriggersStructure('1'); $workflow->setIsActive(true); //Add trigger $trigger = new TriggerForWorkflowForm('WorkflowsTestModule', 'WorkflowModelTestItem', $workflow->getType()); $trigger->attributeIndexOrDerivedType = 'string'; $trigger->value = 'aValue'; $trigger->operator = 'equals'; $workflow->addTrigger($trigger); //Add action $action = new ActionForWorkflowForm('WorkflowModelTestItem', Workflow::TYPE_ON_SAVE); $action->type = ActionForWorkflowForm::TYPE_CREATE; $action->relation = 'hasOne'; $attributes = array('name' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'jason'), 'permissions' => array('shouldSetValue' => '1', 'type' => ExplicitReadWriteModelPermissionsWorkflowActionAttributeForm::TYPE_DYNAMIC_EVERYONE_GROUP)); $action->setAttributes(array(ActionForWorkflowForm::ACTION_ATTRIBUTES => $attributes)); $workflow->addAction($action); //Create the saved Workflow $savedWorkflow = new SavedWorkflow(); SavedWorkflowToWorkflowAdapter::resolveWorkflowToSavedWorkflow($workflow, $savedWorkflow); $saved = $savedWorkflow->save(); $this->assertTrue($saved); $model = new WorkflowModelTestItem(); $model->string = 'aValue'; $saved = $savedWorkflow->save(); $this->assertTrue($saved); $this->assertEquals(0, WorkflowModelTestItem2::getCount()); WorkflowActionsUtil::processAfterSave($workflow, $model, Yii::app()->user->userModel); $workflowModelTestItem2s = WorkflowModelTestItem2::getAll(); $this->assertEquals(1, count($workflowModelTestItem2s)); //Confirm permissions are on the everyone group $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($workflowModelTestItem2s[0]); $this->assertEquals(1, $explicitReadWriteModelPermissions->getReadWritePermitablesCount()); $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables(); $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME); $this->assertTrue(isset($readWritePermitables[$everyoneGroup->getClassId('Permitable')])); }
public function testResolveWorkflowToSavedWorkflow() { $workflow = new Workflow(); $workflow->setDescription('aDescription'); $workflow->setIsActive(true); $workflow->setOrder(5); $workflow->setModuleClassName('WorkflowsTestModule'); $workflow->setName('myFirstWorkflow'); $workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW); $workflow->setType(Workflow::TYPE_ON_SAVE); $workflow->setTriggersStructure('1 and 2 or 3 or 4'); $trigger = new TriggerForWorkflowForm('WorkflowsTestModule', 'WorkflowModelTestItem', $workflow->getType()); $trigger->attributeIndexOrDerivedType = 'string'; $trigger->value = 'aValue'; $trigger->operator = 'equals'; $workflow->addTrigger($trigger); $trigger = new TriggerForWorkflowForm('WorkflowsTestModule', 'WorkflowModelTestItem', $workflow->getType()); $trigger->attributeIndexOrDerivedType = 'currencyValue'; $trigger->value = 'aValue'; $trigger->secondValue = 'bValue'; $trigger->operator = 'between'; $trigger->currencyIdForValue = '4'; $workflow->addTrigger($trigger); $trigger = new TriggerForWorkflowForm('WorkflowsTestModule', 'WorkflowModelTestItem', $workflow->getType()); $trigger->attributeIndexOrDerivedType = 'owner__User'; $trigger->value = 'aValue'; $trigger->stringifiedModelForValue = 'someName'; $workflow->addTrigger($trigger); $trigger = new TriggerForWorkflowForm('WorkflowsTestModule', 'WorkflowModelTestItem', $workflow->getType()); $trigger->attributeIndexOrDerivedType = 'createdDateTime'; $trigger->value = 'aValue'; $trigger->secondValue = 'bValue'; $trigger->operator = null; $trigger->currencyIdForValue = null; $trigger->valueType = 'Between'; $workflow->addTrigger($trigger); $trigger = new TimeTriggerForWorkflowForm('WorkflowsTestModule', 'WorkflowModelTestItem', $workflow->getType()); $trigger->attributeIndexOrDerivedType = 'date'; $trigger->durationInterval = 500; $trigger->valueType = 'Is Time For'; $workflow->setTimeTrigger($trigger); $action = new ActionForWorkflowForm('WorkflowModelTestItem', Workflow::TYPE_ON_SAVE); $action->type = ActionForWorkflowForm::TYPE_UPDATE_SELF; $attributes = array('string' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'jason')); $action->setAttributes(array(ActionForWorkflowForm::ACTION_ATTRIBUTES => $attributes)); $workflow->addAction($action); $message = new EmailMessageForWorkflowForm('WorkflowModelTestItem', Workflow::TYPE_ON_SAVE); $message->sendAfterDurationInterval = 86400; $message->sendAfterDurationType = TimeDurationUtil::DURATION_TYPE_WEEK; $message->emailTemplateId = 5; $message->sendFromType = EmailMessageForWorkflowForm::SEND_FROM_TYPE_DEFAULT; $recipients = array(array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL_USER, 'audienceType' => EmailMessageRecipient::TYPE_TO, 'dynamicUserType' => DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm::DYNAMIC_USER_TYPE_CREATED_BY_USER)); $message->setAttributes(array(EmailMessageForWorkflowForm::EMAIL_MESSAGE_RECIPIENTS => $recipients)); $workflow->addEmailMessage($message); $savedWorkflow = new SavedWorkflow(); $this->assertNull($savedWorkflow->serializedData); SavedWorkflowToWorkflowAdapter::resolveWorkflowToSavedWorkflow($workflow, $savedWorkflow); $this->assertEquals('WorkflowsTestModule', $savedWorkflow->moduleClassName); $this->assertEquals('1', $savedWorkflow->isActive); $this->assertEquals('myFirstWorkflow', $savedWorkflow->name); $this->assertEquals('aDescription', $savedWorkflow->description); $this->assertEquals(5, $savedWorkflow->order); $this->assertEquals(Workflow::TRIGGER_ON_NEW, $savedWorkflow->triggerOn); $this->assertEquals(Workflow::TYPE_ON_SAVE, $savedWorkflow->type); $this->assertEquals('1 and 2 or 3 or 4', $workflow->getTriggersStructure()); $compareData = array('Triggers' => array(array('currencyIdForValue' => null, 'value' => 'aValue', 'secondValue' => null, 'stringifiedModelForValue' => null, 'valueType' => null, 'attributeIndexOrDerivedType' => 'string', 'operator' => 'equals', 'relationFilter' => TriggerForWorkflowForm::RELATION_FILTER_ANY), array('currencyIdForValue' => '4', 'value' => 'aValue', 'secondValue' => 'bValue', 'stringifiedModelForValue' => null, 'valueType' => null, 'attributeIndexOrDerivedType' => 'currencyValue', 'operator' => 'between', 'relationFilter' => TriggerForWorkflowForm::RELATION_FILTER_ANY), array('currencyIdForValue' => null, 'value' => 'aValue', 'secondValue' => null, 'stringifiedModelForValue' => 'someName', 'valueType' => null, 'attributeIndexOrDerivedType' => 'owner__User', 'operator' => null, 'relationFilter' => TriggerForWorkflowForm::RELATION_FILTER_ANY), array('value' => 'aValue', 'secondValue' => 'bValue', 'stringifiedModelForValue' => null, 'valueType' => 'Between', 'attributeIndexOrDerivedType' => 'createdDateTime', 'operator' => null, 'currencyIdForValue' => null, 'relationFilter' => TriggerForWorkflowForm::RELATION_FILTER_ANY))); $compareData['Actions'] = array(array('type' => ActionForWorkflowForm::TYPE_UPDATE_SELF, 'relation' => null, 'relationFilter' => ActionForWorkflowForm::RELATION_FILTER_ALL, 'relatedModelRelation' => null, 'ActionAttributes' => array('string' => array('type' => 'Static', 'value' => 'jason', 'shouldSetValue' => 1)))); $compareData['EmailMessages'] = array(array('emailTemplateId' => 5, 'sendAfterDurationInterval' => 86400, 'sendAfterDurationType' => TimeDurationUtil::DURATION_TYPE_WEEK, 'sendFromType' => 'Default', 'sendFromName' => null, 'sendFromAddress' => null, 'EmailMessageRecipients' => array(array('dynamicUserType' => 'CreatedByUser', 'type' => 'DynamicTriggeredModelUser', 'audienceType' => 1)))); $compareData['TimeTrigger'] = array('durationInterval' => 500, 'durationSign' => TimeDurationUtil::DURATION_SIGN_POSITIVE, 'durationType' => TimeDurationUtil::DURATION_TYPE_DAY, 'currencyIdForValue' => null, 'value' => null, 'secondValue' => null, 'valueType' => 'Is Time For', 'relationFilter' => 'RelationFilterAny', 'attributeIndexOrDerivedType' => 'date', 'operator' => null); $unserializedData = unserialize($savedWorkflow->serializedData); $this->assertEquals($compareData['Triggers'], $unserializedData['Triggers']); $this->assertEquals($compareData['Actions'], $unserializedData['Actions']); $this->assertEquals($compareData['EmailMessages'], $unserializedData['EmailMessages']); $this->assertEquals($compareData['TimeTrigger'], $unserializedData['TimeTrigger']); $this->assertEquals('1 and 2 or 3 or 4', $unserializedData['triggersStructure']); $saved = $savedWorkflow->save(); $this->assertTrue($saved); }
/** * Tests that a bug involving creating a required custom picklist on projects causes the workflow * to break when creating a task */ public function testProcessWorkflowForTaskWhenProjectAsARequiredCustomPicklist() { Yii::app()->user->userModel = User::getByUsername('super'); //Create a required picklist for projects ModulesSearchWithDataProviderTestHelper::createDropDownAttribute(new Project(), 'pick', true); //Create workflow $workflow = new Workflow(); $workflow->setDescription('aDescription'); $workflow->setIsActive(true); $workflow->setOrder(5); $workflow->setModuleClassName('TasksModule'); $workflow->setName('myFirstWorkflow'); $workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW_AND_EXISTING); $workflow->setType(Workflow::TYPE_BY_TIME); $workflow->setTriggersStructure('1'); //Add trigger $trigger = new TimeTriggerForWorkflowForm('TasksModule', 'Task', $workflow->getType()); $trigger->attributeIndexOrDerivedType = 'dueDateTime'; $trigger->valueType = MixedDateTypesSearchFormAttributeMappingRules::TYPE_IS_TIME_FOR; $trigger->durationInterval = 5; $trigger->durationType = TimeDurationUtil::DURATION_TYPE_MONTH; $trigger->durationSign = TimeDurationUtil::DURATION_SIGN_NEGATIVE; $workflow->setTimeTrigger($trigger); //Create the saved Workflow $savedWorkflow = new SavedWorkflow(); SavedWorkflowToWorkflowAdapter::resolveWorkflowToSavedWorkflow($workflow, $savedWorkflow); $saved = $savedWorkflow->save(); $this->assertTrue($saved); //Confirm that the workflow processes $model = new Task(); $model->name = 'aTask'; $model->dueDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()); $this->assertTrue($model->save()); }
/** * @depends testGetSelectableRelationsDataForEmailMessageRecipientModelRelation */ public function testGetSelectableContactRelationsDataForEmailMessageRecipientModelRelation() { $model = new Account(); $rules = new AccountsWorkflowRules(); $workflow = new Workflow(); $workflow->setType(Workflow::TYPE_ON_SAVE); $workflow->setModuleClassName('AccountsModule'); $adapter = new ModelRelationsAndAttributesToWorkflowAdapter($model, $rules, $workflow->getType()); $relations = $adapter->getSelectableContactRelationsDataForEmailMessageRecipientModelRelation(); $this->assertEquals(1, count($relations)); $this->assertTrue(isset($relations['contacts'])); $model = new Contact(); $rules = new ContactsWorkflowRules(); $workflow = new Workflow(); $workflow->setType(Workflow::TYPE_ON_SAVE); $workflow->setModuleClassName('ContactsModule'); $adapter = new ModelRelationsAndAttributesToWorkflowAdapter($model, $rules, $workflow->getType()); $relations = $adapter->getSelectableContactRelationsDataForEmailMessageRecipientModelRelation(); $this->assertEquals(0, count($relations)); $model = new Task(); $rules = new TasksWorkflowRules(); $workflow = new Workflow(); $workflow->setType(Workflow::TYPE_ON_SAVE); $workflow->setModuleClassName('TasksModule'); $adapter = new ModelRelationsAndAttributesToWorkflowAdapter($model, $rules, $workflow->getType()); $relations = $adapter->getSelectableContactRelationsDataForEmailMessageRecipientModelRelation(); $this->assertEquals(1, count($relations)); $this->assertTrue(isset($relations['Contact__activityItems__Inferred'])); }
public static function makeOnSaveWorkflowAndTimeTriggerForDateOrDateTime($attributeIndexOrDerivedType, $valueType, $value, $durationSeconds = 0, $moduleClassName = 'WorkflowsTestModule', $modelClassName = 'WorkflowModelTestItem', $secondValue = null) { assert('is_string($attributeIndexOrDerivedType)'); // Not Coding Standard assert('is_string($valueType)'); // Not Coding Standard assert('is_int($durationSeconds)'); // Not Coding Standard assert('is_string($moduleClassName)'); // Not Coding Standard assert('is_string($modelClassName)'); // Not Coding Standard $workflow = new Workflow(); $workflow->setType(Workflow::TYPE_BY_TIME); $workflow->setTriggersStructure('1'); $trigger = new TimeTriggerForWorkflowForm($moduleClassName, $modelClassName, $workflow->getType()); $trigger->attributeIndexOrDerivedType = $attributeIndexOrDerivedType; $trigger->valueType = $valueType; $trigger->value = $value; $trigger->secondValue = $secondValue; $trigger->durationSeconds = $durationSeconds; $workflow->setTimeTrigger($trigger); return $workflow; }