Fix bug where contribution status is mishandled if label is changed
authoreileen <emcnaughton@wikimedia.org>
Sun, 26 May 2019 22:03:06 +0000 (10:03 +1200)
committereileen <emcnaughton@wikimedia.org>
Mon, 27 May 2019 01:18:16 +0000 (13:18 +1200)
CRM/Contribute/BAO/Contribution.php
tests/phpunit/api/v3/PaymentTest.php

index 99c901e30d3fd5ec5e57ff4f31daf258e5914d26..31564a2a2f59225d70160b6fbd548e414f95fe31 100644 (file)
@@ -1198,7 +1198,6 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
         return [FALSE, $isARefund];
       }
     }
-    // @todo - figure out when, if ever this is reached.
     return [TRUE, $isARefund];
   }
 
@@ -3757,7 +3756,7 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
     $trxnID = NULL;
     $inputParams = $params;
     $isARefund = FALSE;
-    $currentContributionStatus = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $params['contribution']->contribution_status_id);
+    $currentContributionStatus = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $params['contribution']->contribution_status_id);
     $previousContributionStatus = CRM_Contribute_PseudoConstant::contributionStatus($params['prevContribution']->contribution_status_id, 'name');
 
     if (($previousContributionStatus == 'Pending'
index 932a9a8ad5e20639949c0edff06aa4783d54a1ff..106a4b2984c54482927ba24e22ce2d9d477fae9c 100644 (file)
@@ -679,6 +679,8 @@ class api_v3_PaymentTest extends CiviUnitTestCase {
       'contribution_id' => $contribution['id'],
       'total_amount' => 40,
     );
+    // Rename the 'completed' status label first to check that we are not using the labels!
+    $this->callAPISuccess('OptionValue', 'get', ['name' => 'Completed', 'option_group_id' => 'contribution_status', 'api.OptionValue.create' => ['label' => 'Unicorn']]);
     $payment = $this->callAPISuccess('Payment', 'create', $params);
     $expectedResult = array(
       $payment['id'] => array(
@@ -706,11 +708,13 @@ class api_v3_PaymentTest extends CiviUnitTestCase {
     $this->assertEquals($eft['values'][$eft['id']]['amount'], 40);
     // Check contribution for completed status
     $contribution = $this->callAPISuccess('contribution', 'get', array('id' => $contribution['id']));
-    $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status'], 'Completed');
+    $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status'], 'Unicorn');
     $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
     $this->callAPISuccess('Contribution', 'Delete', array(
       'id' => $contribution['id'],
     ));
+    $this->callAPISuccess('OptionValue', 'get', ['name' => 'Completed', 'option_group_id' => 'contribution_status', 'api.OptionValue.create' => ['label' => 'Completed']]);
+
   }
 
   /**