All Data Structures Functions Variables Pages
CampaignItemActivityUtilTest.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  ********************************************************************************/
37  {
38  protected $user;
39 
40  public static function setUpBeforeClass()
41  {
42  parent::setUpBeforeClass();
43  SecurityTestHelper::createSuperAdmin();
44  SecurityTestHelper::createUsers();
45  }
46 
47  public function setUp()
48  {
49  parent::setUp();
50  $this->user = User::getByUsername('super');
51  Yii::app()->user->userModel = $this->user;
52  }
53 
58  {
59  CampaignItemActivityUtil::resolveQueryStringFromUrlAndCreateOrUpdateActivity();
60  }
61 
66  {
67  // setup pre-req data
68  $contact = ContactTestHelper::createContactByNameForOwner('contact 01', $this->user);
69  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 01',
70  'description 01',
71  'fromName 01',
72  'fromAddress01@domain.com');
73  $campaign = CampaignTestHelper::createCampaign('campaign 01',
74  'subject 01',
75  'text Content 01',
76  'html Content 01',
77  'fromName 01',
78  'fromAddress01@zurmo.com',
79  null,
80  null,
81  null,
82  null,
83  $marketingList);
84  $processed = 0;
85  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
86  $modelId = $campaignItem->id;
87  $modelType = get_class($campaignItem);
88  $personId = $contact->getClassId('Person');
89  $this->assertNotNull($personId);
90 
91  // get the modelClassName to use for activity object tests
92  $className = 'CampaignItemActivityUtil';
93  $resolveModelClassNameByModelTypeFunction = static::getProtectedMethod($className,
94  'resolveModelClassNameByModelType');
95  $modelClassName = $resolveModelClassNameByModelTypeFunction->invokeArgs(null,
96  array($modelType));
97  $type = $modelClassName::TYPE_OPEN;
98  $existingActivities = $modelClassName::getByType($type);
99  $this->assertCount(0, $existingActivities);
100 
101  // get base query string
102  $resolveBaseQueryStringArrayFunction = static::getProtectedMethod('ContentTrackingUtil',
103  'resolveBaseQueryStringArray');
104  $queryStringArray = $resolveBaseQueryStringArrayFunction->invokeArgs(null, array(
105  $modelId,
106  $modelType,
107  $personId));
108  $this->assertNotEmpty($queryStringArray);
109  $this->assertCount(3, $queryStringArray);
110  $this->assertArrayHasKey('modelId', $queryStringArray);
111  $this->assertArrayHasKey('modelType', $queryStringArray);
112  $this->assertArrayHasKey('personId', $queryStringArray);
113 
114  // get hash for query string and ensure its what we expect it to be.
115  $queryStringArrayHash = StringUtil::resolveHashForQueryStringArray($queryStringArray);
116  $queryStringArrayDecoded = $className::resolveQueryStringArrayForHash($queryStringArrayHash);
117  $this->assertNotEmpty($queryStringArrayDecoded);
118  $this->assertCount(5, $queryStringArrayDecoded);
119  $this->assertArrayHasKey('modelId', $queryStringArrayDecoded);
120  $this->assertArrayHasKey('modelType', $queryStringArrayDecoded);
121  $this->assertArrayHasKey('personId', $queryStringArrayDecoded);
122  $this->assertArrayHasKey('url', $queryStringArrayDecoded);
123  $this->assertArrayHasKey('type', $queryStringArrayDecoded);
124  $this->assertEquals($queryStringArray['modelId'], $queryStringArrayDecoded['modelId']);
125  $this->assertEquals($queryStringArray['modelType'], $queryStringArrayDecoded['modelType']);
126  $this->assertEquals($queryStringArray['personId'], $queryStringArrayDecoded['personId']);
127  $this->assertNull($queryStringArrayDecoded['url']);
128  $this->assertNull($queryStringArrayDecoded['type']);
129 
130  // do the magic, confirm magic worked by checking return value.
131  $_GET['id'] = $queryStringArrayHash;
132  $result = $className::resolveQueryStringFromUrlAndCreateOrUpdateActivity();
133  $this->assertNotEmpty($result);
134  $this->assertCount(2, $result);
135  $this->assertArrayHasKey('redirect', $result);
136  $this->assertArrayHasKey('imagePath', $result);
137  $this->assertEquals(false, $result['redirect']);
138  $this->assertEquals(PlaceholderImageUtil::resolveOneByOnePixelImagePath(), $result['imagePath']);
139 
140  // check activity object count to confirm we got a new activity
141  $existingActivities = $modelClassName::getByType($type);
142  $this->assertCount(1, $existingActivities);
143  // try fetching an object matching criteria of the one we just inserted.
144  $activity = $modelClassName::getByTypeAndModelIdAndPersonIdAndUrl($type,
145  $modelId,
146  $personId);
147  $this->assertNotEmpty($activity);
148  $this->assertCount(1, $activity);
149  $this->assertEquals(1, $activity[0]->quantity);
150 
151  // do the magic again, this time it should update quantity
152  $result = $className::resolveQueryStringFromUrlAndCreateOrUpdateActivity();
153  $this->assertNotEmpty($result);
154  $this->assertCount(2, $result);
155  $this->assertArrayHasKey('redirect', $result);
156  $this->assertArrayHasKey('imagePath', $result);
157  $this->assertEquals(false, $result['redirect']);
158  $this->assertEquals(PlaceholderImageUtil::resolveOneByOnePixelImagePath(), $result['imagePath']);
159 
160  // check activity object count to confirm we got a new activity
161  $existingActivities = $modelClassName::getByType($type);
162  $this->assertCount(1, $existingActivities);
163  // try fetching an object matching criteria of the one we just inserted.
164  $type = $modelClassName::TYPE_OPEN;
165  $activity = $modelClassName::getByTypeAndModelIdAndPersonIdAndUrl($type,
166  $modelId,
167  $personId);
168  $this->assertNotEmpty($activity);
169  $this->assertCount(1, $activity);
170  $this->assertEquals(2, $activity[0]->quantity);
171  }
172 
178  {
179  // setup pre-req data
180  $contact = ContactTestHelper::createContactByNameForOwner('contact 02', $this->user);
181  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 02',
182  'description 02',
183  'fromName 02',
184  'fromAddress02@domain.com');
185  $campaign = CampaignTestHelper::createCampaign('campaign 02',
186  'subject 02',
187  'text Content 02',
188  'html Content 02',
189  'fromName 02',
190  'fromAddress02@zurmo.com',
191  null,
192  null,
193  null,
194  null,
195  $marketingList);
196  $processed = 0;
197  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
198  $modelId = $campaignItem->id;
199  $modelId += 200;
200  $modelType = get_class($campaignItem);
201  $personId = $contact->getClassId('Person');
202  $this->assertNotNull($personId);
203 
204  // get the modelClassName to use for activity object tests
205  $className = 'CampaignItemActivityUtil';
206  $resolveModelClassNameByModelTypeFunction = static::getProtectedMethod($className,
207  'resolveModelClassNameByModelType');
208  $modelClassName = $resolveModelClassNameByModelTypeFunction->invokeArgs(null,
209  array($modelType));
210  $type = $modelClassName::TYPE_OPEN;
211  $existingActivities = $modelClassName::getByType($type);
212  $this->assertCount(1, $existingActivities);
213 
214  // get base query string
215  $resolveBaseQueryStringArrayFunction = static::getProtectedMethod('ContentTrackingUtil',
216  'resolveBaseQueryStringArray');
217  $queryStringArray = $resolveBaseQueryStringArrayFunction->invokeArgs(null, array(
218  $modelId,
219  $modelType,
220  $personId));
221  $this->assertNotEmpty($queryStringArray);
222  $this->assertCount(3, $queryStringArray);
223  $this->assertArrayHasKey('modelId', $queryStringArray);
224  $this->assertArrayHasKey('modelType', $queryStringArray);
225  $this->assertArrayHasKey('personId', $queryStringArray);
226 
227  // get hash for query string and ensure its what we expect it to be.
228  $queryStringArrayHash = StringUtil::resolveHashForQueryStringArray($queryStringArray);
229  $queryStringArrayDecoded = $className::resolveQueryStringArrayForHash($queryStringArrayHash);
230  $this->assertNotEmpty($queryStringArrayDecoded);
231  $this->assertCount(5, $queryStringArrayDecoded);
232  $this->assertArrayHasKey('modelId', $queryStringArrayDecoded);
233  $this->assertArrayHasKey('modelType', $queryStringArrayDecoded);
234  $this->assertArrayHasKey('personId', $queryStringArrayDecoded);
235  $this->assertArrayHasKey('url', $queryStringArrayDecoded);
236  $this->assertArrayHasKey('type', $queryStringArrayDecoded);
237  $this->assertEquals($queryStringArray['modelId'], $queryStringArrayDecoded['modelId']);
238  $this->assertEquals($queryStringArray['modelType'], $queryStringArrayDecoded['modelType']);
239  $this->assertEquals($queryStringArray['personId'], $queryStringArrayDecoded['personId']);
240  $this->assertNull($queryStringArrayDecoded['url']);
241  $this->assertNull($queryStringArrayDecoded['type']);
242 
243  // do the magic, confirm magic worked by checking return value.
244  $_GET['id'] = $queryStringArrayHash;
245  $result = $className::resolveQueryStringFromUrlAndCreateOrUpdateActivity();
246  }
247 
253  {
254  // setup pre-req data
255  $contact = ContactTestHelper::createContactByNameForOwner('contact 03', $this->user);
256  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 03',
257  'description 03',
258  'fromName 03',
259  'fromAddress03@domain.com');
260  $campaign = CampaignTestHelper::createCampaign('campaign 03',
261  'subject 03',
262  'text Content 03',
263  'html Content 03',
264  'fromName 03',
265  'fromAddress03@zurmo.com',
266  null,
267  null,
268  null,
269  null,
270  $marketingList);
271  $processed = 0;
272  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
273  $modelId = $campaignItem->id;
274  $modelType = get_class($campaignItem);
275  $personId = $contact->getClassId('Person');
276  $this->assertNotNull($personId);
277  $personId = $personId + 200;
278 
279  // get the modelClassName to use for activity object tests
280  $className = 'CampaignItemActivityUtil';
281  $resolveModelClassNameByModelTypeFunction = static::getProtectedMethod($className,
282  'resolveModelClassNameByModelType');
283  $modelClassName = $resolveModelClassNameByModelTypeFunction->invokeArgs(null,
284  array($modelType));
285  $type = $modelClassName::TYPE_OPEN;
286  $existingActivities = $modelClassName::getByType($type);
287  $this->assertCount(1, $existingActivities);
288 
289  // get base query string
290  $resolveBaseQueryStringArrayFunction = static::getProtectedMethod('ContentTrackingUtil',
291  'resolveBaseQueryStringArray');
292  $queryStringArray = $resolveBaseQueryStringArrayFunction->invokeArgs(null, array(
293  $modelId,
294  $modelType,
295  $personId));
296  $this->assertNotEmpty($queryStringArray);
297  $this->assertCount(3, $queryStringArray);
298  $this->assertArrayHasKey('modelId', $queryStringArray);
299  $this->assertArrayHasKey('modelType', $queryStringArray);
300  $this->assertArrayHasKey('personId', $queryStringArray);
301 
302  // get hash for query string and ensure its what we expect it to be.
303  $queryStringArrayHash = StringUtil::resolveHashForQueryStringArray($queryStringArray);
304  $queryStringArrayDecoded = $className::resolveQueryStringArrayForHash($queryStringArrayHash);
305  $this->assertNotEmpty($queryStringArrayDecoded);
306  $this->assertCount(5, $queryStringArrayDecoded);
307  $this->assertArrayHasKey('modelId', $queryStringArrayDecoded);
308  $this->assertArrayHasKey('modelType', $queryStringArrayDecoded);
309  $this->assertArrayHasKey('personId', $queryStringArrayDecoded);
310  $this->assertArrayHasKey('url', $queryStringArrayDecoded);
311  $this->assertArrayHasKey('type', $queryStringArrayDecoded);
312  $this->assertEquals($queryStringArray['modelId'], $queryStringArrayDecoded['modelId']);
313  $this->assertEquals($queryStringArray['modelType'], $queryStringArrayDecoded['modelType']);
314  $this->assertEquals($queryStringArray['personId'], $queryStringArrayDecoded['personId']);
315  $this->assertNull($queryStringArrayDecoded['url']);
316  $this->assertNull($queryStringArrayDecoded['type']);
317 
318  // do the magic, confirm magic worked by checking return value.
319  $_GET['id'] = $queryStringArrayHash;
320  $result = $className::resolveQueryStringFromUrlAndCreateOrUpdateActivity();
321  }
322 
328  {
329  // setup pre-req data
330  $campaignItemActivities = CampaignItemActivity::getByType(
331  CampaignItemActivity::TYPE_OPEN);
332  $this->assertNotEmpty($campaignItemActivities);
333  $campaignActivity = new CampaignItemActivity();
334  $campaignActivity->quantity = $campaignItemActivities[0]->quantity;
335  $campaignActivity->type = $campaignItemActivities[0]->type;
336  $campaignActivity->campaignItem = $campaignItemActivities[0]->campaignItem;
337  $campaignActivity->person = $campaignItemActivities[0]->person;
338  $this->assertTrue($campaignActivity->save());
339 
340  $modelId = $campaignItemActivities[0]->campaignItem->id;
341  $modelType = get_class($campaignItemActivities[0]->campaignItem);
342  $personId = $campaignItemActivities[0]->person->id;
343 
344  // get the modelClassName to use for activity object tests
345  $className = 'CampaignItemActivityUtil';
346  $resolveModelClassNameByModelTypeFunction = static::getProtectedMethod($className,
347  'resolveModelClassNameByModelType');
348  $modelClassName = $resolveModelClassNameByModelTypeFunction->invokeArgs(null,
349  array($modelType));
350  $type = $modelClassName::TYPE_OPEN;
351  $existingActivities = $modelClassName::getByType($type);
352  $this->assertCount(2, $existingActivities);
353 
354  // get base query string
355  $resolveBaseQueryStringArrayFunction = static::getProtectedMethod('ContentTrackingUtil',
356  'resolveBaseQueryStringArray');
357  $queryStringArray = $resolveBaseQueryStringArrayFunction->invokeArgs(null, array(
358  $modelId,
359  $modelType,
360  $personId));
361  $this->assertNotEmpty($queryStringArray);
362  $this->assertCount(3, $queryStringArray);
363  $this->assertArrayHasKey('modelId', $queryStringArray);
364  $this->assertArrayHasKey('modelType', $queryStringArray);
365  $this->assertArrayHasKey('personId', $queryStringArray);
366 
367  // get hash for query string and ensure its what we expect it to be.
368  $queryStringArrayHash = StringUtil::resolveHashForQueryStringArray($queryStringArray);
369  $queryStringArrayDecoded = $className::resolveQueryStringArrayForHash($queryStringArrayHash);
370  $this->assertNotEmpty($queryStringArrayDecoded);
371  $this->assertCount(5, $queryStringArrayDecoded);
372  $this->assertArrayHasKey('modelId', $queryStringArrayDecoded);
373  $this->assertArrayHasKey('modelType', $queryStringArrayDecoded);
374  $this->assertArrayHasKey('personId', $queryStringArrayDecoded);
375  $this->assertArrayHasKey('url', $queryStringArrayDecoded);
376  $this->assertArrayHasKey('type', $queryStringArrayDecoded);
377  $this->assertEquals($queryStringArray['modelId'], $queryStringArrayDecoded['modelId']);
378  $this->assertEquals($queryStringArray['modelType'], $queryStringArrayDecoded['modelType']);
379  $this->assertEquals($queryStringArray['personId'], $queryStringArrayDecoded['personId']);
380  $this->assertNull($queryStringArrayDecoded['url']);
381  $this->assertNull($queryStringArrayDecoded['type']);
382 
383  // do the magic, confirm magic worked by checking return value.
384  $_GET['id'] = $queryStringArrayHash;
385  $result = $className::resolveQueryStringFromUrlAndCreateOrUpdateActivity();
386  }
387 
388  // same tests but with url:
393  {
394  // setup pre-req data
395  $contact = ContactTestHelper::createContactByNameForOwner('contact 04', $this->user);
396  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 04',
397  'description 04',
398  'fromName 04',
399  'fromAddress04@domain.com');
400  $campaign = CampaignTestHelper::createCampaign('campaign 04',
401  'subject 04',
402  'text Content 04',
403  'html Content 04',
404  'fromName 04',
405  'fromAddress04@zurmo.com',
406  null,
407  null,
408  null,
409  null,
410  $marketingList);
411  $processed = 0;
412  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
413  $modelId = $campaignItem->id;
414  $modelType = get_class($campaignItem);
415  $personId = $contact->getClassId('Person');
416  $this->assertNotNull($personId);
417 
418  // get the modelClassName to use for activity object tests
419  $className = 'CampaignItemActivityUtil';
420  $resolveModelClassNameByModelTypeFunction = static::getProtectedMethod($className,
421  'resolveModelClassNameByModelType');
422  $modelClassName = $resolveModelClassNameByModelTypeFunction->invokeArgs(null,
423  array($modelType));
424  $type = $modelClassName::TYPE_CLICK;
425  $existingActivities = $modelClassName::getByType($type);
426  $this->assertCount(0, $existingActivities);
427 
428  // get base query string
429  $resolveBaseQueryStringArrayFunction = static::getProtectedMethod('ContentTrackingUtil', 'resolveBaseQueryStringArray');
430  $queryStringArray = $resolveBaseQueryStringArrayFunction->invokeArgs(null, array(
431  $modelId,
432  $modelType,
433  $personId));
434  $this->assertNotEmpty($queryStringArray);
435  $this->assertCount(3, $queryStringArray);
436  $this->assertArrayHasKey('modelId', $queryStringArray);
437  $this->assertArrayHasKey('modelType', $queryStringArray);
438  $this->assertArrayHasKey('personId', $queryStringArray);
439  $queryStringArray['url'] = 'http://www.zurmo.com';
440 
441  // get hash for query string and ensure its what we expect it to be.
442  $queryStringArrayHash = StringUtil::resolveHashForQueryStringArray($queryStringArray);
443  $queryStringArrayDecoded = $className::resolveQueryStringArrayForHash($queryStringArrayHash);
444  $this->assertNotEmpty($queryStringArrayDecoded);
445  $this->assertCount(5, $queryStringArrayDecoded);
446  $this->assertArrayHasKey('modelId', $queryStringArrayDecoded);
447  $this->assertArrayHasKey('modelType', $queryStringArrayDecoded);
448  $this->assertArrayHasKey('personId', $queryStringArrayDecoded);
449  $this->assertArrayHasKey('url', $queryStringArrayDecoded);
450  $this->assertArrayHasKey('type', $queryStringArrayDecoded);
451  $this->assertEquals($queryStringArray['modelId'], $queryStringArrayDecoded['modelId']);
452  $this->assertEquals($queryStringArray['modelType'], $queryStringArrayDecoded['modelType']);
453  $this->assertEquals($queryStringArray['personId'], $queryStringArrayDecoded['personId']);
454  $this->assertEquals($queryStringArray['url'], $queryStringArrayDecoded['url']);
455  $this->assertNull($queryStringArrayDecoded['type']);
456 
457  // do the magic, confirm magic worked by checking return value.
458  $_GET['id'] = $queryStringArrayHash;
459  $result = $className::resolveQueryStringFromUrlAndCreateOrUpdateActivity();
460  $this->assertNotEmpty($result);
461  $this->assertCount(2, $result);
462  $this->assertArrayHasKey('redirect', $result);
463  $this->assertArrayHasKey('url', $result);
464  $this->assertEquals(true, $result['redirect']);
465  $this->assertEquals($queryStringArray['url'], $result['url']);
466 
467  // check activity object count to confirm we got a new activity
468  $existingActivities = $modelClassName::getByType($type);
469  $this->assertCount(1, $existingActivities);
470  // try fetching an object matching criteria of the one we just inserted.
471  $activity = $modelClassName::getByTypeAndModelIdAndPersonIdAndUrl($type,
472  $modelId,
473  $personId);
474  $this->assertNotEmpty($activity);
475  $this->assertCount(1, $activity);
476  $this->assertEquals(1, $activity[0]->quantity);
477  $this->assertEquals($queryStringArray['url'], $activity[0]->emailMessageUrl->url);
478 
479  // do the magic again, this time it should update quantity
480  $result = $className::resolveQueryStringFromUrlAndCreateOrUpdateActivity();
481  $this->assertNotEmpty($result);
482  $this->assertCount(2, $result);
483  $this->assertArrayHasKey('redirect', $result);
484  $this->assertArrayHasKey('url', $result);
485  $this->assertEquals(true, $result['redirect']);
486  $this->assertEquals($queryStringArray['url'], $result['url']);
487 
488  // check activity object count to confirm we got a new activity
489  $existingActivities = $modelClassName::getByType($type);
490  $this->assertCount(1, $existingActivities);
491  // try fetching an object matching criteria of the one we just inserted.
492 
493  $activity = $modelClassName::getByTypeAndModelIdAndPersonIdAndUrl($type,
494  $modelId,
495  $personId);
496  $this->assertNotEmpty($activity);
497  $this->assertCount(1, $activity);
498  $this->assertEquals(2, $activity[0]->quantity);
499  }
500 
506  {
507  // setup pre-req data
508  $contact = ContactTestHelper::createContactByNameForOwner('contact 05', $this->user);
509  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 05',
510  'description 05',
511  'fromName 05',
512  'fromAddress05@domain.com');
513  $campaign = CampaignTestHelper::createCampaign('campaign 05',
514  'subject 05',
515  'text Content 05',
516  'html Content 05',
517  'fromName 05',
518  'fromAddress05@zurmo.com',
519  null,
520  null,
521  null,
522  null,
523  $marketingList);
524  $processed = 0;
525  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
526  $modelId = $campaignItem->id;
527  $modelId += 200;
528  $modelType = get_class($campaignItem);
529  $personId = $contact->getClassId('Person');
530  $this->assertNotNull($personId);
531 
532  // get the modelClassName to use for activity object tests
533  $className = 'CampaignItemActivityUtil';
534  $resolveModelClassNameByModelTypeFunction = static::getProtectedMethod($className,
535  'resolveModelClassNameByModelType');
536  $modelClassName = $resolveModelClassNameByModelTypeFunction->invokeArgs(null,
537  array($modelType));
538  $type = $modelClassName::TYPE_CLICK;
539  $existingActivities = $modelClassName::getByType($type);
540  $this->assertCount(1, $existingActivities);
541 
542  // get base query string
543  $resolveBaseQueryStringArrayFunction = static::getProtectedMethod('ContentTrackingUtil',
544  'resolveBaseQueryStringArray');
545  $queryStringArray = $resolveBaseQueryStringArrayFunction->invokeArgs(null, array(
546  $modelId,
547  $modelType,
548  $personId));
549  $this->assertNotEmpty($queryStringArray);
550  $this->assertCount(3, $queryStringArray);
551  $this->assertArrayHasKey('modelId', $queryStringArray);
552  $this->assertArrayHasKey('modelType', $queryStringArray);
553  $this->assertArrayHasKey('personId', $queryStringArray);
554  $queryStringArray['url'] = 'http://www.zurmo.com';
555 
556  // get hash for query string and ensure its what we expect it to be.
557  $queryStringArrayHash = StringUtil::resolveHashForQueryStringArray($queryStringArray);
558  $queryStringArrayDecoded = $className::resolveQueryStringArrayForHash($queryStringArrayHash);
559  $this->assertNotEmpty($queryStringArrayDecoded);
560  $this->assertCount(5, $queryStringArrayDecoded);
561  $this->assertArrayHasKey('modelId', $queryStringArrayDecoded);
562  $this->assertArrayHasKey('modelType', $queryStringArrayDecoded);
563  $this->assertArrayHasKey('personId', $queryStringArrayDecoded);
564  $this->assertArrayHasKey('url', $queryStringArrayDecoded);
565  $this->assertArrayHasKey('type', $queryStringArrayDecoded);
566  $this->assertEquals($queryStringArray['modelId'], $queryStringArrayDecoded['modelId']);
567  $this->assertEquals($queryStringArray['modelType'], $queryStringArrayDecoded['modelType']);
568  $this->assertEquals($queryStringArray['personId'], $queryStringArrayDecoded['personId']);
569  $this->assertEquals($queryStringArray['url'], $queryStringArrayDecoded['url']);
570  $this->assertNull($queryStringArrayDecoded['type']);
571 
572  // do the magic, confirm magic worked by checking return value.
573  $_GET['id'] = $queryStringArrayHash;
574  $result = $className::resolveQueryStringFromUrlAndCreateOrUpdateActivity();
575  }
576 
582  {
583  // setup pre-req data
584  $contact = ContactTestHelper::createContactByNameForOwner('contact 06', $this->user);
585  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 06',
586  'description 06',
587  'fromName 06',
588  'fromAddress06@domain.com');
589  $campaign = CampaignTestHelper::createCampaign('campaign 06',
590  'subject 06',
591  'text Content 06',
592  'html Content 06',
593  'fromName 06',
594  'fromAddress06@zurmo.com',
595  null,
596  null,
597  null,
598  null,
599  $marketingList);
600  $processed = 0;
601  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
602  $modelId = $campaignItem->id;
603  $modelType = get_class($campaignItem);
604  $personId = $contact->getClassId('Person');
605  $this->assertNotNull($personId);
606  $personId = $personId + 200;
607 
608  // get the modelClassName to use for activity object tests
609  $className = 'CampaignItemActivityUtil';
610  $resolveModelClassNameByModelTypeFunction = static::getProtectedMethod($className,
611  'resolveModelClassNameByModelType');
612  $modelClassName = $resolveModelClassNameByModelTypeFunction->invokeArgs(null,
613  array($modelType));
614  $type = $modelClassName::TYPE_CLICK;
615  $existingActivities = $modelClassName::getByType($type);
616  $this->assertCount(1, $existingActivities);
617 
618  // get base query string
619  $resolveBaseQueryStringArrayFunction = static::getProtectedMethod('ContentTrackingUtil',
620  'resolveBaseQueryStringArray');
621  $queryStringArray = $resolveBaseQueryStringArrayFunction->invokeArgs(null, array(
622  $modelId,
623  $modelType,
624  $personId));
625  $this->assertNotEmpty($queryStringArray);
626  $this->assertCount(3, $queryStringArray);
627  $this->assertArrayHasKey('modelId', $queryStringArray);
628  $this->assertArrayHasKey('modelType', $queryStringArray);
629  $this->assertArrayHasKey('personId', $queryStringArray);
630  $queryStringArray['url'] = 'http://www.zurmo.com';
631 
632  // get hash for query string and ensure its what we expect it to be.
633  $queryStringArrayHash = StringUtil::resolveHashForQueryStringArray($queryStringArray);
634  $queryStringArrayDecoded = $className::resolveQueryStringArrayForHash($queryStringArrayHash);
635  $this->assertNotEmpty($queryStringArrayDecoded);
636  $this->assertCount(5, $queryStringArrayDecoded);
637  $this->assertArrayHasKey('modelId', $queryStringArrayDecoded);
638  $this->assertArrayHasKey('modelType', $queryStringArrayDecoded);
639  $this->assertArrayHasKey('personId', $queryStringArrayDecoded);
640  $this->assertArrayHasKey('url', $queryStringArrayDecoded);
641  $this->assertArrayHasKey('type', $queryStringArrayDecoded);
642  $this->assertEquals($queryStringArray['modelId'], $queryStringArrayDecoded['modelId']);
643  $this->assertEquals($queryStringArray['modelType'], $queryStringArrayDecoded['modelType']);
644  $this->assertEquals($queryStringArray['personId'], $queryStringArrayDecoded['personId']);
645  $this->assertEquals($queryStringArray['url'], $queryStringArrayDecoded['url']);
646  $this->assertNull($queryStringArrayDecoded['type']);
647 
648  // do the magic, confirm magic worked by checking return value.
649  $_GET['id'] = $queryStringArrayHash;
650  $result = $className::resolveQueryStringFromUrlAndCreateOrUpdateActivity();
651  }
652 
658  {
659  // setup pre-req data
660  $campaignItemActivities = CampaignItemActivity::getByType(
661  CampaignItemActivity::TYPE_CLICK);
662  $this->assertNotEmpty($campaignItemActivities);
663  $campaignActivity = new CampaignItemActivity();
664  $campaignActivity->quantity = $campaignItemActivities[0]->quantity;
665  $campaignActivity->type = $campaignItemActivities[0]->type;
666  $campaignActivity->campaignItem = $campaignItemActivities[0]->campaignItem;
667  $campaignActivity->person = $campaignItemActivities[0]->person;
668  $campaignActivity->emailMessageUrl = $campaignItemActivities[0]->emailMessageUrl;
669  $this->assertTrue($campaignActivity->save());
670 
671  $modelId = $campaignItemActivities[0]->campaignItem->id;
672  $modelType = get_class($campaignItemActivities[0]->campaignItem);
673  $personId = $campaignItemActivities[0]->person->id;
674 
675  // get the modelClassName to use for activity object tests
676  $className = 'CampaignItemActivityUtil';
677  $resolveModelClassNameByModelTypeFunction = static::getProtectedMethod($className,
678  'resolveModelClassNameByModelType');
679  $modelClassName = $resolveModelClassNameByModelTypeFunction->invokeArgs(null, array($modelType));
680  $type = $modelClassName::TYPE_CLICK;
681  $existingActivities = $modelClassName::getByType($type);
682  $this->assertCount(2, $existingActivities);
683 
684  // get base query string
685  $resolveBaseQueryStringArrayFunction = static::getProtectedMethod('ContentTrackingUtil',
686  'resolveBaseQueryStringArray');
687  $queryStringArray = $resolveBaseQueryStringArrayFunction->invokeArgs(null, array(
688  $modelId,
689  $modelType,
690  $personId));
691  $this->assertNotEmpty($queryStringArray);
692  $this->assertCount(3, $queryStringArray);
693  $this->assertArrayHasKey('modelId', $queryStringArray);
694  $this->assertArrayHasKey('modelType', $queryStringArray);
695  $this->assertArrayHasKey('personId', $queryStringArray);
696  $queryStringArray['url'] = 'http://www.zurmo.com';
697 
698  // get hash for query string and ensure its what we expect it to be.
699  $queryStringArrayHash = StringUtil::resolveHashForQueryStringArray($queryStringArray);
700  $queryStringArrayDecoded = $className::resolveQueryStringArrayForHash($queryStringArrayHash);
701  $this->assertNotEmpty($queryStringArrayDecoded);
702  $this->assertCount(5, $queryStringArrayDecoded);
703  $this->assertArrayHasKey('modelId', $queryStringArrayDecoded);
704  $this->assertArrayHasKey('modelType', $queryStringArrayDecoded);
705  $this->assertArrayHasKey('personId', $queryStringArrayDecoded);
706  $this->assertArrayHasKey('url', $queryStringArrayDecoded);
707  $this->assertArrayHasKey('type', $queryStringArrayDecoded);
708  $this->assertEquals($queryStringArray['modelId'], $queryStringArrayDecoded['modelId']);
709  $this->assertEquals($queryStringArray['modelType'], $queryStringArrayDecoded['modelType']);
710  $this->assertEquals($queryStringArray['personId'], $queryStringArrayDecoded['personId']);
711  $this->assertEquals($queryStringArray['url'], $queryStringArrayDecoded['url']);
712  $this->assertNull($queryStringArrayDecoded['type']);
713 
714  // do the magic, confirm magic worked by checking return value.
715  $_GET['id'] = $queryStringArrayHash;
716  $result = $className::resolveQueryStringFromUrlAndCreateOrUpdateActivity();
717  }
718  }
719 ?>
testResolveQueryStringFromUrlAndCreateOrUpdateActivityThrowsExceptionForInvalidCampaignItemIdForEmailOpenTracking()
testResolveQueryStringFromUrlAndCreateOrUpdateActivityThrowsExceptionForDuplicateActivityForUrlClickTracking()
static getByUsername($username)
Definition: User.php:49
testResolveQueryStringFromUrlAndCreateOrUpdateActivityForEmailOpenTrackingWithoutExceptions()
testResolveQueryStringFromUrlAndCreateOrUpdateActivityThrowsExceptionForInvalidPersonIdForUrlClickTracking()
testResolveQueryStringFromUrlAndCreateOrUpdateActivityThrowsExceptionForInvalidCampaignItemIdForUrlClickTracking()
testResolveQueryStringFromUrlAndCreateOrUpdateActivityThrowsExceptionForInvalidPersonIdForEmailOpenTracking()
testResolveQueryStringFromUrlAndCreateOrUpdateActivityThrowsExceptionWhenNoIdInQueryString()
testResolveQueryStringFromUrlAndCreateOrUpdateActivityThrowsExceptionForDuplicateActivityForEmailOpenTracking()
testResolveQueryStringFromUrlAndCreateOrUpdateActivityForUrlClickTrackingWithoutExceptions()
Generated on Fri Jun 5 2020 07:10:30