Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-18503 - Membership join_date is incorrectly set by CiviContribute… #9358

Merged
merged 2 commits into from
Nov 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CRM/Member/BAO/MembershipType.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,10 @@ public static function getRenewalDatesForMembershipType($membershipId, $changeTo
$membershipDates['start_date'] = $renewalDates['start_date'];
$membershipDates['end_date'] = $renewalDates['end_date'];
$membershipDates['log_start_date'] = $renewalDates['start_date'];
// CRM-18503 - set join_date as today in case the membership type is fixed.
if ($membershipTypeDetails['period_type'] == 'fixed' && !isset($membershipDates['join_date'])) {
$membershipDates['join_date'] = $renewalDates['join_date'];
}
}
if (!isset($membershipDates['join_date'])) {
$membershipDates['join_date'] = $membershipDates['start_date'];
Expand Down
44 changes: 44 additions & 0 deletions tests/phpunit/api/v3/MembershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,50 @@ public function testEmptyStartEndDateFixedMultiYear() {
$this->assertEquals('2014-02-28', $result['end_date']);
}

/**
* CRM-18503 - Test membership join date is correctly set for fixed memberships.
*/
public function testMembershipJoinDateFixed() {
$memStatus = CRM_Member_PseudoConstant::membershipStatus();
// Update the fixed membership type to 1 year duration.
$this->callAPISuccess('membership_type', 'create', array('id' => $this->_membershipTypeID2, 'duration_interval' => 1));
$contactId = $this->createLoggedInUser();
// Create membership with 'Pending' status.
$params = array(
'contact_id' => $contactId,
'membership_type_id' => $this->_membershipTypeID2,
'source' => 'test membership',
'is_pay_later' => 0,
'status_id' => array_search('Pending', $memStatus),
'skipStatusCal' => 1,
'is_for_organization' => 1,
);
$ids = array();
$membership = CRM_Member_BAO_Membership::create($params, $ids);

// Update membership to 'Completed' and check the dates.
$memParams = array(
'id' => $membership->id,
'contact_id' => $contactId,
'is_test' => 0,
'membership_type_id' => $this->_membershipTypeID2,
'num_terms' => 1,
'status_id' => array_search('New', $memStatus),
);
$result = $this->callAPISuccess('Membership', 'create', $memParams);

$expectedDates = array(
'join_date' => date('Ymd'),
'start_date' => date('Ymd', strtotime(date('Y-03-01'))),
'end_date' => date('Ymd', strtotime(date('Y-03-01') . '+ 1 year - 1 day')),
);
foreach ($result['values'] as $values) {
foreach ($expectedDates as $date => $val) {
$this->assertEquals($val, $values[$date]);
}
}
}

/**
* Test correct end and start dates are calculated for fixed multi year memberships.
*
Expand Down