From 96ea99c8e94244e3947a0ecd23600b0e4156e129 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 11 Oct 2021 15:34:16 +1300 Subject: [PATCH] Fix another instance of double token rendering --- CRM/Event/Form/SelfSvcTransfer.php | 44 ++++++------------- .../CRM/Event/Form/ParticipantTest.php | 5 +++ tests/phpunit/CiviTest/CiviUnitTestCase.php | 16 +++++++ 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/CRM/Event/Form/SelfSvcTransfer.php b/CRM/Event/Form/SelfSvcTransfer.php index 22381d1efc..8d6a3488ec 100644 --- a/CRM/Event/Form/SelfSvcTransfer.php +++ b/CRM/Event/Form/SelfSvcTransfer.php @@ -159,7 +159,7 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { $this->_event_title = CRM_Event_BAO_Event::getFieldValue('CRM_Event_DAO_Event', $this->_event_id, $daoName); $daoName = 'start_date'; $this->_event_start_date = CRM_Event_BAO_Event::getFieldValue('CRM_Event_DAO_Event', $this->_event_id, $daoName); - list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_from_contact_id); + [$displayName, $email] = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_from_contact_id); $this->_contact_name = $displayName; $this->_contact_email = $email; @@ -342,21 +342,18 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { /** * Based on input, create participant row for transferee and send email * - * return @ void + * @param $participant * + * @throws \API_Exception * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception */ - public function participantTransfer($participant) { - $contactDetails = []; - $contactIds[] = $participant->contact_id; - list($currentContactDetails) = CRM_Utils_Token::getTokenDetails($contactIds, NULL, - FALSE, FALSE, NULL, [], 'CRM_Event_BAO_Participant'); - foreach ($currentContactDetails as $contactId => $contactValues) { - $contactDetails[$contactId] = $contactValues; - } + public function participantTransfer($participant): void { + $contactDetails = civicrm_api3('Contact', 'getsingle', ['id' => $participant->contact_id, 'return' => ['display_name', 'email']]); + $participantRoles = CRM_Event_PseudoConstant::participantRole(); $participantDetails = []; - $query = "SELECT * FROM civicrm_participant WHERE id = " . $participant->id; + $query = 'SELECT * FROM civicrm_participant WHERE id = ' . $participant->id; $dao = CRM_Core_DAO::executeQuery($query); while ($dao->fetch()) { $participantDetails[$dao->id] = [ @@ -371,23 +368,7 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { 'registered_by_id' => $dao->registered_by_id, ]; } - $domainValues = []; - if (empty($domainValues)) { - $domain = CRM_Core_BAO_Domain::getDomain(); - $tokens = [ - 'domain' => - [ - 'name', - 'phone', - 'address', - 'email', - ], - 'contact' => CRM_Core_SelectValues::contactTokens(), - ]; - foreach ($tokens['domain'] as $token) { - $domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain); - } - } + $eventDetails = []; $eventParams = ['id' => $participant->event_id]; CRM_Event_BAO_Event::retrieve($eventParams, $eventDetails); @@ -399,14 +380,15 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { 'entity_table' => 'civicrm_event', ]; $eventDetails['location'] = CRM_Core_BAO_Location::getValues($locParams, TRUE); - $toEmail = $contactDetails[$participant->contact_id]['email'] ?? NULL; + $toEmail = $contactDetails['email'] ?? NULL; if ($toEmail) { //take a receipt from as event else domain. - $receiptFrom = $domainValues['name'] . ' <' . $domainValues['email'] . '>'; + $receiptFrom = CRM_Core_BAO_Domain::getNameAndEmail(FALSE, TRUE); + $receiptFrom = reset($receiptFrom); if (!empty($eventDetails['confirm_from_name']) && !empty($eventDetails['confirm_from_email'])) { $receiptFrom = $eventDetails['confirm_from_name'] . ' <' . $eventDetails['confirm_from_email'] . '>'; } - $participantName = $contactDetails[$participant->contact_id]['display_name']; + $participantName = $contactDetails['display_name']; $tplParams = [ 'event' => $eventDetails, 'participant' => $participantDetails[$participant->id], diff --git a/tests/phpunit/CRM/Event/Form/ParticipantTest.php b/tests/phpunit/CRM/Event/Form/ParticipantTest.php index 9ec0c4b44d..8229939a45 100644 --- a/tests/phpunit/CRM/Event/Form/ParticipantTest.php +++ b/tests/phpunit/CRM/Event/Form/ParticipantTest.php @@ -830,7 +830,12 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { /* @var CRM_Event_Form_SelfSvcTransfer $form */ $form = $this->getFormObject('CRM_Event_Form_SelfSvcTransfer'); $toContactId = $this->individualCreate(); + $mut = new CiviMailUtils($this); + $this->swapMessageTemplateForInput('event_online_receipt', '{domain.name} {contact.first_name}'); $form->transferParticipantRegistration($toContactId, $participantId); + $mut->checkAllMailLog(['Default Domain Name Anthony']); + $mut->clearMessages(); + $this->revertTemplateToReservedTemplate('event_online_receipt', 'html'); //Assert participant is transferred to $toContactId. $participant = $this->callAPISuccess('Participant', 'getsingle', [ diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index c3adf73644..e717eec4f3 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -2704,6 +2704,22 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { return $this->callAPISuccess('PriceFieldValue', 'get', ['price_field_id' => $priceField->id]); } + /** + * Replace the template with a test-oriented template designed to show all the variables. + * + * @param string $templateName + * @param string $input + * @param string $type + */ + protected function swapMessageTemplateForInput(string $templateName, string $input, string $type = 'html'): void { + CRM_Core_DAO::executeQuery( + "UPDATE civicrm_msg_template + SET msg_{$type} = %1 + WHERE workflow_name = '{$templateName}' + AND is_default = 1", [1 => [$input, 'String']] + ); + } + /** * Replace the template with a test-oriented template designed to show all the variables. * -- 2.25.1