3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
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 testGetInSyntax() {
166 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
167 $this->_membershipID2
= $this->contactMembershipCreate($this->_params
);
168 $this->_membershipID3
= $this->contactMembershipCreate($this->_params
);
170 'id' => array('IN' => array($this->_membershipID
, $this->_membershipID3
)),
172 $membership = $this->callAPISuccess('membership', 'get', $params);
173 $this->assertEquals(2, $membership['count']);
174 $this->assertEquals(array($this->_membershipID
, $this->_membershipID3
), array_keys($membership['values']));
176 'id' => array('NOT IN' => array($this->_membershipID
, $this->_membershipID3
)),
178 $membership = $this->callAPISuccess('membership', 'get', $params);
179 $this->assertEquals(1, $membership['count']);
180 $this->assertEquals(array($this->_membershipID2
), array_keys($membership['values']));
185 * Test civicrm_membership_get with params not array.
186 * Gets treated as contact_id, memberships expected.
188 function testGetWithParamsMemberShipTypeId() {
189 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
191 'membership_type_id' => $this->_membershipTypeID
,
193 $membership = $this->callAPISuccess('membership', 'get', $params);
194 $result = $this->callAPISuccess('Membership', 'Delete', array(
195 'id' => $membership['id'],
197 $result = $membership['values'][$membership['id']];
198 $this->assertEquals($result['contact_id'], $this->_contactID
, "In line " . __LINE__
);
199 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID
, "In line " . __LINE__
);
200 $this->assertEquals($result['status_id'], $this->_membershipStatusID
, "In line " . __LINE__
);
201 $this->assertEquals($result['join_date'], '2009-01-21', "In line " . __LINE__
);
202 $this->assertEquals($result['start_date'], '2009-01-21', "In line " . __LINE__
);
203 $this->assertEquals($result['end_date'], '2009-12-21', "In line " . __LINE__
);
204 $this->assertEquals($result['source'], 'Payment', "In line " . __LINE__
);
205 $this->assertEquals($result['is_override'], 1, "In line " . __LINE__
);
206 $this->assertEquals($result['id'], $membership['id']);
210 * check with complete array + custom field
211 * Note that the test is written on purpose without any
212 * variables specific to participant so it can be replicated into other entities
213 * and / or moved to the automated test suite
215 function testGetWithParamsMemberShipIdAndCustom() {
216 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
218 $params = $this->_params
;
219 $params['custom_' . $ids['custom_field_id']] = "custom string";
221 $result = $this->callAPISuccess($this->_entity
, 'create', $params);
223 $getParams = array('membership_type_id' => $params['membership_type_id']);
224 $check = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
);
225 $this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
227 $result = $this->callAPISuccess('Membership', 'Delete', array(
228 'id' => $result['id'],
233 * Test civicrm_membership_get with proper params.
234 * Memberships expected.
237 $membershipID = $this->contactMembershipCreate($this->_params
);
239 'contact_id' => $this->_contactID
,
242 $membership = $this->callAPISuccess('membership', 'get', $params);
243 $result = $membership['values'][$membershipID];
244 $this->callAPISuccess('Membership', 'Delete', array(
245 'id' => $membership['id'],
247 $this->assertEquals($result['join_date'], '2009-01-21', "In line " . __LINE__
);
248 $this->assertEquals($result['contact_id'], $this->_contactID
, "In line " . __LINE__
);
249 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID
, "In line " . __LINE__
);
250 $this->assertEquals($result['status_id'], $this->_membershipStatusID
, "In line " . __LINE__
);
252 $this->assertEquals($result['start_date'], '2009-01-21', "In line " . __LINE__
);
253 $this->assertEquals($result['end_date'], '2009-12-21', "In line " . __LINE__
);
254 $this->assertEquals($result['source'], 'Payment', "In line " . __LINE__
);
255 $this->assertEquals($result['is_override'], 1, "In line " . __LINE__
);
260 * Test civicrm_membership_get with proper params.
261 * Memberships expected.
263 function testGetWithId() {
264 $membershipID = $this->contactMembershipCreate($this->_params
);
266 'contact_id' => $this->_contactID
,
267 'id' => $this->__membershipID
,
270 $result = $this->callAPISuccess('membership', 'get', $params);
271 $this->assertEquals($membershipID, $result['id']);
273 'contact_id' => $this->_contactID
,
274 'membership_id' => $this->__membershipID
,
275 'return' => 'membership_id',
277 $result = $this->callAPISuccess('membership', 'get', $params);
278 $this->assertEquals($membershipID, $result['id']);
282 * Test civicrm_membership_get for only active.
283 * Memberships expected.
285 function testGetOnlyActive() {
286 $description = "Demonstrates use of 'filter' active_only' param";
287 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
288 $subfile = 'filterIsCurrent';
290 'contact_id' => $this->_contactID
,
294 $membership = $this->callAPISuccess('membership', 'get', $params);
295 $result = $membership['values'][$this->_membershipID
];
296 $this->assertEquals($membership['values'][$this->_membershipID
]['status_id'], $this->_membershipStatusID
, "In line " . __LINE__
);
297 $this->assertEquals($membership['values'][$this->_membershipID
]['contact_id'], $this->_contactID
, "In line " . __LINE__
);
299 'contact_id' => $this->_contactID
,
305 $membership = $this->callAPIAndDocument('membership', 'get', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
306 $result = $membership['values'][$this->_membershipID
];
307 $this->assertEquals($membership['values'][$this->_membershipID
]['status_id'], $this->_membershipStatusID
, "In line " . __LINE__
);
308 $this->assertEquals($membership['values'][$this->_membershipID
]['contact_id'], $this->_contactID
, "In line " . __LINE__
);
311 $result = $this->callAPISuccess('Membership', 'Delete', array(
312 'id' => $this->_membershipID
,
317 * Test civicrm_membership_get for non exist contact.
320 function testGetNoContactExists() {
322 'contact_id' => 55555,
325 $membership = $this->callAPISuccess('membership', 'get', $params);
326 $this->assertEquals($membership['count'], 0, "In line " . __LINE__
);
330 * Test civicrm_membership_get with relationship.
333 function testGetWithRelationship() {
334 $membershipOrgId = $this->organizationCreate(NULL);
335 $memberContactId = $this->individualCreate();
337 $relTypeParams = array(
338 'name_a_b' => 'Relation 1',
339 'name_b_a' => 'Relation 2',
340 'description' => 'Testing relationship type',
341 'contact_type_a' => 'Organization',
342 'contact_type_b' => 'Individual',
346 $relTypeID = $this->relationshipTypeCreate($relTypeParams);
349 'name' => 'test General',
350 'duration_unit' => 'year',
351 'duration_interval' => 1,
352 'period_type' => 'rolling',
353 'member_of_contact_id' => $membershipOrgId,
355 'financial_type_id' => 1,
356 'relationship_type_id' => $relTypeID,
357 'relationship_direction' => 'b_a',
360 $memType = $this->callAPISuccess('membership_type', 'create', $params);
363 'contact_id' => $memberContactId,
364 'membership_type_id' => $memType['id'],
365 'join_date' => '2009-01-21',
366 'start_date' => '2009-01-21',
367 'end_date' => '2009-12-21',
368 'source' => 'Payment',
370 'status_id' => $this->_membershipStatusID
,
372 $membershipID = $this->contactMembershipCreate($params);
375 'contact_id' => $memberContactId,
376 'membership_type_id' => $memType['id'],
379 $result = $this->callAPISuccess('membership', 'get', $params);
381 $membership = $result['values'][$membershipID];
382 $this->assertEquals($this->_membershipStatusID
, $membership['status_id']);
383 $result = $this->callAPISuccess('Membership', 'Delete', array(
384 'id' => $membership['id'],
386 $this->membershipTypeDelete(array('id' => $memType['id']));
387 $this->relationshipTypeDelete($relTypeID);
388 $this->contactDelete($membershipOrgId);
389 $this->contactDelete($memberContactId);
392 ///////////////// civicrm_membership_create methods
395 * Test civicrm_contact_memberships_create with empty params.
398 function testCreateWithEmptyParams() {
400 $result = $this->callAPIFailure('membership', 'create', $params);
404 * If is_overide is passed in status must also be passed in
406 function testCreateOverrideNoStatus() {
407 $params = $this->_params
;
408 unset($params['status_id']);
409 $result = $this->callAPIFailure('membership', 'create', $params);
412 function testMembershipCreateMissingRequired() {
414 'membership_type_id' => '1',
415 'join_date' => '2006-01-21',
416 'start_date' => '2006-01-21',
417 'end_date' => '2006-12-21',
418 'source' => 'Payment',
422 $result = $this->callAPIFailure('membership', 'create', $params);
425 function testMembershipCreate() {
427 'contact_id' => $this->_contactID
,
428 'membership_type_id' => $this->_membershipTypeID
,
429 'join_date' => '2006-01-21',
430 'start_date' => '2006-01-21',
431 'end_date' => '2006-12-21',
432 'source' => 'Payment',
434 'status_id' => $this->_membershipStatusID
,
437 $result = $this->callAPIAndDocument('membership', 'create', $params, __FUNCTION__
, __FILE__
);
438 $this->getAndCheck($params, $result['id'], $this->_entity
);
439 $this->assertNotNull($result['id']);
440 $this->assertEquals($this->_contactID
, $result['values'][$result['id']]['contact_id'], " in line " . __LINE__
);
441 $this->assertEquals($result['id'], $result['values'][$result['id']]['id'], " in line " . __LINE__
);
444 * Check for useful message if contact doesn't exist
446 function testMembershipCreateWithInvalidContact() {
449 'membership_type_id' => $this->_membershipTypeID
,
450 'join_date' => '2006-01-21',
451 'start_date' => '2006-01-21',
452 'end_date' => '2006-12-21',
453 'source' => 'Payment',
455 'status_id' => $this->_membershipStatusID
,
458 $result = $this->callAPIFailure('membership', 'create', $params,
459 'contact_id is not valid : 999'
462 function testMembershipCreateWithInvalidStatus() {
463 $params = $this->_params
;
464 $params['status_id'] = 999;
465 $result = $this->callAPIFailure('membership', 'create', $params,
466 "'999' is not a valid option for field status_id"
470 function testMembershipCreateWithInvalidType() {
471 $params = $this->_params
;
472 $params['membership_type_id'] = 999;
474 $result = $this->callAPIFailure('membership', 'create', $params,
475 "'999' is not a valid option for field membership_type_id"
480 * check with complete array + custom field
481 * Note that the test is written on purpose without any
482 * variables specific to participant so it can be replicated into other entities
483 * and / or moved to the automated test suite
485 function testCreateWithCustom() {
486 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
488 $params = $this->_params
;
489 $params['custom_' . $ids['custom_field_id']] = "custom string";
491 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
492 $check = $this->callAPISuccess($this->_entity
, 'get', array('id' => $result['id'], 'contact_id' => $this->_contactID
));
493 $this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
497 * Test civicrm_contact_memberships_create with membership id (edit
501 function testMembershipCreateWithId() {
502 $membershipID = $this->contactMembershipCreate($this->_params
);
504 'id' => $membershipID,
505 'contact_id' => $this->_contactID
,
506 'membership_type_id' => $this->_membershipTypeID
,
507 'join_date' => '2006-01-21',
508 'start_date' => '2006-01-21',
509 'end_date' => '2006-12-21',
510 'source' => 'Payment',
512 'status_id' => $this->_membershipStatusID
,
515 $result = $this->callAPISuccess('membership', 'create', $params);
516 $this->callAPISuccess('Membership', 'Delete', array(
517 'id' => $result['id'],
519 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
523 * Test civicrm_contact_memberships_create with membership id (edit
527 function testMembershipCreateUpdateWithIdNoContact() {
528 $membershipID = $this->contactMembershipCreate($this->_params
);
530 'id' => $membershipID,
531 'membership_type_id' => $this->_membershipTypeID
,
532 'contact_id' => $this->_contactID
,
533 'join_date' => '2006-01-21',
534 'start_date' => '2006-01-21',
535 'end_date' => '2006-12-21',
536 'source' => 'Payment',
538 'status_id' => $this->_membershipStatusID
,
541 $result = $this->callAPISuccess('membership', 'create', $params);
542 $this->callAPISuccess('Membership', 'Delete', array(
543 'id' => $result['id'],
546 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
550 * Test civicrm_contact_memberships_create with membership id (edit
554 function testMembershipCreateUpdateWithIdNoDates() {
555 $membershipID = $this->contactMembershipCreate($this->_params
);
557 'id' => $membershipID,
558 'contact_id' => $this->_contactID
,
559 'membership_type_id' => $this->_membershipTypeID
,
560 'source' => 'Payment',
562 'status_id' => $this->_membershipStatusID
,
565 $result = $this->callAPISuccess('membership', 'create', $params);
566 $this->callAPISuccess('Membership', 'Delete', array(
567 'id' => $result['id'],
569 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
573 * Test civicrm_contact_memberships_create with membership id (edit
577 function testMembershipCreateUpdateWithIdNoDatesNoType() {
578 $membershipID = $this->contactMembershipCreate($this->_params
);
580 'id' => $membershipID,
581 'source' => 'not much here',
582 'contact_id' => $this->_contactID
,
584 'status_id' => $this->_membershipStatusID
,
587 $result = $this->callAPISuccess('membership', 'create', $params);
588 $this->callAPISuccess('Membership', 'Delete', array(
589 'id' => $result['id'],
591 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
595 * Test civicrm_contact_memberships_create with membership id (edit
599 function testMembershipCreateUpdateWithIDAndSource() {
600 $membershipID = $this->contactMembershipCreate($this->_params
);
602 'id' => $membershipID,
603 'source' => 'changed',
604 'contact_id' => $this->_contactID
,
605 'status_id' => $this->_membershipStatusID
, 'membership_type_id' => $this->_membershipTypeID
,
606 'skipStatusCal' => 1,
608 $result = $this->callAPISuccess('membership', 'create', $params);
609 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
610 $this->callAPISuccess('Membership', 'Delete', array(
611 'id' => $result['id'],
616 * change custom field using update
618 function testUpdateWithCustom() {
619 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
621 $params = $this->_params
;
622 $params['custom_' . $ids['custom_field_id']] = "custom string";
623 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
624 $result = $this->callAPISuccess($this->_entity
, 'create', array('id' => $result['id'], 'custom_' . $ids['custom_field_id'] => "new custom"));
625 $check = $this->callAPISuccess($this->_entity
, 'get', array('id' => $result['id'], 'contact_id' => $this->_contactID
));
627 $this->assertEquals("new custom", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
628 $delete = $this->callAPISuccess('Membership', 'Delete', array(
629 'id' => $check['id'],
632 $this->customFieldDelete($ids['custom_field_id']);
633 $this->customGroupDelete($ids['custom_group_id']);
637 * Test civicrm_contact_memberships_create Invalid membership data
640 function testMembershipCreateInvalidMemData() {
641 //membership_contact_id as string
643 'membership_contact_id' => 'Invalid',
644 'membership_type_id' => $this->_membershipTypeID
,
645 'join_date' => '2011-01-21',
646 'start_date' => '2010-01-21',
647 'end_date' => '2008-12-21',
648 'source' => 'Payment',
650 'status_id' => $this->_membershipStatusID
, );
652 $result = $this->callAPIFailure('membership', 'create', $params);
654 //membership_contact_id which is no in contact table
655 $params['membership_contact_id'] = 999;
656 $result = $this->callAPIFailure('membership', 'create', $params);
659 unset($params['membership_contact_id']);
660 $params['join_date'] = "invalid";
661 $result = $this->callAPIFailure('Membership', 'Create', $params);
665 * Test civicrm_contact_memberships_create with membership_contact_id
669 function testMembershipCreateWithMemContact() {
671 'membership_contact_id' => $this->_contactID
,
672 'membership_type_id' => $this->_membershipTypeID
,
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);
683 $result = $this->callAPISuccess('Membership', 'Delete', array(
684 'id' => $result['id'],
688 * Test civicrm_contact_memberships_create with membership_contact_id
692 function testMembershipCreateValidMembershipTypeString() {
694 'membership_contact_id' => $this->_contactID
,
695 'membership_type_id' => 'General',
696 'join_date' => '2011-01-21',
697 'start_date' => '2010-01-21',
698 'end_date' => '2008-12-21',
699 'source' => 'Payment',
701 'status_id' => $this->_membershipStatusID
,
704 $result = $this->callAPISuccess('membership', 'create', $params);
705 $this->assertEquals($this->_membershipTypeID
, $result['values'][$result['id']]['membership_type_id']);
706 $result = $this->callAPISuccess('Membership', 'Delete', array(
707 'id' => $result['id'],
712 * Test civicrm_contact_memberships_create with membership_contact_id
716 function testMembershipCreateInValidMembershipTypeString() {
718 'membership_contact_id' => $this->_contactID
,
719 'membership_type_id' => 'invalid',
720 'join_date' => '2011-01-21',
721 'start_date' => '2010-01-21',
722 'end_date' => '2008-12-21',
723 'source' => 'Payment',
725 'status_id' => $this->_membershipStatusID
,
728 $result = $this->callAPIFailure('membership', 'create', $params);
732 * Test that if membership join date is not set it defaults to today
734 function testEmptyJoinDate() {
735 unset($this->_params
['join_date'], $this->_params
['is_override']);
736 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
737 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
738 $this->assertEquals(date('Y-m-d', strtotime('now')), $result['join_date']);
739 $this->assertEquals('2009-01-21', $result['start_date']);
740 $this->assertEquals('2009-12-21', $result['end_date']);
743 * Test that if membership start date is not set it defaults to correct end date
746 function testEmptyStartDateFixed() {
747 unset($this->_params
['start_date'], $this->_params
['is_override']);
748 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
749 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
750 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
751 $this->assertEquals('2009-01-21', $result['join_date']);
752 $this->assertEquals('2008-03-01', $result['start_date']);
753 $this->assertEquals('2009-12-21', $result['end_date']);
757 * Test that if membership start date is not set it defaults to correct end date
760 function testEmptyStartDateRolling() {
761 unset($this->_params
['start_date'], $this->_params
['is_override']);
762 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
763 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
764 $this->assertEquals('2009-01-21', $result['join_date']);
765 $this->assertEquals('2009-01-21', $result['start_date']);
766 $this->assertEquals('2009-12-21', $result['end_date']);
769 * Test that if membership end date is not set it defaults to correct end date
772 function testEmptyEndDateFixed() {
773 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
774 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
775 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
776 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
777 $this->assertEquals('2009-01-21', $result['join_date']);
778 $this->assertEquals('2008-03-01', $result['start_date']);
779 $this->assertEquals('2010-02-28', $result['end_date']);
782 * Test that if membership end date is not set it defaults to correct end date
785 function testEmptyEndDateRolling() {
786 unset($this->_params
['is_override'], $this->_params
['end_date']);
787 $this->_params
['membership_type_id'] = $this->_membershipTypeID
;
788 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
789 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
790 $this->assertEquals('2009-01-21', $result['join_date']);
791 $this->assertEquals('2009-01-21', $result['start_date']);
792 $this->assertEquals('2010-01-20', $result['end_date']);
797 * Test that if datesdate are not set they not over-ridden if id is passed in
799 function testMembershipDatesNotOverridden() {
800 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
801 unset($this->_params
['end_date'], $this->_params
['start_date']);
802 $this->_params
['id'] = $result['id'];
803 $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
804 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
805 $this->assertEquals('2009-01-21', $result['join_date']);
806 $this->assertEquals('2009-01-21', $result['start_date']);
807 $this->assertEquals('2009-12-21', $result['end_date']);