From 5266e7b8f572764cc90611b5bc061d90e91ef465 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 14 Sep 2020 10:12:54 +1200 Subject: [PATCH] Move definition of userName to where it is used and remove an unused paramter --- CRM/Member/Form/MembershipRenewal.php | 4 ++-- .../CRM/Member/Form/MembershipRenewalTest.php | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index e7ea294229..7d22be90dc 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -495,7 +495,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { $now = CRM_Utils_Date::getToday(NULL, 'YmdHis'); $this->assign('receive_date', CRM_Utils_Array::value('receive_date', $this->_params, date('Y-m-d H:i:s'))); $this->processBillingAddress(); - list($userName) = CRM_Contact_BAO_Contact_Location::getEmailDetails(CRM_Core_Session::singleton()->get('userID')); + $this->_params['total_amount'] = CRM_Utils_Array::value('total_amount', $this->_params, CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee') ); @@ -602,10 +602,10 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { if (!empty($this->_params['record_contribution']) || $this->_mode) { // set the source + list($userName) = CRM_Contact_BAO_Contact_Location::getEmailDetails(CRM_Core_Session::singleton()->get('userID')); $this->_params['contribution_source'] = "{$this->membershipTypeName} Membership: Offline membership renewal (by {$userName})"; //create line items - $lineItem = []; $this->_params = $this->setPriceSetParameters($this->_params); $order = new CRM_Financial_BAO_Order(); diff --git a/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php b/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php index f13fdf4c52..8a8b26d31a 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php @@ -9,6 +9,8 @@ +--------------------------------------------------------------------+ */ +use Civi\Api4\Contact; + /** * Test CRM_Member_Form_Membership functions. * @@ -132,7 +134,8 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { */ public function testSubmit() { $form = $this->getForm(); - $this->createLoggedInUser(); + $loggedInUserID = $this->createLoggedInUser(); + $loggedInUserDisplayName = Contact::get()->addWhere('id', '=', $loggedInUserID)->addSelect('display_name')->execute()->first()['display_name']; $params = $this->getBaseSubmitParams(); $form->_contactID = $this->_individualId; @@ -140,10 +143,12 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { $form->setRenewalMessage(); $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); $this->callAPISuccessGetCount('ContributionRecur', ['contact_id' => $this->_individualId], 0); - $contribution = $this->callAPISuccess('Contribution', 'get', [ + $contribution = $this->callAPISuccessGetSingle('Contribution', [ 'contact_id' => $this->_individualId, 'is_test' => TRUE, ]); + $expectedContributionSource = 'AnnualFixed Membership: Offline membership renewal (by ' . $loggedInUserDisplayName . ')'; + $this->assertEquals($expectedContributionSource, $contribution['contribution_source']); $this->callAPISuccessGetCount('LineItem', [ 'entity_id' => $membership['id'], @@ -234,7 +239,7 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { $params = [ 'cid' => $this->_individualId, 'price_set_id' => 0, - 'join_date' => date('m/d/Y', time()), + 'join_date' => date('m/d/Y'), 'start_date' => '', 'end_date' => '', 'campaign_id' => '', @@ -443,7 +448,7 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { $originalMembership = $this->callAPISuccessGetSingle('membership', []); $params = [ 'cid' => $this->_individualId, - 'join_date' => date('m/d/Y', time()), + 'join_date' => date('m/d/Y'), 'start_date' => '', 'end_date' => '', // This format reflects the 23 being the organisation & the 25 being the type. @@ -554,7 +559,7 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { $originalMembership = $this->callAPISuccessGetSingle('membership', []); $params = [ 'cid' => $this->_individualId, - 'join_date' => date('m/d/Y', time()), + 'join_date' => date('m/d/Y'), 'start_date' => '', 'end_date' => '', // This format reflects the 23 being the organisation & the 25 being the type. -- 2.25.1