Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
AutoresponderQueueMessagesInOutboxJobTest.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  }
45 
46  public function setUp()
47  {
48  parent::setUp();
49  $this->user = User::getByUsername('super');
50  Yii::app()->user->userModel = $this->user;
51  }
52 
53  public function testGetDisplayName()
54  {
56  $this->assertEquals('Process autoresponder messages', $displayName);
57  }
58 
59  public function testGetType()
60  {
62  $this->assertEquals('AutoresponderQueueMessagesInOutbox', $type);
63  }
64 
65  public function testGetRecommendedRunFrequencyContent()
66  {
67  $recommendedRunFrequency = AutoresponderQueueMessagesInOutboxJob::getRecommendedRunFrequencyContent();
68  $this->assertEquals('Every hour', $recommendedRunFrequency);
69  }
70 
71  public function testRunWithoutAnyItems()
72  {
73  $autoresponderItems = AutoresponderItem::getAll();
74  $this->assertEmpty($autoresponderItems);
76  $this->assertTrue($job->run());
77  }
78 
82  public function testRunWithoutContact()
83  {
85  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 01');
86  $autoresponder = AutoresponderTestHelper::createAutoresponder('subject 01',
87  'text content',
88  'html content',
89  1,
90  Autoresponder::OPERATION_SUBSCRIBE,
91  false,
92  $marketingList);
93  $processed = 0;
94  $processDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()-10);
95  AutoresponderItemTestHelper::createAutoresponderItem($processed, $processDateTime, $autoresponder);
96  $this->assertTrue($job->run());
97  $autoresponderItems = AutoresponderItem::getAll();
98  $this->assertEmpty($autoresponderItems);
99  }
100 
105  {
107  $contact = ContactTestHelper::createContactByNameForOwner('contact 01', $this->user);
108  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 02');
109  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
110  $autoresponder = AutoresponderTestHelper::createAutoresponder('subject 02',
111  'text content',
112  'html content',
113  1,
114  Autoresponder::OPERATION_SUBSCRIBE,
115  true,
116  $marketingList);
117  $processed = 0;
118  $processDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()-10);
119  AutoresponderItemTestHelper::createAutoresponderItem($processed, $processDateTime, $autoresponder, $contact);
120  $this->assertTrue($job->run());
121  $autoresponderItems = AutoresponderItem::getAll();
122  $this->assertCount(1, $autoresponderItems);
123  $autoresponderItemsProcessed = AutoresponderItem::getByProcessedAndAutoresponderId(
124  1,
125  $autoresponder->id);
126  $this->assertCount(1, $autoresponderItemsProcessed);
127  }
128 
133  {
135  $email = new Email();
136  $email->emailAddress = 'demo@zurmo.com';
137  $contact = ContactTestHelper::createContactByNameForOwner('contact 02', $this->user);
138  $contact->primaryEmail = $email;
139  $this->assertTrue($contact->save());
140  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 03');
141  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
142  $autoresponder = AutoresponderTestHelper::createAutoresponder('subject 03',
143  'text content',
144  'html content',
145  1,
146  Autoresponder::OPERATION_SUBSCRIBE,
147  false,
148  $marketingList);
149  $processed = 0;
150  $processDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()-10);
151  AutoresponderItemTestHelper::createAutoresponderItem($processed, $processDateTime, $autoresponder, $contact);
152  $this->assertTrue($job->run());
153  $autoresponderItems = AutoresponderItem::getAll();
154  $this->assertCount(2, $autoresponderItems);
155  $autoresponderItemsProcessed = AutoresponderItem::getByProcessedAndAutoresponderId(
156  1,
157  $autoresponder->id);
158  $this->assertCount(1, $autoresponderItemsProcessed);
159  }
160 
165  {
167  $email = new Email();
168  $email->emailAddress = 'demo@zurmo.com';
169  $contact = ContactTestHelper::createContactByNameForOwner('contact 03', $this->user);
170  $contact->primaryEmail = $email;
171  $this->assertTrue($contact->save());
172  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 04',
173  'description goes here',
174  'fromName',
175  'from@domain.com');
176  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
177  $autoresponder = AutoresponderTestHelper::createAutoresponder('subject 04',
178  'text content',
179  'html content',
180  1,
181  Autoresponder::OPERATION_SUBSCRIBE,
182  true,
183  $marketingList);
184  $processed = 0;
185  $processDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()-10);
186  AutoresponderItemTestHelper::createAutoresponderItem($processed, $processDateTime, $autoresponder, $contact);
187  $this->assertTrue($job->run());
188  $autoresponderItems = AutoresponderItem::getAll();
189  $this->assertCount(3, $autoresponderItems);
190  $autoresponderItemsProcessed = AutoresponderItem::getByProcessedAndAutoresponderId(
191  1,
192  $autoresponder->id);
193  $this->assertCount(1, $autoresponderItemsProcessed);
194  }
195 
199  public function testRunWithInvalidMergeTags()
200  {
202  $email = new Email();
203  $email->emailAddress = 'demo@zurmo.com';
204  $contact = ContactTestHelper::createContactByNameForOwner('contact 04', $this->user);
205  $contact->primaryEmail = $email;
206  $this->assertTrue($contact->save());
207  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 05',
208  'description goes here',
209  'fromName',
210  'from@domain.com');
211  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
212  $autoresponder = AutoresponderTestHelper::createAutoresponder('subject 05',
213  '[[TEXT^CONTENT]]',
214  '[[HTML^CONTENT]]',
215  1,
216  Autoresponder::OPERATION_SUBSCRIBE,
217  false,
218  $marketingList,
219  false);
220  $processed = 0;
221  $processDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()-10);
222  $autoresponderItem = AutoresponderItemTestHelper::createAutoresponderItem($processed,
223  $processDateTime,
224  $autoresponder,
225  $contact);
226  $this->assertFalse($job->run());
227  $this->assertEquals('Provided content contains few invalid merge tags.', $job->getErrorMessage());
228  $autoresponderItems = AutoresponderItem::getAll();
229  $this->assertCount(4, $autoresponderItems);
230  $autoresponderItemsProcessed = AutoresponderItem::getByProcessedAndAutoresponderId(
231  1,
232  $autoresponder->id);
233  $this->assertCount(0, $autoresponderItemsProcessed);
234  $this->assertTrue($autoresponderItem->delete()); // Need to get rid of this so it doesn't interfere with next test.
235  }
236 
240  public function testRunWithValidMergeTags()
241  {
243  $email = new Email();
244  $email->emailAddress = 'demo@zurmo.com';
245  $contact = ContactTestHelper::createContactByNameForOwner('contact 05', $this->user);
246  $contact->primaryEmail = $email;
247  $this->assertTrue($contact->save());
248  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 06',
249  'description goes here',
250  'fromName',
251  'from@domain.com');
252  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
253  $autoresponder = AutoresponderTestHelper::createAutoresponder('subject 06',
254  '[[FIRST^NAME]]',
255  '[[LAST^NAME]]',
256  1,
257  Autoresponder::OPERATION_SUBSCRIBE,
258  true,
259  $marketingList);
260  $processed = 0;
261  $processDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()-10);
262  AutoresponderItemTestHelper::createAutoresponderItem($processed, $processDateTime, $autoresponder, $contact);
263  $this->assertTrue($job->run());
264  $autoresponderItems = AutoresponderItem::getAll();
265  $this->assertCount(4, $autoresponderItems);
266  $autoresponderItemsProcessed = AutoresponderItem::getByProcessedAndAutoresponderId(
267  1,
268  $autoresponder->id);
269  $this->assertCount(1, $autoresponderItemsProcessed);
270  }
271 
275  public function testRunWithCustomBatchSize()
276  {
277  $unprocessedItems = AutoresponderItem::getByProcessed(0);
278  $this->assertEmpty($unprocessedItems);
280  $email = new Email();
281  $email->emailAddress = 'demo@zurmo.com';
282  $contact = ContactTestHelper::createContactByNameForOwner('contact 06', $this->user);
283  $contact->primaryEmail = $email;
284  $this->assertTrue($contact->save());
285  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 07',
286  'description goes here',
287  'fromName',
288  'from@domain.com');
289  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
290  $autoresponder = AutoresponderTestHelper::createAutoresponder('subject 07',
291  '[[FIRST^NAME]]',
292  '[[LAST^NAME]]',
293  1,
294  Autoresponder::OPERATION_SUBSCRIBE,
295  true,
296  $marketingList);
297  for ($i = 0; $i < 10; $i++)
298  {
299  $processed = 0;
300  $processDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - rand(10, 500));
301  AutoresponderItemTestHelper::createAutoresponderItem($processed, $processDateTime, $autoresponder, $contact);
302  }
304  0,
305  $autoresponder->id);
306  $this->assertCount(10, $unprocessedItems);
307  Yii::app()->jobQueue->deleteAll();
308  $this->assertCount(0, Yii::app()->jobQueue->getAll());
310  $this->assertTrue($job->run());
312  0,
313  $autoresponder->id);
314  $this->assertCount(5, $unprocessedItems);
315  $jobs = Yii::app()->jobQueue->getAll();
316  $this->assertCount(2, $jobs);
317  $this->assertEquals('ProcessOutboundEmail', $jobs[0][0]['jobType']);
318  $this->assertEquals('AutoresponderQueueMessagesInOutbox', $jobs[5][0]['jobType']);
320  $this->assertTrue($job->run());
322  0,
323  $autoresponder->id);
324  $this->assertCount(2, $unprocessedItems);
326  Yii::app()->jobQueue->deleteAll();
327  $this->assertCount(0, Yii::app()->jobQueue->getAll());
328  $this->assertTrue($job->run());
330  0,
331  $autoresponder->id);
332  $this->assertCount(0, $unprocessedItems);
333  $jobs = Yii::app()->jobQueue->getAll();
334  $this->assertCount(1, $jobs);
335  $this->assertEquals('ProcessOutboundEmail', $jobs[0][0]['jobType']);
336  }
337 
342  {
343  $unprocessedItems = AutoresponderItem::getByProcessed(0);
344  $this->assertEmpty($unprocessedItems);
346  $email = new Email();
347  $email->emailAddress = 'demo@zurmo.com';
348  $email->optOut = true;
349  $contact = ContactTestHelper::createContactByNameForOwner('contact 07', $this->user);
350  $contact->primaryEmail = $email;
351  $this->assertTrue($contact->save());
352  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 08',
353  'description goes here',
354  'fromName',
355  'from@domain.com');
356  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
357  $autoresponder = AutoresponderTestHelper::createAutoresponder('subject 08',
358  '[[FIRST^NAME]]',
359  '[[LAST^NAME]]',
360  1,
361  Autoresponder::OPERATION_SUBSCRIBE,
362  true,
363  $marketingList);
364  $processed = 0;
365  $processDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - rand(10, 500));
366  $autoresponderItem = AutoresponderItemTestHelper::createAutoresponderItem($processed,
367  $processDateTime,
368  $autoresponder,
369  $contact);
371  0,
372  $autoresponder->id);
373  $this->assertCount(1, $unprocessedItems);
374  $this->assertTrue($job->run());
376  0,
377  $autoresponder->id);
378  $this->assertCount(0, $unprocessedItems);
379  $personId = $contact->getClassId('Person');
380  $activities = AutoresponderItemActivity::getByTypeAndModelIdAndPersonIdAndUrl(
381  AutoresponderItemActivity::TYPE_SKIP,
382  $autoresponderItem->id,
383  $personId);
384  $this->assertNotEmpty($activities);
385  $this->assertCount(1, $activities);
386  }
387  }
388 ?>
Definition: Email.php:37
static getByUsername($username)
Definition: User.php:49
static getByProcessedAndAutoresponderId($processed, $autoresponderId, $pageSize=null)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
Generated on Fri Jul 10 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.