Merge pull request #13984 from seamuslee001/nfc_comment_fix_ang
[civicrm-core.git] / tests / phpunit / CRM / Contact / BAO / IndividualTest.php
CommitLineData
3cae4b8a
FV
1<?php
2
3/**
4 * Class CRM_Contact_BAO_IndividualTest
5 * @group headless
6 */
7class 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 = array(
26f87f3a
FV
16 'contact_type' => 'Individual',
17 'birth_date' => 'null',
18 'deceased_date' => 'null',
3cae4b8a
FV
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 }
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
34 $params = array(
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 = array(
58 'contact_type' => 'Individual',
59 'first_name' => 'Ben',
60 'last_name' => 'Lee',
61 'prefix_id' => 4, // this is the doctor
62 'suffix_id' => 2, // and the doctor is a senior
63 );
64
65 $contact = new CRM_Contact_DAO_Contact();
66
67 CRM_Contact_BAO_Individual::format($params, $contact);
68
69 $this->assertEquals("Dr. Ben Lee Sr.", $contact->display_name);
70 }
71
72 /**
73 * Testing the use of adding prefix and suffix by id.
74 * Standard Prefixes and Suffixes are assumed part of
75 * the test database
76 */
77 public function testFormatDisplayNameNoIndividual() {
78
79 $params = array(
80 'contact_type' => 'Organization',
81 'first_name' => 'Ben',
82 'last_name' => 'Lee',
83 );
84
85 $contact = new CRM_Contact_DAO_Contact();
86
87 CRM_Contact_BAO_Individual::format($params, $contact);
88
89 $this->assertNotEquals("Ben Lee", $contact->display_name);
90 }
91
92 /**
93 * When no first name or last name are defined, the primary email is used
94 */
95 public function testFormatDisplayNameOnlyEmail() {
96
97 $email['1'] = array('email' => "bleu01@example.com");
98 $email['2'] = array('email' => "bleu02@example.com", 'is_primary' => 1);
99 $email['3'] = array('email' => "bleu03@example.com");
100
101 $params = array(
102 'contact_type' => 'Individual',
103 'email' => $email ,
104 );
105
106 $contact = new CRM_Contact_DAO_Contact();
107
108 CRM_Contact_BAO_Individual::format($params, $contact);
109
110 $this->assertEquals("bleu02@example.com", $contact->display_name);
111 $this->assertEquals("bleu02@example.com", $contact->sort_name);
112
113 }
114
3cae4b8a 115}