From 55d094e7bcc3e3d382dd462f81c17e384360fc68 Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Mon, 25 Apr 2016 16:50:32 +0530 Subject: [PATCH] CRM-18000: Membership Batch Data Entry: Renewal not working minor fix --- CRM/Batch/Form/Entry.php | 9 +++- tests/phpunit/CRM/Batch/Form/EntryTest.php | 60 ++++++++++++++++++++++ 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/CRM/Batch/Form/Entry.php b/CRM/Batch/Form/Entry.php index 710ca0068a..1eeed172b6 100644 --- a/CRM/Batch/Form/Entry.php +++ b/CRM/Batch/Form/Entry.php @@ -650,6 +650,7 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { foreach ($dateTypes as $dateField => $dateVariable) { $$dateVariable = CRM_Utils_Date::processDate($value[$dateField]); + $fDate[$dateField] = CRM_Utils_Array::value($dateField, $value); } $calcDates = array(); @@ -806,12 +807,16 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { } } foreach (array('join_date', 'start_date', 'end_date') as $dateType) { - $formDates[$dateType] = CRM_Utils_Array::value($dateType, $value); + //CRM-18000 - ignore $dateType if its not explicitly passed + if (!empty($fDate[$dateType]) || !empty($fDate['membership_' . $dateType])) { + $formDates[$dateType] = CRM_Utils_Array::value($dateType, $value); + } } $membershipSource = CRM_Utils_Array::value('source', $value); list($membership) = CRM_Member_BAO_Membership::renewMembership( $value['contact_id'], $value['membership_type_id'], FALSE, - NULL, NULL, $value['custom'], NULL, NULL, FALSE, + //$numTerms should be default to 1. + NULL, NULL, $value['custom'], 1, NULL, FALSE, NULL, $membershipSource, $isPayLater, $campaignId, $formDates ); diff --git a/tests/phpunit/CRM/Batch/Form/EntryTest.php b/tests/phpunit/CRM/Batch/Form/EntryTest.php index a2f78a3bc9..f93ae000b1 100644 --- a/tests/phpunit/CRM/Batch/Form/EntryTest.php +++ b/tests/phpunit/CRM/Batch/Form/EntryTest.php @@ -99,6 +99,22 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase { $membershipType = $this->callAPISuccess('membership_type', 'create', $params); $this->_membershipTypeID = $membershipType['id']; + $this->_orgContactID2 = $this->organizationCreate(); + $params = array( + 'name' => 'General', + 'duration_unit' => 'year', + 'duration_interval' => 1, + 'period_type' => 'rolling', + 'member_of_contact_id' => $this->_orgContactID2, + 'domain_id' => 1, + 'financial_type_id' => 1, + 'is_active' => 1, + 'sequential' => 1, + 'visibility' => 'Public', + ); + $membershipType2 = $this->callAPISuccess('membership_type', 'create', $params); + $this->_membershipTypeID2 = $membershipType2['id']; + $this->_membershipStatusID = $this->membershipStatusCreate('test status'); $this->_contactID = $this->individualCreate(); $contact2Params = array( @@ -188,6 +204,50 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase { } } + /** + * CRM-18000 - Test start_date, end_date after renewal + */ + public function testMembershipRenewalDates() { + $form = new CRM_Batch_Form_Entry(); + foreach (array($this->_contactID, $this->_contactID2) as $contactID) { + $membershipParams = array( + 'membership_type_id' => $this->_membershipTypeID2, + 'contact_id' => $contactID, + 'start_date' => "01/01/2015", + 'join_date' => "01/01/2010", + 'end_date' => "12/31/2015", + ); + $this->contactMembershipCreate($membershipParams); + } + + $params = $this->getMembershipData(); + //ensure membership renewal + $params['member_option'] = array( + 1 => 2, + 2 => 2, + ); + $params['field'][1]['membership_type'] = array(0 => $this->_orgContactID2, 1 => $this->_membershipTypeID2); + $params['field'][1]['receive_date'] = date('Y-m-d'); + + // explicitly specify start and end dates + $params['field'][2]['membership_type'] = array(0 => $this->_orgContactID2, 1 => $this->_membershipTypeID2); + $params['field'][2]['membership_start_date'] = "04/01/2016"; + $params['field'][2]['membership_end_date'] = "03/31/2017"; + $params['field'][2]['receive_date'] = "04/01/2016"; + + $this->assertTrue($form->testProcessMembership($params)); + $result = $this->callAPISuccess('membership', 'get', array()); + + // renewal dates should be from current if start_date and end_date is passed as NULL + $this->assertEquals(date('Y-m-d'), $result['values'][1]['start_date']); + $endDate = date("Y-m-d", strtotime(date("Y-m-d") . " +1 year -1 day")); + $this->assertEquals($endDate, $result['values'][1]['end_date']); + + // verify if the modified dates asserts with the dates passed above + $this->assertEquals('2016-04-01', $result['values'][2]['start_date']); + $this->assertEquals('2017-03-31', $result['values'][2]['end_date']); + } + /** * Data provider for test process membership. * @return array -- 2.25.1