From a1e077e3cb1942b2a49e125388b5fc227b66d0b9 Mon Sep 17 00:00:00 2001 From: Klaas Eikelboom Date: Fri, 10 Mar 2017 14:15:53 +0100 Subject: [PATCH] CRM-20239 Extra tests for the CRM_Contact_BAO_Individual::format function --- .../CRM/Contact/BAO/IndividualTest.php | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/tests/phpunit/CRM/Contact/BAO/IndividualTest.php b/tests/phpunit/CRM/Contact/BAO/IndividualTest.php index dee2b55556..71938a96fc 100644 --- a/tests/phpunit/CRM/Contact/BAO/IndividualTest.php +++ b/tests/phpunit/CRM/Contact/BAO/IndividualTest.php @@ -25,4 +25,91 @@ class CRM_Contact_BAO_IndividualTest extends CiviUnitTestCase { $this->assertEmpty($contact->deceased_date); } + /** + * Test case to check the formatting of the Display name and Sort name + * Standard formatting is assumed. + */ + public function testFormatDisplayName() { + + $params = array( + 'contact_type' => 'Individual', + 'first_name' => 'Ben', + 'last_name' => 'Lee', + 'individual_prefix' => 'Mr.', + 'individual_suffix' => 'Jr.', + ); + + $contact = new CRM_Contact_DAO_Contact(); + + CRM_Contact_BAO_Individual::format($params, $contact); + + $this->assertEquals("Mr. Ben Lee Jr.", $contact->display_name); + $this->assertEquals("Lee, Ben", $contact->sort_name); + } + + /** + * Testing the use of adding prefix and suffix by id. + * Standard Prefixes and Suffixes are assumed part of + * the test database + */ + public function testFormatDisplayNamePrefixesById() { + + $params = array( + 'contact_type' => 'Individual', + 'first_name' => 'Ben', + 'last_name' => 'Lee', + 'prefix_id' => 4, // this is the doctor + 'suffix_id' => 2, // and the doctor is a senior + ); + + $contact = new CRM_Contact_DAO_Contact(); + + CRM_Contact_BAO_Individual::format($params, $contact); + + $this->assertEquals("Dr. Ben Lee Sr.", $contact->display_name); + } + + /** + * Testing the use of adding prefix and suffix by id. + * Standard Prefixes and Suffixes are assumed part of + * the test database + */ + public function testFormatDisplayNameNoIndividual() { + + $params = array( + 'contact_type' => 'Organization', + 'first_name' => 'Ben', + 'last_name' => 'Lee', + ); + + $contact = new CRM_Contact_DAO_Contact(); + + CRM_Contact_BAO_Individual::format($params, $contact); + + $this->assertNotEquals("Ben Lee", $contact->display_name); + } + + /** + * When no first name or last name are defined, the primary email is used + */ + public function testFormatDisplayNameOnlyEmail() { + + $email['1'] = array('email' => "bleu01@example.com"); + $email['2'] = array('email' => "bleu02@example.com", 'is_primary' => 1); + $email['3'] = array('email' => "bleu03@example.com"); + + $params = array( + 'contact_type' => 'Individual', + 'email' => $email , + ); + + $contact = new CRM_Contact_DAO_Contact(); + + CRM_Contact_BAO_Individual::format($params, $contact); + + $this->assertEquals("bleu02@example.com", $contact->display_name); + $this->assertEquals("bleu02@example.com", $contact->sort_name); + + } + } -- 2.25.1