Merge pull request #21231 from civicrm/5.41
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 24 Aug 2021 04:57:43 +0000 (16:57 +1200)
committerGitHub <noreply@github.com>
Tue, 24 Aug 2021 04:57:43 +0000 (16:57 +1200)
5.41

1  2 
tests/phpunit/CiviTest/CiviUnitTestCase.php
tests/phpunit/api/v3/ContributionTest.php

index 35282cf78911fe2a1e9cf6131996a9d6728a0b7d,29e34da7f6750ae22cee4d9c8a7abb0682a63674..e66742f4df35a0ae868eb8ee27663268a2a83cd4
@@@ -3528,16 -3536,71 +3528,31 @@@ class api_v3_ContributionTest extends C
        'status_id' => 'Completed',
      ]);
      $this->assertEquals(1, $activity['count']);
 -    $this->assertEquals('Status changed from Grace to Current', $activity['values'][$activity['id']]['subject']);
 +    $this->assertEquals('Status changed from Pending to New', $activity['values'][$activity['id']]['subject']);
      $membershipLogs = $this->callAPISuccess('MembershipLog', 'get', ['sequential' => 1])['values'];
 -    $this->assertEquals('Grace', CRM_Core_PseudoConstant::getName('CRM_Member_BAO_Membership', 'status_id', $membershipLogs[0]['status_id']));
 -    $this->assertEquals('Current', CRM_Core_PseudoConstant::getName('CRM_Member_BAO_Membership', 'status_id', $membershipLogs[1]['status_id']));
 +    $this->assertEquals('Pending', CRM_Core_PseudoConstant::getName('CRM_Member_BAO_Membership', 'status_id', $membershipLogs[0]['status_id']));
 +    $this->assertEquals('New', CRM_Core_PseudoConstant::getName('CRM_Member_BAO_Membership', 'status_id', $membershipLogs[1]['status_id']));
      //Create another pending contribution for renewal
 -    $contribution = $this->callAPISuccess('contribution', 'create', [
 -      'domain_id' => 1,
 -      'contact_id' => $this->_ids['contact'],
 -      'receive_date' => date('Ymd'),
 -      'total_amount' => 20.00,
 -      'financial_type_id' => 1,
 -      'payment_instrument_id' => 'Credit Card',
 -      'non_deductible_amount' => 10.00,
 -      'trxn_id' => 'rdhfi88',
 -      'invoice_id' => 'dofhiewuyr',
 -      'source' => 'SSF',
 -      'contribution_status_id' => 2,
 -      'contribution_page_id' => $this->_ids['contribution_page'],
 -      // We can't rely on contribution api to link line items correctly to membership
 -      'skipLineItem' => TRUE,
 -      'api.membership_payment.create' => ['membership_id' => $this->_ids['membership']],
 -    ]);
 -
 -    $this->callAPISuccess('line_item', 'create', [
 -      'entity_id' => $contribution['id'],
 -      'entity_table' => 'civicrm_contribution',
 -      'contribution_id' => $contribution['id'],
 -      'price_field_id' => $this->_ids['price_field'][0],
 -      'qty' => 1,
 -      'unit_price' => 20,
 -      'line_total' => 20,
 -      'financial_type_id' => 1,
 -      'price_field_value_id' => $this->_ids['price_field_value']['cont'],
 -    ]);
 -    $this->callAPISuccess('line_item', 'create', [
 -      'entity_id' => $this->_ids['membership'],
 -      'entity_table' => 'civicrm_membership',
 -      'contribution_id' => $contribution['id'],
 -      'price_field_id' => $this->_ids['price_field'][0],
 -      'qty' => 1,
 -      'unit_price' => 20,
 -      'line_total' => 20,
 -      'financial_type_id' => 1,
 -      'price_field_value_id' => $this->_ids['price_field_value'][0],
 -      'membership_type_id' => $this->_ids['membership_type'],
 -    ]);
 +    $this->setUpPendingContribution($this->_ids['price_field_value'][0], 'second', [], ['entity_id' => $this->getMembershipID()], ['id' => $this->getMembershipID()]);
  
      //Update it to Failed.
 -    $form->_params['id'] = $contribution['id'];
 +    $form->_params['id'] = $this->getContributionID('second');
      $form->_params['contribution_status_id'] = 4;
+     // We now have 2 line items of $20 each.
+     // form params['total_amount'] is set to $20 but
+     // now that we have 2 line items of $20 it should be $40
+     // this is an artificial test scenario.
+     // but we need to ensure it is valid enough to
+     // pass validation checks. Note the way these lines are created
+     // above is wrong wrong wrong - but the rc is not the place to fix.
+     // Also note that this test has historically created incorrect
+     // financial data. The financials check was enabled on it
+     // AFTER the code we are honing was merged.
+     // so it used to tolerate incorrect financials, then it started
+     // re-calculating them (correctly in this artificial scenario - but not for tax scenarios)
+     // but as of 5.41 it is 'accepting' the total_amount
+     // so we should pass in a correct one.
+     $form->_params['total_amount'] = 40;
  
      $form->testSubmit($form->_params, CRM_Core_Action::UPDATE);
      //Existing membership should not get updated to expired.