diff --git a/CRM/Member/BAO/MembershipType.php b/CRM/Member/BAO/MembershipType.php index fcc5597e75b8..195e3d13826e 100644 --- a/CRM/Member/BAO/MembershipType.php +++ b/CRM/Member/BAO/MembershipType.php @@ -454,7 +454,7 @@ public static function getDatesForMembershipType($membershipTypeId, $joinDate = * @param string $actualStartDate * @return bool is this in the window where the membership gets an extra part-period added */ - protected static function isDuringFixedAnnualRolloverPeriod($startDate, $membershipTypeDetails, $year, $actualStartDate) { + public static function isDuringFixedAnnualRolloverPeriod($startDate, $membershipTypeDetails, $year, $actualStartDate) { $rolloverMonth = substr($membershipTypeDetails['fixed_period_rollover_day'], 0, strlen($membershipTypeDetails['fixed_period_rollover_day']) - 2 diff --git a/tests/phpunit/api/v3/MembershipTest.php b/tests/phpunit/api/v3/MembershipTest.php index 85ad37b7a01a..47be4355b9a4 100644 --- a/tests/phpunit/api/v3/MembershipTest.php +++ b/tests/phpunit/api/v3/MembershipTest.php @@ -1150,14 +1150,25 @@ public function testMembershipJoinDateFixed() { ); $result = $this->callAPISuccess('Membership', 'create', $memParams); + // Extend duration interval if join_date exceeds the rollover period. + $joinDate = date('Y-m-d'); + $year = date('Y'); + $startDate = date('Y-m-d', strtotime(date('Y-03-01'))); + $membershipTypeDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($this->_membershipTypeID2); + $fixedPeriodRollover = CRM_Member_BAO_MembershipType::isDuringFixedAnnualRolloverPeriod($joinDate, $membershipTypeDetails, $year, $startDate); + $y = 1; + if ($fixedPeriodRollover) { + $y += 1; + } + $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')), + 'start_date' => str_replace('-', '', $startDate), + 'end_date' => date('Ymd', strtotime(date('Y-03-01') . "+ {$y} year - 1 day")), ); foreach ($result['values'] as $values) { foreach ($expectedDates as $date => $val) { - $this->assertEquals($val, $values[$date]); + $this->assertEquals($val, $values[$date], "Failed asserting {$date} values"); } } }