Move definition of userName to where it is used and remove an unused paramter
authoreileen <emcnaughton@wikimedia.org>
Sun, 13 Sep 2020 22:12:54 +0000 (10:12 +1200)
committereileen <emcnaughton@wikimedia.org>
Sun, 13 Sep 2020 23:34:16 +0000 (11:34 +1200)
CRM/Member/Form/MembershipRenewal.php
tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php

index e7ea29422939abe4653f287f6e2c04da75a7f24f..7d22be90dc4bc0d3794850c4cacb0446e1e57a28 100644 (file)
@@ -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();
index f13fdf4c52916636332802b1288e9a381fc6f3e4..8a8b26d31af4849de6d363dc7694a0f1f82f0ec0 100644 (file)
@@ -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.