Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ContactsSuperUserWalkthroughTest.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 
44  {
45  public static function setUpBeforeClass()
46  {
47  parent::setUpBeforeClass();
48  SecurityTestHelper::createSuperAdmin();
49  $super = User::getByUsername('super');
50  Yii::app()->user->userModel = $super;
51 
52  //Setup test data owned by the super user.
53  $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super);
54  AccountTestHelper::createAccountByNameForOwner ('superAccount2', $super);
55  ContactTestHelper::createContactWithAccountByNameForOwner('superContact', $super, $account);
56  ContactTestHelper::createContactWithAccountByNameForOwner('superContact2', $super, $account);
57  ContactTestHelper::createContactWithAccountByNameForOwner('superContact3', $super, $account);
58  ContactTestHelper::createContactWithAccountByNameForOwner('superContact4', $super, $account);
59  ContactTestHelper::createContactWithAccountByNameForOwner('superContact5', $super, $account);
60  ContactTestHelper::createContactWithAccountByNameForOwner('superContact6', $super, $account);
61  ContactTestHelper::createContactWithAccountByNameForOwner('superContact7', $super, $account);
62  ContactTestHelper::createContactWithAccountByNameForOwner('superContact8', $super, $account);
63  ContactTestHelper::createContactWithAccountByNameForOwner('superContact9', $super, $account);
64  ContactTestHelper::createContactWithAccountByNameForOwner('superContact10', $super, $account);
65  ContactTestHelper::createContactWithAccountByNameForOwner('superContact11', $super, $account);
66  ContactTestHelper::createContactWithAccountByNameForOwner('superContact12', $super, $account);
67  OpportunityTestHelper::createOpportunityStagesIfDoesNotExist ();
68  OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp', $super, $account);
69  //Setup default dashboard.
70  Dashboard::getByLayoutIdAndUser (Dashboard::DEFAULT_USER_LAYOUT_ID, $super);
71  //Make contact DetailsAndRelations portlets
72  }
73 
74  public function testSuperUserAllDefaultControllerActions()
75  {
76  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
77 
78  //Test all default controller actions that do not require any POST/GET variables to be passed.
79  //This does not include portlet controller actions.
80  $this->runControllerWithNoExceptionsAndGetContent('contacts/default');
81  $this->runControllerWithNoExceptionsAndGetContent('contacts/default/index');
82  $this->runControllerWithNoExceptionsAndGetContent('contacts/default/create');
83 
84  $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/list');
85  $this->assertContains('anyMixedAttributes', $content);
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('contacts/default/list');
90  $this->assertNotContains('anyMixedAttributes', $content);
91  $this->resetGetArray();
92 
93  //Default Controller actions requiring some sort of parameter via POST or GET
94  //Load Model Edit Views
95  $contacts = Contact::getAll();
96  $this->assertEquals(12, count($contacts));
97  $superContactId = self::getModelIdByModelNameAndName ('Contact', 'superContact superContactson');
98  $superContactId2 = self::getModelIdByModelNameAndName('Contact', 'superContact2 superContact2son');
99  $superContactId3 = self::getModelIdByModelNameAndName('Contact', 'superContact3 superContact3son');
100  $superContactId4 = self::getModelIdByModelNameAndName('Contact', 'superContact4 superContact4son');
101  $superContactId5 = self::getModelIdByModelNameAndName ('Contact', 'superContact5 superContact5son');
102  $superContactId6 = self::getModelIdByModelNameAndName('Contact', 'superContact6 superContact6son');
103  $superContactId7 = self::getModelIdByModelNameAndName('Contact', 'superContact7 superContact7son');
104  $superContactId8 = self::getModelIdByModelNameAndName('Contact', 'superContact8 superContact8son');
105  $superContactId9 = self::getModelIdByModelNameAndName ('Contact', 'superContact9 superContact9son');
106  $superContactId10 = self::getModelIdByModelNameAndName('Contact', 'superContact10 superContact10son');
107  $superContactId11 = self::getModelIdByModelNameAndName('Contact', 'superContact11 superContact11son');
108  $superContactId12 = self::getModelIdByModelNameAndName('Contact', 'superContact12 superContact12son');
109  $superOpportunityId = self::getModelIdByModelNameAndName ('Opportunity', 'superOpp');
110  $this->setGetArray(array('id' => $superContactId));
111  $this->runControllerWithNoExceptionsAndGetContent('contacts/default/edit');
112  //Save contact.
113  $superContact = Contact::getById($superContactId);
114  $this->assertEquals(null, $superContact->officePhone);
115  $this->setPostArray(array('Contact' => array('officePhone' => '456765421')));
116  $this->runControllerWithRedirectExceptionAndGetContent('contacts/default/edit');
117  $superContact = Contact::getById($superContactId);
118  $this->assertEquals('456765421', $superContact->officePhone);
119  //Test having a failed validation on the contact during save.
120  $this->setGetArray (array('id' => $superContactId));
121  $this->setPostArray(array('Contact' => array('lastName' => '')));
122  $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/edit');
123  $this->assertContains('Name cannot be blank', $content);
124 
125  //Load Model Detail Views
126  $this->setGetArray(array('id' => $superContactId));
127  $this->resetPostArray();
128  $this->runControllerWithNoExceptionsAndGetContent('contacts/default/details');
129 
130  //Load Model MassEdit Views.
131  //MassEdit view for single selected ids
132  $this->setGetArray(array('selectedIds' => '4,5,6,7,8,9', 'selectAll' => '')); // Not Coding Standard
133  $this->resetPostArray();
134  $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/massEdit');
135  $this->assertContains('<strong>6</strong>&#160;records selected for updating', $content);
136 
137  //MassEdit view for all result selected ids
138  $this->setGetArray(array('selectAll' => '1'));
139  $this->resetPostArray();
140  $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/massEdit');
141  $this->assertContains('<strong>12</strong>&#160;records selected for updating', $content);
142 
143  //save Model MassEdit for selected Ids
144  //Test that the 4 contacts do not have the office phone number we are populating them with.
145  $contact1 = Contact::getById($superContactId);
146  $contact2 = Contact::getById($superContactId2);
147  $contact3 = Contact::getById($superContactId3);
148  $contact4 = Contact::getById($superContactId4);
149  $this->assertNotEquals('7788', $contact1->officePhone);
150  $this->assertNotEquals('7788', $contact2->officePhone);
151  $this->assertNotEquals('7788', $contact3->officePhone);
152  $this->assertNotEquals('7788', $contact4->officePhone);
153  $this->setGetArray(array(
154  'selectedIds' => $superContactId . ',' . $superContactId2, // Not Coding Standard
155  'selectAll' => '',
156  'Contact_page' => 1));
157  $this->setPostArray(array(
158  'Contact' => array('officePhone' => '7788'),
159  'MassEdit' => array('officePhone' => 1)
160  ));
161  $this->runControllerWithRedirectExceptionAndGetContent('contacts/default/massEdit');
162  //Test that the 2 contacts have the new office phone number and the other contacts do not.
163  $contact1 = Contact::getById($superContactId);
164  $contact2 = Contact::getById($superContactId2);
165  $contact3 = Contact::getById($superContactId3);
166  $contact4 = Contact::getById($superContactId4);
167  $contact5 = Contact::getById($superContactId5);
168  $contact6 = Contact::getById($superContactId6);
169  $contact7 = Contact::getById($superContactId7);
170  $contact8 = Contact::getById($superContactId8);
171  $contact9 = Contact::getById($superContactId9);
172  $contact10 = Contact::getById($superContactId10);
173  $contact11 = Contact::getById($superContactId11);
174  $contact12 = Contact::getById($superContactId12);
175  $this->assertEquals ('7788', $contact1->officePhone);
176  $this->assertEquals ('7788', $contact2->officePhone);
177  $this->assertNotEquals('7788', $contact3->officePhone);
178  $this->assertNotEquals('7788', $contact4->officePhone);
179  $this->assertNotEquals('7788', $contact5->officePhone);
180  $this->assertNotEquals('7788', $contact6->officePhone);
181  $this->assertNotEquals('7788', $contact7->officePhone);
182  $this->assertNotEquals('7788', $contact8->officePhone);
183  $this->assertNotEquals('7788', $contact9->officePhone);
184  $this->assertNotEquals('7788', $contact10->officePhone);
185  $this->assertNotEquals('7788', $contact11->officePhone);
186  $this->assertNotEquals('7788', $contact12->officePhone);
187  //save Model MassEdit for entire search result
188  $this->setGetArray(array(
189  'selectAll' => '1',
190  'Contact_page' => 1));
191  $this->setPostArray(array(
192  'Contact' => array('officePhone' => '1234'),
193  'MassEdit' => array('officePhone' => 1)
194  ));
195  $pageSize = Yii::app()->pagination->getForCurrentUserByType('massEditProgressPageSize');
196  $this->assertEquals(5, $pageSize);
197  Yii::app()->pagination->setForCurrentUserByType('massEditProgressPageSize', 20);
198  $this->runControllerWithRedirectExceptionAndGetContent('contacts/default/massEdit');
199  Yii::app()->pagination->setForCurrentUserByType('massEditProgressPageSize', $pageSize);
200  //Test that all accounts have the new phone number.
201  $contact1 = Contact::getById($superContactId);
202  $contact2 = Contact::getById($superContactId2);
203  $contact3 = Contact::getById($superContactId3);
204  $contact4 = Contact::getById($superContactId4);
205  $contact5 = Contact::getById($superContactId5);
206  $contact6 = Contact::getById($superContactId6);
207  $contact7 = Contact::getById($superContactId7);
208  $contact8 = Contact::getById($superContactId8);
209  $contact9 = Contact::getById($superContactId9);
210  $contact10 = Contact::getById($superContactId10);
211  $contact11 = Contact::getById($superContactId11);
212  $contact12 = Contact::getById($superContactId12);
213  $this->assertEquals ('1234', $contact1->officePhone);
214  $this->assertEquals ('1234', $contact2->officePhone);
215  $this->assertEquals ('1234', $contact3->officePhone);
216  $this->assertEquals ('1234', $contact4->officePhone);
217  $this->assertEquals ('1234', $contact5->officePhone);
218  $this->assertEquals ('1234', $contact6->officePhone);
219  $this->assertEquals ('1234', $contact7->officePhone);
220  $this->assertEquals ('1234', $contact8->officePhone);
221  $this->assertEquals ('1234', $contact9->officePhone);
222  $this->assertEquals ('1234', $contact10->officePhone);
223  $this->assertEquals ('1234', $contact11->officePhone);
224  $this->assertEquals ('1234', $contact12->officePhone);
225 
226  //Run Mass Update using progress save.
227  $pageSize = Yii::app()->pagination->getForCurrentUserByType('massEditProgressPageSize');
228  $this->assertEquals(5, $pageSize);
229  Yii::app()->pagination->setForCurrentUserByType('massEditProgressPageSize', 1);
230  //The page size is smaller than the result set, so it should exit.
231  $this->runControllerWithExitExceptionAndGetContent('contacts/default/massEdit');
232  //save Modal MassEdit using progress load for page 2, 3 and 4.
233  $this->setGetArray(array('selectAll' => '1', 'Contact_page' => 2));
234  $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/massEditProgressSave');
235  $this->assertContains('"value":16', $content);
236  $this->setGetArray(array('selectAll' => '1', 'Contact_page' => 3));
237  $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/massEditProgressSave');
238  $this->assertContains('"value":25', $content);
239  $this->setGetArray(array('selectAll' => '1', 'Contact_page' => 4));
240  $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/massEditProgressSave');
241  $this->assertContains('"value":33', $content);
242  //Set page size back to old value.
243  Yii::app()->pagination->setForCurrentUserByType('massEditProgressPageSize', $pageSize);
244 
245  //Autocomplete for Contact
246  $this->setGetArray(array('term' => 'super'));
247  $this->runControllerWithNoExceptionsAndGetContent('contacts/default/autoComplete');
248  $this->setGetArray(array('term' => 'super'));
249  $this->runControllerWithNoExceptionsAndGetContent('contacts/variableContactState/autoCompleteAllContacts');
250  $this->setGetArray(array('term' => 'super'));
251  $this->runControllerWithNoExceptionsAndGetContent('contacts/variableContactState/autoCompleteAllContactsForMultiSelectAutoComplete');
252 
253  //actionModalList
254  $this->setGetArray(array(
255  'modalTransferInformation' => array('sourceIdFieldId' => 'x', 'sourceNameFieldId' => 'y', 'modalId' => 'z')
256  ));
257  $this->runControllerWithNoExceptionsAndGetContent('contacts/default/modalList');
258 
259  //actionModalListAllContacts
260  $this->setGetArray(array(
261  'modalTransferInformation' => array('sourceIdFieldId' => 'x', 'sourceNameFieldId' => 'y', 'modalId' => 'z')
262  ));
263  $this->runControllerWithNoExceptionsAndGetContent('contacts/variableContactState/modalListAllContacts');
264 
265  //actionAuditEventsModalList
266  $this->setGetArray(array('id' => $superContactId));
267  $this->resetPostArray();
268  $this->runControllerWithNoExceptionsAndGetContent('contacts/default/auditEventsModalList');
269 
270  //Select a related Opportunity for this contact. Go to the select screen.
271  $contact1->forget();
272  $contact1 = Contact::getById($superContactId);
273  $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition(
274  'ContactDetailsAndRelationsView', $super->id, array());
275  $this->assertEquals(2, count($portlets));
276  $this->assertEquals(3, count($portlets[1]));
277  $opportunity = Opportunity::getById($superOpportunityId);
278  $this->assertEquals(0, $contact1->opportunities->count());
279  $this->assertEquals(0, $opportunity->contacts->count());
280  $this->setGetArray(array( 'portletId' => $portlets[1][1]->id, //Doesnt matter which portlet we are using
281  'relationAttributeName' => 'contacts',
282  'relationModuleId' => 'contacts',
283  'relationModelId' => $superContactId,
284  'uniqueLayoutId' => 'ContactDetailsAndRelationsView_' .
285  $portlets[1][1]->id)
286  );
287 
288  $this->resetPostArray();
289  $this->runControllerWithNoExceptionsAndGetContent('opportunities/default/SelectFromRelatedList');
290  //Now add an opportunity to a contact via the select from related list action.
291  $this->setGetArray(array( 'portletId' => $portlets[1][1]->id,
292  'modelId' => $superOpportunityId,
293  'relationAttributeName' => 'contacts',
294  'relationModuleId' => 'contacts',
295  'relationModelId' => $superContactId,
296  'uniqueLayoutId' => 'ContactDetailsAndRelationsView_' .
297  $portlets[1][1]->id)
298  );
299  $this->resetPostArray();
300  $this->runControllerWithRedirectExceptionAndGetContent('opportunities/defaultPortlet/SelectFromRelatedListSave');
301  //Run forget in order to refresh the contact and opportunity showing the new relation
302  $contact1->forget();
303  $opportunity->forget();
304  $contact = Contact::getById($superContactId);
305  $opportunity = Opportunity::getById($superOpportunityId);
306  $this->assertEquals(1, $opportunity->contacts->count());
307  $this->assertEquals($contact, $opportunity->contacts[0]);
308  $this->assertEquals(1, $contact->opportunities->count());
309  $this->assertEquals($opportunity->id, $contact->opportunities[0]->id);
310  }
311 
316  {
317  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
318  $superContactId2 = self::getModelIdByModelNameAndName('Contact', 'superContact2 superContact2son');
319 
320  //Save a layout change. Collapse all portlets in the Contact Details View.
321  //At this point portlets for this view should be created because we have already loaded the 'details' page in a request above.
322  $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition(
323  'ContactDetailsAndRelationsView', $super->id, array());
324  $this->assertEquals (3, count($portlets[1]));
325  $this->assertFalse (array_key_exists(3, $portlets) );
326  $portletPostData = array();
327  $portletCount = 0;
328  foreach ($portlets as $column => $columnPortlets)
329  {
330  foreach ($columnPortlets as $position => $portlet)
331  {
332  $this->assertEquals('0', $portlet->collapsed);
333  $portletPostData['ContactDetailsAndRelationsView_' . $portlet->id] = array(
334  'collapsed' => 'true',
335  'column' => 0,
336  'id' => 'ContactDetailsAndRelationsView_' . $portlet->id,
337  'position' => $portletCount,
338  );
339  $portletCount++;
340  }
341  }
342  //There should have been a total of 2 portlets.
343  $this->assertEquals(7, $portletCount);
344  $this->resetGetArray();
345  $this->setPostArray(array(
346  'portletLayoutConfiguration' => array(
347  'portlets' => $portletPostData,
348  'uniqueLayoutId' => 'ContactDetailsAndRelationsView',
349  )
350  ));
351  $this->runControllerWithNoExceptionsAndGetContent('home/defaultPortlet/saveLayout', true);
352  //Now test that all the portlets are collapsed and moved to the first column.
353  $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition(
354  'ContactDetailsAndRelationsView', $super->id, array());
355  $this->assertEquals (7, count($portlets[1]) );
356  $this->assertFalse (array_key_exists(2, $portlets) );
357  foreach ($portlets as $column => $columns)
358  {
359  foreach ($columns as $position => $positionPortlets)
360  {
361  $this->assertEquals('1', $positionPortlets->collapsed);
362  }
363  }
364  //Load Details View again to make sure everything is ok after the layout change.
365  $this->setGetArray(array('id' => $superContactId2));
366  $this->resetPostArray();
367  $this->runControllerWithNoExceptionsAndGetContent('contacts/default/details');
368  }
369 
373  public function testSuperUserDeleteAction()
374  {
375  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
376  $superContactId4 = self::getModelIdByModelNameAndName ('Contact', 'superContact4 superContact4son');
377  //Delete a contact.
378  $this->setGetArray(array('id' => $superContactId4));
379  $this->resetPostArray();
380  $this->runControllerWithRedirectExceptionAndGetContent('contacts/default/delete');
381  $contacts = Contact::getAll();
382  $this->assertEquals(11, count($contacts));
383  try
384  {
385  Contact::getById($superContactId4);
386  $this->fail();
387  }
388  catch (NotFoundException $e)
389  {
390  //success
391  }
392  }
393 
397  public function testSuperUserCreateAction()
398  {
399  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
400 
401  //Confirm the starting states exist
402  $this->assertEquals(6, count(ContactState::GetAll()));
403  $startingState = ContactsUtil::getStartingState();
404  //Create a new contact.
405  $this->resetGetArray();
406  $this->setPostArray(array('Contact' => array(
407  'firstName' => 'myNewContact',
408  'lastName' => 'myNewContactson',
409  'officePhone' => '456765421',
410  'state' => array('id' => $startingState->id)
411  )
412  )
413  );
414  $this->runControllerWithRedirectExceptionAndGetContent('contacts/default/create');
415  $contacts = Contact::getByName('myNewContact myNewContactson');
416  $this->assertEquals(1, count($contacts));
417  $this->assertTrue($contacts[0]->id > 0);
418  $this->assertTrue($contacts[0]->owner == $super);
419  $this->assertTrue($contacts[0]->state == $startingState);
420  $this->assertEquals('456765421', $contacts[0]->officePhone);
421  $contacts = Contact::getAll();
422  $this->assertEquals(12, count($contacts));
423 
424  //todo: test save with account.
425  }
426 
431  {
432  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
433  $startingState = ContactsUtil::getStartingState();
434  $contacts = Contact::getAll();
435  $this->assertEquals(12, count($contacts));
436  $account = Account::getByName('superAccount2');
437  $account[0]->billingAddress->street1 = 'some street';
438  $account[0]->shippingAddress->street1 = 'some street 2';
439  $saved = $account[0]->save();
440  $this->assertTrue($saved);
441  $opportunity = OpportunityTestHelper::createOpportunityWithAccountByNameForOwner(
442  'superOpp', $super, $account[0]);
443 
444  //Create a new contact from a related account.
445  $this->setGetArray(array( 'relationAttributeName' => 'account',
446  'relationModelId' => $account[0]->id,
447  'relationModuleId' => 'accounts',
448  'redirectUrl' => 'someRedirect'));
449  $this->setPostArray(array('Contact' => array(
450  'firstName' => 'another',
451  'lastName' => 'anotherson',
452  'officePhone' => '456765421',
453  'state' => array('id' => $startingState->id))));
454  $this->runControllerWithRedirectExceptionAndGetContent('contacts/default/createFromRelation');
455  $contacts = Contact::getByName('another anotherson');
456  $this->assertEquals(1, count($contacts));
457  $this->assertTrue($contacts[0]->id > 0);
458  $this->assertTrue($contacts[0]->owner == $super);
459  $this->assertTrue($contacts[0]->account == $account[0]);
460  $this->assertTrue($contacts[0]->state == $startingState);
461  $this->assertEquals('some street', $contacts[0]->primaryAddress->street1);
462  $this->assertEquals('some street 2', $contacts[0]->secondaryAddress->street1);
463  $this->assertEquals('some street', $contacts[0]->account->billingAddress->street1);
464  $this->assertEquals('some street 2', $contacts[0]->account->shippingAddress->street1);
465  $this->assertEquals('456765421', $contacts[0]->officePhone);
466  $contacts = Contact::getAll();
467  $this->assertEquals(13, count($contacts));
468 
469  //Create a new contact from a related opportunity
470  $this->setGetArray(array( 'relationAttributeName' => 'opportunities',
471  'relationModelId' => $opportunity->id,
472  'relationModuleId' => 'opportunities',
473  'redirectUrl' => 'someRedirect'));
474  $this->setPostArray(array('Contact' => array(
475  'firstName' => 'bnother',
476  'lastName' => 'bnotherson',
477  'officePhone' => '456765421',
478  'state' => array('id' => $startingState->id))));
479  $this->runControllerWithRedirectExceptionAndGetContent('contacts/default/createFromRelation');
480  $contacts = Contact::getByName('bnother bnotherson');
481  $this->assertEquals(1, count($contacts));
482  $this->assertTrue($contacts[0]->id > 0);
483  $this->assertTrue($contacts[0]->owner == $super);
484  $this->assertEquals(1, $contacts[0]->opportunities->count());
485  $this->assertTrue($contacts[0]->opportunities[0] == $opportunity);
486  $this->assertTrue($contacts[0]->state == $startingState);
487  $this->assertEquals('456765421', $contacts[0]->officePhone);
488  $contacts = Contact::getAll();
489  $this->assertEquals(14, count($contacts));
490 
491  //todo: test save with account.
492  }
493 
497  public function testSuperUserCopyAction()
498  {
499  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
500 
501  $contacts = Contact::getByName('myNewContact myNewContactson');
502  $this->assertCount(1, $contacts);
503 
504  $postArray = array(
505  'Contact' => array(
506  'firstName' => 'myNewContact',
507  'lastName' => 'myNewContactson',
508  'jobTitle' => 'job title',
509  'account' => array(
510  'name' => 'Linked account',
511  ),
512  'department' => 'Some department',
513  'officePhone' => '456765421',
514  'mobilePhone' => '958462315',
515  'officeFax' => '123456789',
516  'primaryEmail' => array(
517  'emailAddress' => 'a@a.com',
518  ),
519  'secondaryEmail' => array(
520  'emailAddress' => 'b@b.com',
521  ),
522  'primaryAddress' => array(
523  'street1' => 'Street1',
524  'street2' => 'Street2',
525  'city' => 'City',
526  'state' => 'State',
527  'postalCode' => '12345',
528  'country' => 'Country',
529  ),
530  'secondaryAddress' => array(
531  'street1' => 'Street1',
532  'street2' => 'Street2',
533  'city' => 'City',
534  'state' => 'State',
535  'postalCode' => '12345',
536  'country' => 'Country',
537  ),
538  'description' => 'some description',
539  )
540  );
541 
542  $this->updateModelValuesFromPostArray($contacts[0], $postArray);
543  $this->assertModelHasValuesFromPostArray($contacts[0], $postArray);
544 
545  $this->assertTrue($contacts[0]->save());
546  $this->assertTrue(
547  $this->checkCopyActionResponseAttributeValuesFromPostArray($contacts[0], $postArray)
548  );
549 
550  $postArray['Contact']['firstName'] = 'myClonedContact';
551  $postArray['Contact']['lastName'] = 'myClonedContactson';
552  $postArray['Contact']['state'] = array('id' => LeadsUtil::getStartingState()->id);
553  $this->setGetArray(array('id' => $contacts[0]->id));
554  $this->setPostArray($postArray);
555  $this->runControllerWithRedirectExceptionAndGetUrl('contacts/default/copy');
556 
557  $contacts = Contact::getByName('myClonedContact myClonedContactson');
558  $this->assertCount(1, $contacts);
559  $this->assertTrue($contacts[0]->owner->isSame($super));
560 
561  unset($postArray['Contact']['state']);
562  $this->assertModelHasValuesFromPostArray($contacts[0], $postArray);
563 
564  $contacts = Contact::getAll();
565  $this->assertCount(15, $contacts);
566 
567  $contacts = Contact::getByName('myClonedContact myClonedContactson');
568  $this->assertCount(1, $contacts);
569  $this->assertTrue($contacts[0]->delete());
570  }
571 
576  {
577  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
578  $contacts = Contact::getAll();
579  $this->assertEquals(14, count($contacts));
580  $superContactId = self::getModelIdByModelNameAndName('Contact', 'superContact');
581  $superContactId2 = self::getModelIdByModelNameAndName('Contact', 'superContact2 superContact2son');
582  $superContactId3 = self::getModelIdByModelNameAndName('Contact', 'superContact3 superContact3son');
583  $superContactId4 = self::getModelIdByModelNameAndName('Contact', 'myNewContact myNewContactson');
584  $superContactId5 = self::getModelIdByModelNameAndName('Contact', 'superContact5 superContact5son');
585  $superContactId6 = self::getModelIdByModelNameAndName('Contact', 'superContact6 superContact6son');
586  $superContactId7 = self::getModelIdByModelNameAndName('Contact', 'superContact7 superContact7son');
587  $superContactId8 = self::getModelIdByModelNameAndName('Contact', 'superContact8 superContact8son');
588  $superContactId9 = self::getModelIdByModelNameAndName('Contact', 'superContact9 superContact9son');
589  $superContactId10 = self::getModelIdByModelNameAndName('Contact', 'superContact10 superContact10son');
590  $superContactId11 = self::getModelIdByModelNameAndName('Contact', 'superContact11 superContact11son');
591  $superContactId12 = self::getModelIdByModelNameAndName('Contact', 'superContact12 superContact12son');
592  $superContactId13 = self::getModelIdByModelNameAndName('Contact', 'another anotherson');
593  $superContactId14 = self::getModelIdByModelNameAndName('Contact', 'bnother bnotherson');
594  //Load Model MassDelete Views.
595  //MassDelete view for single selected ids
596  $this->setGetArray(array('selectedIds' => '5,6,7,8,9', 'selectAll' => '', )); // Not Coding Standard
597  $this->resetPostArray();
598  $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/massDelete');
599  $this->assertContains('<strong>5</strong>&#160;Contacts selected for removal', $content);
600 
601  //MassDelete view for all result selected ids
602  $this->setGetArray(array('selectAll' => '1'));
603  $this->resetPostArray();
604  $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/massDelete');
605  $this->assertContains('<strong>14</strong>&#160;Contacts selected for removal', $content);
606 
607  //MassDelete for selected Record Count
608  $contacts = contact::getAll();
609  $this->assertEquals(14, count($contacts));
610 
611  //MassDelete for selected ids for paged scenario
612  $contact1 = contact::getById($superContactId);
613  $contact2 = contact::getById($superContactId2);
614  $contact3 = contact::getById($superContactId3);
615  $contact4 = contact::getById($superContactId4);
616  $contact5 = contact::getById($superContactId5);
617  $contact6 = contact::getById($superContactId6);
618  $contact7 = contact::getById($superContactId7);
619 
620  $pageSize = Yii::app()->pagination->getForCurrentUserByType('massDeleteProgressPageSize');
621  $this->assertEquals(5, $pageSize);
622  //MassDelete for selected ids for page 1
623  $this->setGetArray(array(
624  'selectedIds' => $superContactId . ',' . $superContactId2 . ',' . // Not Coding Standard
625  $superContactId3 . ',' . $superContactId4 . ',' . // Not Coding Standard
626  $superContactId5 . ',' . $superContactId6 . ',' . // Not Coding Standard
627  $superContactId7,
628  'selectAll' => '',
629  'massDelete' => '',
630  'Contact_page' => 1));
631  $this->setPostArray(array('selectedRecordCount' => 7));
632  $this->runControllerWithExitExceptionAndGetContent('contacts/default/massDelete');
633 
634  //MassDelete for selected Record Count
635  $contacts = Contact::getAll();
636  $this->assertEquals(9, count($contacts));
637 
638  //MassDelete for selected ids for page 2
639  $this->setGetArray(array(
640  'selectedIds' => $superContactId . ',' . $superContactId2 . ',' . // Not Coding Standard
641  $superContactId3 . ',' . $superContactId4 . ',' . // Not Coding Standard
642  $superContactId5 . ',' . $superContactId6 . ',' . // Not Coding Standard
643  $superContactId7,
644  'selectAll' => '',
645  'massDelete' => '',
646  'Contact_page' => 2));
647  $this->setPostArray(array('selectedRecordCount' => 7));
648  $this->runControllerWithNoExceptionsAndGetContent('contacts/default/massDeleteProgress');
649 
650  //MassDelete for selected Record Count
651  $contacts = Contact::getAll();
652  $this->assertEquals(7, count($contacts));
653  }
654 
660  {
661  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
662 
663  //MassDelete for selected Record Count
664  $contacts = contact::getAll();
665  $this->assertEquals(7, count($contacts));
666 
667  //save Model MassDelete for entire search result
668  $this->setGetArray(array(
669  'selectAll' => '1', // Not Coding Standard
670  'Contact_page' => 1));
671  $this->setPostArray(array('selectedRecordCount' => 7));
672  //Run Mass Delete using progress save for page1.
673  $pageSize = Yii::app()->pagination->getForCurrentUserByType('massDeleteProgressPageSize');
674  $this->assertEquals(5, $pageSize);
675  $this->runControllerWithExitExceptionAndGetContent('contacts/default/massDelete');
676 
677  //check for previous mass delete progress
678  $contacts = contact::getAll();
679  $this->assertEquals(2, count($contacts));
680 
681  $this->setGetArray(array(
682  'selectAll' => '1', // Not Coding Standard
683  'Contact_page' => 2));
684  $this->setPostArray(array('selectedRecordCount' => 7));
685  //Run Mass Delete using progress save for page2.
686  $pageSize = Yii::app()->pagination->getForCurrentUserByType('massDeleteProgressPageSize');
687  $this->assertEquals(5, $pageSize);
688  $this->runControllerWithNoExceptionsAndGetContent('contacts/default/massDeleteProgress');
689 
690  //calculating contact's count
691  $contacts = contact::getAll();
692  $this->assertEquals(0, count($contacts));
693  }
694 
699  {
700  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
701 
702  $account = Account::getByName('superAccount2');
703  $this->setGetArray(array('id' => $account[0]->id));
704  //Run Mass Delete using progress save for page2.
705  $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/getAccountAddressesToCopy');
706  // Begin Not Coding Standard
707  $compareContent = '{"billingAddress_city":null,"billingAddress_country":null,"billingAddress_invalid":"0","billingAddre'
708  . 'ss_latitude":null,"billingAddress_longitude":null,"billingAddress_postalCode":null,"billingAddress_street1":'
709  . '"some street","billingAddress_street2":null,"billingAddress_state":null,"shippingAddress_city":null,"shippin'
710  . 'gAddress_country":null,"shippingAddress_invalid":"0","shippingAddress_latitude":null,"shippingAddress_longit'
711  . 'ude":null,"shippingAddress_postalCode":null,"shippingAddress_street1":"some street 2","shippingAddress_stree'
712  . 't2":null,"shippingAddress_state":null}';
713  // End Not Coding Standard
714  $this->assertEquals($compareContent, $content);
715  }
716 
717  public function testMassSubscribeActionsForSelectedIds()
718  {
719  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
720  $contactsCount = Contact::getCount();
721 
722  $superContactId1 = ContactTestHelper::createContactByNameForOwner('superContact1', $super);
723  $superContactId2 = ContactTestHelper::createContactByNameForOwner('superContact2', $super);
724  $superContactId3 = ContactTestHelper::createContactByNameForOwner('superContact3', $super);
725  $superContactId4 = ContactTestHelper::createContactByNameForOwner('superContact4', $super);
726  $superContactId5 = ContactTestHelper::createContactByNameForOwner('superContact5', $super);
727  $superContactId6 = ContactTestHelper::createContactByNameForOwner('superContact6', $super);
728  $superContactId7 = ContactTestHelper::createContactByNameForOwner('superContact7', $super);
729  $superContactId8 = ContactTestHelper::createContactByNameForOwner('superContact8', $super);
730  $superContactId9 = ContactTestHelper::createContactByNameForOwner('superContact9', $super);
731 
732  $marketingList1 = MarketingListTestHelper::createMarketingListByName('marketingList1');
733  $marketingList2 = MarketingListTestHelper::createMarketingListByName('marketingList2');
734 
735  //Load Model MassSubscribe Views.
736  //MassSubscribe view for single selected ids
737  $selectedIds = implode(',' , array($superContactId1->id, $superContactId4->id)); // Not Coding Standard
738  $this->setGetArray(array('selectedIds' => $selectedIds, 'selectAll' => '', ));
739  $this->resetPostArray();
740  $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/massSubscribe');
741  $this->assertContains('<strong>2</strong>&#160;Contacts selected for subscription', $content);
742 
743  //MassSubscribe view for all result selected ids
744  $this->setGetArray(array('selectAll' => '1'));
745  $this->resetPostArray();
746  $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/massSubscribe');
747  $this->assertContains('<strong>9</strong>&#160;Contacts selected for subscription', $content);
748 
749  //MassSubscribe with no marketingList selected
750 
751  //MassSubscribe for selected ids for paged scenario
752  //MassSubscribe for selected ids for page 1
753  $pageSize = Yii::app()->pagination->getForCurrentUserByType('massEditProgressPageSize');
754  $this->assertEquals(5, $pageSize);
755  $selectedIds = implode(',' , array($superContactId1->id, $superContactId2->id, $superContactId3->id, // Not Coding Standard
756  $superContactId5->id, $superContactId6->id, $superContactId8->id,
757  $superContactId9->id));
758  $this->setGetArray(array(
759  'selectedIds' => $selectedIds,
760  'selectAll' => '',
761  'massSubscribe' => '',
762  'Contact_page' => 1));
763  $this->setPostArray(array('selectedRecordCount' => 7,
764  'MarketingListMember' => array('marketingList' => array('id' => $marketingList1->id))));
765  $this->runControllerWithRedirectExceptionAndGetContent('contacts/default/massSubscribe');
766  $expectedSubscribedCountAfterFirstRequest = 7;
767  $actualSubscribedCountAfterFirstRequest = MarketingListMember::getCountByMarketingListIdAndUnsubscribed($marketingList1->id, 0);
768  $this->assertEquals($expectedSubscribedCountAfterFirstRequest, $actualSubscribedCountAfterFirstRequest);
769  $this->assertEquals(0, MarketingListMember::getCountByMarketingListIdAndUnsubscribed($marketingList2->id, 0));
770  //MassSubscribe for selected ids for page 2
771  /*$this->setGetArray(array(
772  'selectedIds' => $selectedIds,
773  'selectAll' => '',
774  'massSubscribe' => '',
775  'Contact_page' => 2,
776  'MarketingListMember' => array('marketingList' => array('id' => $marketingList1->id))));
777  $this->setPostArray(array('selectedRecordCount' => 7,
778  'MarketingListMember' => array('marketingList' => array('id' => $marketingList1->id))));
779  $this->runControllerWithNoExceptionsAndGetContent('contacts/default/massSubscribeProgress');
780  $expectedSubscribedCountAfterSecondRequest = $actualSubscribedCountAfterFirstRequest + (7 - $pageSize);
781  $actualSubscribedCountAfterSecondRequest = MarketingListMember::getCountByMarketingListIdAndUnsubscribed($marketingList1->id, 0);
782  $this->assertEquals($expectedSubscribedCountAfterSecondRequest, $actualSubscribedCountAfterSecondRequest);
783  $this->assertEquals(0, MarketingListMember::getCountByMarketingListIdAndUnsubscribed($marketingList2->id, 0));*/
784  }
785 
786  public function testSuperUserSearchForDuplicateModelsAction()
787  {
788  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
789  $this->setGetArray(array('attribute' => 'lastName',
790  'value' => 'fakeValue',
791  ));
792  $this->runControllerWithNoExceptionsAndGetContent('leads/default/searchForDuplicateModels', true);
793 
794  $contact = LeadTestHelper::createLeadbyNameForOwner('test', $super);
795  TaskTestHelper::createTaskWithOwnerAndRelatedItem('task for test', $super, $contact);
796 
797  //Test search by lastName
798  $this->setGetArray(array('attribute' => 'lastName',
799  'value' => 'testson',
800  ));
801  $content = $this->runControllerWithNoExceptionsAndGetContent('leads/default/searchForDuplicateModels');
802  $object = json_decode($content);
803  $this->assertEquals ('There is 1 possible match. <span class="underline">Click here</span> to view.', $object->message);
804  $this->assertContains('CreateModelsToMergeListAndChartView', $object->content);
805  //The dupe contact has one task
806  $this->assertTag(array(
807  'tag' => 'span',
808  'attributes' => array('class' => 'total-tasks'),
809  'descendant' => array(
810  'tag' => 'strong',
811  'content' => '1',
812  )
813  ),
814  $object->content);
815 
816  //Test search by phone
817  $contact->mobilePhone = '123456789';
818  $this->assertTrue($contact->save());
819  $this->setGetArray(array('attribute' => 'officePhone',
820  'value' => '123456789',
821  ));
822  $content = $this->runControllerWithNoExceptionsAndGetContent('leads/default/searchForDuplicateModels');
823  $object = json_decode($content);
824  $this->assertEquals ('There is 1 possible match. <span class="underline">Click here</span> to view.', $object->message);
825  $this->assertContains('CreateModelsToMergeListAndChartView', $object->content);
826  //Test search by email
827  $contact->secondaryEmail->emailAddress = 'a@a.a';
828  $this->assertTrue($contact->save());
829  $this->setGetArray(array('attribute' => 'primaryEmail',
830  'value' => 'a@a.a',
831  ));
832  $content = $this->runControllerWithNoExceptionsAndGetContent('leads/default/searchForDuplicateModels');
833  $object = json_decode($content);
834  $this->assertEquals ('There is 1 possible match. <span class="underline">Click here</span> to view.', $object->message);
835  $this->assertContains('CreateModelsToMergeListAndChartView', $object->content);
836  }
837 
838  public function testInlineCreateCommentFromAjax()
839  {
840  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
841  $contact = ContactTestHelper::createContactByNameForOwner('testContact2', $super);
842 
843  $this->setGetArray(array('id' => $contact->id, 'uniquePageId' => 'CommentInlineEditForModelView'));
844  $this->runControllerWithNoExceptionsAndGetContent('contacts/default/inlineCreateCommentFromAjax');
845  }
846 
851  {
852  //Login with super and check subscribe unsubscribe from modal detail view when super
853  //is not owner or requested by user
854  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
855  $mike = UserTestHelper::createBasicUser('mike');
856  $contact = ContactTestHelper::createContactByNameForOwner('contactNew', $mike);
857  $this->assertEquals(1, $contact->notificationSubscribers->count());
858 
859  $this->setGetArray(array('id' => $contact->id));
860  $this->assertFalse(NotificationSubscriberUtil::doNotificationSubscribersContainPerson($contact, $super));
861  $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/addSubscriber', false);
862  $this->assertContains('gravatar', $content);
863  $this->assertContains('users/default/details', $content);
864  $this->assertContains($super->getFullName(), $content);
865  $this->assertEquals(2, $contact->notificationSubscribers->count());
866 
867  $this->setGetArray(array('id' => $contact->id));
868  $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/removeSubscriber', false);
869  $this->assertNotContains($super->getFullName(), $content);
870  $this->assertEquals(1, $contact->notificationSubscribers->count());
871  $contact->owner = $super;
872  $this->assertTrue($contact->save());
873  $this->assertEquals(2, $contact->notificationSubscribers->count());
874 
875  //Super user is owner so even if it is removed, it would be restored
876  $this->setGetArray(array('id' => $contact->id));
877  $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/removeSubscriber', false);
878  $this->assertContains($super->getFullName(), $content);
879  $this->assertEquals(2, $contact->notificationSubscribers->count());
880  }
881  }
882 ?>
static getByLayoutIdAndUser($layoutId, $user)
Definition: Dashboard.php:46
static getByUsername($username)
Definition: User.php:49
runControllerWithRedirectExceptionAndGetContent($route, $compareUrl=null, $compareUrlContains=false)
static getStartingState()
updateModelValuesFromPostArray($model, $postArray)
static getCount(RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter=null, $where=null, $modelClassName=null, $selectDistinct=false)
checkCopyActionResponseAttributeValuesFromPostArray($model, $postArray, $linkClass=null, $controllerId=null)
static doNotificationSubscribersContainPerson(OwnedSecurableItem $model, Item $item)
static getById($id, $modelClassName=null)
logoutCurrentUserLoginNewUserAndGetByUsername($username)
assertModelHasValuesFromPostArray($model, $postArray)
runControllerWithNoExceptionsAndGetContent($route, $empty=false)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
static getStartingState()
Definition: LeadsUtil.php:152
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.