/** * 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' => '*****@*****.**'), 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); $this->assertEquals('DynamicTriggeredByUser', $emailMessageRecipients[8]->type); $this->assertEquals(3, $emailMessageRecipients[8]->audienceType); $this->assertTrue($emailMessageRecipients[9] instanceof StaticUserWorkflowEmailMessageRecipientForm); $this->assertEquals('StaticUser', $emailMessageRecipients[9]->type); $this->assertEquals(1, $emailMessageRecipients[9]->audienceType); $this->assertEquals(6, $emailMessageRecipients[9]->userId); $this->assertTrue($emailMessageRecipients[10] instanceof StaticAddressWorkflowEmailMessageRecipientForm); $this->assertEquals('StaticAddress', $emailMessageRecipients[10]->type); $this->assertEquals(2, $emailMessageRecipients[10]->audienceType); $this->assertEquals('somebody', $emailMessageRecipients[10]->toName); $this->assertEquals('*****@*****.**', $emailMessageRecipients[10]->toAddress); $this->assertTrue($emailMessageRecipients[11] instanceof StaticGroupWorkflowEmailMessageRecipientForm); $this->assertEquals('StaticGroup', $emailMessageRecipients[11]->type); $this->assertEquals(3, $emailMessageRecipients[11]->audienceType); $this->assertEquals(7, $emailMessageRecipients[11]->groupId); }
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)); }