*/
class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase {
+ use CRMTraits_Financial_OrderTrait;
+
+
+ /**
+ * Should financials be checked after the test but before tear down.
+ *
+ * Ideally all tests (or at least all that call any financial api calls ) should do this but there
+ * are some test data issues and some real bugs currently blocking.
+ *
+ * @var bool
+ */
+ protected $isValidateFinancialsOnPostAssert = TRUE;
+
/**
* Contact ID.
*
$mut->stop();
$mut->clearMessages();
- $this->validateAllPayments();
}
/**
// pay additional amount
$this->submitPayment(70);
$this->checkResults([30, 70], 2);
- $this->validateAllPayments();
}
/**
$this->assertEquals(CRM_Core_Session::singleton()->getLoggedInContactID(), $activities[0]['source_contact_id']);
$this->assertEquals([$this->_individualId], $activities[0]['target_contact_id']);
$this->assertEquals([], $activities[0]['assignee_contact_id']);
- $this->validateAllPayments();
}
/**
]);
$mut->stop();
$mut->clearMessages();
- $this->validateAllPayments();
}
/**
]);
$mut->stop();
$mut->clearMessages();
- $this->validateAllPayments();
}
/**
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
- public function testAddPaymentForPendingPayLaterContribution() {
+ public function testAddPaymentForPendingPayLaterContribution(): void {
$this->createPendingOrder();
// pay additional amount
// pay additional amount
$this->submitPayment(30);
$this->checkResults([30, 70], 2);
- $this->validateAllPayments();
}
/**
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
- public function testMembershipStatusAfterCompletingPayLaterContribution() {
- $this->createPendingOrder();
- $membership = $this->createPendingMembershipAndRecordContribution($this->_contributionId);
- // pay additional amount
- $this->submitPayment(100);
- $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]);
- $contributionMembership = $this->callAPISuccessGetSingle('Membership', ['id' => $membership['id']]);
- $membershipStatus = $this->callAPISuccessGetSingle('MembershipStatus', ['id' => $contributionMembership['status_id']]);
- $this->assertEquals('New', $membershipStatus['name']);
- $this->validateAllPayments();
+ public function testMembershipStatusAfterCompletingPayLaterContribution(): void {
+ $this->createContributionAndMembershipOrder();
+ $this->submitPayment(300);
+ $this->callAPISuccessGetSingle('Contribution', ['id' => $this->ids['Contribution'][0]]);
+ $this->callAPISuccessGetSingle('Membership', ['id' => $this->ids['Membership']['order'], 'status_id' => 'New']);
}
/**
* @return array|int
*
* @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
private function createPendingMembershipAndRecordContribution($contributionId) {
$this->_individualId = $this->individualCreate();
$this->submitPayment(10);
$this->checkResults([40, 20, 30, 10], 4);
- $this->validateAllPayments();
}
/**
$this->submitPayment(10, 'live');
$this->checkResults([50, 20, 20, 10], 4);
- $this->validateAllPayments();
}
/**
* @param bool $isEmailReceipt
*
* @throws \CiviCRM_API3_Exception
+ * @throws \CRM_Core_Exception
*/
public function submitPayment($amount, $mode = NULL, $isEmailReceipt = FALSE) {
$form = new CRM_Contribute_Form_AdditionalPayment();
$submitParams = [
- 'contribution_id' => $this->_contributionId,
- 'contact_id' => $this->_individualId,
+ 'contribution_id' => $this->ids['Contribution'][0] ?? $this->_contributionId,
+ 'contact_id' => $this->ids['Contact']['order'] ?? $this->_individualId,
'total_amount' => $amount,
'currency' => 'USD',
'financial_type_id' => 1,
*/
protected function createContributionAndMembershipOrder(): void {
$this->ids['membership_type'][0] = $this->membershipTypeCreate();
- $orderID = $this->callAPISuccess('Order', 'create', [
+ if (empty($this->ids['Contact']['order'])) {
+ $this->ids['Contact']['order'] = $this->individualCreate();
+ }
+ $order = $this->callAPISuccess('Order', 'create', [
'financial_type_id' => 'Donation',
- 'contact_id' => $this->_contactID,
+ 'contact_id' => $this->ids['Contact']['order'],
'is_test' => 0,
'payment_instrument_id' => 'Check',
'receive_date' => date('Y-m-d'),
'line_items' => [
[
'params' => [
- 'contact_id' => $this->_contactID,
+ 'contact_id' => $this->ids['Contact']['order'],
'source' => 'Payment',
],
'line_item' => [
],
[
'params' => [
- 'contact_id' => $this->_contactID,
+ 'contact_id' => $this->ids['Contact']['order'],
'membership_type_id' => 'General',
'source' => 'Payment',
// This is necessary because Membership_BAO otherwise ignores the
'line_item' => $this->getMembershipLineItem(),
],
],
- ])['id'];
+ ]);
- $this->ids['Contribution'][0] = $orderID;
+ $this->ids['Contribution'][0] = $order['id'];
+ $this->ids['Membership']['order'] = $order['values'][$order['id']]['membership_id'][0];
}
/**