From ef45ad8c26b9bf090e791adc23f0fd9bbc9729fb Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 21 Jan 2020 10:33:52 +1300 Subject: [PATCH] Simplify event title retrieval, use cache, add test --- CRM/Event/Form/Participant.php | 19 ++----------------- .../CRM/Event/Form/ParticipantTest.php | 4 ++-- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 54a75290af..f73ea52b24 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -1026,19 +1026,11 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment $now = date('YmdHis'); if ($this->_mode) { - - $eventTitle - = CRM_Core_DAO::getFieldValue( - 'CRM_Event_DAO_Event', - $params['event_id'], - 'title' - ); - // set source if not set if (empty($params['source'])) { $this->_params['participant_source'] = ts('Offline Registration for Event: %2 by: %1', [ 1 => $userName, - 2 => $eventTitle, + 2 => $this->getEventValue('title'), ]); } else { @@ -1242,13 +1234,6 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment } } - if (isset($params['event_id'])) { - $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', - $params['event_id'], - 'title' - ); - } - if ($this->_single) { $this->_contactIds[] = $this->_contactId; } @@ -1273,7 +1258,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment if (!$this->_onlinePendingContributionId) { if (empty($params['source'])) { $contributionParams['source'] = ts('%1 : Offline registration (by %2)', [ - 1 => $eventTitle, + 1 => $this->getEventValue('title'), 2 => $userName, ]); } diff --git a/tests/phpunit/CRM/Event/Form/ParticipantTest.php b/tests/phpunit/CRM/Event/Form/ParticipantTest.php index 69c720d52b..0cc443494b 100644 --- a/tests/phpunit/CRM/Event/Form/ParticipantTest.php +++ b/tests/phpunit/CRM/Event/Form/ParticipantTest.php @@ -188,8 +188,8 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { $form->_quickConfig = TRUE; $paymentProcessorID = $this->processorCreate(['is_test' => 0]); $form->submit($this->getSubmitParams($form->_eventId, $paymentProcessorID)); - $participants = $this->callAPISuccess('Participant', 'get', []); - $this->assertEquals(1, $participants['count']); + $participant = $this->callAPISuccessGetSingle('Participant', []); + $this->assertEquals('Offline Registration for Event: Annual CiviCRM meet by: ', $participant['participant_source']); $contribution = $this->callAPISuccessGetSingle('Contribution', []); $this->assertEquals(1550.55, $contribution['total_amount']); $this->assertEquals('Debit Card', $contribution['payment_instrument']); -- 2.25.1