Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ContactTest.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 
37  class ContactTest extends ZurmoBaseTest
38  {
39  public static function setUpBeforeClass()
40  {
41  parent::setUpBeforeClass();
42  SecurityTestHelper::createSuperAdmin();
43  }
44 
45  public function testCreateSourceValues()
46  {
47  $sourceValues = array(
48  'Word of Mouth',
49  'Outbound',
50  'Trade Show',
51  );
52  $sourceFieldData = CustomFieldData::getByName('LeadSources');
53  $sourceFieldData->serializedData = serialize($sourceValues);
54  $this->assertTrue($sourceFieldData->save());
55  }
56 
60  public function testCreateStateValues()
61  {
62  $this->assertTrue(ContactsModule::loadStartingData());
63  $this->assertEquals(6, count(ContactState::GetAll()));
64  }
65 
69  public function testContactStateIsAudited()
70  {
71  Yii::app()->user->userModel = User::getByUsername('super');
72  $contact = new Contact();
73  $contactStates = ContactState::GetAll();
74  $contact->state = $contactStates[0];
75  $contact->firstName = 'jason';
76  $contact->lastName = 'green';
77  $saved = $contact->save();
78  $this->assertTrue($saved);
79 
80  $contactId = $contact->id;
81  $contact->forget();
82 
83  $contact = Contact::getById($contactId);
84  $contact->state = $contactStates[1];
85  $compareData = array('state' => array('ContactState', $contactStates[0]->id, 'New'));
86  $this->assertEquals($compareData, $contact->originalAttributeValues);
87  $deleted = $contact->delete();
88  $this->assertTrue($deleted);
89  }
90 
94  public function testCreateAndGetContactById()
95  {
96  Yii::app()->user->userModel = User::getByUsername('super');
97 
98  $user = UserTestHelper::createBasicUser('Steven');
99 
100  $account = new Account();
101  $account->name = 'Some Account';
102  $account->owner = $user;
103  $this->assertTrue($account->save());
104 
105  $contactStates = ContactState::getByName('Qualified');
106 
107  $contact = new Contact();
108  $this->assertNull($contact->latestActivityDateTime);
109  $dateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
110  $contact->setLatestActivityDateTime($dateTime);
111  $contact->owner = $user;
112  $contact->title->value = 'Mr.';
113  $contact->firstName = 'Super';
114  $contact->lastName = 'Man';
115  $contact->jobTitle = 'Superhero';
116  $contact->source->value = 'Outbound';
117  $contact->account = $account;
118  $contact->description = 'Some Description';
119  $contact->department = 'Red Tape';
120  $contact->officePhone = '1234567890';
121  $contact->mobilePhone = '0987654321';
122  $contact->officeFax = '1222222222';
123  $contact->state = $contactStates[0];
124  $this->assertTrue($contact->save());
125  $id = $contact->id;
126  unset($contact);
127 
128  $contact = Contact::getById($id);
129  $this->assertEquals('Super', $contact->firstName);
130  $this->assertEquals('Man', $contact->lastName);
131  $this->assertEquals('Mr.', $contact->title->value);
132  $this->assertEquals('Superhero', $contact->jobTitle);
133  $this->assertEquals('Outbound', $contact->source->value);
134  $this->assertEquals($account->id, $contact->account->id);
135  $this->assertEquals($user->id, $contact->owner->id);
136  $this->assertEquals('Some Description', $contact->description);
137  $this->assertEquals('Red Tape', $contact->department);
138  $this->assertEquals('1234567890', $contact->officePhone);
139  $this->assertEquals('0987654321', $contact->mobilePhone);
140  $this->assertEquals('1222222222', $contact->officeFax);
141  $this->assertEquals('Qualified', $contact->state->name);
142  $this->assertEquals($dateTime, $contact->latestActivityDateTime);
143  }
144 
148  public function testEmailAndAddresses()
149  {
150  Yii::app()->user->userModel = User::getByUsername('super');
151 
152  $contacts = Contact::getAll();
153  $this->assertTrue(count($contacts) > 0);
154  $contact = $contacts[0];
155  $contact->primaryEmail->emailAddress = 'thejman@zurmoinc.com';
156  $contact->primaryEmail->optOut = 0;
157  $contact->primaryEmail->isInvalid = 0;
158  $contact->secondaryEmail->emailAddress = 'digi@magic.net';
159  $contact->secondaryEmail->optOut = 1;
160  $contact->secondaryEmail->isInvalid = 1;
161  $contact->primaryAddress->street1 = '129 Noodle Boulevard';
162  $contact->primaryAddress->street2 = 'Apartment 6000A';
163  $contact->primaryAddress->city = 'Noodleville';
164  $contact->primaryAddress->postalCode = '23453';
165  $contact->primaryAddress->country = 'The Good Old US of A';
166  $contact->secondaryAddress->street1 = '25 de Agosto 2543';
167  $contact->secondaryAddress->street2 = 'Local 3';
168  $contact->secondaryAddress->city = 'Ciudad de Los Fideos';
169  $contact->secondaryAddress->postalCode = '5123-4';
170  $contact->secondaryAddress->country = 'Latinoland';
171  $this->assertTrue($contact->save(false));
172  $id = $contact->id;
173  unset($contact);
174  $contact = Contact::getById($id);
175  $this->assertEquals('thejman@zurmoinc.com', $contact->primaryEmail->emailAddress);
176  $this->assertEquals(0, $contact->primaryEmail->optOut);
177  $this->assertEquals(0, $contact->primaryEmail->isInvalid);
178  $this->assertEquals('digi@magic.net', $contact->secondaryEmail->emailAddress);
179  $this->assertEquals(1, $contact->secondaryEmail->optOut);
180  $this->assertEquals(1, $contact->secondaryEmail->isInvalid);
181  $this->assertEquals('129 Noodle Boulevard', $contact->primaryAddress->street1);
182  $this->assertEquals('Apartment 6000A', $contact->primaryAddress->street2);
183  $this->assertEquals('Noodleville', $contact->primaryAddress->city);
184  $this->assertEquals('23453', $contact->primaryAddress->postalCode);
185  $this->assertEquals('The Good Old US of A', $contact->primaryAddress->country);
186  $this->assertEquals('25 de Agosto 2543', $contact->secondaryAddress->street1);
187  $this->assertEquals('Local 3', $contact->secondaryAddress->street2);
188  $this->assertEquals('Ciudad de Los Fideos', $contact->secondaryAddress->city);
189  $this->assertEquals('5123-4', $contact->secondaryAddress->postalCode);
190  $this->assertEquals('Latinoland', $contact->secondaryAddress->country);
191  }
192 
196  public function testGetContactsByName()
197  {
198  Yii::app()->user->userModel = User::getByUsername('super');
199 
200  $contacts = Contact::getByName('Super Man');
201  $this->assertEquals(1, count($contacts));
202  $this->assertEquals('Super Man', strval($contacts[0]));
203  }
204 
208  public function testGetLabel()
209  {
210  Yii::app()->user->userModel = User::getByUsername('super');
211  $contacts = Contact::getByName('Super Man');
212  $this->assertEquals(1, count($contacts));
213  $this->assertEquals('Contact', $contacts[0]::getModelLabelByTypeAndLanguage('Singular'));
214  $this->assertEquals('Contacts', $contacts[0]::getModelLabelByTypeAndLanguage('Plural'));
215  }
216 
221  {
222  Yii::app()->user->userModel = User::getByUsername('super');
223  $contacts = Contact::getByName('I dont exist');
224  $this->assertEquals(0, count($contacts));
225  }
226 
230  public function testGetAll()
231  {
232  Yii::app()->user->userModel = User::getByUsername('super');
233 
234  $user = User::getByUsername('steven');
235 
236  $contactStates = ContactState::getByName('Qualified');
237 
238  $contact = new Contact();
239  $contact->owner = $user;
240  $contact->firstName = 'Super';
241  $contact->lastName = 'Woman';
242  $contact->state = $contactStates[0];
243  $this->assertTrue($contact->save());
244  $contacts = Contact::getAll();
245  $this->assertEquals(2, count($contacts));
246  $this->assertTrue('Super Man' == strval($contacts[0]) &&
247  'Super Woman' == strval($contacts[1]) ||
248  'Super Woman' == strval($contacts[0]) &&
249  'Super Man' == strval($contacts[1]));
250  }
251 
255  public function testSetAndGetOwner()
256  {
257  Yii::app()->user->userModel = User::getByUsername('super');
258 
259  $user = UserTestHelper::createBasicUser('Billy');
260 
261  $contacts = Contact::getByName('Super Man');
262  $this->assertEquals(1, count($contacts));
263  $contact = $contacts[0];
264  $contact->owner = $user;
265  $this->assertTrue($contact->save());
266  unset($user);
267  $this->assertTrue($contact->owner !== null);
268  $user = $contact->owner;
269  $contact->owner = null;
270  $this->assertFalse($contact->validate());
271  $contact->forget();
272  unset($contact);
273  }
274 
278  public function testReplaceOwnerUser()
279  {
280  Yii::app()->user->userModel = User::getByUsername('super');
281 
282  $contacts = Contact::getByName('Super Man');
283  $this->assertEquals(1, count($contacts));
284  $contact = $contacts[0];
285  $user = User::getByUsername('billy');
286  $this->assertEquals($user->id, $contact->owner->id);
287  unset($user);
288  $user2 = UserTestHelper::createBasicUser('Benny');
289  $contact->owner = $user2;
290  unset($user2);
291  $this->assertTrue($contact->owner !== null);
292  $user = $contact->owner;
293  $this->assertEquals('benny', $user->username);
294  unset($user);
295  }
296 
300  public function testUpdateContactFromForm()
301  {
302  Yii::app()->user->userModel = User::getByUsername('super');
303 
304  $user = User::getByUsername('steven');
305 
306  $contacts = Contact::getByName('Super Man');
307  $contact = $contacts[0];
308  $this->assertEquals(strval($contact), 'Super Man');
309  $postData = array(
310  'owner' => array(
311  'id' => $user->id
312  ),
313  'firstName' => 'New',
314  'lastName' => 'Name',
315  );
316  $contact->setAttributes($postData);
317  $this->assertTrue($contact->save());
318 
319  $id = $contact->id;
320  unset($contact);
321  $contact = Contact::getById($id);
322  $this->assertEquals('New Name', strval($contact));
323  }
324 
328  public function testDeleteContact()
329  {
330  Yii::app()->user->userModel = User::getByUsername('super');
331 
332  $contacts = Contact::getAll();
333  $this->assertEquals(2, count($contacts));
334  $contacts[0]->delete();
335  $contacts = Contact::getAll();
336  $this->assertEquals(1, count($contacts));
337  $contacts[0]->delete();
338  $contacts = Contact::getAll();
339  $this->assertEquals(0, count($contacts));
340  }
341 
345  public function testGetAllWhenThereAreNone()
346  {
347  Yii::app()->user->userModel = User::getByUsername('super');
348  $contacts = Contact::getAll();
349  $this->assertEquals(0, count($contacts));
350  }
351 
355  public function testSetAndGetStartingState()
356  {
357  $startingStateId = ContactsUtil::getStartingState()->id;
358  $contactStates = ContactState::getAll();
359  foreach ($contactStates as $contactState)
360  {
361  if ($contactState->id != $startingStateId)
362  {
363  $otherStateId = $contactState->id;
364  break;
365  }
366  }
367  $metadata = ContactsModule::getMetadata();
368  $this->assertEquals($startingStateId, $metadata['global']['startingStateId']);
369  ContactsUtil::setStartingStateById($otherStateId);
370  $metadata = ContactsModule::getMetadata();
371  $this->assertEquals($otherStateId, $metadata['global']['startingStateId']);
372  }
373 
377  public function testCreateContactFromForm()
378  {
379  Yii::app()->user->userModel = User::getByUsername('super');
380 
381  $states = ContactState::GetAll();
382  $user = User::getByUsername('billy');
383  $contact = new Contact();
384  $postData = array(
385  'firstName' => 'Something',
386  'lastName' => 'NewAndExciting',
387  'owner' => array(
388  'id' => $user->id
389  ),
390  'state' => array(
391  'id' => $states[0]->id,
392  )
393  );
394  $contact->setAttributes($postData);
395  $this->assertTrue($contact->save());
396  $id = $contact->id;
397  unset($contact);
398  $contact = Contact::getById($id);
399  $this->assertEquals('Something NewAndExciting', strval($contact));
400  $this->assertEquals($user->id, $contact->owner->id);
401  $this->assertEquals($states[0]->id, $contact->state->id);
402  }
403 
408  {
409  $this->assertEquals(6, count(ContactState::GetAll()));
410  $metadata = ContactsModule::getMetadata();
411  $startingStateId = ContactsUtil::getStartingState()->id;
412  $this->assertEquals($startingStateId, $metadata['global']['startingStateId']);
414  $this->assertEquals(6, count($statesToInclude));
415  $metadata = array('clauses' => array(), 'structure' => '');
416  $adapter = new ContactsStateMetadataAdapter($metadata);
417  $adaptedMetadata = $adapter->getAdaptedDataProviderMetadata();
418  $compareMetadata['clauses'] = array();
419  $compareMetadata['structure'] = null;
420  $index = 1;
421  foreach ($statesToInclude as $stateId => $notUsed)
422  {
423  $compareMetadata['clauses'][$index] = array(
424  'attributeName' => 'state',
425  'operatorType' => 'equals',
426  'value' => $stateId
427  );
428  $index++;
429  }
430  $compareMetadata['structure'] = '(1 or 2 or 3 or 4 or 5 or 6)';
431  $this->assertEquals($compareMetadata, $adaptedMetadata);
432 
433  $metadata = array(
434  'clauses' => array(
435  1 => array(
436  'attributeName' => 'name',
437  'operatorType' => 'equals',
438  'value' => 'Vomo'
439  ),
440  2 => array(
441  'attributeName' => 'billingAddress',
442  'relatedAttributeName' => 'city',
443  'operatorType' => 'startsWith',
444  'value' => 'Chicago'
445  ),
446  ),
447  'structure' => '1 and 2',
448  );
449  $adapter = new ContactsStateMetadataAdapter($metadata);
450  $adaptedMetadata = $adapter->getAdaptedDataProviderMetadata();
451  $compareMetadata = array(
452  'clauses' => array(
453  1 => array(
454  'attributeName' => 'name',
455  'operatorType' => 'equals',
456  'value' => 'Vomo'
457  ),
458  2 => array(
459  'attributeName' => 'billingAddress',
460  'relatedAttributeName' => 'city',
461  'operatorType' => 'startsWith',
462  'value' => 'Chicago'
463  ),
464  ),
465  'structure' => '(1 and 2) and (3 or 4 or 5 or 6 or 7 or 8)',
466  );
467  $index = 3;
468  foreach ($statesToInclude as $stateId => $notUsed)
469  {
470  $compareMetadata['clauses'][$index] = array(
471  'attributeName' => 'state',
472  'operatorType' => 'equals',
473  'value' => $stateId
474  );
475  $index++;
476  }
477  $this->assertEquals($compareMetadata, $adaptedMetadata);
478  }
479 
480  public function testDeleteContactCascadesToDeleteEverythingItShould()
481  {
482  Yii::app()->user->userModel = User::getByUsername('super');
483  $this->assertEquals(6, count(ContactState::GetAll()));
484  $manager = UserTestHelper::createBasicUser('Godzilla');
485  $this->assertTrue($manager->save());
486 
487  $account = new Account();
488  $account->name = 'Os Drogas Mais Legais';
489  $this->assertTrue($account->save());
490 
491  $contact = new Contact();
492  $contact->title->value = 'Senhor';
493  $contact->firstName = 'José';
494  $contact->lastName = 'Olivereira';
495  $contact->jobTitle = 'Traficante';
496  $contact->primaryAddress->street1 = 'R. das Mulheres, 69';
497  $contact->primaryAddress->street2 = '';
498  $contact->primaryAddress->city = 'Centro';
499  $contact->primaryAddress->state = 'RJ';
500  $contact->primaryAddress->postalCode = '';
501  $contact->primaryAddress->country = 'Brasil';
502  $contact->primaryEmail->emailAddress = 'jose@gmail.com';
503  $contact->primaryEmail->optOut = 1;
504  $contact->primaryEmail->isInvalid = 0;
505  $contact->secondaryAddress->street1 = 'Passagem do Comando Vermelho';
506  $contact->secondaryAddress->street2 = '';
507  $contact->secondaryAddress->city = 'Complexo do Alemão';
508  $contact->secondaryAddress->state = 'RJ';
509  $contact->secondaryAddress->postalCode = '';
510  $contact->secondaryAddress->country = 'Brasil';
511  $contact->account = $account;
512  $contact->state->name = 'Novo Hermão';
513  $contact->state->order = 6;
514  $this->assertTrue($contact->save());
515 
516  $titleId = $contact->title ->id;
517  $primaryAddressId = $contact->primaryAddress ->id;
518  $primaryEmailId = $contact->primaryEmail ->id;
519  $secondaryAddressId = $contact->secondaryAddress->id;
520  $accountId = $account ->id;
521  $stateId = $contact->state ->id;
522 
523  $this->assertEquals(7, count(ContactState::GetAll())); //new state created. Confirm this
524  $contact->delete();
525  unset($contact);
526  unset($manager);
527  unset($account);
528  User::getByUsername('godzilla');
529  Account::getById($accountId);
530  ContactState::getById($stateId);
531 
532  try
533  {
534  CustomField::getById($titleId);
535  $this->fail("Title should have been deleted.");
536  }
537  catch (NotFoundException $e)
538  {
539  }
540 
541  try
542  {
543  Address::getById($primaryAddressId);
544  $this->fail("Primary address should have been deleted.");
545  }
546  catch (NotFoundException $e)
547  {
548  }
549 
550  try
551  {
552  Email::getById($primaryEmailId);
553  $this->fail("Primary email should have been deleted.");
554  }
555  catch (NotFoundException $e)
556  {
557  }
558 
559  try
560  {
561  Address::getById($secondaryAddressId);
562  $this->fail("Secondary address should have been deleted.");
563  }
564  catch (NotFoundException $e)
565  {
566  }
567  }
568 
569  public function testContactStateAdapterReturnsCorrectStatesUponStartingStateChange()
570  {
571  $this->assertEquals(7, count(ContactState::GetAll()));
572  $metadata = ContactsModule::getMetadata();
573  $metadata['global']['startingStateId'] = ContactsUtil::getStartingState()->id;
574  ContactsModule::setMetadata($metadata);
575  $metadata = array('clauses' => array(), 'structure' => '');
576  $adapter = new ContactsStateMetadataAdapter($metadata);
577  $adaptedMetadata = $adapter->getAdaptedDataProviderMetadata();
579  $this->assertEquals(7, count($statesToInclude));
580  $compareMetadata['clauses'] = array();
581  $compareMetadata['structure'] = '(1 or 2 or 3 or 4 or 5 or 6 or 7)';
582  $index = 1;
583  foreach ($statesToInclude as $stateId => $notUsed)
584  {
585  $compareMetadata['clauses'][$index] = array(
586  'attributeName' => 'state',
587  'operatorType' => 'equals',
588  'value' => $stateId
589  );
590  $index++;
591  }
592  $this->assertEquals($compareMetadata, $adaptedMetadata);
593  }
594 
599  {
600  Yii::app()->user->userModel = User::getByUsername('super');
601 
602  //Save contact without account.
603  $startingState = ContactsUtil::getStartingState();
604  $contacts = Contact::getByName('jilly simpson');
605  $this->assertEmpty($contacts);
606  $fakePostData = array(
607  'firstName' => 'jilly',
608  'lastName' => 'simpson',
609  'account' => array('id' => ''),
610  'state' => array('id' => $startingState->id),
611  );
612  $contact = new Contact();
613  $contact->setAttributes($fakePostData);
614  $saved = $contact->save();
615  $this->assertTrue($saved);
616  $contactId = $contact->id;
617  $contact->forget();
618 
619  //Now try to make a change to that contact. Still no account.
620  $fakePostData = array(
621  'firstName' => 'jilly',
622  'lastName' => 'simpson',
623  'officePhone' => '12345',
624  'account' => array('id' => ''),
625  'state' => array('id' => $startingState->id),
626  );
627  $contact = Contact::getById($contactId);
628  $contact->setAttributes($fakePostData);
629  $saved = $contact->save();
630  $this->assertTrue($saved);
631 
632  //Create a contact not through post without an account.
633  $contact = ContactTestHelper::createContactByNameForOwner('shozin', Yii::app()->user->userModel);
634  $contactId = $contact->id;
635  $contact->forget();
636 
637  //Now try to make a change to that contact via post. Still no account.
638  $fakePostData = array(
639  'firstName' => 'shozin',
640  'lastName' => 'shozinson',
641  'officePhone' => '12345',
642  'account' => array('id' => ''),
643  'state' => array('id' => $startingState->id),
644  );
645  $contact = Contact::getById($contactId);
646  $contact->setAttributes($fakePostData);
647  $saved = $contact->save();
648  $this->assertTrue($saved);
649  }
650 
651  public function testContactsUtilGetContactStateDataKeyedByOrder()
652  {
653  $contactStatesData = ContactsUtil::getContactStateDataKeyedByOrder();
654  $compareData = array(
655  0 => 'New',
656  1 => 'In Progress',
657  2 => 'Recycled',
658  3 => 'Dead',
659  4 => 'Qualified',
660  5 => 'Customer',
661  6 => 'Novo Hermão',
662  );
663  $this->assertEquals($compareData, $contactStatesData);
664  }
665 
666  public function testContactsUtilGetAndSetStartingStateById()
667  {
668  $expectedStartingStateId = ContactsUtil::getStartingState()->id;
669  $contactStates = ContactState::getAll();
670  foreach ($contactStates as $contactState)
671  {
672  if ($contactState->id != $expectedStartingStateId)
673  {
674  $otherStateId = $contactState->id;
675  break;
676  }
677  }
678  $startingStateId = ContactsUtil::getStartingStateId();
679  $this->assertEquals($expectedStartingStateId, $startingStateId);
680  ContactsUtil::setStartingStateById($otherStateId);
681  $startingStateId = ContactsUtil::getStartingStateId();
682  $this->assertEquals($otherStateId, $startingStateId);
683  }
684 
685  public function testContactsUtilSetStartingStateByOrder()
686  {
687  $startingStateId = ContactsUtil::getStartingStateId();
688  $startingState = ContactState::getById($startingStateId);
689  $startingState->delete();
690  $this->assertEquals(6, count(ContactState::GetAll()));
692  $startingStateId = ContactsUtil::getStartingStateId();
693  $states = ContactState::getAll('order');
694  $this->assertEquals($states[1]->id, $startingStateId);
695  $startingState = ContactState::getByName('Recycled');
696  $this->assertEquals(1, count($startingState));
697  $this->assertEquals($startingState[0]->id, $startingStateId);
698  }
699 
700  public function testContactsUtilGetContactStateDataKeyedById()
701  {
702  $contactStatesData = ContactsUtil::getContactStateDataKeyedById();
703  $state1 = ContactState::getByName('New');
704  $state3 = ContactState::getByName('Recycled');
705  $state4 = ContactState::getByName('Dead');
706  $state5 = ContactState::getByName('Qualified');
707  $state6 = ContactState::getByName('Customer');
708  $state7 = ContactState::getByName('Novo Hermão');
709  $compareData = array(
710  $state1[0]->id => 'New',
711  $state3[0]->id => 'Recycled',
712  $state4[0]->id => 'Dead',
713  $state5[0]->id => 'Qualified',
714  $state6[0]->id => 'Customer',
715  $state7[0]->id => 'Novo Hermão',
716  );
717  $this->assertEquals($compareData, $contactStatesData);
718  }
719 
720  public function testGetModelClassNames()
721  {
722  $modelClassNames = ContactsModule::getModelClassNames();
723  $this->assertEquals(4, count($modelClassNames));
724  $this->assertEquals('Contact', $modelClassNames[0]);
725  $this->assertEquals('ContactSearch', $modelClassNames[1]);
726  $this->assertEquals('ContactStarred', $modelClassNames[2]);
727  $this->assertEquals('ContactState', $modelClassNames[3]);
728  }
729 
730  public function testChangingContactWithoutChangingRelatedAccountShouldNotAuditAccountChangeWhenDoneViaPost()
731  {
732  Yii::app()->user->userModel = User::getByUsername('super');
733  $contactStates = ContactState::getByName('Qualified');
734 
735  $contact = new Contact();
736  $contact->owner = Yii::app()->user->userModel;
737  $contact->title->value = 'Mr.';
738  $contact->firstName = 'Supero';
739  $contact->lastName = 'Mano';
740  $contact->state = $contactStates[0];
741  $this->assertTrue($contact->save());
742  $beforeCount = AuditEvent::getCount();
743 
744  //Test that saving an existing contact without a related contact will not produce an audit event showing the
745  //related account has changed. This is a test to show when the account is not populated but has a negative
746  //id.
747  $contactId = $contact->id;
748  $contact->forget();
749  unset($contact);
750  $contact = Contact::getById($contactId);
751  $fakePostData = array('account' => array('id' => ''));
752  $contact->setAttributes($fakePostData);
753  $this->assertTrue($contact->save());
754  $this->assertEquals($beforeCount, AuditEvent::getCount());
755  }
756 
757  public function testJobTitleLength()
758  {
759  Yii::app()->user->userModel = User::getByUsername('super');
760  $user = Yii::app()->user->userModel;
761  $contactStates = ContactState::getByName('Qualified');
762  $contact = new Contact();
763  $contact->owner = $user;
764  $contact->title->value = 'Mr.';
765  $contact->firstName = 'length';
766  $contact->lastName = 'username';
767  $contact->jobTitle = 'S';
768  $contact->state = $contactStates[0];
769  $this->assertTrue($contact->save());
770  }
771 
772  public function testDeleteContactCascadesMarketingListMemmers()
773  {
774  Yii::app()->user->userModel = User::getByUsername('super');
775  $contactStates = ContactState::getByName('Qualified');
776  $contact = new Contact();
777  $contact->owner = Yii::app()->user->userModel;
778  $contact->title->value = 'Mr.';
779  $contact->firstName = 'Member';
780  $contact->lastName = 'One';
781  $contact->state = $contactStates[0];
782  $this->assertTrue($contact->save());
783  $contactId = $contact->id;
784  $marketingList = MarketingListTestHelper::createMarketingListByName('Test Marketing List Member Deleted');
785  $member = MarketingListMemberTestHelper::populateValidMarketingListMember(1, $marketingList, $contact);
786  $this->assertTrue($member->unrestrictedSave());
787  $this->assertEquals(1, count(MarketingListMember::getByContactId($contactId)));
788  $testContact = new Contact();
789  $testContact->owner = Yii::app()->user->userModel;
790  $testContact->title->value = 'Mr.';
791  $testContact->firstName = 'Member';
792  $testContact->lastName = 'Two';
793  $testContact->state = $contactStates[0];
794  $this->assertTrue($testContact->save());
795  $testContactId = $testContact->id;
796  $member2 = MarketingListMemberTestHelper::populateValidMarketingListMember(1, $marketingList, $testContact);
797  $this->assertTrue($member2->unrestrictedSave());
798  $this->assertEquals(1, count(MarketingListMember::getByContactId($testContact->id)));
799  $subscribedCount = MarketingListMember::getCountByMarketingListIdAndUnsubscribed($marketingList->id, 1);
800  $this->assertEquals(2, $subscribedCount);
801  $this->assertTrue($contact->delete());
802  $this->assertEquals(0, count(MarketingListMember::getByContactId($contactId)));
803  $this->assertTrue($testContact->delete());
804  $this->assertEquals(0, count(MarketingListMember::getByContactId($testContactId)));
805  $subscribedCount = MarketingListMember::getCountByMarketingListIdAndUnsubscribed($marketingList->id, 1);
806  $this->assertEquals(0, $subscribedCount);
807  }
808  }
809 ?>
testContactsStateMetadataAdapter()
static getMetadata(User $user=null)
Definition: Module.php:502
testSaveContactFromPostWithoutAccount()
static getByUsername($username)
Definition: User.php:49
testEmailAndAddresses()
static getStartingStateId()
testCreateContactFromForm()
testGetAllWhenThereAreNone()
testContactStateIsAudited()
Definition: ContactTest.php:69
static loadStartingData()
static getStartingState()
testCreateAndGetContactById()
Definition: ContactTest.php:94
static setStartingStateByOrder($startingStateOrder)
testGetContactsByNameForNonExistentName()
static getModelClassNames()
Definition: Module.php:565
static getByName($name, $shouldCache=true)
testUpdateContactFromForm()
testGetContactsByName()
static getContactStateDataKeyedByOrder()
testCreateStateValues()
Definition: ContactTest.php:60
static getCount(RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter=null, $where=null, $modelClassName=null, $selectDistinct=false)
static getContactStateDataFromStartingStateOnAndKeyedById()
testReplaceOwnerUser()
static getById($id, $modelClassName=null)
static setMetadata(array $metadata, User $user=null)
Definition: Module.php:533
static getByContactId($contactId)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
testSetAndGetStartingState()
static setStartingStateById($startingStateId)
static getContactStateDataKeyedById()
Generated on Wed Oct 21 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.