All Data Structures Functions Variables Pages
MarketingListDefaultControllerSuperUserWalkthroughTest.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  $super = User::getByUsername('super');
46  Yii::app()->user->userModel = $super;
48  }
49 
50  public function setUp()
51  {
52  parent::setUp();
53  $this->user = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
54  Yii::app()->user->userModel = $this->user;
55  }
56 
57  public function testSuperUserAllDefaultControllerActions()
58  {
59  // Test all default controller actions that do not require any POST/GET variables to be passed.
60  $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default');
61  $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/index');
62  $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/list');
63  $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/create');
64 
65  MarketingListTestHelper::createMarketingListByName('MarketingListName', 'MarketingList Description',
66  'first', 'first@zurmo.com');
67  MarketingListTestHelper::createMarketingListByName('MarketingListName2', 'MarketingList Description2',
68  'second', 'second@zurmo.com');
69 
70  $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default');
71  $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/index');
72  $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/list');
73  $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/create');
74  }
75 
79  public function testSuperUserListAction()
80  {
81  $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/list');
82  $this->assertContains('anyMixedAttributes', $content);
83  $this->assertContains('MarketingListName', $content);
84  $this->assertContains('MarketingListName2', $content);
85  $this->assertEquals(2, substr_count($content, 'MarketingListName'));
86  //Test the search or paging of the listview.
87  Yii::app()->clientScript->reset(); //to make sure old js doesn't make it to the UI
88  $this->setGetArray(array('ajax' => 'list-view'));
89  $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/list');
90  $this->assertNotContains('anyMixedAttributes', $content);
91  }
92 
97  {
98  StickyReportUtil::clearDataByKey('MarketingListsSearchForm');
99  $this->setGetArray(array(
100  'MarketingListsSearchForm' => array(
101  'anyMixedAttributesScope' => array('All'),
102  'anyMixedAttributes' => 'xyz',
103  ) ,
104  ));
105  $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/list');
106  $this->assertContains('No results found', $content);
107 
108  StickyReportUtil::clearDataByKey('MarketingListsSearchForm');
109  $this->setGetArray(array(
110  'MarketingListsSearchForm' => array(
111  'anyMixedAttributesScope' => array('All'),
112  'anyMixedAttributes' => 'Marketing',
113  ) ,
114  ));
115  $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/list');
116  $this->assertContains('2 result(s)', $content);
117  $this->assertEquals(2, substr_count($content, 'MarketingListName'));
118  $this->assertContains('Clark Kent', $content);
119 
120  StickyReportUtil::clearDataByKey('MarketingListsSearchForm');
121  $this->setGetArray(array(
122  'MarketingListsSearchForm' => array(
123  'anyMixedAttributesScope' => array('All'),
124  'anyMixedAttributes' => 'Marketing',
125  'selectedListAttributes' => array('name', 'createdByUser', 'fromAddress', 'fromName'),
126  ) ,
127  ));
128  $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/list');
129  $this->assertContains('2 result(s)', $content);
130  $this->assertEquals(2, substr_count($content, 'MarketingListName'));
131  $this->assertContains('Clark Kent', $content);
132  $this->assertEquals(3, substr_count($content, 'Clark Kent'));
133  $this->assertContains('@zurmo.com', $content);
134  $this->assertEquals(4, substr_count($content, '@zurmo.com'));
135  $this->assertEquals(2, substr_count($content, 'first@zurmo.com'));
136  $this->assertEquals(2, substr_count($content, 'second@zurmo.com'));
137 
138  StickyReportUtil::clearDataByKey('MarketingListsSearchForm');
139  $this->setGetArray(array(
140  'clearingSearch' => 1,
141  'MarketingListsSearchForm' => array(
142  'anyMixedAttributesScope' => array('All'),
143  'anyMixedAttributes' => '',
144  'selectedListAttributes' => array('name', 'createdByUser', 'fromAddress', 'fromName'),
145  'dynamicClauses' => array(array(
146  'attributeIndexOrDerivedType' => 'fromAddress',
147  'structurePosition' => 1,
148  'fromAddress' => 'second@zurmo.com',
149  )),
150  'dynamicStructure' => '1',
151  ) ,
152  ));
153  $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/list');
154  $this->assertContains('1 result(s)', $content);
155  $this->assertEquals(1, substr_count($content, 'MarketingListName2'));
156  $this->assertContains('Clark Kent', $content);
157  $this->assertEquals(2, substr_count($content, 'Clark Kent'));
158  $this->assertContains('@zurmo.com', $content);
159  $this->assertEquals(2, substr_count($content, '@zurmo.com'));
160  $this->assertEquals(2, substr_count($content, 'second@zurmo.com'));
161 
162  StickyReportUtil::clearDataByKey('MarketingListsSearchForm');
163  $this->setGetArray(array(
164  'clearingSearch' => 1,
165  'MarketingListsSearchForm' => array(
166  'anyMixedAttributesScope' => array('All'),
167  'anyMixedAttributes' => '',
168  'selectedListAttributes' => array('name', 'createdByUser', 'fromAddress', 'fromName'),
169  'dynamicClauses' => array(array(
170  'attributeIndexOrDerivedType' => 'fromName',
171  'structurePosition' => 1,
172  'fromName' => 'first',
173  )),
174  'dynamicStructure' => '1',
175  ) ,
176  ));
177  $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/list');
178  $this->assertContains('1 result(s)', $content);
179  $this->assertEquals(1, substr_count($content, 'MarketingListName'));
180  $this->assertContains('Clark Kent', $content);
181  $this->assertEquals(2, substr_count($content, 'Clark Kent'));
182  $this->assertContains('@zurmo.com', $content);
183  $this->assertEquals(2, substr_count($content, '@zurmo.com'));
184  $this->assertEquals(2, substr_count($content, 'first@zurmo.com'));
185  }
186 
190  public function testSuperUserCreateAction()
191  {
192  $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/create');
193  $this->assertContains('Create Marketing List', $content);
194  $this->assertContains('<label for="MarketingList_name" class="required">Name ' .
195  '<span class="required">*</span></label>', $content);
196  $this->assertContains('<label for="MarketingList_description">Description</label>', $content);
197  $this->assertContains('<label for="MarketingList_fromName">From Name</label>', $content);
198  $this->assertContains('<label for="MarketingList_fromAddress">From Address</label>', $content);
199  $this->assertContains('<span class="z-label">Cancel</span>', $content);
200  $this->assertContains('<span class="z-label">Save</span>', $content);
201 
202  $this->resetGetArray();
203  $this->setPostArray(array('MarketingList' => array(
204  'name' => '',
205  'description' => '',
206  'fromName' => '',
207  'fromAddress' => '',
208  )));
209  $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/create');
210  $this->assertContains('class="errorMessage">Name cannot be blank.</div>', $content);
211  $this->assertContains('<input id="MarketingList_name" name="MarketingList[name]" type="text"' .
212  ' maxlength="64" value="" class="error"', $content);
213  $this->assertContains('<label class="error required" for="MarketingList_name">Name ' .
214  '<span class="required">*</span></label>', $content);
215  $this->resetGetArray();
216  $this->setPostArray(array('MarketingList' => array(
217  'name' => 'New MarketingListName using Create',
218  'description' => 'New MarketingList Description using Create',
219  'fromName' => 'Zurmo Sales',
220  'fromAddress' => 'sales@zurmo.com',
221  )));
222  $redirectUrl = $this->runControllerWithRedirectExceptionAndGetUrl('marketingLists/default/create');
223  $marketingList = MarketingList::getByName('New MarketingListName using Create');
224  $this->assertEquals(1, count($marketingList));
225  $this->assertTrue ($marketingList[0]->id > 0);
226  $this->assertEquals('sales@zurmo.com', $marketingList[0]->fromAddress);
227  $this->assertEquals('Zurmo Sales', $marketingList[0]->fromName);
228  $this->assertEquals('New MarketingList Description using Create', $marketingList[0]->description);
229  $this->assertTrue ($marketingList[0]->owner == $this->user);
230  $compareRedirectUrl = Yii::app()->createUrl('marketingLists/default/details', array('id' => $marketingList[0]->id));
231  $this->assertEquals($compareRedirectUrl, $redirectUrl);
232  $marketingList = MarketingList::getAll();
233  $this->assertEquals(3, count($marketingList));
234  }
235 
236  public function testSuperUserDetailsAction()
237  {
238  $marketingListId = self::getModelIdByModelNameAndName ('MarketingList', 'MarketingListName2');
239  $this->setGetArray(array('id' => $marketingListId));
240  $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/details');
241  $this->assertContains('MarketingListName2', $content);
242  $this->assertEquals(3, substr_count($content, 'MarketingListName2'));
243  $this->assertContains('<span class="button-label">Details</span>', $content);
244  $this->assertContains('<strong class="marketing-list-subscribers-stats">' .
245  '0 Subscribed</strong>', $content);
246  $this->assertContains('<strong class="marketing-list-unsubscribers-stats">' .
247  '0 Unsubscribed</strong>', $content);
248  $this->assertContains('MarketingList Description2', $content);
249  $this->assertContains('<span class="button-label">Options</span>', $content);
250  $this->assertContains('>Edit</a></li>', $content);
251  $this->assertContains('>Delete</a></li>', $content);
252  $this->assertContains('<h3>Contacts/Leads</h3>', $content);
253  $this->assertContains('<span class="button-label">Add Contact/Lead</span>', $content);
254  $this->assertContains('From Contacts/Leads</label>', $content);
255  $this->assertContains('From Report</label>', $content);
256  $this->assertContains('<span class="button-label">Unsubscribe</span>', $content);
257  $this->assertContains('<span class="button-label">Delete</span>', $content);
258  }
259 
263  public function testSuperUserEditAction()
264  {
265  $marketingListId = self::getModelIdByModelNameAndName ('MarketingList', 'New MarketingListName using Create');
266  $this->setGetArray(array('id' => $marketingListId));
267  $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/edit');
268  $this->assertContains('New MarketingListName using Create', $content);
269  $this->assertEquals(2, substr_count($content, 'New MarketingListName using Create'));
270  $this->assertContains('New MarketingList Description using Create', $content);
271  $this->assertContains('Zurmo Sales', $content);
272  $this->assertContains('sales@zurmo.com', $content);
273  $this->assertNotContains('Create Marketing List', $content);
274 
275  $this->setPostArray(array('MarketingList' => array(
276  'name' => 'New MarketingListName',
277  'description' => 'New MarketingList Description',
278  'fromName' => 'Zurmo Support',
279  'fromAddress' => 'support@zurmo.com',
280  )));
281  $redirectUrl = $this->runControllerWithRedirectExceptionAndGetUrl('marketingLists/default/edit');
282  $marketingList = MarketingList::getByName('New MarketingListName');
283  $this->assertEquals(1, count($marketingList));
284  $this->assertTrue ($marketingList[0]->id > 0);
285  $this->assertEquals('support@zurmo.com', $marketingList[0]->fromAddress);
286  $this->assertEquals('Zurmo Support', $marketingList[0]->fromName);
287  $this->assertEquals('New MarketingList Description', $marketingList[0]->description);
288  $compareRedirectUrl = Yii::app()->createUrl('marketingLists/default/details', array('id' => $marketingList[0]->id));
289  $this->assertEquals($compareRedirectUrl, $redirectUrl);
290  $marketingList = MarketingList::getAll();
291  $this->assertEquals(3, count($marketingList));
292  }
293 
297  public function testSuperUserDeleteAction()
298  {
299  $marketingListId = self::getModelIdByModelNameAndName ('MarketingList', 'New MarketingListName');
300 
301  // Delete a marketingList.
302  $this->setGetArray(array('id' => $marketingListId));
303  $this->resetPostArray();
304  $redirectUrl = $this->runControllerWithRedirectExceptionAndGetUrl('marketingLists/default/delete');
305  $compareRedirectUrl = Yii::app()->createUrl('marketingLists/default/index');
306  $this->assertEquals($redirectUrl, $compareRedirectUrl);
307  $marketingLists = MarketingList::getAll();
308  $this->assertEquals(2, count($marketingLists));
309  }
310 
311  public function testMarketingListDashboardGroupByActions()
312  {
313  $portlets = Portlet::getAll();
314  foreach ($portlets as $portlet)
315  {
316  if ($portlet->viewType = 'MarketingListOverallMetrics')
317  {
318  $marketingListPortlet = $portlet;
319  }
320  }
321  $marketingLists = MarketingList::getAll();
322 
323  $this->setGetArray(array(
324  'portletId' => $portlet->id,
325  'uniqueLayoutId' => 'MarketingListDetailsAndRelationsViewLeftBottomView',
326  'portletParams' => array('relationModelId' => $marketingLists[0]->id,
327  'relationModuleId' => 'marketingLists',
328  ),
329  ));
330  $this->setPostArray(array(
331  'MarketingOverallMetricsForm' => array('groupBy' => MarketingOverallMetricsForm::GROUPING_TYPE_DAY)
332  ));
333  $this->runControllerWithNoExceptionsAndGetContent('home/defaultPortlet/modalConfigSave');
334  $this->setPostArray(array(
335  'MarketingOverallMetricsForm' => array('groupBy' => MarketingOverallMetricsForm::GROUPING_TYPE_MONTH)
336  ));
337  $this->runControllerWithNoExceptionsAndGetContent('home/defaultPortlet/modalConfigSave');
338  $this->setPostArray(array(
339  'MarketingOverallMetricsForm' => array('groupBy' => MarketingOverallMetricsForm::GROUPING_TYPE_WEEK)
340  ));
341  $this->runControllerWithNoExceptionsAndGetContent('home/defaultPortlet/modalConfigSave');
342  }
343 
344  public function testAutoComplete()
345  {
346  $this->setGetArray(array('term' => 'inexistant'));
347  $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/autoComplete');
348  $decodedContent = CJSON::decode($content);
349  $this->assertNotEmpty($decodedContent);
350  $this->assertArrayHasKey(0, $decodedContent);
351  $decodedContent = $decodedContent[0];
352  $this->assertArrayHasKey('id', $decodedContent);
353  $this->assertArrayHasKey('value', $decodedContent);
354  $this->assertArrayHasKey('label', $decodedContent);
355  $this->assertNull($decodedContent['id']);
356  $this->assertNull($decodedContent['value']);
357  $this->assertNotNull($decodedContent['label']);
358  $this->assertEquals('No results found', $decodedContent['label']);
359 
360  $this->setGetArray(array('term' => 'Mark'));
361  $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/autoComplete');
362  $decodedContent = CJSON::decode($content);
363  $this->assertNotEmpty($decodedContent);
364  $this->assertArrayHasKey(0, $decodedContent);
365  $this->assertArrayHasKey(1, $decodedContent);
366  $result1 = $decodedContent[0];
367  $result2 = $decodedContent[1];
368 
369  $this->assertArrayHasKey('id', $result1);
370  $this->assertArrayHasKey('value', $result1);
371  $this->assertArrayHasKey('label', $result1);
372  $this->assertNotNull($result1['id']);
373  $this->assertEquals($result1['value'], $result1['label']);
374  $this->assertNotNull($result1['label']);
375  $this->assertEquals('MarketingListName', $result1['label']);
376 
377  $this->assertArrayHasKey('id', $result2);
378  $this->assertArrayHasKey('value', $result2);
379  $this->assertArrayHasKey('label', $result2);
380  $this->assertNotNull($result2['id']);
381  $this->assertEquals($result2['value'], $result2['label']);
382  $this->assertNotNull($result2['label']);
383  $this->assertEquals('MarketingListName2', $result2['label']);
384  }
385 
386  public function testGetInfoToCopyToCampaign()
387  {
388  $marketingListId = self::getModelIdByModelNameAndName('MarketingList', 'MarketingListName');
389  $marketingList = MarketingList::getById($marketingListId);
390  $this->setGetArray(array('id' => $marketingListId));
392  'marketingLists/default/getInfoToCopyToCampaign');
393  $decodedContent = CJSON::decode($content);
394  $this->assertNotEmpty($decodedContent);
395  $this->assertArrayHasKey('fromName', $decodedContent);
396  $this->assertArrayHasKey('fromAddress', $decodedContent);
397  $this->assertEquals($marketingList->fromName, $decodedContent['fromName']);
398  $this->assertEquals($marketingList->fromAddress, $decodedContent['fromAddress']);
399  }
400 
401  public function testModalList()
402  {
403  $this->setGetArray(array(
404  'modalTransferInformation' => array(
405  'sourceIdFieldId' => 'Campaign_marketingList_id',
406  'sourceNameFieldId' => 'Campaign_marketingList_name',
407  'modalId' => 'modalContainer-edit-form',
408  )
409  ));
410  $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/modalList');
411  $this->assertContains('<div id="ModalView">', $content);
412  $this->assertContains('<div id="MarketingListsModalSearchAndListView" ' .
413  'class="ModalSearchAndListView GridView">', $content);
414  $this->assertContains('<div id="MarketingListsModalSearchView" class="SearchView ModelView' .
415  ' ConfigurableMetadataView MetadataView">', $content);
416  $this->assertContains('<div class="wide form">', $content);
417  $this->assertContains('<form id="search-formmodal" method="post">', $content);
418  $this->assertContains('</div><div class="search-view-0"', $content);
419  $this->assertContains('<table><tr><th></th><td colspan="3">', $content);
420  $this->assertContains('<select class="ignore-style ignore-clearform" id="MarketingListsSearch' .
421  'Form_anyMixedAttributesScope" multiple="multiple" ' .
422  'style="display:none;" size="4" name="MarketingListsSearchForm' .
423  '[anyMixedAttributesScope][]">', $content);
424  $this->assertContains('<option value="All" selected="selected">All</option>', $content);
425  $this->assertContains('<option value="name">Name</option>', $content);
426  $this->assertContains('<input class="input-hint anyMixedAttributes-input" ' .
427  'onfocus="$(this).select();" size="80" id="MarketingListsSearchForm' .
428  '_anyMixedAttributes" name="MarketingListsSearchForm' .
429  '[anyMixedAttributes]" type="text"', $content);
430  $this->assertContains('</div><div class="search-form-tools">', $content);
431  $this->assertContains('<a id="clear-search-linkmodal" style="display:none;" href="#">' .
432  'Clear</a>', $content);
433  $this->assertContains('<input id="clearingSearch-search-formmodal" type="hidden" ' .
434  'name="clearingSearch"', $content);
435  $this->assertContains('</div></form>', $content);
436  $this->assertContains('<div id="modalContainer-search-formmodal"></div>', $content);
437  $this->assertContains('<div id="MarketingListsModalListView" class="ModalListView ListView ' .
438  'ModelView ConfigurableMetadataView MetadataView">', $content);
439  $this->assertContains('<div class="cgrid-view type-marketingLists" id="list-viewmodal">', $content);
440  $this->assertContains('<div class="summary">1-2 of 2 result(s).</div>', $content);
441  $this->assertContains('<table class="items">', $content);
442  $this->assertContains('<th id="list-viewmodal_c0">', $content);
443  $this->assertContains('<a class="sort-link" href="', $content);
444  $this->assertContains('marketingLists/default/modalList?modalTransferInformation%5BsourceId' . // Not Coding Standard
445  'FieldId%5D=Campaign_marketingList_id&amp;modalTransferInformation%5B' . // Not Coding Standard
446  'sourceNameFieldId%5D=Campaign_marketingList_name&amp;modalTransfer' . // Not Coding Standard
447  'Information%5BmodalId%5D=modalContainer-edit-form&amp;MarketingList' . // Not Coding Standard
448  '_sort=name">Name</a></th></tr>', $content); // Not Coding Standard
449  $this->assertContains('<tr class="odd">', $content);
450  $this->assertContains('MarketingListName</a></td></tr>', $content);
451  $this->assertContains('<tr class="even">', $content);
452  $this->assertContains('MarketingListName2</a></td></tr>', $content);
453  $this->assertContains('<div class="pager horizontal">', $content);
454  $this->assertContains('<li class="refresh hidden">', $content);
455  $this->assertContains('marketingLists/default/modalList?modalTransferInformation%5Bsource'. // Not Coding Standard
456  'IdFieldId%5D=Campaign_marketingList_id&amp;modalTransferInformation'. // Not Coding Standard
457  '%5BsourceNameFieldId%5D=Campaign_marketingList_name&amp;modal' . // Not Coding Standard
458  'TransferInformation%5BmodalId%5D=modalContainer-edit-form">' . // Not Coding Standard
459  'refresh</a></li></ul>', $content);
460  $this->assertContains('</div><div class="list-preloader">', $content);
461  $this->assertContains('<span class="z-spinner"></span></div>', $content);
462  }
463  }
464 ?>
static rebuild($overwriteExistingTables=true, $forcePhp=false, $messageStreamer=null)
static getByUsername($username)
Definition: User.php:49
static getById($id, $modelClassName=null)
static clearDataByKey($key)
logoutCurrentUserLoginNewUserAndGetByUsername($username)
runControllerWithNoExceptionsAndGetContent($route, $empty=false)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
Generated on Wed Feb 26 2020 07:10:39