Skip to content

Commit

Permalink
Fix testMultipleMembershipsContribution to use order api
Browse files Browse the repository at this point in the history
This test was not creating valid financial records prior to this
  • Loading branch information
eileenmcnaughton committed Jan 7, 2022
1 parent 9ea6ff4 commit 8504859
Showing 1 changed file with 56 additions and 67 deletions.
123 changes: 56 additions & 67 deletions tests/phpunit/api/v3/MembershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,97 +189,86 @@ public function testActivityForCancelledContribution(): void {
* Test Multiple Membership Status for same contribution id.
*/
public function testMultipleMembershipsContribution(): void {
// Set up for this test creates invalid financialts.
$this->isValidateFinancialsOnPostAssert = FALSE;
// Main contact
$memStatus = CRM_Member_PseudoConstant::membershipStatus();
// Pending Membership Status
$pendingMembershipId = array_search('Pending', $memStatus);
// New Membership Status
$newMembershipId = array_search('test status', $memStatus);

$membershipParam = [
'membership_type_id' => 'General',
'source' => 'Webform Payment',
'status_id' => $pendingMembershipId,
'is_pay_later' => 1,
'skipStatusCal' => 1,
];

// Contact 1
$contactId1 = $this->individualCreate();
$membershipParam['contact_id'] = $contactId1;
$membershipID1 = $this->contactMembershipCreate($membershipParam);

// Pending Payment Status
$contribution = $this->callAPISuccess('Contribution', 'create', [
$contactId2 = $this->individualCreate();
$contactId3 = $this->individualCreate();
$order = $this->callAPISuccess('Order', 'create', [
'financial_type_id' => '1',
'total_amount' => 100,
'contact_id' => $contactId1,
'payment_instrument_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'),
'contribution_status_id' => 2,
'is_pay_later' => 1,
'receive_date' => date('Ymd'),
]);
$this->callAPISuccess('MembershipPayment', 'create', [
'sequential' => 1,
'contribution_id' => $contribution['id'],
'membership_id' => $membershipID1,
]);

// Contact 2
$contactId2 = $this->individualCreate();
$membershipParam['contact_id'] = $contactId2;
$membershipID2 = $this->contactMembershipCreate($membershipParam);
$this->callAPISuccess('MembershipPayment', 'create', [
'sequential' => 1,
'contribution_id' => $contribution['id'],
'membership_id' => $membershipID2,
'line_items' => [
[
'line_item' => [
[
'membership_type_id' => 'General',
'source' => 'Webform Payment',
'line_total' => 50,
'qty' => 1,
],
],
'params' => [
'contact_id' => $contactId1,
'membership_type_id' => 'General',
],
],
[
'line_item' => [
[
'membership_type_id' => 'General',
'source' => 'Webform Payment',
'line_total' => 50,
'qty' => 1,
],
],
'params' => [
'contact_id' => $contactId2,
'membership_type_id' => 'General',
],
],
[
'line_item' => [
[
'membership_type_id' => 'General',
'source' => 'Webform Payment',
'line_total' => 50,
'qty' => 1,
],
],
'params' => [
'contact_id' => $contactId3,
'membership_type_id' => 'General',
],
],
],
]);

// Contact 3
$contactId3 = $this->individualCreate();
$membershipParam['contact_id'] = $contactId3;
$membershipID3 = $this->contactMembershipCreate($membershipParam);
$this->callAPISuccess('MembershipPayment', 'create', [
'sequential' => 1,
'contribution_id' => $contribution['id'],
'membership_id' => $membershipID3,
]);
$_REQUEST['action'] = 'update';
$_REQUEST['id'] = $contribution['id'];
$_REQUEST['id'] = $order['id'];
// Change Payment Status to Completed
/* @var CRM_Contribute_Form_Contribution $form */
$form = $this->getFormObject('CRM_Contribute_Form_Contribution', [
'total_amount' => 100,
'total_amount' => 150,
'financial_type_id' => '1',
'contact_id' => $contactId1,
'payment_instrument_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'),
'contribution_status_id' => 1,
]);
$form->buildForm();
$form->postProcess();
$memberships = $this->callAPISuccess('Membership', 'get', ['sort' => 'contact_id', 'sequential' => 1])['values'];

// check for Membership 1
$params = ['id' => $membershipID1, 'return' => ['contact_id', 'status_id']];
$membership1 = $this->callAPISuccess('Membership', 'get', $params);
$result1 = $membership1['values'][$membershipID1];
$this->assertEquals($result1['contact_id'], $contactId1);
$this->assertEquals($result1['status_id'], $newMembershipId);
$this->assertEquals($contactId1, $memberships[0]['contact_id']);
$this->assertEquals('test status', CRM_Core_PseudoConstant::getName('CRM_Member_BAO_Membership', 'status_id', $memberships[0]['status_id']));

// check for Membership 2
$params = ['id' => $membershipID2];
$membership2 = $this->callAPISuccess('membership', 'get', $params);
$result2 = $membership2['values'][$membershipID2];
$this->assertEquals($result2['contact_id'], $contactId2);
$this->assertEquals($result2['status_id'], $newMembershipId);
$this->assertEquals($contactId2, $memberships[1]['contact_id']);
$this->assertEquals('test status', CRM_Core_PseudoConstant::getName('CRM_Member_BAO_Membership', 'status_id', $memberships[1]['status_id']));

// check for Membership 3
$params = ['id' => $membershipID3];
$membership3 = $this->callAPISuccess('membership', 'get', $params);
$result3 = $membership3['values'][$membershipID3];
$this->assertEquals($result3['contact_id'], $contactId3);
$this->assertEquals($result3['status_id'], $newMembershipId);
$this->assertEquals($contactId3, $memberships[2]['contact_id']);
$this->assertEquals('test status', CRM_Core_PseudoConstant::getName('CRM_Member_BAO_Membership', 'status_id', $memberships[2]['status_id']));
}

/**
Expand Down

0 comments on commit 8504859

Please sign in to comment.