All Data Structures Functions Variables Pages
CampaignItemsUtilTest.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  // We don't need to add separate tests for tracking scenarios here because we have already gained more than
39  // sufficient coverage in CampaignItemActivityUtilTest and EmailMessageActivityUtilTest for those.
40  protected $user;
41 
42  public static function setUpBeforeClass()
43  {
44  parent::setUpBeforeClass();
45  SecurityTestHelper::createSuperAdmin();
46  }
47 
48  public function setUp()
49  {
50  parent::setUp();
51  $this->user = User::getByUsername('super');
52  Yii::app()->user->userModel = $this->user;
54  }
55 
60  {
61  $html = "[[FIRST^NAME]], You are receiving this email";
62  $text = null;
63  $contact = ContactTestHelper::createContactByNameForOwner('contact 01', $this->user);
64  $marketingList = MarketingListTestHelper::populateMarketingListByName('marketingList 01');
65  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
66  $campaign = CampaignTestHelper::createCampaign('campaign 01',
67  'subject 01',
68  $text,
69  $html,
70  null,
71  null,
72  null,
73  null,
74  null,
75  null,
76  $marketingList,
77  false);
78  $processed = 0;
79  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
80  $this->processDueItem($campaignItem);
81  }
82 
88  {
89  $text = "[[FIRST^NAME]], You are receiving this email";
90  $html = null;
91  $contact = ContactTestHelper::createContactByNameForOwner('contact 01', $this->user);
92  $marketingList = MarketingListTestHelper::populateMarketingListByName('marketingList 01');
93  $campaign = CampaignTestHelper::createCampaign('campaign 01',
94  'subject 01',
95  $text,
96  $html,
97  null,
98  null,
99  null,
100  null,
101  null,
102  null,
103  $marketingList,
104  false);
105  $processed = 0;
106  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
107  $this->processDueItem($campaignItem);
108  }
109 
115  {
116  $campaignItem = new CampaignItem();
117  $this->processDueItem($campaignItem);
118  }
119 
126  {
127  $contact = ContactTestHelper::createContactByNameForOwner('contact 01', $this->user);
128  $marketingList = MarketingListTestHelper::populateMarketingListByName('marketingList 01');
129  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
130  $campaign = CampaignTestHelper::createCampaign('campaign 01',
131  'subject 01',
132  '[[TEXT^CONTENT]]',
133  '[[HTML^CONTENT]]',
134  null,
135  null,
136  null,
137  null,
138  null,
139  null,
140  $marketingList,
141  false);
142  $processed = 0;
143  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
144  $this->processDueItem($campaignItem);
145  }
146 
151  {
152  $contact = ContactTestHelper::createContactByNameForOwner('contact 02', $this->user);
153  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 02');
154  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
155  $campaign = CampaignTestHelper::createCampaign('campaign 02',
156  'subject 02',
157  'text content',
158  'html content',
159  null,
160  null,
161  null,
162  null,
163  null,
164  0,
165  $marketingList);
166  $processed = 0;
167  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
168  $this->processDueItem($campaignItem);
169  $this->assertEquals(1, $campaignItem->processed);
170  $emailMessage = $campaignItem->emailMessage;
171  $this->assertEquals($marketingList->owner->id, $emailMessage->owner->id);
172  $marketingListPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($marketingList);
173  $emailMessagePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($emailMessage);
174  $this->assertEquals($marketingListPermissions, $emailMessagePermissions);
175  $this->assertNull($emailMessage->subject);
176  $this->assertNull($emailMessage->content->textContent);
177  $this->assertNull($emailMessage->content->htmlContent);
178  $this->assertNull($emailMessage->sender->fromAddress);
179  $this->assertNull($emailMessage->sender->fromName);
180  $this->assertEquals(0, $emailMessage->recipients->count());
181 
182  //Test with empty primary email address
183  $contact->primaryEmail->emailAddress = '';
184  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
185  $this->processDueItem($campaignItem);
186  $this->assertEquals(1, $campaignItem->processed);
187  $emailMessage = $campaignItem->emailMessage;
188  $this->assertEquals($marketingList->owner->id, $emailMessage->owner->id);
189  $marketingListPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($marketingList);
190  $emailMessagePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($emailMessage);
191  $this->assertEquals($marketingListPermissions, $emailMessagePermissions);
192  $this->assertNull($emailMessage->subject);
193  $this->assertNull($emailMessage->content->textContent);
194  $this->assertNull($emailMessage->content->htmlContent);
195  $this->assertNull($emailMessage->sender->fromAddress);
196  $this->assertNull($emailMessage->sender->fromName);
197  $this->assertEquals(0, $emailMessage->recipients->count());
198  }
199 
204  {
205  $email = new Email();
206  $email->emailAddress = 'demo@zurmo.com';
207  $contact = ContactTestHelper::createContactByNameForOwner('contact 03', $this->user);
208  $contact->primaryEmail = $email;
209  $this->assertTrue($contact->save());
210  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 03');
211  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
212  $campaign = CampaignTestHelper::createCampaign('campaign 03',
213  'subject 03',
214  'text content',
215  'html content',
216  null,
217  null,
218  null,
219  null,
220  null,
221  null,
222  $marketingList);
223 
224  $processed = 0;
225  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
226  $this->processDueItem($campaignItem);
227  $this->assertEquals(1, $campaignItem->processed);
228  $emailMessage = $campaignItem->emailMessage;
229  $this->assertEquals($marketingList->owner->id, $emailMessage->owner->id);
230  $marketingListPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($marketingList);
231  $emailMessagePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($emailMessage);
232  $this->assertEquals($marketingListPermissions, $emailMessagePermissions);
233  $this->assertEquals($campaign->subject, $emailMessage->subject);
234  $this->assertContains($campaign->textContent, $emailMessage->content->textContent);
235  $this->assertContains('/marketingLists/external/', $emailMessage->content->textContent);
236  $this->assertEquals(2, substr_count($emailMessage->content->textContent, '/marketingLists/external/'));
237  $this->assertContains($campaign->htmlContent, $emailMessage->content->htmlContent);
238  $this->assertContains('/marketingLists/external/', $emailMessage->content->htmlContent);
239  $this->assertEquals(2, substr_count($emailMessage->content->htmlContent, '/marketingLists/external/'));
240  $this->assertEquals('support@zurmo.com', $emailMessage->sender->fromAddress);
241  $this->assertEquals('Support Team', $emailMessage->sender->fromName);
242  $this->assertEquals(1, $emailMessage->recipients->count());
243  $recipients = $emailMessage->recipients;
244  $this->assertEquals(strval($contact), $recipients[0]->toName);
245  $this->assertEquals($email->emailAddress, $recipients[0]->toAddress);
246  $this->assertEquals(EmailMessageRecipient::TYPE_TO, $recipients[0]->type);
247  $this->assertEquals($contact->getClassId('Item'), $recipients[0]->personsOrAccounts[0]->id);
248  $headersArray = array('zurmoItemId' => $campaignItem->id,
249  'zurmoItemClass' => get_class($campaignItem),
250  'zurmoPersonId' => $contact->getClassId('Person'));
251  $expectedHeaders = serialize($headersArray);
252  $this->assertEquals($expectedHeaders, $emailMessage->headers);
253  }
254 
259  {
260  $email = new Email();
261  $email->emailAddress = 'demo@zurmo.com';
262  $contact = ContactTestHelper::createContactByNameForOwner('contact 04', $this->user);
263  $contact->primaryEmail = $email;
264  $this->assertTrue($contact->save());
265  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 04',
266  'description',
267  'CustomFromName',
268  'custom@from.com');
269  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
270  $campaign = CampaignTestHelper::createCampaign('campaign 04',
271  'subject 04',
272  'text content',
273  'html content',
274  null,
275  null,
276  null,
277  null,
278  null,
279  0,
280  $marketingList);
281  $processed = 0;
282  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
283  $this->processDueItem($campaignItem);
284  $this->assertEquals(1, $campaignItem->processed);
285  $emailMessage = $campaignItem->emailMessage;
286  $this->assertEquals($marketingList->owner->id, $emailMessage->owner->id);
287  $marketingListPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($marketingList);
288  $emailMessagePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($emailMessage);
289  $this->assertEquals($marketingListPermissions, $emailMessagePermissions);
290  $this->assertEquals($campaign->subject, $emailMessage->subject);
291  $this->assertContains($campaign->textContent, $emailMessage->content->textContent);
292  $this->assertContains('/marketingLists/external/', $emailMessage->content->textContent);
293  $this->assertEquals(2, substr_count($emailMessage->content->textContent, '/marketingLists/external/'));
294  $this->assertContains($campaign->htmlContent, $emailMessage->content->htmlContent);
295  $this->assertContains('/marketingLists/external/', $emailMessage->content->htmlContent);
296  $this->assertEquals(2, substr_count($emailMessage->content->htmlContent, '/marketingLists/external/'));
297  $this->assertEquals('support@zurmo.com', $emailMessage->sender->fromAddress);
298  $this->assertEquals('Support Team', $emailMessage->sender->fromName);
299  $this->assertEquals(1, $emailMessage->recipients->count());
300  $recipients = $emailMessage->recipients;
301  $this->assertEquals(strval($contact), $recipients[0]->toName);
302  $this->assertEquals($email->emailAddress, $recipients[0]->toAddress);
303  $this->assertEquals(EmailMessageRecipient::TYPE_TO, $recipients[0]->type);
304  $this->assertEquals($contact->getClassId('Item'), $recipients[0]->personsOrAccounts[0]->id);
305  $headersArray = array('zurmoItemId' => $campaignItem->id,
306  'zurmoItemClass' => get_class($campaignItem),
307  'zurmoPersonId' => $contact->getClassId('Person'));
308  $expectedHeaders = serialize($headersArray);
309  $this->assertEquals($expectedHeaders, $emailMessage->headers);
310  }
311 
316  {
317  $email = new Email();
318  $email->emailAddress = 'demo@zurmo.com';
319  $contact = ContactTestHelper::createContactByNameForOwner('contact 05', $this->user);
320  $contact->primaryEmail = $email;
321  $this->assertTrue($contact->save());
322  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 05',
323  'description',
324  'CustomFromName',
325  'custom@from.com');
326  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
327  $campaign = CampaignTestHelper::createCampaign('campaign 05',
328  'subject 05',
329  'Dr. [[FIRST^NAME]] [[LAST^NAME]]',
330  '<b>[[LAST^NAME]]</b>, [[FIRST^NAME]]',
331  null,
332  null,
333  null,
334  null,
335  null,
336  null,
337  $marketingList);
338  $processed = 0;
339  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
340  $this->processDueItem($campaignItem);
341  $this->assertEquals(1, $campaignItem->processed);
342  $emailMessage = $campaignItem->emailMessage;
343  $this->assertEquals($marketingList->owner->id, $emailMessage->owner->id);
344  $marketingListPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($marketingList);
345  $emailMessagePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($emailMessage);
346  $this->assertEquals($marketingListPermissions, $emailMessagePermissions);
347  $this->assertEquals($campaign->subject, $emailMessage->subject);
348  $this->assertNotEquals($campaign->textContent, $emailMessage->content->textContent);
349  $this->assertNotEquals($campaign->htmlContent, $emailMessage->content->htmlContent);
350  $this->assertContains('Dr. contact 05 contact 05son', $emailMessage->content->textContent);
351  $this->assertContains('/marketingLists/external/', $emailMessage->content->textContent);
352  $this->assertEquals(2, substr_count($emailMessage->content->textContent, '/marketingLists/external/'));
353  $this->assertContains('<b>contact 05son</b>, contact 05', $emailMessage->content->htmlContent);
354  $this->assertContains('/marketingLists/external/', $emailMessage->content->htmlContent);
355  $this->assertEquals(2, substr_count($emailMessage->content->htmlContent, '/marketingLists/external/'));
356  $this->assertEquals('support@zurmo.com', $emailMessage->sender->fromAddress);
357  $this->assertEquals('Support Team', $emailMessage->sender->fromName);
358  $this->assertEquals(1, $emailMessage->recipients->count());
359  $recipients = $emailMessage->recipients;
360  $this->assertEquals(strval($contact), $recipients[0]->toName);
361  $this->assertEquals($email->emailAddress, $recipients[0]->toAddress);
362  $this->assertEquals(EmailMessageRecipient::TYPE_TO, $recipients[0]->type);
363  $this->assertEquals($contact->getClassId('Item'), $recipients[0]->personsOrAccounts[0]->id);
364  $headersArray = array('zurmoItemId' => $campaignItem->id,
365  'zurmoItemClass' => get_class($campaignItem),
366  'zurmoPersonId' => $contact->getClassId('Person'));
367  $expectedHeaders = serialize($headersArray);
368  $this->assertEquals($expectedHeaders, $emailMessage->headers);
369  }
370 
375  {
376  $email = new Email();
377  $email->emailAddress = 'demo@zurmo.com';
378  $contact = ContactTestHelper::createContactByNameForOwner('contact 06', $this->user);
379  $contact->primaryEmail = $email;
380  $this->assertTrue($contact->save());
381  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 06',
382  'description',
383  'CustomFromName',
384  'custom@from.com');
385  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
386  $campaign = CampaignTestHelper::createCampaign('campaign 06',
387  'subject 06',
388  'Dr. [[FIRST^NAME]] [[LAST^NAME]]',
389  '<b>[[LAST^NAME]]</b>, [[FIRST^NAME]]',
390  null,
391  null,
392  null,
393  null,
394  null,
395  null,
396  $marketingList);
397  $fileNames = array('testImage.png', 'testZip.zip', 'testPDF.pdf');
398  $files = array();
399  foreach ($fileNames as $index => $fileName)
400  {
401  $file = ZurmoTestHelper::createFileModel($fileName);
402  $files[$index]['name'] = $fileName;
403  $files[$index]['type'] = $file->type;
404  $files[$index]['size'] = $file->size;
405  $files[$index]['contents'] = $file->fileContent->content;
406  $campaign->files->add($file);
407  }
408  $this->assertTrue($campaign->save());
409  $processed = 0;
410  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
411  $this->processDueItem($campaignItem);
412  $this->assertEquals(1, $campaignItem->processed);
413  $emailMessage = $campaignItem->emailMessage;
414  $this->assertEquals($marketingList->owner->id, $emailMessage->owner->id);
415  $marketingListPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($marketingList);
416  $emailMessagePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($emailMessage);
417  $this->assertEquals($marketingListPermissions, $emailMessagePermissions);
418  $this->assertEquals($campaign->subject, $emailMessage->subject);
419  $this->assertNotEquals($campaign->textContent, $emailMessage->content->textContent);
420  $this->assertNotEquals($campaign->htmlContent, $emailMessage->content->htmlContent);
421  $this->assertContains('Dr. contact 06 contact 06son', $emailMessage->content->textContent);
422  $this->assertContains('/marketingLists/external/', $emailMessage->content->textContent);
423  $this->assertEquals(2, substr_count($emailMessage->content->textContent, '/marketingLists/external/'));
424  $this->assertContains('<b>contact 06son</b>, contact 06', $emailMessage->content->htmlContent);
425  $this->assertContains('/marketingLists/external/', $emailMessage->content->htmlContent);
426  $this->assertEquals(2, substr_count($emailMessage->content->htmlContent, '/marketingLists/external/'));
427  $this->assertEquals('support@zurmo.com', $emailMessage->sender->fromAddress);
428  $this->assertEquals('Support Team', $emailMessage->sender->fromName);
429  $this->assertEquals(1, $emailMessage->recipients->count());
430  $recipients = $emailMessage->recipients;
431  $this->assertEquals(strval($contact), $recipients[0]->toName);
432  $this->assertEquals($email->emailAddress, $recipients[0]->toAddress);
433  $this->assertEquals(EmailMessageRecipient::TYPE_TO, $recipients[0]->type);
434  $this->assertEquals($contact->getClassId('Item'), $recipients[0]->personsOrAccounts[0]->id);
435  $this->assertNotEmpty($emailMessage->files);
436  $this->assertCount(count($files), $emailMessage->files);
437  foreach ($campaign->files as $index => $file)
438  {
439  $this->assertEquals($file->name, $emailMessage->files[$index]->name);
440  $this->assertEquals($file->type, $emailMessage->files[$index]->type);
441  $this->assertEquals($file->size, $emailMessage->files[$index]->size);
442  //CampaingItem should share the Attachments content from Campaign
443  $this->assertEquals($file->fileContent->content, $emailMessage->files[$index]->fileContent->content);
444  }
445  $headersArray = array('zurmoItemId' => $campaignItem->id,
446  'zurmoItemClass' => get_class($campaignItem),
447  'zurmoPersonId' => $contact->getClassId('Person'));
448  $expectedHeaders = serialize($headersArray);
449  $this->assertEquals($expectedHeaders, $emailMessage->headers);
450  }
451 
456  {
457  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 07');
458  $marketingListId = $marketingList->id;
459  for ($i = 0; $i < 5; $i++)
460  {
461  $contact = ContactTestHelper::createContactByNameForOwner('campaignContact ' . $i, $this->user);
462  MarketingListMemberTestHelper::createMarketingListMember($i % 2, $marketingList, $contact);
463  }
464  $marketingList->forgetAll();
465 
466  $marketingList = MarketingList::getById($marketingListId);
467  $campaign = CampaignTestHelper::createCampaign('campaign 07',
468  'subject 07',
469  'text 07',
470  'html 07',
471  null,
472  null,
473  null,
474  null,
475  null,
476  null,
477  $marketingList);
478  $this->assertNotNull($campaign);
479  $campaign->forgetAll();
480  $campaignId = $campaign->id;
481  $campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaignId);
482  $this->assertEmpty($campaignItems);
483  //Process open campaigns.
484  Yii::app()->jobQueue->deleteAll();
485  $this->assertCount(0, Yii::app()->jobQueue->getAll());
486  $util = new CampaignItemsUtil();
487  $this->assertTrue($util->generateCampaignItemsForDueCampaigns());
488  $jobs = Yii::app()->jobQueue->getAll();
489  $this->assertCount(1, $jobs);
490  $this->assertEquals('CampaignQueueMessagesInOutbox', $jobs[5][0]['jobType']);
491  $campaign = Campaign::getById($campaignId);
492  $this->assertNotNull($campaign);
493  $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
494  $campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaignId);
495  $this->assertNotEmpty($campaignItems);
496  $this->assertCount(5, $campaignItems);
497  // TODO: @Shoaibi: Low: Add tests for the other campaign type.
498  }
499 
504  {
505  $email = new Email();
506  $email->emailAddress = 'demo@zurmo.com';
507  $email->optOut = true;
508  $contact = ContactTestHelper::createContactByNameForOwner('contact 08', $this->user);
509  $contact->primaryEmail = $email;
510  $this->assertTrue($contact->save());
511  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 08',
512  'description',
513  'CustomFromName',
514  'custom@from.com');
515  $campaign = CampaignTestHelper::createCampaign('campaign 08',
516  'subject 08',
517  'Dr. [[FIRST^NAME]] [[LAST^NAME]]',
518  '<b>[[LAST^NAME]]</b>, [[FIRST^NAME]]',
519  null,
520  null,
521  null,
522  null,
523  null,
524  null,
525  $marketingList);
526  $processed = 0;
527  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
528  $this->processDueItem($campaignItem);
529  $this->assertEquals(1, $campaignItem->processed);
530  $personId = $contact->getClassId('Person');
531  $activities = CampaignItemActivity::getByTypeAndModelIdAndPersonIdAndUrl(
532  CampaignItemActivity::TYPE_SKIP,
533  $campaignItem->id,
534  $personId);
535  $this->assertNotEmpty($activities);
536  $this->assertCount(1, $activities);
537  }
538 
543  {
544  ZurmoConfigurationUtil::setByModuleName('EmailMessagesModule', 'bounceReturnPath', 'bounce@zurmo.com');
545  $email = new Email();
546  $email->emailAddress = 'demo@zurmo.com';
547  $contact = ContactTestHelper::createContactByNameForOwner('contact 09', $this->user);
548  $contact->primaryEmail = $email;
549  $this->assertTrue($contact->save());
550  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 09',
551  'description',
552  'CustomFromName',
553  'custom@from.com');
554  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
555  $campaign = CampaignTestHelper::createCampaign('campaign 09',
556  'subject 09',
557  'Dr. [[FIRST^NAME]] [[LAST^NAME]]',
558  '<b>[[LAST^NAME]]</b>, [[FIRST^NAME]]',
559  null,
560  null,
561  null,
562  null,
563  null,
564  null,
565  $marketingList);
566  $processed = 0;
567  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
568  $this->processDueItem($campaignItem);
569  $this->assertEquals(1, $campaignItem->processed);
570  $emailMessage = $campaignItem->emailMessage;
571  $this->assertEquals($marketingList->owner->id, $emailMessage->owner->id);
572  $marketingListPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($marketingList);
573  $emailMessagePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($emailMessage);
574  $this->assertEquals($marketingListPermissions, $emailMessagePermissions);
575  $this->assertEquals($campaign->subject, $emailMessage->subject);
576  $this->assertNotEquals($campaign->textContent, $emailMessage->content->textContent);
577  $this->assertNotEquals($campaign->htmlContent, $emailMessage->content->htmlContent);
578  $this->assertContains('Dr. contact 09 contact 09son', $emailMessage->content->textContent);
579  $this->assertContains('/marketingLists/external/', $emailMessage->content->textContent);
580  $this->assertEquals(2, substr_count($emailMessage->content->textContent, '/marketingLists/external/'));
581  $this->assertContains('<b>contact 09son</b>, contact 09', $emailMessage->content->htmlContent);
582  $this->assertContains('/marketingLists/external/', $emailMessage->content->htmlContent);
583  $this->assertEquals(2, substr_count($emailMessage->content->htmlContent, '/marketingLists/external/'));
584  $this->assertEquals('support@zurmo.com', $emailMessage->sender->fromAddress);
585  $this->assertEquals('Support Team', $emailMessage->sender->fromName);
586  $this->assertEquals(1, $emailMessage->recipients->count());
587  $recipients = $emailMessage->recipients;
588  $this->assertEquals(strval($contact), $recipients[0]->toName);
589  $this->assertEquals($email->emailAddress, $recipients[0]->toAddress);
590  $this->assertEquals(EmailMessageRecipient::TYPE_TO, $recipients[0]->type);
591  $this->assertEquals($contact->getClassId('Item'), $recipients[0]->personsOrAccounts[0]->id);
592  $headersArray = array('zurmoItemId' => $campaignItem->id,
593  'zurmoItemClass' => get_class($campaignItem),
594  'zurmoPersonId' => $contact->getClassId('Person'),
595  'Return-Path' => 'bounce@zurmo.com');
596  $expectedHeaders = serialize($headersArray);
597  $this->assertEquals($expectedHeaders, $emailMessage->headers);
598  }
599 
604  {
605  $email = new Email();
606  $email->emailAddress = 'demo10@zurmo.com';
607  $contact = ContactTestHelper::createContactByNameForOwner('contact 10', $this->user);
608  $contact->primaryEmail = $email;
609  $this->assertTrue($contact->save());
610  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 10',
611  'description',
612  'CustomFromName',
613  'custom@from.com');
614  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
615  $campaign = CampaignTestHelper::createCampaign('campaign 10',
616  'subject 10',
617  'Dr. [[FIRST^NAME]] [[LAST^NAME]]',
618  null,
619  null,
620  null,
621  false,
622  null,
623  null,
624  null,
625  $marketingList);
626  $processed = 0;
627  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
628  $this->processDueItem($campaignItem);
629  $emailMessage = $campaignItem->emailMessage;
630  $this->assertNotNull($emailMessage->content->textContent);
631  $this->assertNull ($emailMessage->content->htmlContent);
632  }
633 
638  {
639  $email = new Email();
640  $email->emailAddress = 'demo11@zurmo.com';
641  $contact = ContactTestHelper::createContactByNameForOwner('contact 11', $this->user);
642  $contact->primaryEmail = $email;
643  $this->assertTrue($contact->save());
644  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 11',
645  'description',
646  'CustomFromName',
647  'custom@from.com');
648  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
649  $campaign = CampaignTestHelper::createCampaign('campaign 11',
650  'subject 11',
651  null,
652  '<b>[[LAST^NAME]]</b>, [[FIRST^NAME]]',
653  null,
654  null,
655  null,
656  null,
657  null,
658  null,
659  $marketingList);
660  $processed = 0;
661  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
662  $this->processDueItem($campaignItem);
663  $emailMessage = $campaignItem->emailMessage;
664  $this->assertNull ($emailMessage->content->textContent);
665  $this->assertNotNull($emailMessage->content->htmlContent);
666  }
667 
672  {
673  $email = new Email();
674  $email->emailAddress = 'demo12@zurmo.com';
675  $contact = ContactTestHelper::createContactByNameForOwner('contact 12', $this->user);
676  $contact->primaryEmail = $email;
677  $this->assertTrue($contact->save());
678  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 12',
679  'description',
680  'CustomFromName',
681  'custom@from.com');
682  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
683  $campaign = CampaignTestHelper::createCampaign('campaign 12',
684  'subject 12',
685  'Dr. [[FIRST^NAME]] [[LAST^NAME]]',
686  '<b>[[LAST^NAME]]</b>, [[FIRST^NAME]]',
687  null,
688  null,
689  false,
690  null,
691  null,
692  null,
693  $marketingList);
694  $processed = 0;
695  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
696  $this->processDueItem($campaignItem);
697  $emailMessage = $campaignItem->emailMessage;
698  $this->assertNotNull($emailMessage->content->textContent);
699  $this->assertNull ($emailMessage->content->htmlContent);
700  }
701 
706  {
707  $email = new Email();
708  $email->emailAddress = 'demo13@zurmo.com';
709  $contact = ContactTestHelper::createContactByNameForOwner('contact 13', $this->user);
710  $contact->primaryEmail = $email;
711  $this->assertTrue($contact->save());
712  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 13',
713  'description',
714  'CustomFromName',
715  'custom@from.com');
716  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
717  $campaign = CampaignTestHelper::createCampaign('campaign 13',
718  'subject 13',
719  'Url: [[MODEL^URL]]',
720  'Click <a href="[[MODEL^URL]]">here</a>',
721  null,
722  null,
723  null,
724  null,
725  null,
726  null,
727  $marketingList);
728  $processed = 0;
729  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
730  $this->processDueItem($campaignItem);
731  $emailMessage = $campaignItem->emailMessage;
732  $this->assertNotNull ($emailMessage->content->textContent);
733  $this->assertNotNull($emailMessage->content->htmlContent);
734  $this->assertContains('/contacts/default/details?id=' . $contact->id, $emailMessage->content->textContent);
735  $this->assertContains('/contacts/default/details?id=' . $contact->id, $emailMessage->content->htmlContent);
736  }
737 
742  {
743  $email = new Email();
744  $email->emailAddress = 'demo14@zurmo.com';
745  $contact = ContactTestHelper::createContactByNameForOwner('contact 14', $this->user);
746  $contact->primaryEmail = $email;
747  $this->assertTrue($contact->save());
748  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 14',
749  'description',
750  null,
751  null);
752  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
753  $campaign = CampaignTestHelper::createCampaign('campaign 12',
754  'subject 12',
755  'Dr. [[FIRST^NAME]] [[LAST^NAME]]',
756  '<b>[[LAST^NAME]]</b>, [[FIRST^NAME]]',
757  'testFromName',
758  'test@zurmo.com',
759  null,
760  null,
761  null,
762  null,
763  $marketingList);
764  $processed = 0;
765  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
766  $this->processDueItem($campaignItem);
767  $emailMessage = $campaignItem->emailMessage;
768  $this->assertEquals('testFromName', $emailMessage->sender->fromName);
769  $this->assertEquals('test@zurmo.com', $emailMessage->sender->fromAddress);
770  }
771 
776  {
777  $email = new Email();
778  $email->emailAddress = 'demo15@zurmo.com';
779  $contact = ContactTestHelper::createContactByNameForOwner('contact 15', $this->user);
780  $contact->primaryEmail = $email;
781  $this->assertTrue($contact->save());
782  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 15',
783  'description',
784  null,
785  null);
786  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
787  $campaign = CampaignTestHelper::createCampaign('campaign 13',
788  'subject 13',
789  GlobalMarketingFooterUtil::resolveUnsubscribeUrlMergeTag(),
790  GlobalMarketingFooterUtil::resolveUnsubscribeUrlMergeTag(),
791  'testFromName',
792  'test@zurmo.com',
793  null,
794  null,
795  null,
796  null,
797  $marketingList);
798  $processed = 0;
799  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
800  $this->processDueItem($campaignItem);
801  $textContent = $campaignItem->emailMessage->content->textContent;
802  $htmlContent = $campaignItem->emailMessage->content->htmlContent;
803  $this->assertNotEquals($campaign->textContent, $textContent);
804  $this->assertNotEquals($campaign->htmlContent, $htmlContent);
805  $this->assertContains('localhost', $textContent);
806  $this->assertEquals(1, substr_count($textContent, '/marketingLists/external/unsubscribe?hash='));
807  $this->assertContains('localhost', $htmlContent);
808  $this->assertEquals(1, substr_count($htmlContent, '/marketingLists/external/unsubscribe?hash='));
809  $this->assertContains('<img width="1" height="1" src="localhost', $htmlContent);
810  $this->assertContains('/tracking/default/track?id=', $htmlContent);
811  $this->assertNotContains('/marketingLists/external/manageSubscriptions', $htmlContent);
812  }
813 
818  {
819  $email = new Email();
820  $email->emailAddress = 'demo16@zurmo.com';
821  $contact = ContactTestHelper::createContactByNameForOwner('contact 16', $this->user);
822  $contact->primaryEmail = $email;
823  $this->assertTrue($contact->save());
824  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 16',
825  'description',
826  null,
827  null);
828  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
829  $campaign = CampaignTestHelper::createCampaign('campaign 14',
830  'subject 14',
831  GlobalMarketingFooterUtil::resolveManageSubscriptionsMergeTag(),
832  GlobalMarketingFooterUtil::resolveManageSubscriptionsMergeTag(),
833  'testFromName',
834  'test@zurmo.com',
835  null,
836  null,
837  null,
838  null,
839  $marketingList);
840  $processed = 0;
841  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
842  $this->processDueItem($campaignItem);
843  $textContent = $campaignItem->emailMessage->content->textContent;
844  $htmlContent = $campaignItem->emailMessage->content->htmlContent;
845  $this->assertNotEquals($campaign->textContent, $textContent);
846  $this->assertNotEquals($campaign->htmlContent, $htmlContent);
847  $this->assertContains('localhost', $textContent);
848  $this->assertEquals(1, substr_count($textContent, '/marketingLists/external/manageSubscriptions?hash='));
849  $this->assertContains('localhost', $htmlContent);
850  $this->assertEquals(1, substr_count($htmlContent, '/marketingLists/external/manageSubscriptions?hash='));
851  $this->assertContains('<img width="1" height="1" src="localhost', $htmlContent);
852  $this->assertContains('/tracking/default/track?id=', $htmlContent);
853  $this->assertNotContains('/marketingLists/external/unsubscribe', $htmlContent);
854  }
855 
860  {
861  $email = new Email();
862  $email->emailAddress = 'demo17@zurmo.com';
863  $contact = ContactTestHelper::createContactByNameForOwner('contact 17', $this->user);
864  $contact->primaryEmail = $email;
865  $this->assertTrue($contact->save());
866  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 17',
867  'description',
868  null,
869  null);
870  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
871  $campaign = CampaignTestHelper::createCampaign('campaign 15',
872  'subject 15',
873  GlobalMarketingFooterUtil::resolveUnsubscribeUrlMergeTag() . ', ' . // Not Coding Standard
874  GlobalMarketingFooterUtil::resolveManageSubscriptionsMergeTag(),
875  GlobalMarketingFooterUtil::resolveUnsubscribeUrlMergeTag() . ', ' . // Not Coding Standard
876  GlobalMarketingFooterUtil::resolveManageSubscriptionsMergeTag(),
877  'testFromName',
878  'test@zurmo.com',
879  null,
880  null,
881  null,
882  null,
883  $marketingList);
884  $processed = 0;
885  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
886  $this->processDueItem($campaignItem);
887  $textContent = $campaignItem->emailMessage->content->textContent;
888  $htmlContent = $campaignItem->emailMessage->content->htmlContent;
889  $this->assertNotEquals($campaign->textContent, $textContent);
890  $this->assertNotEquals($campaign->htmlContent, $htmlContent);
891  $this->assertContains('localhost', $textContent);
892  $this->assertEquals(1, substr_count($textContent, '/marketingLists/external/unsubscribe?hash='));
893  $this->assertContains('localhost', $htmlContent);
894  $this->assertEquals(1, substr_count($htmlContent, '/marketingLists/external/unsubscribe?hash='));
895  $this->assertContains('<img width="1" height="1" src="localhost', $htmlContent);
896  $this->assertContains('/tracking/default/track?id=', $htmlContent);
897  $this->assertContains(', localhost', $textContent);
898  $this->assertEquals(1, substr_count($textContent, '/marketingLists/external/manageSubscriptions?hash='));
899  $this->assertContains(', localhost', $htmlContent);
900  $this->assertEquals(1, substr_count($htmlContent, '/marketingLists/external/manageSubscriptions?hash='));
901  $this->assertContains('<img width="1" height="1" src="localhost', $htmlContent);
902  $this->assertContains('/tracking/default/track?id=', $htmlContent);
903  }
904 
909  {
910  $email = new Email();
911  $email->emailAddress = 'demo18@zurmo.com';
912  $contact = ContactTestHelper::createContactByNameForOwner('contact 18', $this->user);
913  $contact->primaryEmail = $email;
914  $this->assertTrue($contact->save());
915  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 18',
916  'description',
917  null,
918  null);
919  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
920  $campaign = CampaignTestHelper::createCampaign('campaign 16',
921  'subject 16',
922  'Plain Text',
923  'HTML',
924  'testFromName',
925  'test@zurmo.com',
926  null,
927  null,
928  null,
929  null,
930  $marketingList);
931  $processed = 0;
932  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
933  $this->processDueItem($campaignItem);
934  $textContent = $campaignItem->emailMessage->content->textContent;
935  $htmlContent = $campaignItem->emailMessage->content->htmlContent;
936  $this->assertNotEquals($campaign->textContent, $textContent);
937  $this->assertNotEquals($campaign->htmlContent, $htmlContent);
938  $this->assertContains('Plain Text', $textContent);
939  $this->assertContains('/marketingLists/external/unsubscribe?hash=', $textContent);
940  $this->assertEquals(1, substr_count($textContent, '/marketingLists/external/unsubscribe?hash='));
941  $this->assertContains('/marketingLists/external/manageSubscriptions?hash=', $textContent);
942  $this->assertEquals(1, substr_count($textContent, '/marketingLists/external/manageSubscriptions?hash='));
943  $this->assertContains('HTML<br /><br /><a href="localhost/', $htmlContent);
944  $this->assertContains('<img width="1" height="1" src="localhost', $htmlContent);
945  $this->assertContains('/tracking/default/track?id=', $htmlContent);
946  $this->assertEquals(1, substr_count($htmlContent, '/tracking/default/track?id='));
947  $this->assertContains('/marketingLists/external/unsubscribe?hash=', $htmlContent);
948  $this->assertEquals(1, substr_count($htmlContent, '/marketingLists/external/unsubscribe?hash='));
949  $this->assertEquals(2, substr_count($htmlContent, '<br /><a href="localhost/'));
950  $this->assertContains('/marketingLists/external/manageSubscriptions?hash=', $htmlContent);
951  $this->assertEquals(1, substr_count($htmlContent, '/marketingLists/external/manageSubscriptions?hash='));
952  }
953 
954  public function testProcessDueCampaignItemContactUnsubscribed()
955  {
956  $email = new Email();
957  $email->emailAddress = 'demo@zurmo.com';
958  $email->optOut = false;
959  $contact = ContactTestHelper::createContactByNameForOwner('contact 17', $this->user);
960  $contact->primaryEmail = $email;
961  $this->assertTrue($contact->save());
962  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 17',
963  'description',
964  'CustomFromName',
965  'custom@from.com');
966  MarketingListMemberTestHelper::createMarketingListMember(true, $marketingList, $contact);
967  $campaign = CampaignTestHelper::createCampaign('campaign 17',
968  'subject 17',
969  'Dear. Sir',
970  'Dear. Sir',
971  null,
972  null,
973  null,
974  null,
975  null,
976  null,
977  $marketingList);
978  $processed = 0;
979  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
980  $this->processDueItem($campaignItem);
981  $this->assertEquals(1, $campaignItem->processed);
982  $personId = $contact->getClassId('Person');
983  $activities = CampaignItemActivity::getByTypeAndModelIdAndPersonIdAndUrl(
984  CampaignItemActivity::TYPE_SKIP,
985  $campaignItem->id,
986  $personId);
987  $this->assertNotEmpty($activities);
988  $this->assertCount(1, $activities);
989  }
990  }
991 ?>
static makeBySecurableItem(SecurableItem $securableItem)
testProcessDueCampaignItemThrowsExceptionWhenNoContactIsAvailable()
Definition: Email.php:37
testProcessDueCampaignItemWithManageSubscriptionsUrlMergeTag()
static getByProcessedAndCampaignId($processed, $campaignId, $pageSize=null)
static getByUsername($username)
Definition: User.php:49
testProcessDueCampaignItemThrowsExceptionWhenContentHasInvalidMergeTagsForOnlyText()
testProcessDueCampaignItemThrowsExceptionWhenContentHasInvalidMergeTags()
testProcessDueCampaignItemWithUnsubscribeAndManageSubscriptionsUrlMergeTags()
testProcessDueCampaignItemDoesNotThrowExceptionWhenContactHasPrimaryEmail()
testProcessDueCampaignItemWithoutUnsubscribeAndManageSubscriptionsUrlMergeTags()
static deleteAll()
static getById($id, $modelClassName=null)
testProcessDueCampaignItemThrowsExceptionWhenContentHasInvalidMergeTagsForOnlyHtml()
testProcessDueCampaignItemDoesNotThrowExceptionWhenContactHasNoPrimaryEmail()
static setByModuleName($moduleName, $key, $value, $cache=true)
Generated on Fri Jun 5 2020 07:10:30