Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
AutoresponderItemTest.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  public static function setUpBeforeClass()
39  {
40  parent::setUpBeforeClass();
41  SecurityTestHelper::createSuperAdmin();
42  SecurityTestHelper::createUsers();
43  // Delete item from jobQueue, that is created when new user is created
44  Yii::app()->jobQueue->deleteAll();
45  }
46 
47  public function setUp()
48  {
49  parent::setUp();
50  Yii::app()->user->userModel = User::getByUsername('super');
51  }
52 
53  public function testCreateAndGetAutoresponderItemById()
54  {
55  $timeStamp = strtotime('+1 week'); // Not Coding Standard
56  $time = DateTimeUtil::convertTimestampToDbFormatDateTime($timeStamp); // Not Coding Standard
57  $autoresponderItem = new AutoresponderItem();
58  $autoresponderItem->processed = 0;
59  $autoresponderItem->processDateTime = $time;
60  $this->assertCount(0, Yii::app()->jobQueue->getAll());
61  $this->assertTrue($autoresponderItem->unrestrictedSave());
62  $jobs = Yii::app()->jobQueue->getAll();
63  $this->assertCount(1, $jobs);
64  $this->assertEquals('AutoresponderQueueMessagesInOutbox', $jobs[$timeStamp - time() + 5][0]['jobType']);
65  $id = $autoresponderItem->id;
66  unset($autoresponderItem);
67  $autoresponderItem = AutoresponderItem::getById($id);
68  $this->assertEquals(0, $autoresponderItem->processed);
69  $this->assertEquals($time, $autoresponderItem->processDateTime);
70 
71  //Test changing processDateTime to make sure a new job is added
72  Yii::app()->jobQueue->deleteAll();
73  $this->assertCount(0, Yii::app()->jobQueue->getAll());
74  $timeStamp = strtotime('+2 week'); // Not Coding Standard
75  $autoresponderItem->processDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime($timeStamp);
76  $this->assertTrue($autoresponderItem->unrestrictedSave());
77  $jobs = Yii::app()->jobQueue->getAll();
78  $this->assertCount(1, $jobs);
79  $this->assertEquals('AutoresponderQueueMessagesInOutbox', $jobs[$timeStamp - time() + 5][0]['jobType']);
80  }
81 
85  public function testRequiredAttributes()
86  {
87  $autoresponderItem = new AutoresponderItem();
88  $this->assertFalse($autoresponderItem->unrestrictedSave());
89  $errors = $autoresponderItem->getErrors();
90  $this->assertNotEmpty($errors);
91  $this->assertCount(1, $errors);
92  $this->assertArrayHasKey('processDateTime', $errors);
93  $this->assertEquals('Process Date Time cannot be blank.', $errors['processDateTime'][0]);
94 
95  $time = DateTimeUtil::convertTimestampToDbFormatDateTime(strtotime('+1 week')); // Not Coding Standard
96  $autoresponderItem = new AutoresponderItem();
97  $autoresponderItem->processed = 1;
98  $autoresponderItem->processDateTime = $time;
99  $this->assertTrue($autoresponderItem->unrestrictedSave());
100  $id = $autoresponderItem->id;
101  unset($autoresponderItem);
102  $autoresponderItem = AutoresponderItem::getById($id);
103  $this->assertEquals(1, $autoresponderItem->processed);
104  $this->assertEquals($time, $autoresponderItem->processDateTime);
105  }
106 
110  public function testGetByProcessed()
111  {
112  for ($i = 0; $i < 5; $i++)
113  {
114  $time = DateTimeUtil::convertTimestampToDbFormatDateTime(strtotime('+1 day')); // Not Coding Standard
115  $processed = 0;
116  if ($i % 2)
117  {
118  $processed = 1;
119  }
120  $autoresponderItem = new AutoresponderItem();
121  $autoresponderItem->processed = $processed;
122  $autoresponderItem->processDateTime = $time;
123  $this->assertTrue($autoresponderItem->unrestrictedSave());
124  }
125  $autoresponderItems = AutoresponderItem::getAll();
126  $this->assertCount(7, $autoresponderItems);
127  $processedItems = AutoresponderItem::getByProcessed(1);
128  $this->assertCount(3, $processedItems);
129  $notProcessedItems = AutoresponderItem::getByProcessed(0);
130  $this->assertCount(4, $notProcessedItems);
131  }
132 
136  public function testGetByProcessedAndTime()
137  {
138  $autoresponderItems = AutoresponderItem::getAll();
139  $this->assertCount(7, $autoresponderItems);
140  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 01');
141  $this->assertNotNull($marketingList);
142  $autoresponderToday = AutoresponderTestHelper::createAutoresponder('subject Today',
143  'text Today',
144  'html Today',
145  1,
146  Autoresponder::OPERATION_UNSUBSCRIBE,
147  true,
148  $marketingList);
149  $autoresponderItems = AutoresponderItem::getAll();
150  $this->assertCount(7, $autoresponderItems);
151  $this->assertNotNull($autoresponderToday);
152  $autoresponderTenDaysFromNow = AutoresponderTestHelper::createAutoresponder('subject Ten Days',
153  'text Ten Days',
154  'html Ten Days',
155  60*60*24*10,
156  Autoresponder::OPERATION_SUBSCRIBE,
157  false,
158  $marketingList);
159  $this->assertNotNull($autoresponderTenDaysFromNow);
160  $autoresponderItems = AutoresponderItem::getAll();
161  $this->assertCount(7, $autoresponderItems);
162  for ($i = 0; $i < 10; $i++)
163  {
164  $contact = ContactTestHelper::createContactByNameForOwner('contact ' . $i, Yii::app()->user->userModel);
165  $this->assertNotNull($contact);
166  if ($i % 3)
167  {
168  $processed = 1;
169  }
170  else
171  {
172  $processed = 0;
173  }
174  if ($i % 2)
175  {
176  $autoresponder = $autoresponderToday;
177  }
178  else
179  {
180  $autoresponder = $autoresponderTenDaysFromNow;
181  }
182  $timestamp = time() - 10000000000; //forces all processed stamps to be in the past
183  $processDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime((int)$timestamp);
184  $autoresponderItem = AutoresponderItemTestHelper::createAutoresponderItem($processed,
185  $processDateTime,
186  $autoresponder);
187  $this->assertNotNull($autoresponderItem);
188  }
189 
190  $autoresponderItems = AutoresponderItem::getAll();
191  $this->assertNotEmpty($autoresponderItems);
192  $this->assertCount(17, $autoresponderItems);
193  $autoresponderTodayProcessed = AutoresponderItem::getByProcessedAndAutoresponderId(1,
194  $autoresponderToday->id);
195  $this->assertNotEmpty($autoresponderTodayProcessed);
196  $this->assertCount(3, $autoresponderTodayProcessed);
197  $autoresponderTodayNotProcessed = AutoresponderItem::getByProcessedAndAutoresponderId(0,
198  $autoresponderToday->id);
199  $this->assertNotEmpty($autoresponderTodayNotProcessed);
200  $this->assertCount(2, $autoresponderTodayNotProcessed);
201  $autoresponderTenDaysFromNowProcessed = AutoresponderItem::getByProcessedAndAutoresponderId(1,
202  $autoresponderTenDaysFromNow->id);
203  $this->assertNotEmpty($autoresponderTenDaysFromNowProcessed);
204  $this->assertCount(3, $autoresponderTenDaysFromNowProcessed);
205  $autoresponderTenDaysFromNowNotProcessed = AutoresponderItem::getByProcessedAndAutoresponderId(0,
206  $autoresponderTenDaysFromNow->id);
207  $this->assertNotEmpty($autoresponderTenDaysFromNowNotProcessed);
208  $this->assertCount(2, $autoresponderTenDaysFromNowNotProcessed);
209  }
210 
215  {
216  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 02');
217  $this->assertNotNull($marketingList);
218  $autoresponder1 = AutoresponderTestHelper::createAutoresponder('subject 01', 'text 01', 'html 01', 10,
219  Autoresponder::OPERATION_UNSUBSCRIBE, true, $marketingList);
220  $this->assertNotNull($autoresponder1);
221  $autoresponder2 = AutoresponderTestHelper::createAutoresponder('subject 02', 'text 02', 'html 02', 20,
222  Autoresponder::OPERATION_SUBSCRIBE, false, $marketingList);
223  $this->assertNotNull($autoresponder2);
224  for ($i = 0; $i < 10; $i++)
225  {
226  $contact = ContactTestHelper::createContactByNameForOwner('contact 0' . $i, Yii::app()->user->userModel);
227  $this->assertNotNull($contact);
228  $time = DateTimeUtil::convertTimestampToDbFormatDateTime(strtotime('+1 day')); // Not Coding Standard
229  if ($i % 3)
230  {
231  $processed = 1;
232  }
233  else
234  {
235  $processed = 0;
236  }
237  if ($i % 2)
238  {
239  $autoresponder = $autoresponder1;
240  }
241  else
242  {
243  $autoresponder = $autoresponder2;
244  }
245  $autoresponderItem = AutoresponderItemTestHelper::createAutoresponderItem($processed, $time, $autoresponder);
246  $this->assertNotNull($autoresponderItem);
247  }
248  $autoresponderItems = AutoresponderItem::getAll();
249  $this->assertNotEmpty($autoresponderItems);
250  $this->assertCount(27, $autoresponderItems);
251  $autoresponder1Processed = AutoresponderItem::getByProcessedAndAutoresponderId(1,
252  $autoresponder1->id);
253  $this->assertNotEmpty($autoresponder1Processed);
254  $this->assertCount(3, $autoresponder1Processed);
255  $autoresponder1NotProcessed = AutoresponderItem::getByProcessedAndAutoresponderId(0,
256  $autoresponder1->id);
257  $this->assertNotEmpty($autoresponder1NotProcessed);
258  $this->assertCount(2, $autoresponder1NotProcessed);
259  $autoresponder2Processed = AutoresponderItem::getByProcessedAndAutoresponderId(1,
260  $autoresponder2->id);
261  $this->assertNotEmpty($autoresponder2Processed);
262  $this->assertCount(3, $autoresponder2Processed);
263  $autoresponder2NotProcessed = AutoresponderItem::getByProcessedAndAutoresponderId(0,
264  $autoresponder2->id);
265  $this->assertNotEmpty($autoresponder2NotProcessed);
266  $this->assertCount(2, $autoresponder2NotProcessed);
267  }
268 
273  {
274  $intervals = array('hour', 'day');
275  $marketingList = MarketingList::getByName('marketingList 01');
276  $this->assertNotEmpty($marketingList);
277  $autoresponder3 = AutoresponderTestHelper::createAutoresponder('subject 03', 'text 03', 'html 03', 10,
278  Autoresponder::OPERATION_UNSUBSCRIBE, true, $marketingList[0]);
279  $this->assertNotNull($autoresponder3);
280  $autoresponder4 = AutoresponderTestHelper::createAutoresponder('subject 04', 'text 04', 'html 04', 20,
281  Autoresponder::OPERATION_SUBSCRIBE, false, $marketingList[0]);
282  $this->assertNotNull($autoresponder4);
283  for ($i = 0; $i < 10; $i++)
284  {
285  if ($i % 3)
286  {
287  $pastOrFuture = "-";
288  $processed = 1;
289  }
290  else
291  {
292  $pastOrFuture = "+"; // Not Coding Standard
293  $processed = 0;
294  }
295  if ($i % 2)
296  {
297  $autoresponder = $autoresponder3;
298  $interval = $intervals[1];
299  }
300  else
301  {
302  $autoresponder = $autoresponder4;
303  $interval = $intervals[0];
304  }
305  $timestamp = strtotime($pastOrFuture . ($i + 1) . ' ' . $interval);
306  $time = DateTimeUtil::convertTimestampToDbFormatDateTime($timestamp);
307  $autoresponderItem = AutoresponderItemTestHelper::createAutoresponderItem($processed, $time, $autoresponder);
308  $this->assertNotNull($autoresponderItem);
309  }
310 
311  $autoresponderItems = AutoresponderItem::getAll();
312  $this->assertCount(37, $autoresponderItems);
314  1,
315  $autoresponder3->id);
316  $this->assertNotEmpty($autoresponder3ProcessedBeforeNow);
317  $this->assertCount(3, $autoresponder3ProcessedBeforeNow);
319  1,
320  $autoresponder3->id,
321  strtotime("-5 day"));
322  $this->assertNotEmpty($autoresponder3ProcessedFiveDaysAgo);
323  $this->assertCount(2, $autoresponder3ProcessedFiveDaysAgo);
324  $autoresponder3NotProcessedBeforeNow = AutoresponderItem::getByProcessedAndAutoresponderIdWithProcessDateTime(
325  0,
326  $autoresponder3->id);
327  $this->assertEmpty($autoresponder3NotProcessedBeforeNow);
328  $autoresponder3NotProcessedFiveDaysFromNow = AutoresponderItem::getByProcessedAndAutoresponderIdWithProcessDateTime(
329  0,
330  $autoresponder3->id,
331  strtotime("+5 day")); // Not Coding Standard
332  $this->assertNotEmpty($autoresponder3NotProcessedFiveDaysFromNow);
333  $this->assertCount(1, $autoresponder3NotProcessedFiveDaysFromNow);
335  1,
336  $autoresponder4->id);
337  $this->assertNotEmpty($autoresponder4ProcessedBeforeNow);
338  $this->assertCount(3, $autoresponder4ProcessedBeforeNow);
340  1,
341  $autoresponder4->id,
342  strtotime("-5 day"));
343  $this->assertEmpty($autoresponder4ProcessedFiveDaysAgo);
344  $autoresponder4NotProcessedBeforeNow = AutoresponderItem::getByProcessedAndAutoresponderIdWithProcessDateTime(
345  0,
346  $autoresponder4->id);
347  $this->assertEmpty($autoresponder4NotProcessedBeforeNow);
348  $autoresponder4NotProcessedFiveDaysFromNow = AutoresponderItem::getByProcessedAndAutoresponderIdWithProcessDateTime(
349  0,
350  $autoresponder4->id,
351  strtotime("+5 day")); // Not Coding Standard
352  $this->assertNotEmpty($autoresponder4NotProcessedFiveDaysFromNow);
353  $this->assertCount(2, $autoresponder4NotProcessedFiveDaysFromNow);
354  }
355 
359  public function testGetLabel()
360  {
362  $this->assertNotNull($autoresponderItem);
363  $this->assertEquals('Autoresponder Item', $autoresponderItem::getModelLabelByTypeAndLanguage('Singular'));
364  $this->assertEquals('Autoresponder Items', $autoresponderItem::getModelLabelByTypeAndLanguage('Plural'));
365  }
366 
370  public function testDeleteAutoresponderItem()
371  {
372  $autoresponderItems = AutoresponderItem::getAll();
373  $this->assertCount(37, $autoresponderItems);
374 
375  $autoresponderItemActivity = new AutoresponderItemActivity();
376  $autoresponderItemActivity->type = AutoresponderItemActivity::TYPE_OPEN;
377  $autoresponderItemActivity->quantity = 10;
378  $autoresponderItemActivity->latestSourceIP = '10.11.12.13';
379  $autoresponderItemActivity->autoresponderItem = $autoresponderItems[0];
380  $this->assertTrue($autoresponderItemActivity->save());
381 
382  $autoresponderItemActivities = AutoresponderItemActivity::getAll();
383  $this->assertCount(1, $autoresponderItemActivities);
384 
385  $autoresponderItems[0]->delete();
386  $autoresponderItems = AutoresponderItem::getAll();
387  $this->assertEquals(36, count($autoresponderItems));
388 
389  $autoresponderItemActivities = AutoresponderItemActivity::getAll();
390  $this->assertCount(0, $autoresponderItemActivities);
391  }
392 
396  public function testAddNewItem()
397  {
398  $super = User::getByUsername('super');
399  $processed = 0;
400  $processDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
401  $contact = ContactTestHelper::createContactByNameForOwner('autoresponderContact', Yii::app()->user->userModel);
402  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 03');
403  $autoresponder = AutoresponderTestHelper::createAutoresponder('test autoresponder 01',
404  'This is text content 01',
405  'This is <b>html</b> content 01',
406  10,
407  Autoresponder::OPERATION_SUBSCRIBE,
408  true,
409  $marketingList
410  );
411  $saved = AutoresponderItem::addNewItem($processed, $processDateTime, $contact, $autoresponder);
412  $this->assertTrue($saved);
414  $autoresponder->id);
415  $this->assertNotEmpty($autoresponderItems);
416  $this->assertCount(1, $autoresponderItems);
417  }
418 
423  {
424  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 04');
425  $autoresponderSubscribe = AutoresponderTestHelper::createAutoresponder('test autoresponder Subscribe',
426  'This is text content Subscribe',
427  'This is <b>html</b> content Subscribe',
428  10,
429  Autoresponder::OPERATION_SUBSCRIBE,
430  true,
431  $marketingList
432  );
433  $this->assertNotNull($autoresponderSubscribe);
434  $autoresponderUnsubscribe = AutoresponderTestHelper::createAutoresponder('test autoresponder Unsubscribe',
435  'This is text content Unsubscribe',
436  'This is <b>html</b> content Unsubscribe',
437  20,
438  Autoresponder::OPERATION_UNSUBSCRIBE,
439  true,
440  $marketingList
441  );
442  $this->assertNotNull($autoresponderUnsubscribe);
443  $contact1 = ContactTestHelper::createContactByNameForOwner('autoresponderContact 01',
444  Yii::app()->user->userModel);
445  $contact2 = ContactTestHelper::createContactByNameForOwner('autoresponderContact 02',
446  Yii::app()->user->userModel);
447  $contact3 = ContactTestHelper::createContactByNameForOwner('autoresponderContact 03',
448  Yii::app()->user->userModel);
449  $contact4 = ContactTestHelper::createContactByNameForOwner('autoresponderContact 04',
450  Yii::app()->user->userModel);
451  AutoresponderItem::registerAutoresponderItemsByAutoresponderOperation(Autoresponder::OPERATION_SUBSCRIBE,
452  $marketingList->id,
453  $contact1);
454  AutoresponderItem::registerAutoresponderItemsByAutoresponderOperation(Autoresponder::OPERATION_SUBSCRIBE,
455  $marketingList->id,
456  $contact2);
457  $autoresponderItemsSubscribe = AutoresponderItem::getByProcessedAndAutoresponderId(0,
458  $autoresponderSubscribe->id);
459  $this->assertNotEmpty($autoresponderItemsSubscribe);
460  $this->assertCount(2, $autoresponderItemsSubscribe);
461 
462  AutoresponderItem::registerAutoresponderItemsByAutoresponderOperation(Autoresponder::OPERATION_UNSUBSCRIBE,
463  $marketingList->id, $contact3);
464  AutoresponderItem::registerAutoresponderItemsByAutoresponderOperation(Autoresponder::OPERATION_UNSUBSCRIBE,
465  $marketingList->id, $contact4);
466  $autoresponderItemsUnsubscribe = AutoresponderItem::getByProcessedAndAutoresponderId(0,
467  $autoresponderUnsubscribe->id);
468  $this->assertNotEmpty($autoresponderItemsUnsubscribe);
469  $this->assertCount(2, $autoresponderItemsUnsubscribe);
470  }
471  }
472 ?>
static getByUsername($username)
Definition: User.php:49
static getByProcessedAndAutoresponderId($processed, $autoresponderId, $pageSize=null)
static getRandomValueFromArray($array)
static getById($id, $modelClassName=null)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
static getByProcessedAndAutoresponderIdWithProcessDateTime($processed, $autoresponderId, $timestamp=null, $pageSize=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.