本文整理汇总了PHP中Workflow::setType方法的典型用法代码示例。如果您正苦于以下问题:PHP Workflow::setType方法的具体用法?PHP Workflow::setType怎么用?PHP Workflow::setType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Workflow
的用法示例。
在下文中一共展示了Workflow::setType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: makeWorkflowBySavedWorkflow
/**
* @param SavedWorkflow $savedWorkflow
* @return Workflow
*/
public static function makeWorkflowBySavedWorkflow(SavedWorkflow $savedWorkflow)
{
$workflow = new Workflow();
if ($savedWorkflow->id > 0) {
$workflow->setId((int) $savedWorkflow->id);
}
$workflow->setDescription($savedWorkflow->description);
$workflow->setIsActive((bool) $savedWorkflow->isActive);
$workflow->setModuleClassName($savedWorkflow->moduleClassName);
$workflow->setName($savedWorkflow->name);
$workflow->setOrder((int) $savedWorkflow->order);
$workflow->setType($savedWorkflow->type);
$workflow->setTriggerOn($savedWorkflow->triggerOn);
if ($savedWorkflow->serializedData != null) {
$unserializedData = unserialize($savedWorkflow->serializedData);
if (isset($unserializedData['triggersStructure'])) {
$workflow->setTriggersStructure($unserializedData['triggersStructure']);
}
self::makeComponentFormAndPopulateWorkflowFromData($unserializedData[ComponentForWorkflowForm::TYPE_TRIGGERS], $workflow, 'Trigger');
self::makeActionForWorkflowFormAndPopulateWorkflowFromData($unserializedData[ComponentForWorkflowForm::TYPE_ACTIONS], $workflow);
self::makeEmailMessageForWorkflowFormAndPopulateWorkflowFromData($unserializedData[ComponentForWorkflowForm::TYPE_EMAIL_MESSAGES], $workflow);
if (isset($unserializedData[ComponentForWorkflowForm::TYPE_TIME_TRIGGER])) {
$moduleClassName = $workflow->getModuleClassName();
$timeTrigger = new TimeTriggerForWorkflowForm($moduleClassName, $moduleClassName::getPrimaryModelName(), $workflow->getType());
$timeTrigger->setAttributes($unserializedData[ComponentForWorkflowForm::TYPE_TIME_TRIGGER]);
$workflow->setTimeTrigger($timeTrigger);
$workflow->setTimeTriggerAttribute($timeTrigger->getAttributeIndexOrDerivedType());
}
}
return $workflow;
}
示例2: testRun
public function testRun()
{
//Create workflow
$workflow = new Workflow();
$workflow->setDescription('aDescription');
$workflow->setIsActive(true);
$workflow->setOrder(5);
$workflow->setModuleClassName('WorkflowsTest2Module');
$workflow->setName('myFirstWorkflow');
$workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW_AND_EXISTING);
$workflow->setType(Workflow::TYPE_ON_SAVE);
$workflow->setTriggersStructure('1');
//Add action that is missing required owner
$action = new ActionForWorkflowForm('WorkflowModelTestItem2', Workflow::TYPE_ON_SAVE);
$action->type = ActionForWorkflowForm::TYPE_CREATE;
$action->relation = 'hasMany2';
$attributes = array('string' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'jason'), 'lastName' => 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);
$this->assertEquals(0, count(Notification::getAll()));
$job = new WorkflowValidityCheckJob();
$this->assertTrue($job->run());
$notifications = Notification::getAll();
$this->assertEquals(1, count($notifications));
}
示例3: makeOnSaveWorkflowAndTimeTriggerForDateOrDateTime
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;
}
示例4: testSetAndGetWorkflow
/**
* @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());
}
示例5: testProcessBeforeSaveOnModifiedByUserEquals
/**
* 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);
}
示例6: testEmailMessageValues
/**
* A person assoicated with the triggered model TYPE_DYNAMIC_TRIGGERED_MODEL_USER
* to,cc,bcc
* type of user
* user who created model
* manager of user who created model
* user who last modified model
* manager of user who last modified model
* user who is assigned model
* manager of user who is assigned model
*
* A person assoicated with a related model TYPE_DYNAMIC_TRIGGERED_MODEL_RELATION_USER
* to,cc,bcc
* type of user
* user who created model
* manager of user who created model
* user who last modified model
* manager of user who last modified model
* user who is assigned model
* manager of user who is assigned model
* relation
*
* All users in a specific role TYPE_STATIC_ROLE
* to,cc,bcc
* roleId
*
* User who triggered process TYPE_DYNAMIC_TRIGGERED_BY_USER
* to,cc,bcc
*
* A specific user TYPE_STATIC_USER
* to,cc,bcc
* userId
*
* A specific e-mail address TYPE_STATIC_ADDRESS
* to,cc,bcc
* toName
* toAddress
*
* All users in a specific group TYPE_STATIC_GROUP
* to,cc,bcc
* groupId
*
* @depends testResolveCreateRelatedActionWithValues
*/
public function testEmailMessageValues()
{
$bobby = User::getByUsername('bobby');
$workflow = new Workflow();
$workflow->setType(Workflow::TYPE_ON_SAVE);
$workflow->setModuleClassName('WorkflowsTestModule');
$data = array();
$data[ComponentForWorkflowForm::TYPE_EMAIL_MESSAGES][0]['emailTemplateId'] = '5';
$data[ComponentForWorkflowForm::TYPE_EMAIL_MESSAGES][0]['sendFromType'] = EmailMessageForWorkflowForm::SEND_FROM_TYPE_DEFAULT;
$data[ComponentForWorkflowForm::TYPE_EMAIL_MESSAGES][0]['sendAfterDurationInterval'] = '0';
$data[ComponentForWorkflowForm::TYPE_EMAIL_MESSAGES][0]['sendAfterDurationType'] = TimeDurationUtil::DURATION_TYPE_WEEK;
$data[ComponentForWorkflowForm::TYPE_EMAIL_MESSAGES][0][EmailMessageForWorkflowForm::EMAIL_MESSAGE_RECIPIENTS] = array(array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL_USER, 'audienceType' => EmailMessageRecipient::TYPE_TO, 'dynamicUserType' => DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm::DYNAMIC_USER_TYPE_CREATED_BY_USER), array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL_USER, 'audienceType' => EmailMessageRecipient::TYPE_CC, 'dynamicUserType' => DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm::DYNAMIC_USER_TYPE_MANAGER_OF_CREATED_BY_USER), array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL_USER, 'audienceType' => EmailMessageRecipient::TYPE_BCC, 'dynamicUserType' => DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm::DYNAMIC_USER_TYPE_MODIFIED_BY_USER), array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL_USER, 'audienceType' => EmailMessageRecipient::TYPE_TO, 'dynamicUserType' => DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm::DYNAMIC_USER_TYPE_MANAGER_OF_MODIFIED_BY_USER), array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL_USER, 'audienceType' => EmailMessageRecipient::TYPE_CC, 'dynamicUserType' => DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm::DYNAMIC_USER_TYPE_OWNER), array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL_USER, 'audienceType' => EmailMessageRecipient::TYPE_BCC, 'dynamicUserType' => DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm::DYNAMIC_USER_TYPE_MANAGER_OF_OWNER), array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL_RELATION_USER, 'audienceType' => EmailMessageRecipient::TYPE_TO, 'dynamicUserType' => DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm::DYNAMIC_USER_TYPE_CREATED_BY_USER, 'relation' => 'hasOne'), array('type' => WorkflowEmailMessageRecipientForm::TYPE_STATIC_ROLE, 'audienceType' => EmailMessageRecipient::TYPE_CC, 'roleId' => '5'), array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_BY_USER, 'audienceType' => EmailMessageRecipient::TYPE_BCC), array('type' => WorkflowEmailMessageRecipientForm::TYPE_STATIC_USER, 'audienceType' => EmailMessageRecipient::TYPE_TO, 'userId' => '6'), array('type' => WorkflowEmailMessageRecipientForm::TYPE_STATIC_ADDRESS, 'audienceType' => EmailMessageRecipient::TYPE_CC, 'toName' => 'somebody', 'toAddress' => 'someone@zurmo.com'), array('type' => WorkflowEmailMessageRecipientForm::TYPE_STATIC_GROUP, 'audienceType' => EmailMessageRecipient::TYPE_BCC, 'groupId' => '7'));
DataToWorkflowUtil::resolveEmailMessages($data, $workflow);
$emailMessages = $workflow->getEmailMessages();
$this->assertCount(1, $emailMessages);
$this->assertEquals('5', $emailMessages[0]->emailTemplateId);
$this->assertEquals(EmailMessageForWorkflowForm::SEND_FROM_TYPE_DEFAULT, $emailMessages[0]->sendFromType);
$this->assertEquals(0, $emailMessages[0]->sendAfterDurationInterval);
$this->assertEquals(TimeDurationUtil::DURATION_TYPE_WEEK, $emailMessages[0]->sendAfterDurationType);
$this->assertEquals(12, $emailMessages[0]->getEmailMessageRecipientFormsCount());
$emailMessageRecipients = $emailMessages[0]->getEmailMessageRecipients();
$this->assertTrue($emailMessageRecipients[0] instanceof DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm);
$this->assertEquals('DynamicTriggeredModelUser', $emailMessageRecipients[0]->type);
$this->assertEquals(1, $emailMessageRecipients[0]->audienceType);
$this->assertEquals('CreatedByUser', $emailMessageRecipients[0]->dynamicUserType);
$this->assertTrue($emailMessageRecipients[1] instanceof DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm);
$this->assertEquals('DynamicTriggeredModelUser', $emailMessageRecipients[1]->type);
$this->assertEquals(2, $emailMessageRecipients[1]->audienceType);
$this->assertEquals('ManagerOfCreatedByUser', $emailMessageRecipients[1]->dynamicUserType);
$this->assertTrue($emailMessageRecipients[2] instanceof DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm);
$this->assertEquals('DynamicTriggeredModelUser', $emailMessageRecipients[2]->type);
$this->assertEquals(3, $emailMessageRecipients[2]->audienceType);
$this->assertEquals('ModifiedByUser', $emailMessageRecipients[2]->dynamicUserType);
$this->assertTrue($emailMessageRecipients[3] instanceof DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm);
$this->assertEquals('DynamicTriggeredModelUser', $emailMessageRecipients[3]->type);
$this->assertEquals(1, $emailMessageRecipients[3]->audienceType);
$this->assertEquals('ManagerOfModifiedByUser', $emailMessageRecipients[3]->dynamicUserType);
$this->assertTrue($emailMessageRecipients[4] instanceof DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm);
$this->assertEquals('DynamicTriggeredModelUser', $emailMessageRecipients[4]->type);
$this->assertEquals(2, $emailMessageRecipients[4]->audienceType);
$this->assertEquals('Owner', $emailMessageRecipients[4]->dynamicUserType);
$this->assertTrue($emailMessageRecipients[5] instanceof DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm);
$this->assertEquals('DynamicTriggeredModelUser', $emailMessageRecipients[5]->type);
$this->assertEquals(3, $emailMessageRecipients[5]->audienceType);
$this->assertEquals('ManagerOfOwner', $emailMessageRecipients[5]->dynamicUserType);
$this->assertTrue($emailMessageRecipients[6] instanceof DynamicTriggeredModelRelationUserWorkflowEmailMessageRecipientForm);
$this->assertEquals('DynamicTriggeredModelRelationUser', $emailMessageRecipients[6]->type);
$this->assertEquals(1, $emailMessageRecipients[6]->audienceType);
$this->assertEquals('CreatedByUser', $emailMessageRecipients[6]->dynamicUserType);
$this->assertEquals('hasOne', $emailMessageRecipients[6]->relation);
$this->assertEquals('RelationFilterAll', $emailMessageRecipients[6]->relationFilter);
$this->assertTrue($emailMessageRecipients[7] instanceof StaticRoleWorkflowEmailMessageRecipientForm);
$this->assertEquals('StaticRole', $emailMessageRecipients[7]->type);
$this->assertEquals(2, $emailMessageRecipients[7]->audienceType);
$this->assertEquals(5, $emailMessageRecipients[7]->roleId);
$this->assertTrue($emailMessageRecipients[8] instanceof DynamicTriggeredByUserWorkflowEmailMessageRecipientForm);
//.........这里部分代码省略.........
示例7: resolveSavedWorkflowAndWorkflowByPostData
protected function resolveSavedWorkflowAndWorkflowByPostData(array $postData, &$savedWorkflow, &$workflow, $type, $id = null, $isBeingCopied = false)
{
if ($id == null) {
$this->resolveCanCurrentUserAccessWorkflows();
$savedWorkflow = new SavedWorkflow();
$workflow = new Workflow();
$workflow->setType($type);
} elseif ($isBeingCopied) {
$savedWorkflow = new SavedWorkflow();
$oldWorkflow = SavedWorkflow::getById(intval($id));
ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($oldWorkflow);
ZurmoCopyModelUtil::copy($oldWorkflow, $savedWorkflow);
$workflow = SavedWorkflowToWorkflowAdapter::makeWorkflowBySavedWorkflow($savedWorkflow);
} else {
$savedWorkflow = SavedWorkflow::getById(intval($id));
ControllerSecurityUtil::resolveAccessCanCurrentUserWriteModel($savedWorkflow);
$workflow = SavedWorkflowToWorkflowAdapter::makeWorkflowBySavedWorkflow($savedWorkflow);
}
DataToWorkflowUtil::resolveWorkflowByWizardPostData($workflow, $postData, WorkflowToWizardFormAdapter::getFormClassNameByType($type));
}
示例8: testWorkflowDoesLinkRelatedModelWhenPermissionsIsSetToOwner
public function testWorkflowDoesLinkRelatedModelWhenPermissionsIsSetToOwner()
{
$super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
$contactStates = ContactState::getAll();
$this->assertEquals(0, Contact::getCount());
//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 action
$action = new ActionForWorkflowForm('Account', Workflow::TYPE_ON_SAVE);
$action->type = ActionForWorkflowForm::TYPE_CREATE;
$action->relation = 'contacts';
$attributes = array('lastName' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'smith'), 'firstName' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'john'), 'owner__User' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => Yii::app()->user->userModel->id), 'state' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => $contactStates[0]->id));
$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);
$account = new Account();
$account->name = 'myTestAccount';
$account->owner = $super;
$account->save();
RedBeanModel::forgetAll();
$contacts = Contact::getAll();
$this->assertCount(1, $contacts);
$this->assertEquals('myTestAccount', $contacts[0]->account->name);
$this->assertEquals('john smith', strval($account->contacts[0]));
$this->assertTrue($account->contacts[0]->id > 0);
}
示例9: testProcessOnByTimeWorkflowInQueueJob
/**
* @depends testProcessAfterSave
*/
public function testProcessOnByTimeWorkflowInQueueJob()
{
$model = WorkflowTestHelper::createWorkflowModelTestItem('Green', '514');
$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 action
$action = new ActionForWorkflowForm('WorkflowModelTestItem', Workflow::TYPE_ON_SAVE);
$action->type = ActionForWorkflowForm::TYPE_UPDATE_SELF;
$action->relation = 'hasOne';
$attributes = array('string' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'jason'));
$action->setAttributes(array(ActionForWorkflowForm::ACTION_ATTRIBUTES => $attributes));
$workflow->addAction($action);
WorkflowActionsUtil::processOnByTimeWorkflowInQueueJob($workflow, $model, Yii::app()->user->userModel);
$this->assertEquals('jason', $model->string);
}
示例10: testResolveWorkflowToSavedWorkflow
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);
}
示例11: testMakeEmailMessageForWorkflowFormByQueueModelAndWorkflow
public function testMakeEmailMessageForWorkflowFormByQueueModelAndWorkflow()
{
$model = ContactTestHelper::createContactByNameForOwner('Jason', Yii::app()->user->userModel);
$savedWorkflow = new SavedWorkflow();
$savedWorkflow->name = 'some workflow';
$savedWorkflow->description = 'description';
$savedWorkflow->moduleClassName = 'WorkflowsTestModule';
$savedWorkflow->triggerOn = Workflow::TRIGGER_ON_NEW;
$savedWorkflow->type = 'some type';
$savedWorkflow->order = 1;
$savedWorkflow->serializedData = serialize(array('something'));
$savedWorkflow->isActive = true;
$saved = $savedWorkflow->save();
$this->assertTrue($saved);
$emailMessage = null;
$emailMessage['emailTemplateId'] = 5;
$emailMessage['sendFromType'] = EmailMessageForWorkflowForm::SEND_FROM_TYPE_DEFAULT;
$emailMessage['sendAfterDurationType'] = TimeDurationUtil::DURATION_TYPE_DAY;
$emailMessage['sendAfterDurationInterval'] = '44';
$emailMessage[EmailMessageForWorkflowForm::EMAIL_MESSAGE_RECIPIENTS] = array(array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL, 'audienceType' => EmailMessageRecipient::TYPE_TO));
$workflowMessageInQueue = WorkflowTestHelper::createExpiredWorkflowMessageInQueue($model, $savedWorkflow, serialize(array($emailMessage)));
$workflow = new Workflow();
$workflow->setModuleClassName('WorkflowsTestModule');
$workflow->setType(Workflow::TYPE_ON_SAVE);
$emailMessageForWorkflowForm = WorkflowEmailMessagesUtil::makeEmailMessageForWorkflowFormByQueueModelAndWorkflow($workflowMessageInQueue, $workflow);
$this->assertEquals(5, $emailMessageForWorkflowForm->emailTemplateId);
$this->assertEquals(EmailMessageForWorkflowForm::SEND_FROM_TYPE_DEFAULT, $emailMessageForWorkflowForm->sendFromType);
$this->assertEquals(TimeDurationUtil::DURATION_TYPE_DAY, $emailMessageForWorkflowForm->sendAfterDurationType);
$this->assertEquals(44, $emailMessageForWorkflowForm->sendAfterDurationInterval);
$this->assertEquals(1, count($emailMessageForWorkflowForm->getEmailMessageRecipients()));
}
示例12: testProcessWorkflowForTaskWhenProjectAsARequiredCustomPicklist
/**
* 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());
}
示例13: testGetSelectableContactRelationsDataForEmailMessageRecipientModelRelation
/**
* @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']));
}
开发者ID:maruthisivaprasad,项目名称:zurmo,代码行数:32,代码来源:ModelRelationsAndAttributesToWorkflowAdapterTest.php
示例14: makeOnSaveWorkflowAndTimeTriggerForDateOrDateTime
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;
}
示例15: makeSampleOnSaveWorkflow
protected function makeSampleOnSaveWorkflow()
{
Yii::app()->user->userModel = User::getByUsername('super');
$emailTemplate = new EmailTemplate();
$emailTemplate->type = EmailTemplate::TYPE_WORKFLOW;
$emailTemplate->builtType = EmailTemplate::BUILT_TYPE_BUILDER_TEMPLATE;
$emailTemplate->subject = 'We closed a deal';
$emailTemplate->name = 'We closed a deal - Sample Email Template';
$emailTemplate->textContent = 'Hello!!!
We just closed new deal, please check details: [[MODEL^URL]]
Thanks!';
$emailTemplate->htmlContent = '<p>Hello!!!</p>
<p>We just closed new deal, please check details: [[MODEL^URL]]</p>
<p>Thanks!</p>';
$emailTemplate->modelClassName = 'Opportunity';
$emailTemplate->isDraft = false;
$emailTemplate->save();
$trigger = new TriggerForWorkflowForm('OpportunitiesModule', 'Opportunity', Workflow::TYPE_ON_SAVE);
$trigger->attributeIndexOrDerivedType = 'stage';
$trigger->value = 'Closed Won';
$trigger->operator = OperatorRules::TYPE_BECOMES;
$trigger->relationFilter = TriggerForWorkflowForm::RELATION_FILTER_ANY;
$message = new EmailMessageForWorkflowForm('Opportunity', Workflow::TYPE_ON_SAVE);
$message->sendAfterDurationInterval = 0;
$message->sendAfterDurationType = TimeDurationUtil::DURATION_TYPE_MINUTE;
$message->emailTemplateId = $emailTemplate->id;
$message->sendFromType = EmailMessageForWorkflowForm::SEND_FROM_TYPE_DEFAULT;
$recipients = array(array('type' => WorkflowEmailMessageRecipientForm::TYPE_STATIC_ADDRESS, 'audienceType' => EmailMessageRecipient::TYPE_TO, 'toName' => 'The Sales Team', 'toAddress' => 'SalesTeam@mycompany.com'));
$message->setAttributes(array(EmailMessageForWorkflowForm::EMAIL_MESSAGE_RECIPIENTS => $recipients));
$workflow = new Workflow();
$workflow->setDescription('This will send an email to recipients that you choose when you close a deal!');
$workflow->setIsActive(false);
$workflow->setOrder(2);
$workflow->setModuleClassName('OpportunitiesModule');
$workflow->setName('Closed won Opportunity alert');
$workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW_AND_EXISTING);
$workflow->setType(Workflow::TYPE_ON_SAVE);
$workflow->setTriggersStructure('1');
$workflow->addTrigger($trigger);
$workflow->addEmailMessage($message);
$savedWorkflow = new SavedWorkflow();
SavedWorkflowToWorkflowAdapter::resolveWorkflowToSavedWorkflow($workflow, $savedWorkflow);
$savedWorkflow->save();
}