+--------------------------------------------------------------------+
| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
* Memberships expected.
*/
public function testGetOnlyActive() {
- $description = "Demonstrates use of 'filter' active_only' param";
+ $description = "Demonstrates use of 'filter' active_only' param.";
$this->_membershipID = $this->contactMembershipCreate($this->_params);
- $subfile = 'filterIsCurrent';
$params = array(
'contact_id' => $this->_contactID,
'active_only' => 1,
),
);
- $membership = $this->callAPIAndDocument('membership', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile);
+ $membership = $this->callAPIAndDocument('membership', 'get', $params, __FUNCTION__, __FILE__, $description, 'FilterIsCurrent');
$this->assertEquals($membership['values'][$this->_membershipID]['status_id'], $this->_membershipStatusID);
$this->assertEquals($membership['values'][$this->_membershipID]['contact_id'], $this->_contactID);
$result = $this->callAPISuccess('membership', 'get', $params);
$this->assertEquals(0, $result['count']);
+ // Set up params for enable/disable checks
+ $relationship1 = $this->callAPISuccess('relationship', 'get', array('contact_id_a' => $memberContactId[1]));
+ $params = array(
+ 'contact_id' => $memberContactId[1],
+ 'membership_type_id' => $membershipTypeId,
+ );
+
+ // Deactivate relationship using create and assert membership is not inherited
+ $this->callAPISuccess('relationship', 'create', array('id' => $relationship1['id'], 'is_active' => 0));
+ $result = $this->callAPISuccess('membership', 'get', $params);
+ $this->assertEquals(0, $result['count']);
+
+ // Re-enable relationship using create and assert membership is inherited
+ $this->callAPISuccess('relationship', 'create', array('id' => $relationship1['id'], 'is_active' => 1));
+ $result = $this->callAPISuccess('membership', 'get', $params);
+ $this->assertEquals(1, $result['count']);
+
+ // Deactivate relationship using setvalue and assert membership is not inherited
+ $this->callAPISuccess('relationship', 'setvalue', array('id' => $relationship1['id'], 'field' => 'is_active', 'value' => 0));
+ $result = $this->callAPISuccess('membership', 'get', $params);
+ $this->assertEquals(0, $result['count']);
+
+ // Re-enable relationship using setvalue and assert membership is inherited
+ $this->callAPISuccess('relationship', 'setvalue', array('id' => $relationship1['id'], 'field' => 'is_active', 'value' => 1));
+ $result = $this->callAPISuccess('membership', 'get', $params);
+ $this->assertEquals(1, $result['count']);
+
+ // Delete relationship and assert membership is not inherited
+ $this->callAPISuccess('relationship', 'delete', array('id' => $relationship1['id']));
+ $result = $this->callAPISuccess('membership', 'get', $params);
+ $this->assertEquals(0, $result['count']);
+
// Tear down - reverse of creation to be safe
$this->contactDelete($memberContactId[2]);
$this->contactDelete($memberContactId[1]);
}
/**
- * If is_overide is passed in status must also be passed in
+ * If is_overide is passed in status must also be passed in.
*/
public function testCreateOverrideNoStatus() {
$params = $this->_params;
$params = $this->_params;
$params['custom_' . $ids['custom_field_id']] = "custom string";
- $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
+ $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, NULL, 'CreateWithCustomData');
$check = $this->callAPISuccess($this->_entity, 'get', array(
'id' => $result['id'],
'contact_id' => $this->_contactID,
}
/**
- * Change custom field using update
+ * Change custom field using update.
*/
public function testUpdateWithCustom() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
$params = $this->_params;
$params['custom_' . $ids['custom_field_id']] = "custom string";
- $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
+ $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, NULL, 'UpdateCustomData');
$result = $this->callAPISuccess($this->_entity, 'create', array(
'id' => $result['id'],
'custom_' . $ids['custom_field_id'] => "new custom",
}
/**
- * Test civicrm_contact_memberships_create Invalid membership data
+ * Test civicrm_contact_memberships_create Invalid membership data.
* Error expected.
*/
public function testMembershipCreateInvalidMemData() {
}
/**
- * Test that if membership join date is not set it defaults to today
+ * Test that if membership join date is not set it defaults to today.
*/
public function testEmptyJoinDate() {
unset($this->_params['join_date'], $this->_params['is_override']);
}
/**
- * Test that if membership start date is not set it defaults to correct end date
+ * Test that if membership start date is not set it defaults to correct end date.
* - fixed
*/
public function testEmptyStartDateFixed() {
}
/**
- * Test that if membership start date is not set it defaults to correct end date for rolling memberships.
+ * Test that if membership start date is not set it defaults to correct end date for fixed multi year memberships.
+ */
+ public function testEmptyStartEndDateFixedMultiYear() {
+ unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
+ $this->callAPISuccess('membership_type', 'create', array('id' => $this->_membershipTypeID2, 'duration_interval' => 5));
+ $this->_params['membership_type_id'] = $this->_membershipTypeID2;
+ $result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $this->assertEquals('2009-01-21', $result['join_date']);
+ $this->assertEquals('2008-03-01', $result['start_date']);
+ $this->assertEquals('2014-02-28', $result['end_date']);
+ }
+
+ /**
+ * Test correct end and start dates are calculated for fixed multi year memberships.
+ *
+ * The empty start date is calculated to be the start_date (1 Jan prior to the join_date - so 1 Jan 15)
+ *
+ * In this set our start date is after the start day and before the rollover day so we don't get an extra year
+ * and we end one day before the rollover day. Start day is 1 Jan so we end on 31 Dec
+ * and we add on 4 years rather than 5 because we are not after the rollover day - so we calculate 31 Dec 2019
+ */
+ public function testFixedMultiYearDateSetTwoEmptyStartEndDate() {
+ unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
+
+ $this->callAPISuccess('membership_type', 'create', array(
+ 'id' => $this->_membershipTypeID2,
+ 'duration_interval' => 5,
+ // Ie 1 Jan.
+ 'fixed_period_start_day' => '101',
+ // Ie. 1 Nov.
+ 'fixed_period_rollover_day' => '1101',
+ ));
+ $this->_params['membership_type_id'] = $this->_membershipTypeID2;
+ $dates = array(
+ 'join_date' => '28-Jan 2015',
+ );
+ $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $this->assertEquals('2015-01-28', $result['join_date']);
+ $this->assertEquals('2015-01-01', $result['start_date']);
+ $this->assertEquals('2019-12-31', $result['end_date']);
+ }
+
+ /**
+ * Test that correct end date is calculated for fixed multi year memberships and start date is not changed.
+ *
+ * In this set our start date is after the start day and before the rollover day so we don't get an extra year
+ * and we end one day before the rollover day. Start day is 1 Jan so we end on 31 Dec
+ * and we add on 4 years rather than 5 because we are not after the rollover day - so we calculate 31 Dec 2019
+ */
+ public function testFixedMultiYearDateSetTwoEmptyEndDate() {
+ unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
+
+ $this->callAPISuccess('membership_type', 'create', array(
+ 'id' => $this->_membershipTypeID2,
+ 'duration_interval' => 5,
+ // Ie 1 Jan.
+ 'fixed_period_start_day' => '101',
+ // Ie. 1 Nov.
+ 'fixed_period_rollover_day' => '1101',
+ ));
+ $this->_params['membership_type_id'] = $this->_membershipTypeID2;
+ $dates = array(
+ 'start_date' => '28-Jan 2015',
+ 'join_date' => '28-Jan 2015',
+ );
+ $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $this->assertEquals('2015-01-28', $result['join_date']);
+ $this->assertEquals('2015-01-28', $result['start_date']);
+ $this->assertEquals('2019-12-31', $result['end_date']);
+ }
+
+ /**
+ * Test correct end and start dates are calculated for fixed multi year memberships.
+ *
+ * The empty start date is calculated to be the start_date (1 Jan prior to the join_date - so 1 Jan 15)
+ *
+ * In this set our start date is after the start day and before the rollover day so we don't get an extra year
+ * and we end one day before the rollover day. Start day is 1 Jan so we end on 31 Dec
+ * and we add on <1 years rather than > 1 because we are not after the rollover day - so we calculate 31 Dec 2015
+ */
+ public function testFixedSingleYearDateSetTwoEmptyStartEndDate() {
+ unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
+
+ $this->callAPISuccess('membership_type', 'create', array(
+ 'id' => $this->_membershipTypeID2,
+ 'duration_interval' => 1,
+ // Ie 1 Jan.
+ 'fixed_period_start_day' => '101',
+ // Ie. 1 Nov.
+ 'fixed_period_rollover_day' => '1101',
+ ));
+ $this->_params['membership_type_id'] = $this->_membershipTypeID2;
+ $dates = array(
+ 'join_date' => '28-Jan 2015',
+ );
+ $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $this->assertEquals('2015-01-28', $result['join_date']);
+ $this->assertEquals('2015-01-01', $result['start_date']);
+ $this->assertEquals('2015-12-31', $result['end_date']);
+ }
+
+ /**
+ * Test correct end date for fixed single year memberships is calculated and start_date is not changed.
+ *
+ * In this set our start date is after the start day and before the rollover day so we don't get an extra year
+ * and we end one day before the rollover day. Start day is 1 Jan so we end on 31 Dec
+ * and we add on <1 years rather than > 1 because we are not after the rollover day - so we calculate 31 Dec 2015
+ */
+ public function testFixedSingleYearDateSetTwoEmptyEndDate() {
+ unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
+
+ $this->callAPISuccess('membership_type', 'create', array(
+ 'id' => $this->_membershipTypeID2,
+ 'duration_interval' => 1,
+ // Ie 1 Jan.
+ 'fixed_period_start_day' => '101',
+ // Ie. 1 Nov.
+ 'fixed_period_rollover_day' => '1101',
+ ));
+ $this->_params['membership_type_id'] = $this->_membershipTypeID2;
+ $dates = array(
+ 'start_date' => '28-Jan 2015',
+ 'join_date' => '28-Jan 2015',
+ );
+ $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $this->assertEquals('2015-01-28', $result['join_date']);
+ $this->assertEquals('2015-01-28', $result['start_date']);
+ $this->assertEquals('2015-12-31', $result['end_date']);
+ }
+
+ /**
+ * Test that correct end date is calculated for fixed multi year memberships and start date is not changed.
+ *
+ * In this set our start date is after the start day and after the rollover day so we do get an extra year
+ * and we end one day before the rollover day. Start day is 1 Nov so we end on 31 Oct
+ * and we add on 1 year we are after the rollover day - so we calculate 31 Oct 2016
+ */
+ public function testFixedSingleYearDateSetThreeEmptyEndDate() {
+ unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
+
+ $this->callAPISuccess('membership_type', 'create', array(
+ 'id' => $this->_membershipTypeID2,
+ 'duration_interval' => 1,
+ // Ie. 1 Nov.
+ 'fixed_period_start_day' => '1101',
+ // Ie 1 Jan.
+ 'fixed_period_rollover_day' => '101',
+ ));
+ $this->_params['membership_type_id'] = $this->_membershipTypeID2;
+ $dates = array(
+ 'start_date' => '28-Jan 2015',
+ 'join_date' => '28-Jan 2015',
+ );
+ $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $this->assertEquals('2015-01-28', $result['join_date']);
+ $this->assertEquals('2015-01-28', $result['start_date']);
+ $this->assertEquals('2016-10-31', $result['end_date']);
+ }
+
+ /**
+ * Test correct end and start dates are calculated for fixed multi year memberships.
+ *
+ * The empty start date is calculated to be the start_date (1 Nov prior to the join_date - so 1 Nov 14)
+ *
+ * In this set our start date is after the start day and after the rollover day so we do get an extra year
+ * and we end one day before the rollover day. Start day is 1 Nov so we end on 31 Oct
+ * and we add on 1 year we are after the rollover day - so we calculate 31 Oct 2016
+ */
+ public function testFixedSingleYearDateSetThreeEmptyStartEndDate() {
+ unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
+
+ $this->callAPISuccess('membership_type', 'create', array(
+ 'id' => $this->_membershipTypeID2,
+ 'duration_interval' => 1,
+ // Ie. 1 Nov.
+ 'fixed_period_start_day' => '1101',
+ // Ie 1 Jan.
+ 'fixed_period_rollover_day' => '101',
+ ));
+ $this->_params['membership_type_id'] = $this->_membershipTypeID2;
+ $dates = array(
+ 'join_date' => '28-Jan 2015',
+ );
+ $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $this->assertEquals('2015-01-28', $result['join_date']);
+ $this->assertEquals('2014-11-01', $result['start_date']);
+ $this->assertEquals('2016-10-31', $result['end_date']);
+ }
+
+ /**
+ * Test that correct end date is calculated for fixed multi year memberships and start date is not changed.
+ *
+ * In this set our start date is after the start day and after the rollover day so we do get an extra year
+ * and we end one day before the rollover day. Start day is 1 Nov so we end on 31 Oct
+ * and we add on 5 years we are after the rollover day - so we calculate 31 Oct 2020
+ */
+ public function testFixedMultiYearDateSetThreeEmptyEndDate() {
+ unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
+
+ $this->callAPISuccess('membership_type', 'create', array(
+ 'id' => $this->_membershipTypeID2,
+ 'duration_interval' => 5,
+ // Ie. 1 Nov.
+ 'fixed_period_start_day' => '1101',
+ // Ie 1 Jan.
+ 'fixed_period_rollover_day' => '101',
+ ));
+ $this->_params['membership_type_id'] = $this->_membershipTypeID2;
+ $dates = array(
+ 'start_date' => '28-Jan 2015',
+ 'join_date' => '28-Jan 2015',
+ );
+ $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $this->assertEquals('2015-01-28', $result['join_date']);
+ $this->assertEquals('2015-01-28', $result['start_date']);
+ $this->assertEquals('2020-10-31', $result['end_date']);
+ }
+
+ /**
+ * Test correct end and start dates are calculated for fixed multi year memberships.
+ *
+ * The empty start date is calculated to be the start_date (1 Nov prior to the join_date - so 1 Nov 14)
+ *
+ * The empty start date is calculated to be the start_date (1 Nov prior to the join_date - so 1 Nov 14)
+ * In this set our join date is after the start day and after the rollover day so we do get an extra year
+ * and we end one day before the rollover day. Start day is 1 Nov so we end on 31 Oct
+ * and we add on 5 years we are after the rollover day - so we calculate 31 Oct 2020
+ */
+ public function testFixedMultiYearDateSetThreeEmptyStartEndDate() {
+ unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
+
+ $this->callAPISuccess('membership_type', 'create', array(
+ 'id' => $this->_membershipTypeID2,
+ 'duration_interval' => 5,
+ // Ie. 1 Nov.
+ 'fixed_period_start_day' => '1101',
+ // Ie 1 Jan.
+ 'fixed_period_rollover_day' => '101',
+ ));
+ $this->_params['membership_type_id'] = $this->_membershipTypeID2;
+ $dates = array(
+ 'join_date' => '28-Jan 2015',
+ );
+ $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $this->assertEquals('2015-01-28', $result['join_date']);
+ $this->assertEquals('2014-11-01', $result['start_date']);
+ $this->assertEquals('2020-10-31', $result['end_date']);
+ }
+
+ /**
+ * Test that if membership start date is not set it defaults to correct end date for fixed single year memberships.
*/
public function testEmptyStartDateRolling() {
unset($this->_params['start_date'], $this->_params['is_override']);
}
/**
- * Test that if membership end date is not set it defaults to correct end date
+ * Test that if membership end date is not set it defaults to correct end date.
* - rolling
*/
public function testEmptyEndDateFixed() {
}
/**
- * Test that if membership end date is not set it defaults to correct end date
+ * Test that if membership end date is not set it defaults to correct end date.
* - rolling
*/
public function testEmptyEndDateRolling() {