Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
SavedWorkflowToWorkflowAdapterTest.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
38  {
39  public function testResolveWorkflowToSavedWorkflow()
40  {
41  $workflow = new Workflow();
42  $workflow->setDescription ('aDescription');
43  $workflow->setIsActive (true);
44  $workflow->setOrder (5);
45  $workflow->setModuleClassName('WorkflowsTestModule');
46  $workflow->setName ('myFirstWorkflow');
47  $workflow->setTriggerOn (Workflow::TRIGGER_ON_NEW);
48  $workflow->setType (Workflow::TYPE_ON_SAVE);
49  $workflow->setTriggersStructure('1 and 2 or 3 or 4 or 5');
50 
51  $trigger = new TriggerForWorkflowForm('WorkflowsTestModule', 'WorkflowModelTestItem', $workflow->getType());
52  $trigger->attributeIndexOrDerivedType = 'string';
53  $trigger->value = 'aValue';
54  $trigger->operator = 'equals';
55  $workflow->addTrigger($trigger);
56 
57  $trigger = new TriggerForWorkflowForm('WorkflowsTestModule', 'WorkflowModelTestItem', $workflow->getType());
58  $trigger->attributeIndexOrDerivedType = 'currencyValue';
59  $trigger->value = 'aValue';
60  $trigger->secondValue = 'bValue';
61  $trigger->operator = 'between';
62  $trigger->currencyIdForValue = '4';
63  $workflow->addTrigger($trigger);
64 
65  $trigger = new TriggerForWorkflowForm('WorkflowsTestModule', 'WorkflowModelTestItem', $workflow->getType());
66  $trigger->attributeIndexOrDerivedType = 'owner__User';
67  $trigger->value = 'aValue';
68  $trigger->stringifiedModelForValue = 'someName';
69  $workflow->addTrigger($trigger);
70 
71  $trigger = new TriggerForWorkflowForm('WorkflowsTestModule', 'WorkflowModelTestItem', $workflow->getType());
72  $trigger->attributeIndexOrDerivedType = 'createdDateTime';
73  $trigger->value = 'aValue';
74  $trigger->secondValue = 'bValue';
75  $trigger->operator = null;
76  $trigger->currencyIdForValue = null;
77  $trigger->valueType = 'Between';
78  $workflow->addTrigger($trigger);
79 
80  $trigger = new TriggerForWorkflowForm('WorkflowsTestModule', 'WorkflowModelTestItem', $workflow->getType());
81  $trigger->attributeIndexOrDerivedType = 'createdDateTime';
82  $trigger->value = null;
83  $trigger->secondValue = null;
84  $trigger->thirdValueDurationInterval = 5;
85  $trigger->thirdValueDurationType = TimeDurationUtil::DURATION_TYPE_DAY;
86  $trigger->operator = null;
87  $trigger->currencyIdForValue = null;
88  $trigger->valueType = 'At Least X After Triggered Date';
89  $workflow->addTrigger($trigger);
90 
91  $trigger = new TimeTriggerForWorkflowForm('WorkflowsTestModule', 'WorkflowModelTestItem', $workflow->getType());
92  $trigger->attributeIndexOrDerivedType = 'date';
93  $trigger->durationInterval = 500;
94  $trigger->valueType = 'Is Time For';
95  $workflow->setTimeTrigger($trigger);
96 
97  $action = new ActionForWorkflowForm('WorkflowModelTestItem', Workflow::TYPE_ON_SAVE);
99  $attributes = array(
100  'string' => array('shouldSetValue' => '1',
101  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
102  'value' => 'jason'));
103  $action->setAttributes(array(ActionForWorkflowForm::ACTION_ATTRIBUTES => $attributes));
104  $workflow->addAction($action);
105 
106  $message = new EmailMessageForWorkflowForm('WorkflowModelTestItem', Workflow::TYPE_ON_SAVE);
107  $message->sendAfterDurationInterval = 86400;
108  $message->sendAfterDurationType = TimeDurationUtil::DURATION_TYPE_WEEK;
109  $message->emailTemplateId = 5;
110  $message->sendFromType = EmailMessageForWorkflowForm::SEND_FROM_TYPE_DEFAULT;
111  $recipients = array(array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL_USER,
112  'audienceType' => EmailMessageRecipient::TYPE_TO,
114  DYNAMIC_USER_TYPE_CREATED_BY_USER));
115  $message->setAttributes(array(EmailMessageForWorkflowForm::EMAIL_MESSAGE_RECIPIENTS => $recipients));
116  $workflow->addEmailMessage($message);
117 
118  $savedWorkflow = new SavedWorkflow();
119  $this->assertNull($savedWorkflow->serializedData);
121 
122  $this->assertEquals('WorkflowsTestModule', $savedWorkflow->moduleClassName);
123  $this->assertEquals('1', $savedWorkflow->isActive);
124  $this->assertEquals('myFirstWorkflow', $savedWorkflow->name);
125  $this->assertEquals('aDescription', $savedWorkflow->description);
126  $this->assertEquals(5, $savedWorkflow->order);
127  $this->assertEquals(Workflow::TRIGGER_ON_NEW, $savedWorkflow->triggerOn);
128  $this->assertEquals(Workflow::TYPE_ON_SAVE, $savedWorkflow->type);
129  $this->assertEquals('1 and 2 or 3 or 4 or 5', $workflow->getTriggersStructure());
130  $compareData = array('Triggers' => array(
131  array(
132  'currencyIdForValue' => null,
133  'value' => 'aValue',
134  'secondValue' => null,
135  'thirdValueDurationInterval' => null,
136  'thirdValueDurationType' => null,
137  'stringifiedModelForValue' => null,
138  'valueType' => null,
139  'attributeIndexOrDerivedType' => 'string',
140  'operator' => 'equals',
142  ),
143  array(
144  'currencyIdForValue' => '4',
145  'value' => 'aValue',
146  'secondValue' => 'bValue',
147  'thirdValueDurationInterval' => null,
148  'thirdValueDurationType' => null,
149  'stringifiedModelForValue' => null,
150  'valueType' => null,
151  'attributeIndexOrDerivedType' => 'currencyValue',
152  'operator' => 'between',
154  ),
155  array(
156  'currencyIdForValue' => null,
157  'value' => 'aValue',
158  'secondValue' => null,
159  'thirdValueDurationInterval' => null,
160  'thirdValueDurationType' => null,
161  'stringifiedModelForValue' => 'someName',
162  'valueType' => null,
163  'attributeIndexOrDerivedType' => 'owner__User',
164  'operator' => null,
166  ),
167  array(
168  'value' => 'aValue',
169  'secondValue' => 'bValue',
170  'thirdValueDurationInterval' => null,
171  'thirdValueDurationType' => null,
172  'stringifiedModelForValue' => null,
173  'valueType' => 'Between',
174  'attributeIndexOrDerivedType' => 'createdDateTime',
175  'operator' => null,
176  'currencyIdForValue' => null,
178  ),
179  array(
180  'value' => null,
181  'secondValue' => null,
182  'thirdValueDurationInterval' => 5,
183  'thirdValueDurationType' => TimeDurationUtil::DURATION_TYPE_DAY,
184  'stringifiedModelForValue' => null,
185  'valueType' => 'At Least X After Triggered Date',
186  'attributeIndexOrDerivedType' => 'createdDateTime',
187  'operator' => null,
188  'currencyIdForValue' => null,
190  ),
191  ));
192  $compareData['Actions'] = array(array('type' => ActionForWorkflowForm::TYPE_UPDATE_SELF,
193  'relation' => null,
194  'relationFilter' => ActionForWorkflowForm::RELATION_FILTER_ALL,
195  'relatedModelRelation' => null,
196  'ActionAttributes' => array(
197  'string' => array(
198  'type' => 'Static',
199  'value' => 'jason',
200  'shouldSetValue' => 1,
201  ),
202  )));
203  $compareData['EmailMessages'] = array(array('emailTemplateId' => 5,
204  'sendAfterDurationInterval' => 86400,
205  'sendAfterDurationType' => TimeDurationUtil::DURATION_TYPE_WEEK,
206  'sendFromType' => 'Default',
207  'sendFromName' => null,
208  'sendFromAddress' => null,
209  'EmailMessageRecipients' =>
210  array(array(
211  'dynamicUserType' => 'CreatedByUser',
212  'type' => 'DynamicTriggeredModelUser',
213  'audienceType' => 1,
214  )),
215  'excludeIfTriggeredByUser' => false));
216  $compareData['TimeTrigger'] = array('durationInterval' => 500,
217  'durationSign' => TimeDurationUtil::DURATION_SIGN_POSITIVE,
218  'durationType' => TimeDurationUtil::DURATION_TYPE_DAY,
219  'currencyIdForValue' => null,
220  'value' => null,
221  'secondValue' => null,
222  'thirdValueDurationInterval' => null,
223  'thirdValueDurationType' => null,
224  'valueType' => 'Is Time For',
225  'relationFilter' => 'RelationFilterAny',
226  'attributeIndexOrDerivedType' => 'date',
227  'operator' => null);
228  $unserializedData = unserialize($savedWorkflow->serializedData);
229  $this->assertEquals($compareData['Triggers'], $unserializedData['Triggers']);
230  $this->assertEquals($compareData['Actions'], $unserializedData['Actions']);
231  $this->assertEquals($compareData['EmailMessages'], $unserializedData['EmailMessages']);
232  $this->assertEquals($compareData['TimeTrigger'], $unserializedData['TimeTrigger']);
233  $this->assertEquals('1 and 2 or 3 or 4 or 5', $unserializedData['triggersStructure']);
234  $saved = $savedWorkflow->save();
235  $this->assertTrue($saved);
236  }
237 
242  {
243  $savedWorkflows = SavedWorkflow::getAll();
244  $this->assertEquals (1, count($savedWorkflows));
245  $savedWorkflow = $savedWorkflows[0];
247  $triggers = $workflow->getTriggers();
248  $this->assertEquals ('WorkflowsTestModule', $workflow->getModuleClassName());
249  $this->assertEquals ('myFirstWorkflow', $workflow->getName());
250  $this->assertEquals ('aDescription', $workflow->getDescription());
251  $this->assertTrue ($workflow->getIsActive());
252  $this->assertEquals (5, $workflow->getOrder());
253  $this->assertEquals (Workflow::TRIGGER_ON_NEW, $workflow->getTriggerOn());
254  $this->assertEquals (Workflow::TYPE_ON_SAVE, $workflow->getType());
255  $this->assertEquals ('1 and 2 or 3 or 4 or 5', $workflow->getTriggersStructure());
256  $this->assertCount (5, $triggers);
257  }
258  }
259 ?>
static makeWorkflowBySavedWorkflow(SavedWorkflow $savedWorkflow)
static resolveWorkflowToSavedWorkflow(Workflow $workflow, SavedWorkflow $savedWorkflow)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
Generated on Tue Jul 14 2020 07:10:36
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.