Commit | Line | Data |
---|---|---|
3cae4b8a FV |
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() { | |
9099cab3 | 15 | $params = [ |
26f87f3a FV |
16 | 'contact_type' => 'Individual', |
17 | 'birth_date' => 'null', | |
18 | 'deceased_date' => 'null', | |
9099cab3 | 19 | ]; |
3cae4b8a FV |
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 | } | |
26f87f3a | 27 | |
a1e077e3 KE |
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 | ||
9099cab3 | 34 | $params = [ |
a1e077e3 KE |
35 | 'contact_type' => 'Individual', |
36 | 'first_name' => 'Ben', | |
37 | 'last_name' => 'Lee', | |
38 | 'individual_prefix' => 'Mr.', | |
39 | 'individual_suffix' => 'Jr.', | |
9099cab3 | 40 | ]; |
a1e077e3 KE |
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 | ||
9099cab3 | 57 | $params = [ |
a1e077e3 KE |
58 | 'contact_type' => 'Individual', |
59 | 'first_name' => 'Ben', | |
60 | 'last_name' => 'Lee', | |
39b959db SL |
61 | // this is the doctor |
62 | 'prefix_id' => 4, | |
63 | // and the doctor is a senior | |
64 | 'suffix_id' => 2, | |
9099cab3 | 65 | ]; |
a1e077e3 KE |
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 | ||
9099cab3 | 81 | $params = [ |
a1e077e3 KE |
82 | 'contact_type' => 'Organization', |
83 | 'first_name' => 'Ben', | |
84 | 'last_name' => 'Lee', | |
9099cab3 | 85 | ]; |
a1e077e3 KE |
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 | ||
9099cab3 CW |
99 | $email['1'] = ['email' => "bleu01@example.com"]; |
100 | $email['2'] = ['email' => "bleu02@example.com", 'is_primary' => 1]; | |
101 | $email['3'] = ['email' => "bleu03@example.com"]; | |
a1e077e3 | 102 | |
9099cab3 | 103 | $params = [ |
a1e077e3 KE |
104 | 'contact_type' => 'Individual', |
105 | 'email' => $email , | |
9099cab3 | 106 | ]; |
a1e077e3 KE |
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 | ||
3cae4b8a | 117 | } |