4 * Class CRM_Contact_BAO_IndividualTest
7 class CRM_Contact_BAO_IndividualTest
extends CiviUnitTestCase
{
10 * Test case for format() with "null" value dates.
12 * See CRM-19123: Merging contacts: blank date fields write as 1970
14 public function testFormatNullDates() {
16 'contact_type' => 'Individual',
17 'birth_date' => 'null',
18 'deceased_date' => 'null',
20 $contact = new CRM_Contact_DAO_Contact();
22 CRM_Contact_BAO_Individual
::format($params, $contact);
24 $this->assertEmpty($contact->birth_date
);
25 $this->assertEmpty($contact->deceased_date
);
29 * Test case to check the formatting of the Display name and Sort name
30 * Standard formatting is assumed.
32 public function testFormatDisplayName() {
35 'contact_type' => 'Individual',
36 'first_name' => 'Ben',
38 'individual_prefix' => 'Mr.',
39 'individual_suffix' => 'Jr.',
42 $contact = new CRM_Contact_DAO_Contact();
44 CRM_Contact_BAO_Individual
::format($params, $contact);
46 $this->assertEquals("Mr. Ben Lee Jr.", $contact->display_name
);
47 $this->assertEquals("Lee, Ben", $contact->sort_name
);
51 * Testing the use of adding prefix and suffix by id.
52 * Standard Prefixes and Suffixes are assumed part of
55 public function testFormatDisplayNamePrefixesById() {
58 'contact_type' => 'Individual',
59 'first_name' => 'Ben',
63 // and the doctor is a senior
67 $contact = new CRM_Contact_DAO_Contact();
69 CRM_Contact_BAO_Individual
::format($params, $contact);
71 $this->assertEquals("Dr. Ben Lee Sr.", $contact->display_name
);
75 * Testing the use of adding prefix and suffix by id.
76 * Standard Prefixes and Suffixes are assumed part of
79 public function testFormatDisplayNameNoIndividual() {
82 'contact_type' => 'Organization',
83 'first_name' => 'Ben',
87 $contact = new CRM_Contact_DAO_Contact();
89 CRM_Contact_BAO_Individual
::format($params, $contact);
91 $this->assertNotEquals("Ben Lee", $contact->display_name
);
95 * When no first name or last name are defined, the primary email is used
97 public function testFormatDisplayNameOnlyEmail() {
99 $email['1'] = ['email' => "bleu01@example.com"];
100 $email['2'] = ['email' => "bleu02@example.com", 'is_primary' => 1];
101 $email['3'] = ['email' => "bleu03@example.com"];
104 'contact_type' => 'Individual',
108 $contact = new CRM_Contact_DAO_Contact();
110 CRM_Contact_BAO_Individual
::format($params, $contact);
112 $this->assertEquals("bleu02@example.com", $contact->display_name
);
113 $this->assertEquals("bleu02@example.com", $contact->sort_name
);