Merge pull request #20496 from seamuslee001/php8_array_key_actionscheduletest
[civicrm-core.git] / tests / phpunit / CRM / Contact / BAO / IndividualTest.php
1 <?php
2
3 /**
4 * Class CRM_Contact_BAO_IndividualTest
5 * @group headless
6 */
7 class CRM_Contact_BAO_IndividualTest extends CiviUnitTestCase {
8
9 /**
10 * Test case for format() with "null" value dates.
11 *
12 * See CRM-19123: Merging contacts: blank date fields write as 1970
13 */
14 public function testFormatNullDates() {
15 $params = [
16 'contact_type' => 'Individual',
17 'birth_date' => 'null',
18 'deceased_date' => 'null',
19 ];
20 $contact = new CRM_Contact_DAO_Contact();
21
22 CRM_Contact_BAO_Individual::format($params, $contact);
23
24 $this->assertEmpty($contact->birth_date);
25 $this->assertEmpty($contact->deceased_date);
26 }
27
28 /**
29 * Test case to check the formatting of the Display name and Sort name
30 * Standard formatting is assumed.
31 */
32 public function testFormatDisplayName() {
33
34 $params = [
35 'contact_type' => 'Individual',
36 'first_name' => 'Ben',
37 'last_name' => 'Lee',
38 'individual_prefix' => 'Mr.',
39 'individual_suffix' => 'Jr.',
40 ];
41
42 $contact = new CRM_Contact_DAO_Contact();
43
44 CRM_Contact_BAO_Individual::format($params, $contact);
45
46 $this->assertEquals("Mr. Ben Lee Jr.", $contact->display_name);
47 $this->assertEquals("Lee, Ben", $contact->sort_name);
48 }
49
50 /**
51 * Testing the use of adding prefix and suffix by id.
52 * Standard Prefixes and Suffixes are assumed part of
53 * the test database
54 */
55 public function testFormatDisplayNamePrefixesById() {
56
57 $params = [
58 'contact_type' => 'Individual',
59 'first_name' => 'Ben',
60 'last_name' => 'Lee',
61 // this is the doctor
62 'prefix_id' => 4,
63 // and the doctor is a senior
64 'suffix_id' => 2,
65 ];
66
67 $contact = new CRM_Contact_DAO_Contact();
68
69 CRM_Contact_BAO_Individual::format($params, $contact);
70
71 $this->assertEquals("Dr. Ben Lee Sr.", $contact->display_name);
72 }
73
74 /**
75 * Testing the use of adding prefix and suffix by id.
76 * Standard Prefixes and Suffixes are assumed part of
77 * the test database
78 */
79 public function testFormatDisplayNameNoIndividual() {
80
81 $params = [
82 'contact_type' => 'Organization',
83 'first_name' => 'Ben',
84 'last_name' => 'Lee',
85 ];
86
87 $contact = new CRM_Contact_DAO_Contact();
88
89 CRM_Contact_BAO_Individual::format($params, $contact);
90
91 $this->assertNotEquals("Ben Lee", $contact->display_name);
92 }
93
94 /**
95 * When no first name or last name are defined, the primary email is used
96 */
97 public function testFormatDisplayNameOnlyEmail() {
98
99 $email['1'] = ['email' => "bleu01@example.com"];
100 $email['2'] = ['email' => "bleu02@example.com", 'is_primary' => 1];
101 $email['3'] = ['email' => "bleu03@example.com"];
102
103 $params = [
104 'contact_type' => 'Individual',
105 'email' => $email ,
106 ];
107
108 $contact = new CRM_Contact_DAO_Contact();
109
110 CRM_Contact_BAO_Individual::format($params, $contact);
111
112 $this->assertEquals("bleu02@example.com", $contact->display_name);
113 $this->assertEquals("bleu02@example.com", $contact->sort_name);
114
115 }
116
117 }