Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
DataToWorkflowUtilTest.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 static function setUpBeforeClass()
40  {
41  parent::setUpBeforeClass();
43  UserTestHelper::createBasicUser('bobby');
44  Currency::getAll(); //Ensure USD is present
45  }
46 
47  public function testResolveOnSaveWorkflowByWizardPostData()
48  {
49  $workflow = new Workflow();
50  $workflow->setType(Workflow::TYPE_ON_SAVE);
51  $data = array();
52  $data['OnSaveWorkflowWizardForm'] = array('description' => 'someDescription',
53  'isActive' => '1',
54  'name' => 'someName',
55  'triggerOn' => Workflow::TRIGGER_ON_NEW,
56  'triggersStructure' => '1 AND 2',
57  'moduleClassName' => 'WorkflowsTestModule');
58  DataToWorkflowUtil::resolveWorkflowByWizardPostData($workflow, $data, 'OnSaveWorkflowWizardForm');
59  $this->assertEquals('someDescription', $workflow->getDescription());
60  $this->assertTrue($workflow->getIsActive());
61  $this->assertEquals('someName', $workflow->getName());
62  $this->assertEquals(Workflow::TRIGGER_ON_NEW, $workflow->getTriggerOn());
63  $this->assertEquals('1 AND 2', $workflow->getTriggersStructure());
64  $this->assertEquals('WorkflowsTestModule', $workflow->getModuleClassName());
65 
66  //Test false isActive
67  $workflow = new Workflow();
68  $workflow->setType(Workflow::TYPE_ON_SAVE);
69  $data = array();
70  $data['OnSaveWorkflowWizardForm'] = array('description' => 'someDescription',
71  'isActive' => '0',
72  'name' => 'someName',
73  'triggerOn' => Workflow::TRIGGER_ON_NEW,
74  'triggersStructure' => '1 AND 2',
75  'moduleClassName' => 'WorkflowsTestModule');
76  DataToWorkflowUtil::resolveWorkflowByWizardPostData($workflow, $data, 'OnSaveWorkflowWizardForm');
77  $this->assertFalse($workflow->getIsActive());
78  }
79 
83  public function testResolveTriggers()
84  {
85  $workflow = new Workflow();
86  $workflow->setType(Workflow::TYPE_ON_SAVE);
87  $workflow->setModuleClassName('WorkflowsTestModule');
88  $data = array();
89  $data[ComponentForWorkflowForm::TYPE_TRIGGERS][] = array('attributeIndexOrDerivedType' => 'date',
90  'operator' => null,
91  'valueType' => 'Between',
92  'value' => '2/24/2012',
93  'secondValue' => '2/28/2012');
94  $data[ComponentForWorkflowForm::TYPE_TRIGGERS][] = array('attributeIndexOrDerivedType' => 'string',
95  'operator' => OperatorRules::TYPE_EQUALS,
96  'value' => 'something');
97  DataToWorkflowUtil::resolveTriggers($data, $workflow);
98  $triggers = $workflow->getTriggers();
99  $this->assertCount(2, $triggers);
100  $this->assertEquals('2012-02-24', $triggers[0]->value);
101  $this->assertEquals('Between', $triggers[0]->valueType);
102  $this->assertEquals('2012-02-28', $triggers[0]->secondValue);
103  $this->assertEquals('something', $triggers[1]->value);
104  $this->assertEquals(OperatorRules::TYPE_EQUALS, $triggers[1]->operator);
105 
106  //Test removing triggers when none are specified
107  $workflow = new Workflow();
108  $workflow->setType(Workflow::TYPE_ON_SAVE);
109  $workflow->setModuleClassName('WorkflowsTestModule');
110  $trigger = new TriggerForWorkflowForm('WorkflowsTestModule', 'WorkflowModelTestItem', Workflow::TYPE_ON_SAVE);
111  $workflow->addTrigger($trigger);
112  $triggers = $workflow->getTriggers();
113  $this->assertCount(1, $triggers);
114  $data = array();
116  DataToWorkflowUtil::resolveTriggers($data, $workflow);
117  $triggers = $workflow->getTriggers();
118  $this->assertCount(0, $triggers);
119  }
120 
124  public function testResolveTimeTrigger()
125  {
126  $workflow = new Workflow();
127  $workflow->setType(Workflow::TYPE_BY_TIME);
128  $workflow->setModuleClassName('WorkflowsTestModule');
129  $data = array();
130  $data[ComponentForWorkflowForm::TYPE_TIME_TRIGGER] = array('attributeIndexOrDerivedType' => 'string',
131  'operator' => OperatorRules::TYPE_EQUALS,
132  'value' => '514',
133  'durationInterval' => '10',
134  'durationSign' => TimeDurationUtil::DURATION_SIGN_NEGATIVE,
135  'durationType' => TimeDurationUtil::DURATION_TYPE_WEEK);
136  DataToWorkflowUtil::resolveTimeTrigger($data, $workflow);
137  $trigger = $workflow->getTimeTrigger();
138  $this->assertEquals('514', $trigger->value);
139  $this->assertEquals('10', $trigger->durationInterval);
140  $this->assertEquals(TimeDurationUtil::DURATION_SIGN_NEGATIVE, $trigger->durationSign);
141  $this->assertEquals(TimeDurationUtil::DURATION_TYPE_WEEK, $trigger->durationType);
142  $this->assertEquals(OperatorRules::TYPE_EQUALS, $trigger->operator);
143  }
144 
149  {
150  $workflow = new Workflow();
151  $workflow->setType(Workflow::TYPE_ON_SAVE);
152  $workflow->setModuleClassName('WorkflowsTestModule');
153  $data = array();
154  $data[ComponentForWorkflowForm::TYPE_TRIGGERS][] = array('attributeIndexOrDerivedType' => 'date',
155  'operator' => null,
156  'valueType' => 'Between',
157  'value' => '2/24/2012',
158  'secondValue' => '2/28/2012');
159  DataToWorkflowUtil::resolveTriggers($data, $workflow);
160  $triggers = $workflow->getTriggers();
161  $this->assertCount(1, $triggers);
162  $this->assertEquals('2012-02-24', $triggers[0]->value);
163  $this->assertEquals('Between', $triggers[0]->valueType);
164  $this->assertEquals('2012-02-28', $triggers[0]->secondValue);
165  }
166 
170  public function testSanitizeTriggersData()
171  {
172  //test specifically for date/dateTime conversion from local to db format.
173  $triggersData = array();
174  $triggersData[0] = array('attributeIndexOrDerivedType' => 'date', 'value' => '2/24/2012');
175  $triggersData[1] = array('attributeIndexOrDerivedType' => 'dateTime', 'value' => '2/25/2012');
176  $triggersData[2] = array('attributeIndexOrDerivedType' => 'date', 'value' => '2/24/2012',
177  'secondValue' => '2/28/2012');
178  $sanitizedTriggerData = DataToWorkflowUtil::sanitizeTriggersData('WorkflowsTestModule',
179  Workflow::TYPE_ON_SAVE, $triggersData);
180  $this->assertEquals('2012-02-24', $sanitizedTriggerData[0]['value']);
181  $this->assertEquals('2012-02-25', $sanitizedTriggerData[1]['value']);
182  $this->assertEquals('2012-02-24', $sanitizedTriggerData[2]['value']);
183  $this->assertEquals('2012-02-28', $sanitizedTriggerData[2]['secondValue']);
184  }
185 
190  {
191  $contactStates = ContactState::getAll();
192  $this->assertTrue($contactStates[0]->id > 0);
193  $contactState = $contactStates[0];
194  $currency = Currency::getByCode('USD');
195  $bobby = User::getByUsername('bobby');
196  $workflow = new Workflow();
197  $workflow->setType(Workflow::TYPE_ON_SAVE);
198  $workflow->setModuleClassName('WorkflowsTestModule');
199  $data = array();
202  array(
203  'boolean' => array('shouldSetValue' => '1',
204  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
205  'value' => '1'),
206  'boolean2' => array('shouldSetValue' => '1',
207  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
208  'value' => '0'),
209  'currencyValue' => array('shouldSetValue' => '1',
210  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
211  'value' => '362.24',
212  'currencyId' => $currency->id),
213  'date' => array('shouldSetValue' => '1',
214  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
215  'value' => '2/24/2012'),
216  'dateTime' => array('shouldSetValue' => '1',
217  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
218  'value' => '2/24/2012 03:00 AM'),
219  'dropDown' => array('shouldSetValue' => '1',
220  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
221  'value' => 'Value 1'),
222  'float' => array('shouldSetValue' => '1',
223  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
224  'value' => '54.25'),
225  'integer' => array('shouldSetValue' => '1',
226  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
227  'value' => '32'),
228  'likeContactState' => array('shouldSetValue' => '1',
229  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
230  'value' => $contactState->id),
231  'multiDropDown' => array('shouldSetValue' => '1',
232  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
233  'value' => array('Multi Value 1', 'Multi Value 2')),
234  'owner' => array('shouldSetValue' => '1',
235  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
236  'value' => $bobby->id),
237  'phone' => array('shouldSetValue' => '1',
238  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
239  'value' => '8471112222'),
240  'primaryAddress___street1' => array('shouldSetValue' => '1',
241  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
242  'value' => '123 Main Street'),
243  'primaryEmail___emailAddress' => array('shouldSetValue' => '1',
244  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
245  'value' => 'info@zurmo.com'),
246  'radioDropDown' => array('shouldSetValue' => '1',
247  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
248  'value' => 'Radio Value 1'),
249  'string' => array('shouldSetValue' => '1',
250  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
251  'value' => 'jason'),
252  'tagCloud' => array('shouldSetValue' => '1',
253  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
254  'value' => array('Tag Value 1', 'Tag Value 2')),
255  'textArea' => array('shouldSetValue' => '1',
256  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
257  'value' => 'some description'),
258  'url' => array('shouldSetValue' => '1',
259  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
260  'value' => 'http://www.zurmo.com'),
261  );
262 
263  DataToWorkflowUtil::resolveActions($data, $workflow);
264  $actions = $workflow->getActions();
265  $this->assertCount(1, $actions);
266  $this->assertEquals(ActionForWorkflowForm::TYPE_UPDATE_SELF, $actions[0]->type);
267  $this->assertEquals(19, $actions[0]->getActionAttributeFormsCount());
268 
269  $this->assertTrue($actions[0]->getActionAttributeFormByName('boolean') instanceof CheckBoxWorkflowActionAttributeForm);
270  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('boolean')->type);
271  $this->assertEquals('1', $actions[0]->getActionAttributeFormByName('boolean')->value);
272 
273  $this->assertTrue($actions[0]->getActionAttributeFormByName('boolean2') instanceof CheckBoxWorkflowActionAttributeForm);
274  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('boolean2')->type);
275  $this->assertEquals('0', $actions[0]->getActionAttributeFormByName('boolean2')->value);
276 
277  $this->assertTrue($actions[0]->getActionAttributeFormByName('currencyValue') instanceof CurrencyValueWorkflowActionAttributeForm);
278  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('currencyValue')->type);
279  $this->assertEquals(362.24, $actions[0]->getActionAttributeFormByName('currencyValue')->value);
280  $this->assertEquals($currency->id, $actions[0]->getActionAttributeFormByName('currencyValue')->currencyId);
281  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('currencyValue')->currencyIdType);
282 
283  $this->assertTrue($actions[0]->getActionAttributeFormByName('date') instanceof DateWorkflowActionAttributeForm);
284  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('date')->type);
285  $this->assertEquals('2012-02-24', $actions[0]->getActionAttributeFormByName('date')->value);
286 
287  $this->assertTrue($actions[0]->getActionAttributeFormByName('dateTime') instanceof DateTimeWorkflowActionAttributeForm);
288  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('dateTime')->type);
290  $this->assertEquals($compareDateTime, $actions[0]->getActionAttributeFormByName('dateTime')->value);
291 
292  $this->assertTrue($actions[0]->getActionAttributeFormByName('dropDown') instanceof DropDownWorkflowActionAttributeForm);
293  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('dropDown')->type);
294  $this->assertEquals('Value 1', $actions[0]->getActionAttributeFormByName('dropDown')->value);
295 
296  $this->assertTrue($actions[0]->getActionAttributeFormByName('float') instanceof DecimalWorkflowActionAttributeForm);
297  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('float')->type);
298  $this->assertEquals('54.25', $actions[0]->getActionAttributeFormByName('float')->value);
299 
300  $this->assertTrue($actions[0]->getActionAttributeFormByName('integer') instanceof IntegerWorkflowActionAttributeForm);
301  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('integer')->type);
302  $this->assertEquals('32', $actions[0]->getActionAttributeFormByName('integer')->value);
303 
304  $this->assertTrue($actions[0]->getActionAttributeFormByName('likeContactState') instanceof ContactStateWorkflowActionAttributeForm);
305  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('likeContactState')->type);
306  $this->assertEquals($contactState->id, $actions[0]->getActionAttributeFormByName('likeContactState')->value);
307 
308  $this->assertTrue($actions[0]->getActionAttributeFormByName('multiDropDown') instanceof MultiSelectDropDownWorkflowActionAttributeForm);
309  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('multiDropDown')->type);
310  $this->assertEquals(array('Multi Value 1', 'Multi Value 2'), $actions[0]->getActionAttributeFormByName('multiDropDown')->value);
311 
312  $this->assertTrue($actions[0]->getActionAttributeFormByName('owner') instanceof UserWorkflowActionAttributeForm);
313  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('owner')->type);
314  $this->assertEquals($bobby->id, $actions[0]->getActionAttributeFormByName('owner')->value);
315 
316  $this->assertTrue($actions[0]->getActionAttributeFormByName('phone') instanceof PhoneWorkflowActionAttributeForm);
317  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('phone')->type);
318  $this->assertEquals('8471112222', $actions[0]->getActionAttributeFormByName('phone')->value);
319 
320  $this->assertTrue($actions[0]->getActionAttributeFormByName('primaryAddress___street1') instanceof TextWorkflowActionAttributeForm);
321  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('primaryAddress___street1')->type);
322  $this->assertEquals('123 Main Street', $actions[0]->getActionAttributeFormByName('primaryAddress___street1')->value);
323 
324  $this->assertTrue($actions[0]->getActionAttributeFormByName('primaryEmail___emailAddress') instanceof EmailWorkflowActionAttributeForm);
325  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('primaryEmail___emailAddress')->type);
326  $this->assertEquals('info@zurmo.com', $actions[0]->getActionAttributeFormByName('primaryEmail___emailAddress')->value);
327 
328  $this->assertTrue($actions[0]->getActionAttributeFormByName('radioDropDown') instanceof RadioDropDownWorkflowActionAttributeForm);
329  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('radioDropDown')->type);
330  $this->assertEquals('Radio Value 1', $actions[0]->getActionAttributeFormByName('radioDropDown')->value);
331 
332  $this->assertTrue($actions[0]->getActionAttributeFormByName('string') instanceof TextWorkflowActionAttributeForm);
333  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('string')->type);
334  $this->assertEquals('jason', $actions[0]->getActionAttributeFormByName('string')->value);
335 
336  $this->assertTrue($actions[0]->getActionAttributeFormByName('tagCloud') instanceof TagCloudWorkflowActionAttributeForm);
337  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('tagCloud')->type);
338  $this->assertEquals(array('Tag Value 1', 'Tag Value 2'), $actions[0]->getActionAttributeFormByName('tagCloud')->value);
339 
340  $this->assertTrue($actions[0]->getActionAttributeFormByName('textArea') instanceof TextAreaWorkflowActionAttributeForm);
341  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('textArea')->type);
342  $this->assertEquals('some description', $actions[0]->getActionAttributeFormByName('textArea')->value);
343 
344  $this->assertTrue($actions[0]->getActionAttributeFormByName('url') instanceof UrlWorkflowActionAttributeForm);
345  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('url')->type);
346  $this->assertEquals('http://www.zurmo.com', $actions[0]->getActionAttributeFormByName('url')->value);
347  }
348 
353  {
354  $bobby = User::getByUsername('bobby');
355  $workflow = new Workflow();
356  $workflow->setType(Workflow::TYPE_ON_SAVE);
357  $workflow->setModuleClassName('WorkflowsTestModule');
358  $data = array();
361  array(
362  'date' => array('shouldSetValue' => '1',
363  'type' => DateWorkflowActionAttributeForm::TYPE_DYNAMIC_FROM_TRIGGERED_DATE,
364  'value' => '-86400'),
365  'date2' => array('shouldSetValue' => '1',
366  'type' => DateWorkflowActionAttributeForm::TYPE_DYNAMIC_FROM_TRIGGERED_DATE,
367  'value' => '86400'),
368  'date3' => array('shouldSetValue' => '1',
369  'type' => DateWorkflowActionAttributeForm::TYPE_DYNAMIC_FROM_EXISTING_DATE,
370  'value' => '-86400'),
371  'date4' => array('shouldSetValue' => '1',
372  'type' => DateWorkflowActionAttributeForm::TYPE_DYNAMIC_FROM_EXISTING_DATE,
373  'value' => '86400'),
374  'dateTime' => array('shouldSetValue' => '1',
375  'type' => DateTimeWorkflowActionAttributeForm::TYPE_DYNAMIC_FROM_TRIGGERED_DATETIME,
376  'value' => '-3600'),
377  'dateTime2' => array('shouldSetValue' => '1',
378  'type' => DateTimeWorkflowActionAttributeForm::TYPE_DYNAMIC_FROM_TRIGGERED_DATETIME,
379  'value' => '3600'),
380  'dateTime3' => array('shouldSetValue' => '1',
381  'type' => DateTimeWorkflowActionAttributeForm::TYPE_DYNAMIC_FROM_EXISTING_DATETIME,
382  'value' => '-7200'),
383  'dateTime4' => array('shouldSetValue' => '1',
384  'type' => DateTimeWorkflowActionAttributeForm::TYPE_DYNAMIC_FROM_EXISTING_DATETIME,
385  'value' => '7200'),
386  'dropDown' => array('shouldSetValue' => '1',
388  'value' => '2'),
389  'owner' => array('shouldSetValue' => '1',
390  'type' => UserWorkflowActionAttributeForm::TYPE_DYNAMIC_CREATED_BY_USER),
391  'radioDropDown' => array('shouldSetValue' => '1',
393  'value' => '-2'),
394  'user' => array('shouldSetValue' => '1',
395  'type' => UserWorkflowActionAttributeForm::TYPE_DYNAMIC_MODIFIED_BY_USER),
396  'user2' => array('shouldSetValue' => '1',
397  'type' => UserWorkflowActionAttributeForm::TYPE_DYNAMIC_TRIGGERED_BY_USER),
398  );
399  DataToWorkflowUtil::resolveActions($data, $workflow);
400  $actions = $workflow->getActions();
401  $this->assertCount(1, $actions);
402  $this->assertEquals(ActionForWorkflowForm::TYPE_UPDATE_SELF, $actions[0]->type);
403  $this->assertEquals(13, $actions[0]->getActionAttributeFormsCount());
404 
405  $this->assertTrue($actions[0]->getActionAttributeFormByName('date') instanceof DateWorkflowActionAttributeForm);
406  $this->assertEquals('DynamicFromTriggeredDate', $actions[0]->getActionAttributeFormByName('date')->type);
407  $this->assertEquals(-86400, $actions[0]->getActionAttributeFormByName('date')->value);
408  $this->assertTrue($actions[0]->getActionAttributeFormByName('date2') instanceof DateWorkflowActionAttributeForm);
409  $this->assertEquals('DynamicFromTriggeredDate', $actions[0]->getActionAttributeFormByName('date2')->type);
410  $this->assertEquals(86400, $actions[0]->getActionAttributeFormByName('date2')->value);
411  $this->assertTrue($actions[0]->getActionAttributeFormByName('date3') instanceof DateWorkflowActionAttributeForm);
412  $this->assertEquals('DynamicFromExistingDate', $actions[0]->getActionAttributeFormByName('date3')->type);
413  $this->assertEquals(-86400, $actions[0]->getActionAttributeFormByName('date3')->value);
414  $this->assertTrue($actions[0]->getActionAttributeFormByName('date4') instanceof DateWorkflowActionAttributeForm);
415  $this->assertEquals('DynamicFromExistingDate', $actions[0]->getActionAttributeFormByName('date4')->type);
416  $this->assertEquals(86400, $actions[0]->getActionAttributeFormByName('date4')->value);
417 
418  $this->assertTrue($actions[0]->getActionAttributeFormByName('dateTime') instanceof DateTimeWorkflowActionAttributeForm);
419  $this->assertEquals('DynamicFromTriggeredDateTime', $actions[0]->getActionAttributeFormByName('dateTime')->type);
420  $this->assertEquals(-3600, $actions[0]->getActionAttributeFormByName('dateTime')->value);
421  $this->assertTrue($actions[0]->getActionAttributeFormByName('dateTime2') instanceof DateTimeWorkflowActionAttributeForm);
422  $this->assertEquals('DynamicFromTriggeredDateTime', $actions[0]->getActionAttributeFormByName('dateTime2')->type);
423  $this->assertEquals(3600, $actions[0]->getActionAttributeFormByName('dateTime2')->value);
424  $this->assertTrue($actions[0]->getActionAttributeFormByName('dateTime3') instanceof DateTimeWorkflowActionAttributeForm);
425  $this->assertEquals('DynamicFromExistingDateTime', $actions[0]->getActionAttributeFormByName('dateTime3')->type);
426  $this->assertEquals(-7200, $actions[0]->getActionAttributeFormByName('dateTime3')->value);
427  $this->assertTrue($actions[0]->getActionAttributeFormByName('dateTime4') instanceof DateTimeWorkflowActionAttributeForm);
428  $this->assertEquals('DynamicFromExistingDateTime', $actions[0]->getActionAttributeFormByName('dateTime4')->type);
429  $this->assertEquals(7200, $actions[0]->getActionAttributeFormByName('dateTime4')->value);
430 
431  $this->assertTrue($actions[0]->getActionAttributeFormByName('dropDown') instanceof DropDownWorkflowActionAttributeForm);
432  $this->assertEquals('DynamicStepForwardOrBackwards', $actions[0]->getActionAttributeFormByName('dropDown')->type);
433  $this->assertEquals(2, $actions[0]->getActionAttributeFormByName('dropDown')->value);
434 
435  $this->assertTrue($actions[0]->getActionAttributeFormByName('owner') instanceof UserWorkflowActionAttributeForm);
436  $this->assertEquals('DynamicCreatedByUser', $actions[0]->getActionAttributeFormByName('owner')->type);
437  $this->assertNull($actions[0]->getActionAttributeFormByName('owner')->value);
438 
439  $this->assertTrue($actions[0]->getActionAttributeFormByName('radioDropDown') instanceof RadioDropDownWorkflowActionAttributeForm);
440  $this->assertEquals('DynamicStepForwardOrBackwards', $actions[0]->getActionAttributeFormByName('radioDropDown')->type);
441  $this->assertEquals(-2, $actions[0]->getActionAttributeFormByName('radioDropDown')->value);
442 
443  $this->assertTrue($actions[0]->getActionAttributeFormByName('user') instanceof UserWorkflowActionAttributeForm);
444  $this->assertEquals('DynamicModifiedByUser', $actions[0]->getActionAttributeFormByName('user')->type);
445  $this->assertNull($actions[0]->getActionAttributeFormByName('user')->value);
446  $this->assertTrue($actions[0]->getActionAttributeFormByName('user2') instanceof UserWorkflowActionAttributeForm);
447  $this->assertEquals('DynamicTriggeredByUser', $actions[0]->getActionAttributeFormByName('user2')->type);
448  $this->assertNull($actions[0]->getActionAttributeFormByName('user2')->value);
449  }
450 
455  {
456  $contactStates = ContactState::getAll();
457  $this->assertTrue($contactStates[0]->id > 0);
458  $contactState = $contactStates[0];
459  $currency = Currency::getByCode('USD');
460  $bobby = User::getByUsername('bobby');
461  $workflow = new Workflow();
462  $workflow->setType(Workflow::TYPE_ON_SAVE);
463  $workflow->setModuleClassName('WorkflowsTest2Module');
464  $data = array();
466  $data[ComponentForWorkflowForm::TYPE_ACTIONS][0]['relation'] = 'hasMany2';
468  array(
469  'boolean' => array('shouldSetValue' => '1',
470  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
471  'value' => '1'),
472  'boolean2' => array('shouldSetValue' => '1',
473  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
474  'value' => '0'),
475  'currencyValue' => array('shouldSetValue' => '1',
476  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
477  'value' => '362.24',
478  'currencyId' => $currency->id),
479  'date' => array('shouldSetValue' => '1',
480  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
481  'value' => '2/24/2012'),
482  'dateTime' => array('shouldSetValue' => '1',
483  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
484  'value' => '2/24/2012 03:00 AM'),
485  'dropDown' => array('shouldSetValue' => '1',
486  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
487  'value' => 'Value 1'),
488  'float' => array('shouldSetValue' => '1',
489  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
490  'value' => '54.25'),
491  'integer' => array('shouldSetValue' => '1',
492  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
493  'value' => '32'),
494  'likeContactState' => array('shouldSetValue' => '1',
495  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
496  'value' => $contactState->id),
497  'multiDropDown' => array('shouldSetValue' => '1',
498  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
499  'value' => array('Multi Value 1', 'Multi Value 2')),
500  'owner' => array('shouldSetValue' => '1',
501  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
502  'value' => $bobby->id),
503  'phone' => array('shouldSetValue' => '1',
504  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
505  'value' => '8471112222'),
506  'primaryAddress___street1' => array('shouldSetValue' => '1',
507  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
508  'value' => '123 Main Street'),
509  'primaryEmail___emailAddress' => array('shouldSetValue' => '1',
510  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
511  'value' => 'info@zurmo.com'),
512  'radioDropDown' => array('shouldSetValue' => '1',
513  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
514  'value' => 'Radio Value 1'),
515  'string' => array('shouldSetValue' => '1',
516  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
517  'value' => 'jason'),
518  'tagCloud' => array('shouldSetValue' => '1',
519  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
520  'value' => array('Tag Value 1', 'Tag Value 2')),
521  'textArea' => array('shouldSetValue' => '1',
522  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
523  'value' => 'some description'),
524  'url' => array('shouldSetValue' => '1',
525  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
526  'value' => 'http://www.zurmo.com'),
527  );
528 
529  DataToWorkflowUtil::resolveActions($data, $workflow);
530  $actions = $workflow->getActions();
531  $this->assertCount(1, $actions);
532  $this->assertEquals(ActionForWorkflowForm::TYPE_UPDATE_RELATED, $actions[0]->type);
533  $this->assertEquals('hasMany2', $actions[0]->relation);
534  $this->assertEquals(ActionForWorkflowForm::RELATION_FILTER_ALL, $actions[0]->relationFilter);
535 
536  $this->assertEquals(19, $actions[0]->getActionAttributeFormsCount());
537 
538  $this->assertTrue($actions[0]->getActionAttributeFormByName('boolean') instanceof CheckBoxWorkflowActionAttributeForm);
539  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('boolean')->type);
540  $this->assertEquals('1', $actions[0]->getActionAttributeFormByName('boolean')->value);
541 
542  $this->assertTrue($actions[0]->getActionAttributeFormByName('boolean2') instanceof CheckBoxWorkflowActionAttributeForm);
543  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('boolean2')->type);
544  $this->assertEquals('0', $actions[0]->getActionAttributeFormByName('boolean2')->value);
545 
546  $this->assertTrue($actions[0]->getActionAttributeFormByName('currencyValue') instanceof CurrencyValueWorkflowActionAttributeForm);
547  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('currencyValue')->type);
548  $this->assertEquals(362.24, $actions[0]->getActionAttributeFormByName('currencyValue')->value);
549  $this->assertEquals($currency->id, $actions[0]->getActionAttributeFormByName('currencyValue')->currencyId);
550  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('currencyValue')->currencyIdType);
551 
552  $this->assertTrue($actions[0]->getActionAttributeFormByName('date') instanceof DateWorkflowActionAttributeForm);
553  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('date')->type);
554  $this->assertEquals('2012-02-24', $actions[0]->getActionAttributeFormByName('date')->value);
555 
556  $this->assertTrue($actions[0]->getActionAttributeFormByName('dateTime') instanceof DateTimeWorkflowActionAttributeForm);
557  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('dateTime')->type);
559  $this->assertEquals($compareDateTime, $actions[0]->getActionAttributeFormByName('dateTime')->value);
560 
561  $this->assertTrue($actions[0]->getActionAttributeFormByName('dropDown') instanceof DropDownWorkflowActionAttributeForm);
562  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('dropDown')->type);
563  $this->assertEquals('Value 1', $actions[0]->getActionAttributeFormByName('dropDown')->value);
564 
565  $this->assertTrue($actions[0]->getActionAttributeFormByName('float') instanceof DecimalWorkflowActionAttributeForm);
566  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('float')->type);
567  $this->assertEquals('54.25', $actions[0]->getActionAttributeFormByName('float')->value);
568 
569  $this->assertTrue($actions[0]->getActionAttributeFormByName('integer') instanceof IntegerWorkflowActionAttributeForm);
570  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('integer')->type);
571  $this->assertEquals('32', $actions[0]->getActionAttributeFormByName('integer')->value);
572 
573  $this->assertTrue($actions[0]->getActionAttributeFormByName('likeContactState') instanceof ContactStateWorkflowActionAttributeForm);
574  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('likeContactState')->type);
575  $this->assertEquals($contactState->id, $actions[0]->getActionAttributeFormByName('likeContactState')->value);
576 
577  $this->assertTrue($actions[0]->getActionAttributeFormByName('multiDropDown') instanceof MultiSelectDropDownWorkflowActionAttributeForm);
578  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('multiDropDown')->type);
579  $this->assertEquals(array('Multi Value 1', 'Multi Value 2'), $actions[0]->getActionAttributeFormByName('multiDropDown')->value);
580 
581  $this->assertTrue($actions[0]->getActionAttributeFormByName('owner') instanceof UserWorkflowActionAttributeForm);
582  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('owner')->type);
583  $this->assertEquals($bobby->id, $actions[0]->getActionAttributeFormByName('owner')->value);
584 
585  $this->assertTrue($actions[0]->getActionAttributeFormByName('phone') instanceof PhoneWorkflowActionAttributeForm);
586  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('phone')->type);
587  $this->assertEquals('8471112222', $actions[0]->getActionAttributeFormByName('phone')->value);
588 
589  $this->assertTrue($actions[0]->getActionAttributeFormByName('primaryAddress___street1') instanceof TextWorkflowActionAttributeForm);
590  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('primaryAddress___street1')->type);
591  $this->assertEquals('123 Main Street', $actions[0]->getActionAttributeFormByName('primaryAddress___street1')->value);
592 
593  $this->assertTrue($actions[0]->getActionAttributeFormByName('primaryEmail___emailAddress') instanceof EmailWorkflowActionAttributeForm);
594  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('primaryEmail___emailAddress')->type);
595  $this->assertEquals('info@zurmo.com', $actions[0]->getActionAttributeFormByName('primaryEmail___emailAddress')->value);
596 
597  $this->assertTrue($actions[0]->getActionAttributeFormByName('radioDropDown') instanceof RadioDropDownWorkflowActionAttributeForm);
598  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('radioDropDown')->type);
599  $this->assertEquals('Radio Value 1', $actions[0]->getActionAttributeFormByName('radioDropDown')->value);
600 
601  $this->assertTrue($actions[0]->getActionAttributeFormByName('string') instanceof TextWorkflowActionAttributeForm);
602  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('string')->type);
603  $this->assertEquals('jason', $actions[0]->getActionAttributeFormByName('string')->value);
604 
605  $this->assertTrue($actions[0]->getActionAttributeFormByName('tagCloud') instanceof TagCloudWorkflowActionAttributeForm);
606  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('tagCloud')->type);
607  $this->assertEquals(array('Tag Value 1', 'Tag Value 2'), $actions[0]->getActionAttributeFormByName('tagCloud')->value);
608 
609  $this->assertTrue($actions[0]->getActionAttributeFormByName('textArea') instanceof TextAreaWorkflowActionAttributeForm);
610  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('textArea')->type);
611  $this->assertEquals('some description', $actions[0]->getActionAttributeFormByName('textArea')->value);
612 
613  $this->assertTrue($actions[0]->getActionAttributeFormByName('url') instanceof UrlWorkflowActionAttributeForm);
614  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('url')->type);
615  $this->assertEquals('http://www.zurmo.com', $actions[0]->getActionAttributeFormByName('url')->value);
616  }
617 
622  {
623  $bobby = User::getByUsername('bobby');
624  $workflow = new Workflow();
625  $workflow->setType(Workflow::TYPE_ON_SAVE);
626  $workflow->setModuleClassName('WorkflowsTest2Module');
627  $data = array();
629  $data[ComponentForWorkflowForm::TYPE_ACTIONS][0]['relation'] = 'hasMany2';
631  array(
632  'date' => array('shouldSetValue' => '1',
633  'type' => DateWorkflowActionAttributeForm::TYPE_DYNAMIC_FROM_TRIGGERED_DATE,
634  'value' => '-86400'),
635  'date2' => array('shouldSetValue' => '1',
636  'type' => DateWorkflowActionAttributeForm::TYPE_DYNAMIC_FROM_TRIGGERED_DATE,
637  'value' => '86400'),
638  'date3' => array('shouldSetValue' => '1',
639  'type' => DateWorkflowActionAttributeForm::TYPE_DYNAMIC_FROM_EXISTING_DATE,
640  'value' => '-86400'),
641  'date4' => array('shouldSetValue' => '1',
642  'type' => DateWorkflowActionAttributeForm::TYPE_DYNAMIC_FROM_EXISTING_DATE,
643  'value' => '86400'),
644  'dateTime' => array('shouldSetValue' => '1',
645  'type' => DateTimeWorkflowActionAttributeForm::TYPE_DYNAMIC_FROM_TRIGGERED_DATETIME,
646  'value' => '-3600'),
647  'dateTime2' => array('shouldSetValue' => '1',
648  'type' => DateTimeWorkflowActionAttributeForm::TYPE_DYNAMIC_FROM_TRIGGERED_DATETIME,
649  'value' => '3600'),
650  'dateTime3' => array('shouldSetValue' => '1',
651  'type' => DateTimeWorkflowActionAttributeForm::TYPE_DYNAMIC_FROM_EXISTING_DATETIME,
652  'value' => '-7200'),
653  'dateTime4' => array('shouldSetValue' => '1',
654  'type' => DateTimeWorkflowActionAttributeForm::TYPE_DYNAMIC_FROM_EXISTING_DATETIME,
655  'value' => '7200'),
656  'dropDown' => array('shouldSetValue' => '1',
658  'value' => '2'),
659  'owner' => array('shouldSetValue' => '1',
660  'type' => UserWorkflowActionAttributeForm::TYPE_DYNAMIC_CREATED_BY_USER),
661  'radioDropDown' => array('shouldSetValue' => '1',
663  'value' => '-2'),
664  'user' => array('shouldSetValue' => '1',
665  'type' => UserWorkflowActionAttributeForm::TYPE_DYNAMIC_MODIFIED_BY_USER),
666  'user2' => array('shouldSetValue' => '1',
667  'type' => UserWorkflowActionAttributeForm::TYPE_DYNAMIC_TRIGGERED_BY_USER),
668  );
669 
670  DataToWorkflowUtil::resolveActions($data, $workflow);
671  $actions = $workflow->getActions();
672  $this->assertCount(1, $actions);
673  $this->assertEquals(ActionForWorkflowForm::TYPE_UPDATE_RELATED, $actions[0]->type);
674  $this->assertEquals('hasMany2', $actions[0]->relation);
675  $this->assertEquals(ActionForWorkflowForm::RELATION_FILTER_ALL, $actions[0]->relationFilter);
676  $this->assertEquals(13, $actions[0]->getActionAttributeFormsCount());
677 
678  $this->assertTrue($actions[0]->getActionAttributeFormByName('date') instanceof DateWorkflowActionAttributeForm);
679  $this->assertEquals('DynamicFromTriggeredDate', $actions[0]->getActionAttributeFormByName('date')->type);
680  $this->assertEquals(-86400, $actions[0]->getActionAttributeFormByName('date')->value);
681  $this->assertTrue($actions[0]->getActionAttributeFormByName('date2') instanceof DateWorkflowActionAttributeForm);
682  $this->assertEquals('DynamicFromTriggeredDate', $actions[0]->getActionAttributeFormByName('date2')->type);
683  $this->assertEquals(86400, $actions[0]->getActionAttributeFormByName('date2')->value);
684  $this->assertTrue($actions[0]->getActionAttributeFormByName('date3') instanceof DateWorkflowActionAttributeForm);
685  $this->assertEquals('DynamicFromExistingDate', $actions[0]->getActionAttributeFormByName('date3')->type);
686  $this->assertEquals(-86400, $actions[0]->getActionAttributeFormByName('date3')->value);
687  $this->assertTrue($actions[0]->getActionAttributeFormByName('date4') instanceof DateWorkflowActionAttributeForm);
688  $this->assertEquals('DynamicFromExistingDate', $actions[0]->getActionAttributeFormByName('date4')->type);
689  $this->assertEquals(86400, $actions[0]->getActionAttributeFormByName('date4')->value);
690 
691  $this->assertTrue($actions[0]->getActionAttributeFormByName('dateTime') instanceof DateTimeWorkflowActionAttributeForm);
692  $this->assertEquals('DynamicFromTriggeredDateTime', $actions[0]->getActionAttributeFormByName('dateTime')->type);
693  $this->assertEquals(-3600, $actions[0]->getActionAttributeFormByName('dateTime')->value);
694  $this->assertTrue($actions[0]->getActionAttributeFormByName('dateTime2') instanceof DateTimeWorkflowActionAttributeForm);
695  $this->assertEquals('DynamicFromTriggeredDateTime', $actions[0]->getActionAttributeFormByName('dateTime2')->type);
696  $this->assertEquals(3600, $actions[0]->getActionAttributeFormByName('dateTime2')->value);
697  $this->assertTrue($actions[0]->getActionAttributeFormByName('dateTime3') instanceof DateTimeWorkflowActionAttributeForm);
698  $this->assertEquals('DynamicFromExistingDateTime', $actions[0]->getActionAttributeFormByName('dateTime3')->type);
699  $this->assertEquals(-7200, $actions[0]->getActionAttributeFormByName('dateTime3')->value);
700  $this->assertTrue($actions[0]->getActionAttributeFormByName('dateTime4') instanceof DateTimeWorkflowActionAttributeForm);
701  $this->assertEquals('DynamicFromExistingDateTime', $actions[0]->getActionAttributeFormByName('dateTime4')->type);
702  $this->assertEquals(7200, $actions[0]->getActionAttributeFormByName('dateTime4')->value);
703 
704  $this->assertTrue($actions[0]->getActionAttributeFormByName('dropDown') instanceof DropDownWorkflowActionAttributeForm);
705  $this->assertEquals('DynamicStepForwardOrBackwards', $actions[0]->getActionAttributeFormByName('dropDown')->type);
706  $this->assertEquals(2, $actions[0]->getActionAttributeFormByName('dropDown')->value);
707 
708  $this->assertTrue($actions[0]->getActionAttributeFormByName('owner') instanceof UserWorkflowActionAttributeForm);
709  $this->assertEquals('DynamicCreatedByUser', $actions[0]->getActionAttributeFormByName('owner')->type);
710  $this->assertNull($actions[0]->getActionAttributeFormByName('owner')->value);
711 
712  $this->assertTrue($actions[0]->getActionAttributeFormByName('radioDropDown') instanceof RadioDropDownWorkflowActionAttributeForm);
713  $this->assertEquals('DynamicStepForwardOrBackwards', $actions[0]->getActionAttributeFormByName('radioDropDown')->type);
714  $this->assertEquals(-2, $actions[0]->getActionAttributeFormByName('radioDropDown')->value);
715 
716  $this->assertTrue($actions[0]->getActionAttributeFormByName('user') instanceof UserWorkflowActionAttributeForm);
717  $this->assertEquals('DynamicModifiedByUser', $actions[0]->getActionAttributeFormByName('user')->type);
718  $this->assertNull($actions[0]->getActionAttributeFormByName('user')->value);
719  $this->assertTrue($actions[0]->getActionAttributeFormByName('user2') instanceof UserWorkflowActionAttributeForm);
720  $this->assertEquals('DynamicTriggeredByUser', $actions[0]->getActionAttributeFormByName('user2')->type);
721  $this->assertNull($actions[0]->getActionAttributeFormByName('user2')->value);
722  }
723 
728  {
729  $bobby = User::getByUsername('bobby');
730  $workflow = new Workflow();
731  $workflow->setType(Workflow::TYPE_ON_SAVE);
732  $workflow->setModuleClassName('WorkflowsTest2Module');
733  $data = array();
735  $data[ComponentForWorkflowForm::TYPE_ACTIONS][0]['relation'] = 'hasMany2';
737  array(
738  'user' => array('shouldSetValue' => '1',
739  'type' => UserWorkflowActionAttributeForm::TYPE_DYNAMIC_OWNER_OF_TRIGGERED_MODEL),
740  );
741 
742  DataToWorkflowUtil::resolveActions($data, $workflow);
743  $actions = $workflow->getActions();
744  $this->assertCount(1, $actions);
745  $this->assertEquals(ActionForWorkflowForm::TYPE_UPDATE_RELATED, $actions[0]->type);
746  $this->assertEquals('hasMany2', $actions[0]->relation);
747  $this->assertEquals(ActionForWorkflowForm::RELATION_FILTER_ALL, $actions[0]->relationFilter);
748  $this->assertEquals(1, $actions[0]->getActionAttributeFormsCount());
749 
750  $this->assertTrue($actions[0]->getActionAttributeFormByName('user') instanceof UserWorkflowActionAttributeForm);
751  $this->assertEquals('OwnerOfTriggeredModel', $actions[0]->getActionAttributeFormByName('user')->type);
752  $this->assertNull($actions[0]->getActionAttributeFormByName('user')->value);
753  }
754 
760  {
761  $workflow = new Workflow();
762  $workflow->setType(Workflow::TYPE_ON_SAVE);
763  $workflow->setModuleClassName('WorkflowsTest2Module');
764  $data = array();
766  $data[ComponentForWorkflowForm::TYPE_ACTIONS][0]['relation'] = 'hasMany2';
768  array(
769  'string' => array('shouldSetValue' => '1',
770  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
771  'value' => 'jason'),
772  'phone' => array('shouldSetValue' => '1',
773  'type' => WorkflowActionAttributeForm::TYPE_STATIC_NULL,
774  'value' => ''),
775  );
776 
777  DataToWorkflowUtil::resolveActions($data, $workflow);
778  $actions = $workflow->getActions();
779  $this->assertCount(1, $actions);
780  $this->assertEquals(ActionForWorkflowForm::TYPE_CREATE, $actions[0]->type);
781  $this->assertEquals('hasMany2', $actions[0]->relation);
782 
783  $this->assertEquals(2, $actions[0]->getActionAttributeFormsCount());
784 
785  $this->assertTrue($actions[0]->getActionAttributeFormByName('string') instanceof TextWorkflowActionAttributeForm);
786  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('string')->type);
787  $this->assertEquals('jason', $actions[0]->getActionAttributeFormByName('string')->value);
788  $this->assertTrue($actions[0]->getActionAttributeFormByName('phone') instanceof PhoneWorkflowActionAttributeForm);
789  $this->assertEquals('StaticNull', $actions[0]->getActionAttributeFormByName('phone')->type);
790  $this->assertEquals(null, $actions[0]->getActionAttributeFormByName('phone')->value);
791  }
792 
798  {
799  $workflow = new Workflow();
800  $workflow->setType(Workflow::TYPE_ON_SAVE);
801  $workflow->setModuleClassName('WorkflowsTest2Module');
802  $data = array();
804  $data[ComponentForWorkflowForm::TYPE_ACTIONS][0]['relation'] = 'hasMany2';
805  $data[ComponentForWorkflowForm::TYPE_ACTIONS][0]['relatedModelRelation'] = 'hasMany';
807  array(
808  'name' => array('shouldSetValue' => '1',
809  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
810  'value' => 'jason'),
811  );
812 
813  DataToWorkflowUtil::resolveActions($data, $workflow);
814  $actions = $workflow->getActions();
815  $this->assertCount(1, $actions);
816  $this->assertEquals(ActionForWorkflowForm::TYPE_CREATE_RELATED, $actions[0]->type);
817  $this->assertEquals('hasMany2', $actions[0]->relation);
818  $this->assertEquals(ActionForWorkflowForm::RELATION_FILTER_ALL, $actions[0]->relationFilter);
819  $this->assertEquals('hasMany', $actions[0]->relatedModelRelation);
820 
821  $this->assertEquals(1, $actions[0]->getActionAttributeFormsCount());
822 
823  $this->assertTrue($actions[0]->getActionAttributeFormByName('name') instanceof TextWorkflowActionAttributeForm);
824  $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('name')->type);
825  $this->assertEquals('jason', $actions[0]->getActionAttributeFormByName('name')->value);
826  }
827 
872  public function testEmailMessageValues()
873  {
874  $bobby = User::getByUsername('bobby');
875  $workflow = new Workflow();
876  $workflow->setType(Workflow::TYPE_ON_SAVE);
877  $workflow->setModuleClassName('WorkflowsTestModule');
878  $data = array();
879  $data[ComponentForWorkflowForm::TYPE_EMAIL_MESSAGES][0]['emailTemplateId'] = '5';
880  $data[ComponentForWorkflowForm::TYPE_EMAIL_MESSAGES][0]['sendFromType'] =
881  EmailMessageForWorkflowForm::SEND_FROM_TYPE_DEFAULT;
882  $data[ComponentForWorkflowForm::TYPE_EMAIL_MESSAGES][0]['sendAfterDurationInterval'] = '0';
883  $data[ComponentForWorkflowForm::TYPE_EMAIL_MESSAGES][0]['sendAfterDurationType'] = TimeDurationUtil::DURATION_TYPE_WEEK;
885  array(
886  array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL_USER,
887  'audienceType' => EmailMessageRecipient::TYPE_TO,
888  'dynamicUserType' => DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm::DYNAMIC_USER_TYPE_CREATED_BY_USER),
889  array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL_USER,
890  'audienceType' => EmailMessageRecipient::TYPE_CC,
891  'dynamicUserType' => DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm::DYNAMIC_USER_TYPE_MANAGER_OF_CREATED_BY_USER),
892  array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL_USER,
893  'audienceType' => EmailMessageRecipient::TYPE_BCC,
894  'dynamicUserType' => DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm::DYNAMIC_USER_TYPE_MODIFIED_BY_USER),
895  array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL_USER,
896  'audienceType' => EmailMessageRecipient::TYPE_TO,
897  'dynamicUserType' => DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm::DYNAMIC_USER_TYPE_MANAGER_OF_MODIFIED_BY_USER),
898  array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL_USER,
899  'audienceType' => EmailMessageRecipient::TYPE_CC,
900  'dynamicUserType' => DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm::DYNAMIC_USER_TYPE_OWNER),
901  array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL_USER,
902  'audienceType' => EmailMessageRecipient::TYPE_BCC,
903  'dynamicUserType' => DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm::DYNAMIC_USER_TYPE_MANAGER_OF_OWNER),
904  array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL_RELATION_USER,
905  'audienceType' => EmailMessageRecipient::TYPE_TO,
906  'dynamicUserType' => DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm::DYNAMIC_USER_TYPE_CREATED_BY_USER,
907  'relation' => 'hasOne'),
908  array('type' => WorkflowEmailMessageRecipientForm::TYPE_STATIC_ROLE,
909  'audienceType' => EmailMessageRecipient::TYPE_CC,
910  'roleId' => '5'),
911  array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_BY_USER,
912  'audienceType' => EmailMessageRecipient::TYPE_BCC),
913  array('type' => WorkflowEmailMessageRecipientForm::TYPE_STATIC_USER,
914  'audienceType' => EmailMessageRecipient::TYPE_TO,
915  'userId' => '6'),
916  array('type' => WorkflowEmailMessageRecipientForm::TYPE_STATIC_ADDRESS,
917  'audienceType' => EmailMessageRecipient::TYPE_CC,
918  'toName' => 'somebody',
919  'toAddress' => 'someone@zurmo.com'),
920  array('type' => WorkflowEmailMessageRecipientForm::TYPE_STATIC_GROUP,
921  'audienceType' => EmailMessageRecipient::TYPE_BCC,
922  'groupId' => '7'),
923  );
925  $emailMessages = $workflow->getEmailMessages();
926  $this->assertCount(1, $emailMessages);
927  $this->assertEquals('5', $emailMessages[0]->emailTemplateId);
928  $this->assertEquals(EmailMessageForWorkflowForm::SEND_FROM_TYPE_DEFAULT, $emailMessages[0]->sendFromType);
929  $this->assertEquals(0, $emailMessages[0]->sendAfterDurationInterval);
930  $this->assertEquals(TimeDurationUtil::DURATION_TYPE_WEEK, $emailMessages[0]->sendAfterDurationType);
931  $this->assertEquals(12, $emailMessages[0]->getEmailMessageRecipientFormsCount());
932 
933  $emailMessageRecipients = $emailMessages[0]->getEmailMessageRecipients();
934  $this->assertTrue($emailMessageRecipients[0] instanceof DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm);
935  $this->assertEquals('DynamicTriggeredModelUser', $emailMessageRecipients[0]->type);
936  $this->assertEquals(1, $emailMessageRecipients[0]->audienceType);
937  $this->assertEquals('CreatedByUser', $emailMessageRecipients[0]->dynamicUserType);
938  $this->assertTrue($emailMessageRecipients[1] instanceof DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm);
939  $this->assertEquals('DynamicTriggeredModelUser', $emailMessageRecipients[1]->type);
940  $this->assertEquals(2, $emailMessageRecipients[1]->audienceType);
941  $this->assertEquals('ManagerOfCreatedByUser', $emailMessageRecipients[1]->dynamicUserType);
942  $this->assertTrue($emailMessageRecipients[2] instanceof DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm);
943  $this->assertEquals('DynamicTriggeredModelUser', $emailMessageRecipients[2]->type);
944  $this->assertEquals(3, $emailMessageRecipients[2]->audienceType);
945  $this->assertEquals('ModifiedByUser', $emailMessageRecipients[2]->dynamicUserType);
946  $this->assertTrue($emailMessageRecipients[3] instanceof DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm);
947  $this->assertEquals('DynamicTriggeredModelUser', $emailMessageRecipients[3]->type);
948  $this->assertEquals(1, $emailMessageRecipients[3]->audienceType);
949  $this->assertEquals('ManagerOfModifiedByUser', $emailMessageRecipients[3]->dynamicUserType);
950  $this->assertTrue($emailMessageRecipients[4] instanceof DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm);
951  $this->assertEquals('DynamicTriggeredModelUser', $emailMessageRecipients[4]->type);
952  $this->assertEquals(2, $emailMessageRecipients[4]->audienceType);
953  $this->assertEquals('Owner', $emailMessageRecipients[4]->dynamicUserType);
954  $this->assertTrue($emailMessageRecipients[5] instanceof DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm);
955  $this->assertEquals('DynamicTriggeredModelUser', $emailMessageRecipients[5]->type);
956  $this->assertEquals(3, $emailMessageRecipients[5]->audienceType);
957  $this->assertEquals('ManagerOfOwner', $emailMessageRecipients[5]->dynamicUserType);
958  $this->assertTrue($emailMessageRecipients[6] instanceof DynamicTriggeredModelRelationUserWorkflowEmailMessageRecipientForm);
959  $this->assertEquals('DynamicTriggeredModelRelationUser', $emailMessageRecipients[6]->type);
960  $this->assertEquals(1, $emailMessageRecipients[6]->audienceType);
961  $this->assertEquals('CreatedByUser', $emailMessageRecipients[6]->dynamicUserType);
962  $this->assertEquals('hasOne', $emailMessageRecipients[6]->relation);
963  $this->assertEquals('RelationFilterAll', $emailMessageRecipients[6]->relationFilter);
964  $this->assertTrue($emailMessageRecipients[7] instanceof StaticRoleWorkflowEmailMessageRecipientForm);
965  $this->assertEquals('StaticRole', $emailMessageRecipients[7]->type);
966  $this->assertEquals(2, $emailMessageRecipients[7]->audienceType);
967  $this->assertEquals(5, $emailMessageRecipients[7]->roleId);
968  $this->assertTrue($emailMessageRecipients[8] instanceof DynamicTriggeredByUserWorkflowEmailMessageRecipientForm);
969  $this->assertEquals('DynamicTriggeredByUser', $emailMessageRecipients[8]->type);
970  $this->assertEquals(3, $emailMessageRecipients[8]->audienceType);
971  $this->assertTrue($emailMessageRecipients[9] instanceof StaticUserWorkflowEmailMessageRecipientForm);
972  $this->assertEquals('StaticUser', $emailMessageRecipients[9]->type);
973  $this->assertEquals(1, $emailMessageRecipients[9]->audienceType);
974  $this->assertEquals(6, $emailMessageRecipients[9]->userId);
975  $this->assertTrue($emailMessageRecipients[10] instanceof StaticAddressWorkflowEmailMessageRecipientForm);
976  $this->assertEquals('StaticAddress', $emailMessageRecipients[10]->type);
977  $this->assertEquals(2, $emailMessageRecipients[10]->audienceType);
978  $this->assertEquals('somebody', $emailMessageRecipients[10]->toName);
979  $this->assertEquals('someone@zurmo.com', $emailMessageRecipients[10]->toAddress);
980  $this->assertTrue($emailMessageRecipients[11] instanceof StaticGroupWorkflowEmailMessageRecipientForm);
981  $this->assertEquals('StaticGroup', $emailMessageRecipients[11]->type);
982  $this->assertEquals(3, $emailMessageRecipients[11]->audienceType);
983  $this->assertEquals(7, $emailMessageRecipients[11]->groupId);
984  }
985  }
986 ?>
static resolveEmailMessages($data, Workflow $workflow)
static getByUsername($username)
Definition: User.php:49
static getByCode($code)
Definition: Currency.php:90
static resolveTimeTrigger($data, Workflow $workflow)
static convertDateTimeLocaleFormattedDisplayToDbFormattedDateTimeWithSecondsAsZero($localeFormattedDateTime)
static loadStartingData()
static resolveTriggers($data, Workflow $workflow)
static resolveWorkflowByWizardPostData(Workflow $workflow, $postData, $wizardFormClassName)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null, $buildFirstCurrency=true)
Definition: Currency.php:107
static sanitizeTriggersData($moduleClassName, $workflowType, array $triggersData)
testResolveUpdateRelatedActionWithDynamicValuesSpecificallyDynamicOwnerOfTriggeredModel()
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
static resolveActions($data, Workflow $workflow)
Generated on Thu Mar 4 2021 07:10:27
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.