3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Test APIv3 civicrm_membership functions
31 * @package CiviCRM_APIv3
32 * @subpackage API_Member
36 require_once 'CiviTest/CiviUnitTestCase.php';
38 class api_v3_MembershipTest
extends CiviUnitTestCase
{
39 protected $_apiversion;
40 protected $_contactID;
41 protected $_membershipTypeID;
42 protected $_membershipTypeID2;
43 protected $_membershipStatusID;
44 protected $__membershipID;
47 public $_eNoticeCompliant = TRUE;
49 public function setUp() {
50 // Connect to the database
52 $this->_apiversion
= 3;
53 $this->_contactID
= $this->individualCreate();
54 $this->_membershipTypeID
= $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID
));
55 $this->_membershipTypeID2
= $this->membershipTypeCreate(array('period_type' => 'fixed','fixed_period_start_day' => '301', 'fixed_period_rollover_day' => '1111'));
56 $this->_membershipStatusID
= $this->membershipStatusCreate('test status');
58 CRM_Member_PseudoConstant
::membershipType(NULL, TRUE);
59 CRM_Member_PseudoConstant
::membershipStatus(NULL, NULL, 'name', TRUE);
60 CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name');
62 $this->_entity
= 'Membership';
63 $this->_params
= array(
64 'contact_id' => $this->_contactID
,
65 'membership_type_id' => $this->_membershipTypeID
,
66 'join_date' => '2009-01-21',
67 'start_date' => '2009-01-21',
68 'end_date' => '2009-12-21',
69 'source' => 'Payment',
71 'status_id' => $this->_membershipStatusID
,
76 $this->quickCleanup(array(
78 'civicrm_membership_payment',
79 'civicrm_membership_log',
83 $this->membershipStatusDelete($this->_membershipStatusID
);
84 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID2
));
85 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID
));
86 $this->contactDelete($this->_contactID
);
91 * Test civicrm_membership_delete()
93 function testMembershipDelete() {
94 $membershipID = $this->contactMembershipCreate($this->_params
);
95 $this->assertDBRowExist('CRM_Member_DAO_Membership', $membershipID);
99 $result = $this->callAPIAndDocument('membership', 'delete', $params, __FUNCTION__
, __FILE__
);
100 $this->assertDBRowNotExist('CRM_Member_DAO_Membership', $membershipID);
103 function testMembershipDeleteEmpty() {
105 $result = $this->callAPIFailure('membership', 'delete', $params);
108 function testMembershipDeleteInvalidID() {
109 $params = array('id' => 'blah');
110 $result = $this->callAPIFailure('membership', 'delete', $params);
114 * Test civicrm_membership_delete() with invalid Membership Id
116 function testMembershipDeleteWithInvalidMembershipId() {
117 $membershipId = 'membership';
118 $result = $this->callAPIFailure('membership', 'delete', $membershipId);
122 * All other methods calls MembershipType and MembershipContact
123 * api, but putting simple test methods to control existence of
124 * these methods for backwards compatibility, also verifying basic
125 * behaviour is the same as new methods.
127 function testContactMembershipsGet() {
128 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
130 $result = $this->callAPISuccess('membership', 'get', $params);
131 $result = $this->callAPISuccess('Membership', 'Delete', array(
132 'id' => $this->_membershipID
,
137 * Test civicrm_membership_get with params not array.
138 * Gets treated as contact_id, memberships expected.
140 function testGetWithParamsContactId() {
141 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
143 'contact_id' => $this->_contactID
,
145 $membership = $this->callAPISuccess('membership', 'get', $params);
147 $result = $membership['values'][$this->_membershipID
];
148 $this->callAPISuccess('Membership', 'Delete', array(
149 'id' => $this->_membershipID
,
151 $this->assertEquals($result['contact_id'], $this->_contactID
, "In line " . __LINE__
);
152 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID
, "In line " . __LINE__
);
153 $this->assertEquals($result['status_id'], $this->_membershipStatusID
, "In line " . __LINE__
);
154 $this->assertEquals($result['join_date'], '2009-01-21', "In line " . __LINE__
);
155 $this->assertEquals($result['start_date'], '2009-01-21', "In line " . __LINE__
);
156 $this->assertEquals($result['end_date'], '2009-12-21', "In line " . __LINE__
);
157 $this->assertEquals($result['source'], 'Payment', "In line " . __LINE__
);
158 $this->assertEquals($result['is_override'], 1, "In line " . __LINE__
);
162 * Test civicrm_membership_get with params not array.
163 * Gets treated as contact_id, memberships expected.
165 function testGetWithParamsMemberShipTypeId() {
166 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
168 'membership_type_id' => $this->_membershipTypeID
,
170 $membership = $this->callAPISuccess('membership', 'get', $params);
171 $result = $this->callAPISuccess('Membership', 'Delete', array(
172 'id' => $membership['id'],
174 $result = $membership['values'][$membership['id']];
175 $this->assertEquals($result['contact_id'], $this->_contactID
, "In line " . __LINE__
);
176 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID
, "In line " . __LINE__
);
177 $this->assertEquals($result['status_id'], $this->_membershipStatusID
, "In line " . __LINE__
);
178 $this->assertEquals($result['join_date'], '2009-01-21', "In line " . __LINE__
);
179 $this->assertEquals($result['start_date'], '2009-01-21', "In line " . __LINE__
);
180 $this->assertEquals($result['end_date'], '2009-12-21', "In line " . __LINE__
);
181 $this->assertEquals($result['source'], 'Payment', "In line " . __LINE__
);
182 $this->assertEquals($result['is_override'], 1, "In line " . __LINE__
);
183 $this->assertEquals($result['id'], $membership['id']);
187 * check with complete array + custom field
188 * Note that the test is written on purpose without any
189 * variables specific to participant so it can be replicated into other entities
190 * and / or moved to the automated test suite
192 function testGetWithParamsMemberShipIdAndCustom() {
193 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
195 $params = $this->_params
;
196 $params['custom_' . $ids['custom_field_id']] = "custom string";
198 $result = $this->callAPISuccess($this->_entity
, 'create', $params);
200 $getParams = array('membership_type_id' => $params['membership_type_id']);
201 $check = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
);
202 $this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
204 $result = $this->callAPISuccess('Membership', 'Delete', array(
205 'id' => $result['id'],
210 * Test civicrm_membership_get with proper params.
211 * Memberships expected.
214 $membershipID = $this->contactMembershipCreate($this->_params
);
216 'contact_id' => $this->_contactID
,
219 $membership = $this->callAPISuccess('membership', 'get', $params);
220 $result = $membership['values'][$membershipID];
221 $this->callAPISuccess('Membership', 'Delete', array(
222 'id' => $membership['id'],
224 $this->assertEquals($result['join_date'], '2009-01-21', "In line " . __LINE__
);
225 $this->assertEquals($result['contact_id'], $this->_contactID
, "In line " . __LINE__
);
226 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID
, "In line " . __LINE__
);
227 $this->assertEquals($result['status_id'], $this->_membershipStatusID
, "In line " . __LINE__
);
229 $this->assertEquals($result['start_date'], '2009-01-21', "In line " . __LINE__
);
230 $this->assertEquals($result['end_date'], '2009-12-21', "In line " . __LINE__
);
231 $this->assertEquals($result['source'], 'Payment', "In line " . __LINE__
);
232 $this->assertEquals($result['is_override'], 1, "In line " . __LINE__
);
237 * Test civicrm_membership_get with proper params.
238 * Memberships expected.
240 function testGetWithId() {
241 $membershipID = $this->contactMembershipCreate($this->_params
);
243 'contact_id' => $this->_contactID
,
244 'id' => $this->__membershipID
,
247 $result = $this->callAPISuccess('membership', 'get', $params);
248 $this->assertEquals($membershipID, $result['id']);
250 'contact_id' => $this->_contactID
,
251 'membership_id' => $this->__membershipID
,
252 'return' => 'membership_id',
254 $result = $this->callAPISuccess('membership', 'get', $params);
255 $this->assertEquals($membershipID, $result['id']);
259 * Test civicrm_membership_get for only active.
260 * Memberships expected.
262 function testGetOnlyActive() {
263 $description = "Demonstrates use of 'filter' active_only' param";
264 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
265 $subfile = 'filterIsCurrent';
267 'contact_id' => $this->_contactID
,
271 $membership = $this->callAPISuccess('membership', 'get', $params);
272 $result = $membership['values'][$this->_membershipID
];
273 $this->assertEquals($membership['values'][$this->_membershipID
]['status_id'], $this->_membershipStatusID
, "In line " . __LINE__
);
274 $this->assertEquals($membership['values'][$this->_membershipID
]['contact_id'], $this->_contactID
, "In line " . __LINE__
);
276 'contact_id' => $this->_contactID
,
282 $membership = $this->callAPIAndDocument('membership', 'get', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
283 $result = $membership['values'][$this->_membershipID
];
284 $this->assertEquals($membership['values'][$this->_membershipID
]['status_id'], $this->_membershipStatusID
, "In line " . __LINE__
);
285 $this->assertEquals($membership['values'][$this->_membershipID
]['contact_id'], $this->_contactID
, "In line " . __LINE__
);
288 $result = $this->callAPISuccess('Membership', 'Delete', array(
289 'id' => $this->_membershipID
,
294 * Test civicrm_membership_get for non exist contact.
297 function testGetNoContactExists() {
299 'contact_id' => 55555,
302 $membership = $this->callAPISuccess('membership', 'get', $params);
303 $this->assertEquals($membership['count'], 0, "In line " . __LINE__
);
307 * Test civicrm_membership_get with relationship.
310 function testGetWithRelationship() {
311 $membershipOrgId = $this->organizationCreate(NULL);
312 $memberContactId = $this->individualCreate();
314 $relTypeParams = array(
315 'name_a_b' => 'Relation 1',
316 'name_b_a' => 'Relation 2',
317 'description' => 'Testing relationship type',
318 'contact_type_a' => 'Organization',
319 'contact_type_b' => 'Individual',
323 $relTypeID = $this->relationshipTypeCreate($relTypeParams);
326 'name' => 'test General',
327 'duration_unit' => 'year',
328 'duration_interval' => 1,
329 'period_type' => 'rolling',
330 'member_of_contact_id' => $membershipOrgId,
332 'financial_type_id' => 1,
333 'relationship_type_id' => $relTypeID,
334 'relationship_direction' => 'b_a',
337 $memType = $this->callAPISuccess('membership_type', 'create', $params);
340 'contact_id' => $memberContactId,
341 'membership_type_id' => $memType['id'],
342 'join_date' => '2009-01-21',
343 'start_date' => '2009-01-21',
344 'end_date' => '2009-12-21',
345 'source' => 'Payment',
347 'status_id' => $this->_membershipStatusID
,
349 $membershipID = $this->contactMembershipCreate($params);
352 'contact_id' => $memberContactId,
353 'membership_type_id' => $memType['id'],
356 $result = $this->callAPISuccess('membership', 'get', $params);
358 $membership = $result['values'][$membershipID];
359 $this->assertEquals($this->_membershipStatusID
, $membership['status_id']);
360 $result = $this->callAPISuccess('Membership', 'Delete', array(
361 'id' => $membership['id'],
363 $this->membershipTypeDelete(array('id' => $memType['id']));
364 $this->relationshipTypeDelete($relTypeID);
365 $this->contactDelete($membershipOrgId);
366 $this->contactDelete($memberContactId);
369 ///////////////// civicrm_membership_create methods
372 * Test civicrm_contact_memberships_create with empty params.
375 function testCreateWithEmptyParams() {
377 $result = $this->callAPIFailure('membership', 'create', $params);
381 * If is_overide is passed in status must also be passed in
383 function testCreateOverrideNoStatus() {
384 $params = $this->_params
;
385 unset($params['status_id']);
386 $result = $this->callAPIFailure('membership', 'create', $params);
389 function testMembershipCreateMissingRequired() {
391 'membership_type_id' => '1',
392 'join_date' => '2006-01-21',
393 'start_date' => '2006-01-21',
394 'end_date' => '2006-12-21',
395 'source' => 'Payment',
399 $result = $this->callAPIFailure('membership', 'create', $params);
402 function testMembershipCreate() {
404 'contact_id' => $this->_contactID
,
405 'membership_type_id' => $this->_membershipTypeID
,
406 'join_date' => '2006-01-21',
407 'start_date' => '2006-01-21',
408 'end_date' => '2006-12-21',
409 'source' => 'Payment',
411 'status_id' => $this->_membershipStatusID
,
414 $result = $this->callAPIAndDocument('membership', 'create', $params, __FUNCTION__
, __FILE__
);
415 $this->getAndCheck($params, $result['id'], $this->_entity
);
416 $this->assertNotNull($result['id']);
417 $this->assertEquals($this->_contactID
, $result['values'][$result['id']]['contact_id'], " in line " . __LINE__
);
418 $this->assertEquals($result['id'], $result['values'][$result['id']]['id'], " in line " . __LINE__
);
421 * Check for useful message if contact doesn't exist
423 function testMembershipCreateWithInvalidContact() {
426 'membership_type_id' => $this->_membershipTypeID
,
427 'join_date' => '2006-01-21',
428 'start_date' => '2006-01-21',
429 'end_date' => '2006-12-21',
430 'source' => 'Payment',
432 'status_id' => $this->_membershipStatusID
,
435 $result = $this->callAPIFailure('membership', 'create', $params,
436 'contact_id is not valid : 999'
439 function testMembershipCreateWithInvalidStatus() {
440 $params = $this->_params
;
441 $params['status_id'] = 999;
442 $result = $this->callAPIFailure('membership', 'create', $params,
443 "'999' is not a valid option for field status_id"
447 function testMembershipCreateWithInvalidType() {
448 $params = $this->_params
;
449 $params['membership_type_id'] = 999;
451 $result = $this->callAPIFailure('membership', 'create', $params,
452 "'999' is not a valid option for field membership_type_id"
457 * check with complete array + custom field
458 * Note that the test is written on purpose without any
459 * variables specific to participant so it can be replicated into other entities
460 * and / or moved to the automated test suite
462 function testCreateWithCustom() {
463 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
465 $params = $this->_params
;
466 $params['custom_' . $ids['custom_field_id']] = "custom string";
468 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
469 $check = $this->callAPISuccess($this->_entity
, 'get', array('id' => $result['id'], 'contact_id' => $this->_contactID
));
470 $this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
474 * Test civicrm_contact_memberships_create with membership id (edit
478 function testMembershipCreateWithId() {
479 $membershipID = $this->contactMembershipCreate($this->_params
);
481 'id' => $membershipID,
482 'contact_id' => $this->_contactID
,
483 'membership_type_id' => $this->_membershipTypeID
,
484 'join_date' => '2006-01-21',
485 'start_date' => '2006-01-21',
486 'end_date' => '2006-12-21',
487 'source' => 'Payment',
489 'status_id' => $this->_membershipStatusID
,
492 $result = $this->callAPISuccess('membership', 'create', $params);
493 $this->callAPISuccess('Membership', 'Delete', array(
494 'id' => $result['id'],
496 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
500 * Test civicrm_contact_memberships_create with membership id (edit
504 function testMembershipCreateUpdateWithIdNoContact() {
505 $membershipID = $this->contactMembershipCreate($this->_params
);
507 'id' => $membershipID,
508 'membership_type_id' => $this->_membershipTypeID
,
509 'contact_id' => $this->_contactID
,
510 'join_date' => '2006-01-21',
511 'start_date' => '2006-01-21',
512 'end_date' => '2006-12-21',
513 'source' => 'Payment',
515 'status_id' => $this->_membershipStatusID
,
518 $result = $this->callAPISuccess('membership', 'create', $params);
519 $this->callAPISuccess('Membership', 'Delete', array(
520 'id' => $result['id'],
523 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
527 * Test civicrm_contact_memberships_create with membership id (edit
531 function testMembershipCreateUpdateWithIdNoDates() {
532 $membershipID = $this->contactMembershipCreate($this->_params
);
534 'id' => $membershipID,
535 'contact_id' => $this->_contactID
,
536 'membership_type_id' => $this->_membershipTypeID
,
537 'source' => 'Payment',
539 'status_id' => $this->_membershipStatusID
,
542 $result = $this->callAPISuccess('membership', 'create', $params);
543 $this->callAPISuccess('Membership', 'Delete', array(
544 'id' => $result['id'],
546 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
550 * Test civicrm_contact_memberships_create with membership id (edit
554 function testMembershipCreateUpdateWithIdNoDatesNoType() {
555 $membershipID = $this->contactMembershipCreate($this->_params
);
557 'id' => $membershipID,
558 'source' => 'not much here',
559 'contact_id' => $this->_contactID
,
561 'status_id' => $this->_membershipStatusID
,
564 $result = $this->callAPISuccess('membership', 'create', $params);
565 $this->callAPISuccess('Membership', 'Delete', array(
566 'id' => $result['id'],
568 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
572 * Test civicrm_contact_memberships_create with membership id (edit
576 function testMembershipCreateUpdateWithIDAndSource() {
577 $membershipID = $this->contactMembershipCreate($this->_params
);
579 'id' => $membershipID,
580 'source' => 'changed',
581 'contact_id' => $this->_contactID
,
582 'status_id' => $this->_membershipStatusID
, 'membership_type_id' => $this->_membershipTypeID
,
583 'skipStatusCal' => 1,
585 $result = $this->callAPISuccess('membership', 'create', $params);
586 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
587 $this->callAPISuccess('Membership', 'Delete', array(
588 'id' => $result['id'],
593 * change custom field using update
595 function testUpdateWithCustom() {
596 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
598 $params = $this->_params
;
599 $params['custom_' . $ids['custom_field_id']] = "custom string";
600 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
601 $result = $this->callAPISuccess($this->_entity
, 'create', array('id' => $result['id'], 'custom_' . $ids['custom_field_id'] => "new custom"));
602 $check = $this->callAPISuccess($this->_entity
, 'get', array('id' => $result['id'], 'contact_id' => $this->_contactID
));
604 $this->assertEquals("new custom", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
605 $delete = $this->callAPISuccess('Membership', 'Delete', array(
606 'id' => $check['id'],
609 $this->customFieldDelete($ids['custom_field_id']);
610 $this->customGroupDelete($ids['custom_group_id']);
614 * Test civicrm_contact_memberships_create Invalid membership data
617 function testMembershipCreateInvalidMemData() {
618 //membership_contact_id as string
620 'membership_contact_id' => 'Invalid',
621 'membership_type_id' => $this->_membershipTypeID
,
622 'join_date' => '2011-01-21',
623 'start_date' => '2010-01-21',
624 'end_date' => '2008-12-21',
625 'source' => 'Payment',
627 'status_id' => $this->_membershipStatusID
, );
629 $result = $this->callAPIFailure('membership', 'create', $params);
631 //membership_contact_id which is no in contact table
632 $params['membership_contact_id'] = 999;
633 $result = $this->callAPIFailure('membership', 'create', $params);
636 unset($params['membership_contact_id']);
637 $params['join_date'] = "invalid";
638 $result = $this->callAPIFailure('Membership', 'Create', $params);
642 * Test civicrm_contact_memberships_create with membership_contact_id
646 function testMembershipCreateWithMemContact() {
648 'membership_contact_id' => $this->_contactID
,
649 'membership_type_id' => $this->_membershipTypeID
,
650 'join_date' => '2011-01-21',
651 'start_date' => '2010-01-21',
652 'end_date' => '2008-12-21',
653 'source' => 'Payment',
655 'status_id' => $this->_membershipStatusID
,
658 $result = $this->callAPISuccess('membership', 'create', $params);
660 $result = $this->callAPISuccess('Membership', 'Delete', array(
661 'id' => $result['id'],
665 * Test civicrm_contact_memberships_create with membership_contact_id
669 function testMembershipCreateValidMembershipTypeString() {
671 'membership_contact_id' => $this->_contactID
,
672 'membership_type_id' => 'General',
673 'join_date' => '2011-01-21',
674 'start_date' => '2010-01-21',
675 'end_date' => '2008-12-21',
676 'source' => 'Payment',
678 'status_id' => $this->_membershipStatusID
,
681 $result = $this->callAPISuccess('membership', 'create', $params);
682 $this->assertEquals($this->_membershipTypeID
, $result['values'][$result['id']]['membership_type_id']);
683 $result = $this->callAPISuccess('Membership', 'Delete', array(
684 'id' => $result['id'],
689 * Test civicrm_contact_memberships_create with membership_contact_id
693 function testMembershipCreateInValidMembershipTypeString() {
695 'membership_contact_id' => $this->_contactID
,
696 'membership_type_id' => 'invalid',
697 'join_date' => '2011-01-21',
698 'start_date' => '2010-01-21',
699 'end_date' => '2008-12-21',
700 'source' => 'Payment',
702 'status_id' => $this->_membershipStatusID
,
705 $result = $this->callAPIFailure('membership', 'create', $params);
709 * Test that if membership join date is not set it defaults to today
711 function testEmptyJoinDate() {
712 unset($this->_params
['join_date'], $this->_params
['is_override']);
713 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
714 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
715 $this->assertEquals(date('Y-m-d', strtotime('now')), $result['join_date']);
716 $this->assertEquals('2009-01-21', $result['start_date']);
717 $this->assertEquals('2009-12-21', $result['end_date']);
720 * Test that if membership start date is not set it defaults to correct end date
723 function testEmptyStartDateFixed() {
724 unset($this->_params
['start_date'], $this->_params
['is_override']);
725 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
726 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
727 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
728 $this->assertEquals('2009-01-21', $result['join_date']);
729 $this->assertEquals('2008-03-01', $result['start_date']);
730 $this->assertEquals('2009-12-21', $result['end_date']);
734 * Test that if membership start date is not set it defaults to correct end date
737 function testEmptyStartDateRolling() {
738 unset($this->_params
['start_date'], $this->_params
['is_override']);
739 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
740 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
741 $this->assertEquals('2009-01-21', $result['join_date']);
742 $this->assertEquals('2009-01-21', $result['start_date']);
743 $this->assertEquals('2009-12-21', $result['end_date']);
746 * Test that if membership end date is not set it defaults to correct end date
749 function testEmptyEndDateFixed() {
750 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
751 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
752 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
753 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
754 $this->assertEquals('2009-01-21', $result['join_date']);
755 $this->assertEquals('2008-03-01', $result['start_date']);
756 $this->assertEquals('2010-02-28', $result['end_date']);
759 * Test that if membership end date is not set it defaults to correct end date
762 function testEmptyEndDateRolling() {
763 unset($this->_params
['is_override'], $this->_params
['end_date']);
764 $this->_params
['membership_type_id'] = $this->_membershipTypeID
;
765 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
766 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
767 $this->assertEquals('2009-01-21', $result['join_date']);
768 $this->assertEquals('2009-01-21', $result['start_date']);
769 $this->assertEquals('2010-01-20', $result['end_date']);
774 * Test that if datesdate are not set they not over-ridden if id is passed in
776 function testMembershipDatesNotOverridden() {
777 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
778 unset($this->_params
['end_date'], $this->_params
['start_date']);
779 $this->_params
['id'] = $result['id'];
780 $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
781 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
782 $this->assertEquals('2009-01-21', $result['join_date']);
783 $this->assertEquals('2009-01-21', $result['start_date']);
784 $this->assertEquals('2009-12-21', $result['end_date']);