All Data Structures Functions Variables Pages
MarketingListDefaultPortletControllerSuperUserWalkthroughTest.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  ********************************************************************************/
36 
38  {
39  protected $user;
40 
41  public static function setUpBeforeClass()
42  {
43  parent::setUpBeforeClass();
44  SecurityTestHelper::createSuperAdmin();
45  SecurityTestHelper::createUsers();
46  $super = User::getByUsername('super');
47  Yii::app()->user->userModel = $super;
48 
49  //Setup test data owned by the super user.
50  $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super);
51  $account2 = AccountTestHelper::createAccountByNameForOwner('superAccount2', $super);
52  $contact1 = ContactTestHelper::createContactWithAccountByNameForOwner('superContact', $super, $account);
53  $contact2 = ContactTestHelper::createContactWithAccountByNameForOwner('superContact2', $super, $account2);
54  $contact3 = ContactTestHelper::createContactWithAccountByNameForOwner('superContact3', $super, $account);
55  $contact4 = ContactTestHelper::createContactWithAccountByNameForOwner('superContact4', $super, $account2);
56  $contact5 = ContactTestHelper::createContactWithAccountByNameForOwner('superContact5', $super, $account);
57 
58  $marketingList1 = MarketingListTestHelper::createMarketingListByName('MarketingList1', 'MarketingList Description1');
59  $marketingList2 = MarketingListTestHelper::createMarketingListByName('MarketingList2', 'MarketingList Description2');
60  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList1, $contact1);
61  MarketingListMemberTestHelper::createMarketingListMember(1, $marketingList1, $contact2);
62  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList1, $contact3);
63  MarketingListMemberTestHelper::createMarketingListMember(1, $marketingList1, $contact4);
64  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList1, $contact5);
65  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList2, $contact1);
66  MarketingListMemberTestHelper::createMarketingListMember(1, $marketingList2, $contact2);
67 
69  }
70 
71  public function setUp()
72  {
73  parent::setUp();
74  $this->user = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
75  Yii::app()->user->userModel = $this->user;
76  }
77 
78  public function testDelete()
79  {
80  $marketingList = MarketingListTestHelper::createMarketingListByName('MarketingList3', 'MarketingList Description3');
81  $this->assertNotNull($marketingList);
83  $this->assertNotEmpty($contact);
84  $marketingListMember = MarketingListMemberTestHelper::createMarketingListMember(1, $marketingList, $contact);
85  $this->assertNotNull($marketingListMember);
86  $id = $marketingListMember->id;
87  $this->setGetArray(array('id' => $id));
88  $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/defaultPortlet/delete', true);
89  $this->assertEmpty($content);
90  $memberCount = $marketingList->memberAlreadyExists($contact->id);
91  $this->assertEquals(0, $memberCount);
92  }
93 
94  public function testToggleUnsubscribed()
95  {
96  $marketingList = MarketingListTestHelper::createMarketingListByName('MarketingList4',
97  'MarketingList Description4');
98  $this->assertNotNull($marketingList);
100  $this->assertNotEmpty($contact);
101  $previousUnsubcribedValue = 1;
102  $marketingListMember = MarketingListMemberTestHelper::createMarketingListMember($previousUnsubcribedValue,
103  $marketingList,
104  $contact);
105  $marketingListMemberId = $marketingListMember->id;
106  $this->assertNotNull($marketingListMember);
107  $this->setGetArray(array('id' => $marketingListMemberId));
109  'marketingLists/defaultPortlet/toggleUnsubscribed',
110  true);
111  $this->assertEmpty($content);
112  $marketingListMember = MarketingListMember::getById($marketingListMemberId);
113  $newUnsubscribedValue = $marketingListMember->unsubscribed;
114  $this->assertNotEquals($previousUnsubcribedValue, $newUnsubscribedValue);
115  }
116 
117  public function testCountMembers()
118  {
119  $marketingLists = MarketingList::getByName('MarketingList1');
120  $marketingListId = $marketingLists[0]->id;
121  $subscriberCount = 3;
122  $unsubscriberCount = 2;
123  $this->setGetArray(array('marketingListId' => $marketingListId));
124  $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/defaultPortlet/countMembers');
125  $countArray = CJSON::decode($content);
126  $this->assertNotEmpty($countArray);
127  $this->assertArrayHasKey('subscriberCount', $countArray);
128  $this->assertArrayHasKey('unsubscriberCount', $countArray);
129  $this->assertEquals($subscriberCount, $countArray['subscriberCount']);
130  $this->assertEquals($unsubscriberCount, $countArray['unsubscriberCount']);
131  }
132 
133  public function testSubscribeContactsForContactType()
134  {
135  $type = 'contact';
136  $account = AccountTestHelper::createAccountByNameForOwner('superAccount3', $this->user);
137  $contact = ContactTestHelper::createContactWithAccountByNameForOwner('superContact6',
138  $this->user,
139  $account);
140  $contactId = $contact->id;
142  $marketingListId = $marketingList->id;
143  $this->setGetArray(array(
144  'marketingListId' => $marketingListId,
145  'id' => $contact->id,
146  'type' => $type,
147  ));
148  $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/defaultPortlet/subscribeContacts');
149  $contentArray = CJSON::decode($content);
150  $this->assertNotEmpty($contentArray);
151  $this->assertArrayHasKey('type', $contentArray);
152  $this->assertArrayHasKey('message', $contentArray);
153  $this->assertEquals('1 subscribed.', $contentArray['message']);
154  $this->assertEquals('message', $contentArray['type']);
155 
156  $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/defaultPortlet/subscribeContacts');
157  $contentArray = CJSON::decode($content);
158  $this->assertNotEmpty($contentArray);
159  $this->assertArrayHasKey('type', $contentArray);
160  $this->assertArrayHasKey('message', $contentArray);
161  $this->assertEquals('0 subscribed. 1 skipped, already in the list.', $contentArray['message']);
162  $this->assertEquals('message', $contentArray['type']);
163  }
164 
165  public function testSubscribeContactsForReportType()
166  {
167  $type = 'report';
168  $report = SavedReportTestHelper::makeSimpleContactRowsAndColumnsReport();
169  $marketingList = MarketingListTestHelper::createMarketingListByName('MarketingList5', 'MarketingList Description5');
170  $marketingListId = $marketingList->id;
171  $contactCount = Contact::getCount();
172  $this->assertNotNull($report);
173  $this->setGetArray(array(
174  'marketingListId' => $marketingListId,
175  'id' => $report->id,
176  'type' => $type,
177  ));
178  $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/defaultPortlet/subscribeContacts');
179  $contentArray = CJSON::decode($content);
180  $this->assertNotEmpty($contentArray);
181  $this->assertArrayHasKey('type', $contentArray);
182  $this->assertArrayHasKey('message', $contentArray);
183  $this->assertEquals($contactCount . ' subscribed.', $contentArray['message']);
184  $this->assertEquals('message', $contentArray['type']);
185 
186  $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/defaultPortlet/subscribeContacts');
187  $contentArray = CJSON::decode($content);
188  $this->assertNotEmpty($contentArray);
189  $this->assertArrayHasKey('type', $contentArray);
190  $this->assertArrayHasKey('message', $contentArray);
191  $this->assertEquals('0 subscribed. ' . $contactCount . ' skipped, already in the list.', $contentArray['message']);
192  $this->assertEquals('message', $contentArray['type']);
193 
194  //TODO: Uncomment once massSubscribeProgressPageSize field added to pagination
195  Yii::app()->pagination->setForCurrentUserByType('massSubscribeProgressPageSize', 1);
196  $this->setGetArray(array(
197  'marketingListId' => $marketingListId,
198  'id' => $report->id,
199  'type' => $type,
200  'page' => 2,
201  ));
202 
203  $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/defaultPortlet/subscribeContacts');
204  $contentArray = CJSON::decode($content);
205  $percent = round((2 / $contactCount) * 100,0) ; // Not Coding Standard
206  $this->assertNotEmpty($contentArray);
207  $this->assertArrayHasKey('type', $contentArray);
208  $this->assertArrayHasKey('message', $contentArray);
209  $this->assertEquals("Processing: {$percent} % complete", $contentArray['message']);
210  $this->assertEquals('message', $contentArray['type']);
211  $this->assertEquals(3, $contentArray['nextPage']);
212  $this->assertEquals(0, $contentArray['subscribedCount']);
213  $this->assertEquals(1, $contentArray['skippedCount']);
214 
215  $this->setGetArray(array(
216  'marketingListId' => $marketingListId,
217  'id' => $report->id,
218  'type' => $type,
219  'page' => $contactCount,
220  'skippedCount' => $contactCount - 1,
221  'subscribedCount' => 0,
222  ));
223 
224  $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/defaultPortlet/subscribeContacts');
225  $contentArray = CJSON::decode($content);
226  $this->assertNotEmpty($contentArray);
227  $this->assertArrayHasKey('type', $contentArray);
228  $this->assertArrayHasKey('message', $contentArray);
229  $this->assertEquals("0 subscribed. {$contactCount} skipped, already in the list.", $contentArray['message']);
230  $this->assertEquals('message', $contentArray['type']);
231  }
232  }
233 ?>
static rebuild($overwriteExistingTables=true, $forcePhp=false, $messageStreamer=null)
static getByUsername($username)
Definition: User.php:49
static getRandomValueFromArray($array)
static getCount(RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter=null, $where=null, $modelClassName=null, $selectDistinct=false)
static getById($id, $modelClassName=null)
logoutCurrentUserLoginNewUserAndGetByUsername($username)
runControllerWithNoExceptionsAndGetContent($route, $empty=false)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
Generated on Sun May 31 2020 07:10:33