All Data Structures Functions Variables Pages
MarketingListMemberTest.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 
44  $super = User::getByUsername('super');
45  Yii::app()->user->userModel = $super;
46  //Setup test data owned by the super user.
47  $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super);
48  for ($i = 0; $i < 10; $i++)
49  {
50  MarketingListTestHelper::createMarketingListByName('test marketing List ' . $i);
51  ContactTestHelper::createContactWithAccountByNameForOwner('superContact' . $i, $super, $account);
52  }
53  }
54 
55  public function setUp()
56  {
57  parent::setUp();
58  Yii::app()->user->userModel = User::getByUsername('super');
59  }
60 
61  public function testGetModuleClassName()
62  {
63  $this->assertEquals('MarketingListsModule', MarketingListMember::getModuleClassName());
64  }
65 
66  public function testCreateAndGetMarketingListMemberById()
67  {
69  $this->assertNotNull($marketingList);
71  $this->assertNotNull($contact);
72  $marketingListMember = new MarketingListMember();
73  $marketingListMember->unsubscribed = 0;
74  $marketingListMember->marketingList = $marketingList;
75  $marketingListMember->contact = $contact;
76  $this->assertTrue($marketingListMember->unrestrictedSave());
77  $id = $marketingListMember->id;
78  $this->assertTrue($id > 0);
79  unset($marketingListMember);
80  $marketingListMember = MarketingListMember::getById($id);
81  $this->assertEquals(0, $marketingListMember->unsubscribed);
82  $this->assertEquals($contact, $marketingListMember->contact);
83  $this->assertEquals($marketingList, $marketingListMember->marketingList);
84  }
85 
89  public function testGetLabel()
90  {
92  $this->assertNotEmpty($marketingListMember);
93  $this->assertEquals(1, count($marketingListMember));
94  $this->assertEquals('Marketing List Member', $marketingListMember::getModelLabelByTypeAndLanguage('Singular'));
95  $this->assertEquals('Marketing List Members', $marketingListMember::getModelLabelByTypeAndLanguage('Plural'));
96  }
97 
102  {
103  MarketingListMemberTestHelper::createMarketingListMember();
104  $marketingListMembers = MarketingListMember::getAll();
105  $this->assertNotEmpty($marketingListMembers);
106  $this->assertEquals(2, count($marketingListMembers));
107  $marketingListMembers[0]->delete();
108  $marketingListMembers = MarketingListMember::getAll();
109  $this->assertNotEmpty($marketingListMembers);
110  $this->assertEquals(1, count($marketingListMembers));
111  }
112 
117  {
118  $marketingList = MarketingListTestHelper::createMarketingListByName('test marketing List 03');
119  $this->assertNotNull($marketingList);
121  $this->assertNotNull($contact);
122  $added = $marketingList->addNewMember($contact->id, false, $contact);
123  $this->assertTrue($added);
124  $added = $marketingList->addNewMember($contact->id, false, $contact);
125  $this->assertFalse($added);
126  $memberCount = $marketingList->memberAlreadyExists($contact->id);
127  $this->assertEquals(1, $memberCount);
128  $marketingList = MarketingListTestHelper::createMarketingListByName('test marketing List 04');
129  $this->assertNotNull($marketingList);
130  $added = $marketingList->addNewMember($contact->id, false, $contact);
131  $this->assertTrue($added);
132  }
133 
138  {
139  $marketingList = MarketingListTestHelper::createMarketingListByName('test marketing List 05');
140  $this->assertNotNull($marketingList);
141  $contacts = Contact::getAll();
142  $this->assertNotEmpty($contacts);
143  $unsubscribedCount = 0;
144  $subscribedCount = 0;
145  foreach ($contacts as $index => $contact)
146  {
147  $unsubcribed = ($index % 2);
148  $member = MarketingListMemberTestHelper::populateValidMarketingListMember($unsubcribed, $marketingList, $contact);
149  $this->assertTrue($member->unrestrictedSave());
150  if ($unsubcribed)
151  {
152  $unsubscribedCount++;
153  }
154  else
155  {
156  $subscribedCount++;
157  }
158  }
159  $calculatedSubscribedCount = MarketingListMember::getCountByMarketingListIdAndUnsubscribed($marketingList->id, 0);
160  $calculatedUnsubscribedCount = MarketingListMember::getCountByMarketingListIdAndUnsubscribed($marketingList->id, 1);
161  $this->assertEquals($subscribedCount, $calculatedSubscribedCount);
162  $this->assertEquals($unsubscribedCount, $calculatedUnsubscribedCount);
163  }
164 
169  {
170  $marketingList = MarketingListTestHelper::createMarketingListByName('test marketing List 06');
171  $this->assertNotNull($marketingList);
172  $autoresponderSubscribe = AutoresponderTestHelper::createAutoresponder(
173  'test autoresponder Subscribe',
174  'This is text content Subscribe',
175  'This is <b>html</b> content Subscribe',
176  10,
177  Autoresponder::OPERATION_SUBSCRIBE,
178  false,
179  $marketingList
180  );
181  $this->assertNotNull($autoresponderSubscribe);
182  $autoresponderUnsubscribe = AutoresponderTestHelper::createAutoresponder(
183  'test autoresponder Unsubscribe',
184  'This is text content Unsubscribe',
185  'This is <b>html</b> content Unsubscribe',
186  20,
187  Autoresponder::OPERATION_UNSUBSCRIBE,
188  true,
189  $marketingList
190  );
191  $this->assertNotNull($autoresponderUnsubscribe);
192  $member = MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList);
193  $autoresponderItemsSubscribe = AutoresponderItem::getByProcessedAndAutoresponderId(
194  0,
195  $autoresponderSubscribe->id);
196  $this->assertNotEmpty($autoresponderItemsSubscribe);
197  $this->assertCount(1, $autoresponderItemsSubscribe);
198  $autoresponderItemsUnsubscribe = AutoresponderItem::getByProcessedAndAutoresponderId(
199  0,
200  $autoresponderUnsubscribe->id);
201  $this->assertEmpty($autoresponderItemsUnsubscribe);
202 
203  $member->unsubscribed = 1;
204  $saved = $member->unrestrictedSave();
205  $this->assertTrue($saved);
206 
207  $autoresponderItemsSubscribe = AutoresponderItem::getByProcessedAndAutoresponderId(
208  0,
209  $autoresponderSubscribe->id);
210  $this->assertNotEmpty($autoresponderItemsSubscribe);
211  $this->assertCount(1, $autoresponderItemsSubscribe);
212  $autoresponderItemsUnsubscribe = AutoresponderItem::getByProcessedAndAutoresponderId(
213  0,
214  $autoresponderUnsubscribe->id);
215  $this->assertNotEmpty($autoresponderItemsUnsubscribe);
216  $this->assertCount(1, $autoresponderItemsUnsubscribe);
217  }
218 
223  {
224  $marketingList = MarketingListTestHelper::createMarketingListByName('test marketing List 06');
225  $this->assertNotNull($marketingList);
226  $super = User::getByUsername('super');
227  $contact = ContactTestHelper::createContactByNameForOwner('contact 01', $super);
228  $marketingListMember = MarketingListMember::getByMarketingListIdContactIdAndUnsubscribed($marketingList->id, $contact->id, false);
229  $this->assertFalse($marketingListMember);
230  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
231  $marketingListMember = MarketingListMember::getByMarketingListIdContactIdAndUnsubscribed($marketingList->id, $contact->id, false);
232  $this->assertTrue($marketingListMember[0] instanceof MarketingListMember);
233  $marketingListMember[0]->unsubscribed = true;
234  $this->assertTrue($marketingListMember[0]->unrestrictedSave());
235  $marketingListMember = MarketingListMember::getByMarketingListIdContactIdAndUnsubscribed($marketingList->id, $contact->id, false);
236  $this->assertFalse($marketingListMember);
237  }
238 
243  {
244  $marketingList = MarketingListTestHelper::createMarketingListByName('test marketing List 07');
245  $this->assertNotNull($marketingList);
246  $super = User::getByUsername('super');
247  $contact = ContactTestHelper::createContactByNameForOwner('contact 02', $super);
248  $marketingListMember = MarketingListMember::getByMarketingListIdAndContactId($marketingList->id, $contact->id);
249  $this->assertFalse($marketingListMember);
250  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
251  $marketingListMember = MarketingListMember::getByMarketingListIdAndContactId($marketingList->id, $contact->id);
252  $this->assertTrue($marketingListMember[0] instanceof MarketingListMember);
253  }
254  }
255 ?>
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)
Generated on Tue May 26 2020 07:10:33