From ed7e2e9921e95e0563ff4123b91f5a9c96793954 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 5 Aug 2019 11:04:22 +1200 Subject: [PATCH] dev/core#224 Ensure front end profile title is used in confirmation emails --- CRM/Contribute/BAO/Contribution.php | 2 +- CRM/Core/BAO/UFGroup.php | 14 ++++++++++ CRM/Event/BAO/Event.php | 32 +++++++++++++---------- tests/phpunit/api/v3/ContributionTest.php | 19 +++++++++++--- 4 files changed, 48 insertions(+), 19 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 78b2d586a7..0268840ba9 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -5890,7 +5890,7 @@ LIMIT 1;"; $eventParams = [ 'id' => $eventID, ]; - $values = ['event' =>[]]; + $values = ['event' => []]; CRM_Event_BAO_Event::retrieve($eventParams, $values['event']); // add custom fields for event diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index c7d985b299..c3974fbdd7 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -3627,4 +3627,18 @@ SELECT group_id } } + /** + * Get the frontend_title for the profile, falling back on 'title' if none. + * + * @param int $profileID + * + * @return string + * + * @throws \CiviCRM_API3_Exception + */ + public static function getFrontEndTitle(int $profileID) { + $profile = civicrm_api3('UFGroup', 'getsingle', ['id' => $profileID, 'return' => ['title', 'frontend_title']]); + return $profile['frontend_title'] ?? $profile['title']; + } + } diff --git a/CRM/Event/BAO/Event.php b/CRM/Event/BAO/Event.php index cc133d64cb..2506d05a9f 100644 --- a/CRM/Event/BAO/Event.php +++ b/CRM/Event/BAO/Event.php @@ -1050,7 +1050,9 @@ WHERE civicrm_event.is_active = 1 * @param int $participantId * @param bool $isTest * @param bool $returnMessageText + * * @return array|null + * @throws \CiviCRM_API3_Exception */ public static function sendMail($contactID, &$values, $participantId, $isTest = FALSE, $returnMessageText = FALSE) { @@ -1110,43 +1112,44 @@ WHERE civicrm_event.is_active = 1 $postProfileID = CRM_Utils_Array::value('additional_custom_post_id', $values, $postProfileID); } - self::buildCustomDisplay($preProfileID, + $profilePre = self::buildCustomDisplay($preProfileID, 'customPre', $contactID, $template, $participantId, $isTest, - NULL, + TRUE, $participantParams ); - self::buildCustomDisplay($postProfileID, + $profilePost = self::buildCustomDisplay($postProfileID, 'customPost', $contactID, $template, $participantId, $isTest, - NULL, + TRUE, $participantParams ); $sessions = CRM_Event_Cart_BAO_Conference::get_participant_sessions($participantId); + // @todo - the goal is that all params available to the message template are explicitly defined here rather than + // 'in a smattering of places'. Note that leakage can happen between mailings when not explicitly defined. $tplParams = array_merge($values, $participantParams, [ 'email' => $email, 'confirm_email_text' => CRM_Utils_Array::value('confirm_email_text', $values['event']), 'isShowLocation' => CRM_Utils_Array::value('is_show_location', $values['event']), // The concept of contributeMode is deprecated. 'contributeMode' => CRM_Utils_Array::value('contributeMode', $template->_tpl_vars), + 'customPre' => $profilePre[0], + 'customPre_grouptitle' => empty($profilePre[1]) ? NULL : [CRM_Core_BAO_UFGroup::getFrontEndTitle((int) $preProfileID)], + 'customPost' => $profilePost[0], + 'customPost_grouptitle' => empty($profilePost[1]) ? NULL : [CRM_Core_BAO_UFGroup::getFrontEndTitle((int) $postProfileID)], 'participantID' => $participantId, 'conference_sessions' => $sessions, - 'credit_card_number' => - CRM_Utils_System::mungeCreditCard( - CRM_Utils_Array::value('credit_card_number', $participantParams)), - 'credit_card_exp_date' => - CRM_Utils_Date::mysqlToIso( - CRM_Utils_Date::format( - CRM_Utils_Array::value('credit_card_exp_date', $participantParams))), + 'credit_card_number' => CRM_Utils_System::mungeCreditCard(CRM_Utils_Array::value('credit_card_number', $participantParams)), + 'credit_card_exp_date' => CRM_Utils_Date::mysqlToIso(CRM_Utils_Date::format(CRM_Utils_Array::value('credit_card_exp_date', $participantParams))), ]); // CRM-13890 : NOTE wait list condition need to be given so that @@ -1242,10 +1245,11 @@ WHERE civicrm_event.is_active = 1 * @param string $template * @param int $participantId * @param bool $isTest - * @param bool $isCustomProfile + * @param bool $returnResults * @param array $participantParams * * @return array|null + * @throws \CRM_Core_Exception */ public static function buildCustomDisplay( $id, @@ -1254,7 +1258,7 @@ WHERE civicrm_event.is_active = 1 &$template, $participantId, $isTest, - $isCustomProfile = FALSE, + $returnResults = FALSE, $participantParams = [] ) { if (!$id) { @@ -1408,7 +1412,7 @@ WHERE civicrm_event.is_active = 1 } //return if we only require array of participant's info. - if ($isCustomProfile) { + if ($returnResults) { if (count($val)) { return [$val, $groupTitles]; } diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 5245b7498e..0de1e0b4c4 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -34,6 +34,8 @@ */ class api_v3_ContributionTest extends CiviUnitTestCase { + use CRMTraits_Profile_ProfileTrait; + protected $_individualId; protected $_contribution; protected $_financialTypeId = 1; @@ -3008,12 +3010,16 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * * Note that we are creating a logged in user because email goes out from * that person + * + * @throws \CRM_Core_Exception */ public function testCompleteTransactionWithParticipantRecord() { $mut = new CiviMailUtils($this, TRUE); $mut->clearMessages(); $this->_individualId = $this->createLoggedInUser(); $contributionID = $this->createPendingParticipantContribution(); + $this->createJoinedProfile(['entity_id' => $this->_ids['event']['test'], 'entity_table' => 'civicrm_event']); + $this->callAPISuccess('contribution', 'completetransaction', [ 'id' => $contributionID, ] @@ -3025,7 +3031,10 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->assertEquals(1, $participantStatus); //Assert only three activities are created. - $activities = CRM_Activity_BAO_Activity::getContactActivity($this->_individualId); + $activities = $this->callAPISuccess('Activity', 'get', [ + 'contact_id' => $this->_individualId, + ])['values']; + $this->assertEquals(3, count($activities)); $activityNames = array_count_values(CRM_Utils_Array::collect('activity_name', $activities)); // record two activities before and after completing payment for Event registration @@ -3037,7 +3046,9 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'Annual CiviCRM meet', 'Event', 'This letter is a confirmation that your registration has been received and your status has been updated to Registered.', - ]); + 'First Name: Logged In', + 'Public title', + ], ['Back end title']); $mut->stop(); } @@ -3487,8 +3498,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * Create a pending contribution & linked pending participant record (along with an event). */ public function createPendingParticipantContribution() { - $event = $this->eventCreate(['is_email_confirm' => 1, 'confirm_from_email' => 'test@civicrm.org']); - $participantID = $this->participantCreate(['event_id' => $event['id'], 'status_id' => 6, 'contact_id' => $this->_individualId]); + $this->_ids['event']['test'] = $this->eventCreate(['is_email_confirm' => 1, 'confirm_from_email' => 'test@civicrm.org'])['id']; + $participantID = $this->participantCreate(['event_id' => $this->_ids['event']['test'], 'status_id' => 6, 'contact_id' => $this->_individualId]); $this->_ids['participant'] = $participantID; $params = array_merge($this->_params, ['contact_id' => $this->_individualId, 'contribution_status_id' => 2, 'financial_type_id' => 'Event Fee']); $contribution = $this->callAPISuccess('contribution', 'create', $params); -- 2.25.1