Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
MarketingListMembersUtilTest.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 $super;
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->super = User::getByUsername('super');
50  Yii::app()->user->userModel = $this->super;
51  }
52 
53  public function testMakeSearchAttributeData()
54  {
55  $marketingListId = 1;
56  $filterBySubscriptionType = null;
57  $filterBySearchTerm = null;
58  $searchAttributeData1 = MarketingListMembersUtil::makeSearchAttributeData($marketingListId,
59  $filterBySubscriptionType,
60  $filterBySearchTerm);
61 
62  $this->assertCount(1, $searchAttributeData1);
63  $this->assertArrayHasKey(0, $searchAttributeData1);
64  $this->assertArrayHasKey('MarketingListMember', $searchAttributeData1[0]);
65  $this->assertArrayHasKey('clauses', $searchAttributeData1[0]['MarketingListMember']);
66  $this->assertArrayHasKey('structure', $searchAttributeData1[0]['MarketingListMember']);
67  $this->assertEquals(1, $searchAttributeData1[0]['MarketingListMember']['structure']);
68 
69  $clauses1 = $searchAttributeData1[0]['MarketingListMember']['clauses'];
70  $this->assertCount(1, $clauses1);
71  $this->assertArrayHasKey(1, $clauses1);
72  $this->assertCount(4, $clauses1[1]);
73  $this->assertArrayHasKey('attributeName', $clauses1[1]);
74  $this->assertEquals('marketingList', $clauses1[1]['attributeName']);
75  $this->assertArrayHasKey('relatedAttributeName', $clauses1[1]);
76  $this->assertEquals('id', $clauses1[1]['relatedAttributeName']);
77  $this->assertArrayHasKey('operatorType', $clauses1[1]);
78  $this->assertEquals('equals', $clauses1[1]['operatorType']);
79  $this->assertArrayHasKey('value', $clauses1[1]);
80  $this->assertEquals($marketingListId, $clauses1[1]['value']);
81 
82  $filterBySubscriptionType = MarketingListMembersConfigurationForm::FILTERED_USER_ALL;
83  $searchAttributeData2 = MarketingListMembersUtil::makeSearchAttributeData($marketingListId,
84  $filterBySubscriptionType,
85  $filterBySearchTerm);
86  $this->assertEquals($searchAttributeData1, $searchAttributeData2);
87 
88  $filterBySubscriptionType = MarketingListMembersConfigurationForm::FILTER_USER_SUBSCRIBERS;
89  $searchAttributeData3 = MarketingListMembersUtil::makeSearchAttributeData($marketingListId,
90  $filterBySubscriptionType,
91  $filterBySearchTerm);
92  $this->assertCount(1, $searchAttributeData3);
93  $this->assertArrayHasKey(0, $searchAttributeData3);
94  $this->assertArrayHasKey('MarketingListMember', $searchAttributeData3[0]);
95  $this->assertArrayHasKey('clauses', $searchAttributeData3[0]['MarketingListMember']);
96  $this->assertArrayHasKey('structure', $searchAttributeData3[0]['MarketingListMember']);
97  $this->assertEquals('(1 and 2)', $searchAttributeData3[0]['MarketingListMember']['structure']);
98 
99  $clauses3 = $searchAttributeData3[0]['MarketingListMember']['clauses'];
100  $this->assertCount(2, $clauses3);
101  $this->assertArrayHasKey(2, $clauses3);
102  $this->assertCount(3, $clauses3[2]);
103  $this->assertArrayHasKey('attributeName', $clauses3[2]);
104  $this->assertEquals('unsubscribed', $clauses3[2]['attributeName']);
105  $this->assertArrayHasKey('operatorType', $clauses3[2]);
106  $this->assertEquals('equals', $clauses3[2]['operatorType']);
107  $this->assertArrayHasKey('value', $clauses3[2]);
108  $this->assertEquals(0, $clauses3[2]['value']);
109 
110  $filterBySubscriptionType = MarketingListMembersConfigurationForm::FILTER_USER_UNSUBSCRIBERS;
111  $searchAttributeData4 = MarketingListMembersUtil::makeSearchAttributeData($marketingListId,
112  $filterBySubscriptionType,
113  $filterBySearchTerm);
114  $this->assertEquals(1, $searchAttributeData4[0]['MarketingListMember']['clauses'][2]['value']);
115 
116  $filterBySearchTerm = 'ja';
117  $searchAttributeData5 = MarketingListMembersUtil::makeSearchAttributeData($marketingListId,
118  $filterBySubscriptionType,
119  $filterBySearchTerm);
120 
121  $this->assertCount(1, $searchAttributeData5);
122  $this->assertArrayHasKey(0, $searchAttributeData5);
123  $this->assertArrayHasKey('MarketingListMember', $searchAttributeData5[0]);
124  $this->assertArrayHasKey('clauses', $searchAttributeData5[0]['MarketingListMember']);
125  $this->assertArrayHasKey('structure', $searchAttributeData5[0]['MarketingListMember']);
126  $this->assertEquals('(1 and 2) and (3 or 4 or 5 or 6 or 7)', $searchAttributeData5[0]['MarketingListMember']['structure']);
127 
128  $clauses5 = $searchAttributeData5[0]['MarketingListMember']['clauses'];
129  $this->assertCount(7, $clauses5);
130  $this->assertArrayHasKey(3, $clauses5);
131  $this->assertCount(4, $clauses5[3]);
132  $this->assertArrayHasKey('attributeName', $clauses5[3]);
133  $this->assertEquals('contact', $clauses5[3]['attributeName']);
134  $this->assertArrayHasKey('relatedAttributeName', $clauses5[3]);
135  $this->assertEquals('firstName', $clauses5[3]['relatedAttributeName']);
136  $this->assertArrayHasKey('operatorType', $clauses5[3]);
137  $this->assertEquals('startsWith', $clauses5[3]['operatorType']);
138  $this->assertArrayHasKey('value', $clauses5[3]);
139  $this->assertEquals($filterBySearchTerm, $clauses5[3]['value']);
140 
141  $this->assertArrayHasKey(4, $clauses5);
142  $this->assertCount(4, $clauses5[4]);
143  $this->assertArrayHasKey('attributeName', $clauses5[4]);
144  $this->assertEquals('contact', $clauses5[4]['attributeName']);
145  $this->assertArrayHasKey('relatedAttributeName', $clauses5[4]);
146  $this->assertEquals('lastName', $clauses5[4]['relatedAttributeName']);
147  $this->assertArrayHasKey('operatorType', $clauses5[4]);
148  $this->assertEquals('startsWith', $clauses5[4]['operatorType']);
149  $this->assertArrayHasKey('value', $clauses5[4]);
150  $this->assertEquals($filterBySearchTerm, $clauses5[4]['value']);
151 
152  $this->assertArrayHasKey(5, $clauses5);
153  $this->assertCount(2, $clauses5[5]);
154  $this->assertArrayHasKey('attributeName', $clauses5[5]);
155  $this->assertEquals('contact', $clauses5[5]['attributeName']);
156  $this->assertArrayHasKey('relatedModelData', $clauses5[5]);
157  $this->assertCount(3, $clauses5[5]['relatedModelData']);
158  $this->assertArrayHasKey('concatedAttributeNames', $clauses5[5]['relatedModelData']);
159  $this->assertEquals(array('firstName', 'lastName'), $clauses5[5]['relatedModelData']['concatedAttributeNames']);
160  $this->assertArrayHasKey('operatorType', $clauses5[5]['relatedModelData']);
161  $this->assertEquals('contains', $clauses5[5]['relatedModelData']['operatorType']);
162  $this->assertArrayHasKey('value', $clauses5[5]['relatedModelData']);
163  $this->assertEquals('ja', $clauses5[5]['relatedModelData']['value']);
164 
165  $this->assertArrayHasKey(5, $clauses5);
166  $this->assertCount(2, $clauses5[6]);
167  $this->assertArrayHasKey('attributeName', $clauses5[6]);
168  $this->assertEquals('contact', $clauses5[5]['attributeName']);
169  $this->assertArrayHasKey('relatedModelData', $clauses5[6]);
170  $this->assertCount(4, $clauses5[6]['relatedModelData']);
171  $this->assertArrayHasKey('attributeName', $clauses5[6]['relatedModelData']);
172  $this->assertEquals('primaryEmail', $clauses5[6]['relatedModelData']['attributeName']);
173  $this->assertArrayHasKey('relatedAttributeName', $clauses5[6]['relatedModelData']);
174  $this->assertEquals('emailAddress', $clauses5[6]['relatedModelData']['relatedAttributeName']);
175  $this->assertArrayHasKey('operatorType', $clauses5[6]['relatedModelData']);
176  $this->assertEquals('startsWith', $clauses5[6]['relatedModelData']['operatorType']);
177  $this->assertArrayHasKey('value', $clauses5[6]['relatedModelData']);
178  $this->assertEquals($filterBySearchTerm, $clauses5[6]['relatedModelData']['value']);
179 
180  $this->assertArrayHasKey(6, $clauses5);
181  $this->assertCount(2, $clauses5[7]);
182  $this->assertArrayHasKey('attributeName', $clauses5[7]);
183  $this->assertEquals('contact', $clauses5[7]['attributeName']);
184  $this->assertArrayHasKey('relatedModelData', $clauses5[7]);
185  $this->assertCount(4, $clauses5[7]['relatedModelData']);
186  $this->assertArrayHasKey('attributeName', $clauses5[7]['relatedModelData']);
187  $this->assertEquals('secondaryEmail', $clauses5[7]['relatedModelData']['attributeName']);
188  $this->assertArrayHasKey('relatedAttributeName', $clauses5[7]['relatedModelData']);
189  $this->assertEquals('emailAddress', $clauses5[7]['relatedModelData']['relatedAttributeName']);
190  $this->assertArrayHasKey('operatorType', $clauses5[7]['relatedModelData']);
191  $this->assertEquals('startsWith', $clauses5[7]['relatedModelData']['operatorType']);
192  $this->assertArrayHasKey('value', $clauses5[7]['relatedModelData']);
193  $this->assertEquals($filterBySearchTerm, $clauses5[7]['relatedModelData']['value']);
194  }
195 
196  public function testMakeSortAttributeData()
197  {
198  $sortAttributes = MarketingListMembersUtil::makeSortAttributeData();
199  $this->assertArrayHasKey('MarketingListMember', $sortAttributes);
200  $this->assertCount(1, $sortAttributes);
201  $this->assertEquals('createdDateTime', $sortAttributes['MarketingListMember']);
202  }
203 
204  public function testMakeReportDataProviderAndResolveAttributeName()
205  {
206  $contactReport = SavedReportTestHelper::makeSimpleContactRowsAndColumnsReport();
207  $contact1 = ContactTestHelper::createContactByNameForOwner('contact01', $this->super);
208  $contact2 = ContactTestHelper::createContactByNameForOwner('contact02', $this->super);
209 
210  $attributeName = null;
212  $contactReport->id, 1, $attributeName);
213  $this->assertEquals('attribute1', $attributeName);
214  $this->assertInstanceOf('RowsAndColumnsReportDataProvider', $reportDataProvider);
215  $this->assertCount(1, $reportDataProvider->getData());
216 
217  $attributeName = null;
219  $contactReport->id, 2, $attributeName);
220  $this->assertEquals('attribute1', $attributeName);
221  $this->assertInstanceOf('RowsAndColumnsReportDataProvider', $reportDataProvider);
222  $this->assertCount(2, $reportDataProvider->getData());
223  }
224 
229  {
230  $contactReports = SavedReport::getAll();
231  $contactReport = $contactReports[0];
232  $contacts = Contact::getAll();
233  $attributeName = null;
235  $contactReport->id, 1, $attributeName);
237  $reportDataProvider, $attributeName);
238  $this->assertCount(1, $contactIds);
239 
240  $attributeName = null;
242  $contactReport->id, 2, $attributeName);
244  $reportDataProvider, $attributeName);
245  $this->assertCount(2, $contactIds);
246  $this->assertContains($contacts[0]->id, $contactIds);
247  $this->assertContains($contacts[1]->id, $contactIds);
248  }
249  }
250 ?>
static getByUsername($username)
Definition: User.php:49
static getContactIdsByReportDataProviderAndAttributeName(RowsAndColumnsReportDataProvider $reportDataProvider, $attributeName)
static makeReportDataProviderAndResolveAttributeName($id, $pageSize, &$attributeName)
static makeSearchAttributeData($marketingListId, $filterBySubscriptionType, $filterBySearchTerm)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
Generated on Sat Jul 4 2020 07:10:33
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.