3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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';
39 * Class api_v3_MembershipTest
41 class api_v3_MembershipTest
extends CiviUnitTestCase
{
42 protected $_apiversion;
43 protected $_contactID;
44 protected $_membershipID;
45 protected $_membershipID2;
46 protected $_membershipID3;
47 protected $_membershipTypeID;
48 protected $_membershipTypeID2;
49 protected $_membershipStatusID;
54 public function setUp() {
55 // Connect to the database.
57 $this->_apiversion
= 3;
58 $this->_contactID
= $this->individualCreate();
59 $this->_membershipTypeID
= $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID
));
60 $this->_membershipTypeID2
= $this->membershipTypeCreate(array(
61 'period_type' => 'fixed',
63 'fixed_period_start_day' => '301',
65 'fixed_period_rollover_day' => '1111',
67 $this->_membershipStatusID
= $this->membershipStatusCreate('test status');
69 CRM_Member_PseudoConstant
::membershipType(NULL, TRUE);
70 CRM_Member_PseudoConstant
::membershipStatus(NULL, NULL, 'name', TRUE);
71 CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name');
73 $this->_entity
= 'Membership';
74 $this->_params
= array(
75 'contact_id' => $this->_contactID
,
76 'membership_type_id' => $this->_membershipTypeID
,
77 'join_date' => '2009-01-21',
78 'start_date' => '2009-01-21',
79 'end_date' => '2009-12-21',
80 'source' => 'Payment',
82 'status_id' => $this->_membershipStatusID
,
86 public function tearDown() {
87 $this->quickCleanup(array(
89 'civicrm_membership_payment',
90 'civicrm_membership_log',
94 $this->membershipStatusDelete($this->_membershipStatusID
);
95 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID2
));
96 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID
));
97 $this->contactDelete($this->_contactID
);
102 * Test membership deletion.
104 public function testMembershipDelete() {
105 $membershipID = $this->contactMembershipCreate($this->_params
);
106 $this->assertDBRowExist('CRM_Member_DAO_Membership', $membershipID);
108 'id' => $membershipID,
110 $this->callAPIAndDocument('membership', 'delete', $params, __FUNCTION__
, __FILE__
);
111 $this->assertDBRowNotExist('CRM_Member_DAO_Membership', $membershipID);
114 public function testMembershipDeleteEmpty() {
115 $this->callAPIFailure('membership', 'delete', array());
118 public function testMembershipDeleteInvalidID() {
119 $this->callAPIFailure('membership', 'delete', array('id' => 'blah'));
123 * Test civicrm_membership_delete() with invalid Membership Id.
125 public function testMembershipDeleteWithInvalidMembershipId() {
126 $membershipId = 'membership';
127 $this->callAPIFailure('membership', 'delete', $membershipId);
131 * Test membership get.
133 public function testContactMembershipsGet() {
134 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
135 $this->callAPISuccess('membership', 'get', array());
136 $this->callAPISuccess('Membership', 'Delete', array('id' => $this->_membershipID
));
140 * Test civicrm_membership_get with params not array.
142 * Gets treated as contact_id, memberships expected.
144 public function testGetWithParamsContactId() {
145 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
147 'contact_id' => $this->_contactID
,
149 $membership = $this->callAPISuccess('membership', 'get', $params);
151 $result = $membership['values'][$this->_membershipID
];
152 $this->callAPISuccess('Membership', 'Delete', array(
153 'id' => $this->_membershipID
,
155 $this->assertEquals($result['contact_id'], $this->_contactID
, "In line " . __LINE__
);
156 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID
, "In line " . __LINE__
);
157 $this->assertEquals($result['status_id'], $this->_membershipStatusID
, "In line " . __LINE__
);
158 $this->assertEquals($result['join_date'], '2009-01-21', "In line " . __LINE__
);
159 $this->assertEquals($result['start_date'], '2009-01-21', "In line " . __LINE__
);
160 $this->assertEquals($result['end_date'], '2009-12-21', "In line " . __LINE__
);
161 $this->assertEquals($result['source'], 'Payment', "In line " . __LINE__
);
162 $this->assertEquals($result['is_override'], 1, "In line " . __LINE__
);
166 * Test civicrm_membership_get with params not array.
168 * Gets treated as contact_id, memberships expected.
170 public function testGetInSyntax() {
171 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
172 $this->_membershipID2
= $this->contactMembershipCreate($this->_params
);
173 $this->_membershipID3
= $this->contactMembershipCreate($this->_params
);
175 'id' => array('IN' => array($this->_membershipID
, $this->_membershipID3
)),
177 $membership = $this->callAPISuccess('membership', 'get', $params);
178 $this->assertEquals(2, $membership['count']);
179 $this->assertEquals(array($this->_membershipID
, $this->_membershipID3
), array_keys($membership['values']));
181 'id' => array('NOT IN' => array($this->_membershipID
, $this->_membershipID3
)),
183 $membership = $this->callAPISuccess('membership', 'get', $params);
184 $this->assertEquals(1, $membership['count']);
185 $this->assertEquals(array($this->_membershipID2
), array_keys($membership['values']));
189 * Test civicrm_membership_get with params not array.
190 * Gets treated as contact_id, memberships expected.
192 public function testGetInSyntaxOnContactID() {
193 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
194 $contact2 = $this->individualCreate();
195 $contact3 = $this->individualCreate(array('first_name' => 'Scout', 'last_name' => 'Canine'));
196 $this->_membershipID2
= $this->contactMembershipCreate(array_merge($this->_params
, array('contact_id' => $contact2)));
197 $this->_membershipID3
= $this->contactMembershipCreate(array_merge($this->_params
, array('contact_id' => $contact3)));
199 'contact_id' => array('IN' => array($this->_contactID
, $contact3)),
201 $membership = $this->callAPISuccess('membership', 'get', $params);
202 $this->assertEquals(2, $membership['count']);
203 $this->assertEquals(array($this->_membershipID
, $this->_membershipID3
), array_keys($membership['values']));
205 'contact_id' => array('NOT IN' => array($this->_contactID
, $contact3)),
207 $membership = $this->callAPISuccess('membership', 'get', $params);
208 $this->assertEquals(1, $membership['count']);
209 $this->assertEquals(array($this->_membershipID2
), array_keys($membership['values']));
213 * Test civicrm_membership_get with params not array.
214 * Gets treated as contact_id, memberships expected.
216 public function testGetWithParamsMemberShipTypeId() {
217 $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
219 'membership_type_id' => $this->_membershipTypeID
,
221 $membership = $this->callAPISuccess('membership', 'get', $params);
222 $this->callAPISuccess('Membership', 'Delete', array(
223 'id' => $membership['id'],
225 $result = $membership['values'][$membership['id']];
226 $this->assertEquals($result['contact_id'], $this->_contactID
, "In line " . __LINE__
);
227 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID
, "In line " . __LINE__
);
228 $this->assertEquals($result['status_id'], $this->_membershipStatusID
, "In line " . __LINE__
);
229 $this->assertEquals($result['join_date'], '2009-01-21', "In line " . __LINE__
);
230 $this->assertEquals($result['start_date'], '2009-01-21', "In line " . __LINE__
);
231 $this->assertEquals($result['end_date'], '2009-12-21', "In line " . __LINE__
);
232 $this->assertEquals($result['source'], 'Payment', "In line " . __LINE__
);
233 $this->assertEquals($result['is_override'], 1, "In line " . __LINE__
);
234 $this->assertEquals($result['id'], $membership['id']);
238 * Test civicrm_membership_get with params not array.
239 * Gets treated as contact_id, memberships expected.
241 public function testGetWithParamsMemberShipTypeIdContactID() {
242 $params = $this->_params
;
243 $this->callAPISuccess($this->_entity
, 'create', $params);
244 $params['membership_type_id'] = $this->_membershipTypeID2
;
245 $this->callAPISuccess($this->_entity
, 'create', $params);
246 $this->callAPISuccessGetCount('membership', array('contact_id' => $this->_contactID
), 2);
248 'membership_type_id' => $this->_membershipTypeID
,
249 'contact_id' => $this->_contactID
,
251 $result = $this->callAPISuccess('membership', 'getsingle', $params);
252 $this->assertEquals($result['contact_id'], $this->_contactID
);
253 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID
);
256 'membership_type_id' => $this->_membershipTypeID2
,
257 'contact_id' => $this->_contactID
,
259 $result = $this->callAPISuccess('membership', 'getsingle', $params);
260 $this->assertEquals($result['contact_id'], $this->_contactID
);
261 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID2
);
265 * Check with complete array + custom field
266 * Note that the test is written on purpose without any
267 * variables specific to participant so it can be replicated into other entities
268 * and / or moved to the automated test suite
270 public function testGetWithParamsMemberShipIdAndCustom() {
271 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
273 $params = $this->_params
;
274 $params['custom_' . $ids['custom_field_id']] = "custom string";
276 $result = $this->callAPISuccess($this->_entity
, 'create', $params);
278 $getParams = array('membership_type_id' => $params['membership_type_id']);
279 $check = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
);
280 $this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
282 $this->callAPISuccess('Membership', 'Delete', array(
283 'id' => $result['id'],
288 * Test civicrm_membership_get with proper params.
289 * Memberships expected.
291 public function testGet() {
292 $membershipID = $this->contactMembershipCreate($this->_params
);
294 'contact_id' => $this->_contactID
,
297 $membership = $this->callAPISuccess('membership', 'get', $params);
298 $result = $membership['values'][$membershipID];
299 $this->callAPISuccess('Membership', 'Delete', array(
300 'id' => $membership['id'],
302 $this->assertEquals($result['join_date'], '2009-01-21', "In line " . __LINE__
);
303 $this->assertEquals($result['contact_id'], $this->_contactID
, "In line " . __LINE__
);
304 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID
, "In line " . __LINE__
);
305 $this->assertEquals($result['status_id'], $this->_membershipStatusID
, "In line " . __LINE__
);
307 $this->assertEquals($result['start_date'], '2009-01-21', "In line " . __LINE__
);
308 $this->assertEquals($result['end_date'], '2009-12-21', "In line " . __LINE__
);
309 $this->assertEquals($result['source'], 'Payment', "In line " . __LINE__
);
310 $this->assertEquals($result['is_override'], 1, "In line " . __LINE__
);
315 * Test civicrm_membership_get with proper params.
316 * Memberships expected.
318 public function testGetWithId() {
319 $membershipID = $this->contactMembershipCreate($this->_params
);
321 'contact_id' => $this->_contactID
,
322 'id' => $this->_membershipID
,
325 $result = $this->callAPISuccess('membership', 'get', $params);
326 $this->assertEquals($membershipID, $result['id']);
328 'contact_id' => $this->_contactID
,
329 'membership_id' => $this->_membershipID
,
330 'return' => 'membership_id',
332 $result = $this->callAPISuccess('membership', 'get', $params);
333 $this->assertEquals($membershipID, $result['id']);
337 * Test civicrm_membership_get for only active.
338 * Memberships expected.
340 public function testGetOnlyActive() {
341 $description = "Demonstrates use of 'filter' active_only' param.";
342 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
344 'contact_id' => $this->_contactID
,
348 $membership = $this->callAPISuccess('membership', 'get', $params);
349 $this->assertEquals($membership['values'][$this->_membershipID
]['status_id'], $this->_membershipStatusID
);
350 $this->assertEquals($membership['values'][$this->_membershipID
]['contact_id'], $this->_contactID
);
352 'contact_id' => $this->_contactID
,
358 $membership = $this->callAPIAndDocument('membership', 'get', $params, __FUNCTION__
, __FILE__
, $description, 'FilterIsCurrent');
359 $this->assertEquals($membership['values'][$this->_membershipID
]['status_id'], $this->_membershipStatusID
);
360 $this->assertEquals($membership['values'][$this->_membershipID
]['contact_id'], $this->_contactID
);
362 $this->callAPISuccess('Membership', 'Delete', array('id' => $this->_membershipID
));
366 * Test civicrm_membership_get for non exist contact.
369 public function testGetNoContactExists() {
371 'contact_id' => 55555,
374 $membership = $this->callAPISuccess('membership', 'get', $params);
375 $this->assertEquals($membership['count'], 0, "In line " . __LINE__
);
379 * Test civicrm_membership_get with relationship.
382 public function testGetWithRelationship() {
383 $membershipOrgId = $this->organizationCreate(NULL);
384 $memberContactId = $this->individualCreate();
386 $relTypeParams = array(
387 'name_a_b' => 'Relation 1',
388 'name_b_a' => 'Relation 2',
389 'description' => 'Testing relationship type',
390 'contact_type_a' => 'Organization',
391 'contact_type_b' => 'Individual',
395 $relTypeID = $this->relationshipTypeCreate($relTypeParams);
398 'name' => 'test General',
399 'duration_unit' => 'year',
400 'duration_interval' => 1,
401 'period_type' => 'rolling',
402 'member_of_contact_id' => $membershipOrgId,
404 'financial_type_id' => 1,
405 'relationship_type_id' => $relTypeID,
406 'relationship_direction' => 'b_a',
409 $memType = $this->callAPISuccess('membership_type', 'create', $params);
412 'contact_id' => $memberContactId,
413 'membership_type_id' => $memType['id'],
414 'join_date' => '2009-01-21',
415 'start_date' => '2009-01-21',
416 'end_date' => '2009-12-21',
417 'source' => 'Payment',
419 'status_id' => $this->_membershipStatusID
,
421 $membershipID = $this->contactMembershipCreate($params);
424 'contact_id' => $memberContactId,
425 'membership_type_id' => $memType['id'],
428 $result = $this->callAPISuccess('membership', 'get', $params);
430 $membership = $result['values'][$membershipID];
431 $this->assertEquals($this->_membershipStatusID
, $membership['status_id']);
432 $this->callAPISuccess('Membership', 'Delete', array(
433 'id' => $membership['id'],
435 $this->membershipTypeDelete(array('id' => $memType['id']));
436 $this->relationshipTypeDelete($relTypeID);
437 $this->contactDelete($membershipOrgId);
438 $this->contactDelete($memberContactId);
442 * Test civicrm_membership_create with relationships.
443 * create/get Memberships.
445 * Test suite for CRM-14758: API ( contact, create ) does not always create related membership
446 * and max_related property for Membership_Type and Membership entities
448 public function testCreateWithRelationship() {
449 // Create membership type: inherited through employment, max_related = 2
451 'name_a_b' => 'Employee of',
453 $result = $this->callAPISuccess('relationship_type', 'get', $params);
454 $relationshipTypeId = $result['id'];
455 $membershipOrgId = $this->organizationCreate();
457 'name' => 'Corporate Membership',
458 'duration_unit' => 'year',
459 'duration_interval' => 1,
460 'period_type' => 'rolling',
461 'member_of_contact_id' => $membershipOrgId,
463 'financial_type_id' => 1,
464 'relationship_type_id' => $relationshipTypeId,
465 'relationship_direction' => 'b_a',
469 $result = $this->callAPISuccess('membership_type', 'create', $params);
470 $membershipTypeId = $result['id'];
472 // Create employer and first employee
473 $employerId[0] = $this->organizationCreate(array(), 1);
474 $memberContactId[0] = $this->individualCreate(array('employer_id' => $employerId[0]), 0);
476 // Create organization's membership
478 'contact_id' => $employerId[0],
479 'membership_type_id' => $membershipTypeId,
480 'source' => 'Test suite',
481 'start_date' => date('Y-m-d'),
482 'end_date' => "+1 year",
484 $OrganizationMembershipID = $this->contactMembershipCreate($params);
486 // Check that the employee inherited the membership
488 'contact_id' => $memberContactId[0],
489 'membership_type_id' => $membershipTypeId,
492 $result = $this->callAPISuccess('membership', 'get', $params);
494 $this->assertEquals(1, $result['count']);
495 $result = $result['values'][$result['id']];
496 $this->assertEquals($OrganizationMembershipID, $result['owner_membership_id']);
498 // Create second employee
499 $memberContactId[1] = $this->individualCreate(array('employer_id' => $employerId[0]), 1);
501 // Check that the employee inherited the membership
503 'contact_id' => $memberContactId[1],
504 'membership_type_id' => $membershipTypeId,
506 $result = $this->callAPISuccess('membership', 'get', $params);
507 // If it fails here CRM-14758 is not fixed
508 $this->assertEquals(1, $result['count']);
509 $result = $result['values'][$result['id']];
510 $this->assertEquals($OrganizationMembershipID, $result['owner_membership_id']);
512 // Create third employee
513 $memberContactId[2] = $this->individualCreate(array('employer_id' => $employerId[0]), 2);
515 // Check that employee does NOT inherit the membership (max_related = 2)
517 'contact_id' => $memberContactId[2],
518 'membership_type_id' => $membershipTypeId,
520 $result = $this->callAPISuccess('membership', 'get', $params);
521 $this->assertEquals(0, $result['count']);
523 // Increase max_related for the employer's membership
525 'id' => $OrganizationMembershipID,
528 $this->contactMembershipCreate($params);
530 // Check that the employee inherited the membership
532 'contact_id' => $memberContactId[2],
533 'membership_type_id' => $membershipTypeId,
535 $result = $this->callAPISuccess('membership', 'get', $params);
536 $this->assertEquals(1, $result['count']);
537 $result = $result['values'][$result['id']];
538 $this->assertEquals($OrganizationMembershipID, $result['owner_membership_id']);
540 // First employee moves to a new job
541 $employerId[1] = $this->organizationCreate(array(), 2);
543 'id' => $memberContactId[0],
544 'employer_id' => $employerId[1],
546 $this->callAPISuccess('contact', 'create', $params);
548 // Check that employee does NO LONGER inherit the membership
550 'contact_id' => $memberContactId[0],
551 'membership_type_id' => $membershipTypeId,
553 $result = $this->callAPISuccess('membership', 'get', $params);
554 $this->assertEquals(0, $result['count']);
556 // Set up params for enable/disable checks
557 $relationship1 = $this->callAPISuccess('relationship', 'get', array('contact_id_a' => $memberContactId[1]));
559 'contact_id' => $memberContactId[1],
560 'membership_type_id' => $membershipTypeId,
563 // Deactivate relationship using create and assert membership is not inherited
564 $this->callAPISuccess('relationship', 'create', array('id' => $relationship1['id'], 'is_active' => 0));
565 $result = $this->callAPISuccess('membership', 'get', $params);
566 $this->assertEquals(0, $result['count']);
568 // Re-enable relationship using create and assert membership is inherited
569 $this->callAPISuccess('relationship', 'create', array('id' => $relationship1['id'], 'is_active' => 1));
570 $result = $this->callAPISuccess('membership', 'get', $params);
571 $this->assertEquals(1, $result['count']);
573 // Deactivate relationship using setvalue and assert membership is not inherited
574 $this->callAPISuccess('relationship', 'setvalue', array('id' => $relationship1['id'], 'field' => 'is_active', 'value' => 0));
575 $result = $this->callAPISuccess('membership', 'get', $params);
576 $this->assertEquals(0, $result['count']);
578 // Re-enable relationship using setvalue and assert membership is inherited
579 $this->callAPISuccess('relationship', 'setvalue', array('id' => $relationship1['id'], 'field' => 'is_active', 'value' => 1));
580 $result = $this->callAPISuccess('membership', 'get', $params);
581 $this->assertEquals(1, $result['count']);
583 // Delete relationship and assert membership is not inherited
584 $this->callAPISuccess('relationship', 'delete', array('id' => $relationship1['id']));
585 $result = $this->callAPISuccess('membership', 'get', $params);
586 $this->assertEquals(0, $result['count']);
588 // Tear down - reverse of creation to be safe
589 $this->contactDelete($memberContactId[2]);
590 $this->contactDelete($memberContactId[1]);
591 $this->contactDelete($memberContactId[0]);
592 $this->contactDelete($employerId[1]);
593 $this->contactDelete($employerId[0]);
594 $this->membershipTypeDelete(array('id' => $membershipTypeId));
595 $this->contactDelete($membershipOrgId);
599 * We are checking for no enotices + only id & end_date returned
601 public function testMembershipGetWithReturn() {
602 $this->contactMembershipCreate($this->_params
);
603 $result = $this->callAPISuccess('membership', 'get', array('return' => 'end_date'));
604 foreach ($result['values'] as $membership) {
605 $this->assertEquals(array('id', 'end_date'), array_keys($membership));
608 ///////////////// civicrm_membership_create methods
611 * Test civicrm_contact_memberships_create with empty params.
614 public function testCreateWithEmptyParams() {
616 $this->callAPIFailure('membership', 'create', $params);
620 * If is_overide is passed in status must also be passed in.
622 public function testCreateOverrideNoStatus() {
623 $params = $this->_params
;
624 unset($params['status_id']);
625 $this->callAPIFailure('membership', 'create', $params);
628 public function testMembershipCreateMissingRequired() {
630 'membership_type_id' => '1',
631 'join_date' => '2006-01-21',
632 'start_date' => '2006-01-21',
633 'end_date' => '2006-12-21',
634 'source' => 'Payment',
638 $this->callAPIFailure('membership', 'create', $params);
641 public function testMembershipCreate() {
643 'contact_id' => $this->_contactID
,
644 'membership_type_id' => $this->_membershipTypeID
,
645 'join_date' => '2006-01-21',
646 'start_date' => '2006-01-21',
647 'end_date' => '2006-12-21',
648 'source' => 'Payment',
650 'status_id' => $this->_membershipStatusID
,
653 $result = $this->callAPIAndDocument('membership', 'create', $params, __FUNCTION__
, __FILE__
);
654 $this->getAndCheck($params, $result['id'], $this->_entity
);
655 $this->assertNotNull($result['id']);
656 $this->assertEquals($this->_contactID
, $result['values'][$result['id']]['contact_id'], " in line " . __LINE__
);
657 $this->assertEquals($result['id'], $result['values'][$result['id']]['id'], " in line " . __LINE__
);
661 * Check for useful message if contact doesn't exist
663 public function testMembershipCreateWithInvalidContact() {
666 'membership_type_id' => $this->_membershipTypeID
,
667 'join_date' => '2006-01-21',
668 'start_date' => '2006-01-21',
669 'end_date' => '2006-12-21',
670 'source' => 'Payment',
672 'status_id' => $this->_membershipStatusID
,
675 $this->callAPIFailure('membership', 'create', $params,
676 'contact_id is not valid : 999'
680 public function testMembershipCreateWithInvalidStatus() {
681 $params = $this->_params
;
682 $params['status_id'] = 999;
683 $this->callAPIFailure('membership', 'create', $params,
684 "'999' is not a valid option for field status_id"
688 public function testMembershipCreateWithInvalidType() {
689 $params = $this->_params
;
690 $params['membership_type_id'] = 999;
692 $this->callAPIFailure('membership', 'create', $params,
693 "'999' is not a valid option for field membership_type_id"
698 * Check with complete array + custom field
699 * Note that the test is written on purpose without any
700 * variables specific to participant so it can be replicated into other entities
701 * and / or moved to the automated test suite
703 public function testCreateWithCustom() {
704 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
706 $params = $this->_params
;
707 $params['custom_' . $ids['custom_field_id']] = "custom string";
709 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
, NULL, 'CreateWithCustomData');
710 $check = $this->callAPISuccess($this->_entity
, 'get', array(
711 'id' => $result['id'],
712 'contact_id' => $this->_contactID
,
714 $this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
718 * Test civicrm_contact_memberships_create with membership id (edit
722 public function testMembershipCreateWithId() {
723 $membershipID = $this->contactMembershipCreate($this->_params
);
725 'id' => $membershipID,
726 'contact_id' => $this->_contactID
,
727 'membership_type_id' => $this->_membershipTypeID
,
728 'join_date' => '2006-01-21',
729 'start_date' => '2006-01-21',
730 'end_date' => '2006-12-21',
731 'source' => 'Payment',
733 'status_id' => $this->_membershipStatusID
,
736 $result = $this->callAPISuccess('membership', 'create', $params);
737 $this->callAPISuccess('Membership', 'Delete', array(
738 'id' => $result['id'],
740 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
744 * Test civicrm_contact_memberships_create with membership id (edit
748 public function testMembershipCreateUpdateWithIdNoContact() {
749 $membershipID = $this->contactMembershipCreate($this->_params
);
751 'id' => $membershipID,
752 'membership_type_id' => $this->_membershipTypeID
,
753 'contact_id' => $this->_contactID
,
754 'join_date' => '2006-01-21',
755 'start_date' => '2006-01-21',
756 'end_date' => '2006-12-21',
757 'source' => 'Payment',
759 'status_id' => $this->_membershipStatusID
,
762 $result = $this->callAPISuccess('membership', 'create', $params);
763 $this->callAPISuccess('Membership', 'Delete', array(
764 'id' => $result['id'],
767 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
771 * Test civicrm_contact_memberships_create with membership id (edit
775 public function testMembershipCreateUpdateWithIdNoDates() {
776 $membershipID = $this->contactMembershipCreate($this->_params
);
778 'id' => $membershipID,
779 'contact_id' => $this->_contactID
,
780 'membership_type_id' => $this->_membershipTypeID
,
781 'source' => 'Payment',
783 'status_id' => $this->_membershipStatusID
,
786 $result = $this->callAPISuccess('membership', 'create', $params);
787 $this->callAPISuccess('Membership', 'Delete', array(
788 'id' => $result['id'],
790 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
794 * Test civicrm_contact_memberships_create with membership id (edit
798 public function testMembershipCreateUpdateWithIdNoDatesNoType() {
799 $membershipID = $this->contactMembershipCreate($this->_params
);
801 'id' => $membershipID,
802 'source' => 'not much here',
803 'contact_id' => $this->_contactID
,
805 'status_id' => $this->_membershipStatusID
,
808 $result = $this->callAPISuccess('membership', 'create', $params);
809 $this->callAPISuccess('Membership', 'Delete', array(
810 'id' => $result['id'],
812 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
816 * Test civicrm_contact_memberships_create with membership id (edit
820 public function testMembershipCreateUpdateWithIDAndSource() {
821 $membershipID = $this->contactMembershipCreate($this->_params
);
823 'id' => $membershipID,
824 'source' => 'changed',
825 'contact_id' => $this->_contactID
,
826 'status_id' => $this->_membershipStatusID
,
827 'membership_type_id' => $this->_membershipTypeID
,
828 'skipStatusCal' => 1,
830 $result = $this->callAPISuccess('membership', 'create', $params);
831 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
832 $this->callAPISuccess('Membership', 'Delete', array(
833 'id' => $result['id'],
838 * Change custom field using update.
840 public function testUpdateWithCustom() {
841 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
843 $params = $this->_params
;
844 $params['custom_' . $ids['custom_field_id']] = "custom string";
845 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
, NULL, 'UpdateCustomData');
846 $result = $this->callAPISuccess($this->_entity
, 'create', array(
847 'id' => $result['id'],
848 'custom_' . $ids['custom_field_id'] => "new custom",
850 $check = $this->callAPISuccess($this->_entity
, 'get', array(
851 'id' => $result['id'],
852 'contact_id' => $this->_contactID
,
855 $this->assertEquals("new custom", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
856 $this->callAPISuccess('Membership', 'Delete', array(
857 'id' => $check['id'],
860 $this->customFieldDelete($ids['custom_field_id']);
861 $this->customGroupDelete($ids['custom_group_id']);
865 * per CRM-15746 check that the id can be altered in an update hook
867 public function testMembershipUpdateCreateHookCRM15746() {
868 $this->hookClass
->setHook('civicrm_pre', array($this, 'hook_civicrm_pre_update_create_membership'));
869 $result = $this->callAPISuccess('membership', 'create', $this->_params
);
870 $this->callAPISuccess('membership', 'create', array('id' => $result['id'], 'end_date' => '1 year ago'));
871 $this->callAPISuccessGetCount('membership', array(), 2);
872 $this->hookClass
->reset();
873 $this->callAPISuccess('membership', 'create', array('id' => $result['id'], 'end_date' => '1 year ago'));
874 $this->callAPISuccessGetCount('membership', array(), 2);
878 * Custom hook for update membership.
881 * @param object $objectName
883 * @param array $params
887 public function hook_civicrm_pre_update_create_membership($op, $objectName, $id, &$params) {
888 if ($objectName == 'Membership' && $op == 'edit') {
889 $existingMembership = $this->callAPISuccessGetSingle('membership', array('id' => $params['id']));
890 unset($params['id'], $params['membership_id']);
891 $params['join_date'] = $params['membership_start_date'] = $params['start_date'] = date('Ymd000000', strtotime($existingMembership['start_date']));
892 $params = array_merge($existingMembership, $params);
893 $params['id'] = NULL;
898 * Test civicrm_contact_memberships_create Invalid membership data.
901 public function testMembershipCreateInvalidMemData() {
902 //membership_contact_id as string
904 'membership_contact_id' => 'Invalid',
905 'membership_type_id' => $this->_membershipTypeID
,
906 'join_date' => '2011-01-21',
907 'start_date' => '2010-01-21',
908 'end_date' => '2008-12-21',
909 'source' => 'Payment',
911 'status_id' => $this->_membershipStatusID
,
914 $this->callAPIFailure('membership', 'create', $params);
916 //membership_contact_id which is no in contact table
917 $params['membership_contact_id'] = 999;
918 $this->callAPIFailure('membership', 'create', $params);
921 unset($params['membership_contact_id']);
922 $params['join_date'] = "invalid";
923 $this->callAPIFailure('Membership', 'Create', $params);
927 * Test civicrm_contact_memberships_create with membership_contact_id
931 public function testMembershipCreateWithMemContact() {
933 'membership_contact_id' => $this->_contactID
,
934 'membership_type_id' => $this->_membershipTypeID
,
935 'join_date' => '2011-01-21',
936 'start_date' => '2010-01-21',
937 'end_date' => '2008-12-21',
938 'source' => 'Payment',
940 'status_id' => $this->_membershipStatusID
,
943 $result = $this->callAPISuccess('membership', 'create', $params);
945 $this->callAPISuccess('Membership', 'Delete', array(
946 'id' => $result['id'],
951 * Test civicrm_contact_memberships_create with membership_contact_id
955 public function testMembershipCreateValidMembershipTypeString() {
957 'membership_contact_id' => $this->_contactID
,
958 'membership_type_id' => 'General',
959 'join_date' => '2011-01-21',
960 'start_date' => '2010-01-21',
961 'end_date' => '2008-12-21',
962 'source' => 'Payment',
964 'status_id' => $this->_membershipStatusID
,
967 $result = $this->callAPISuccess('membership', 'create', $params);
968 $this->assertEquals($this->_membershipTypeID
, $result['values'][$result['id']]['membership_type_id']);
969 $this->callAPISuccess('Membership', 'Delete', array(
970 'id' => $result['id'],
975 * Test civicrm_contact_memberships_create with membership_contact_id
979 public function testMembershipCreateInValidMembershipTypeString() {
981 'membership_contact_id' => $this->_contactID
,
982 'membership_type_id' => 'invalid',
983 'join_date' => '2011-01-21',
984 'start_date' => '2010-01-21',
985 'end_date' => '2008-12-21',
986 'source' => 'Payment',
988 'status_id' => $this->_membershipStatusID
,
991 $this->callAPIFailure('membership', 'create', $params);
995 * Test that if membership join date is not set it defaults to today.
997 public function testEmptyJoinDate() {
998 unset($this->_params
['join_date'], $this->_params
['is_override']);
999 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1000 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1001 $this->assertEquals(date('Y-m-d', strtotime('now')), $result['join_date']);
1002 $this->assertEquals('2009-01-21', $result['start_date']);
1003 $this->assertEquals('2009-12-21', $result['end_date']);
1007 * Test that if membership start date is not set it defaults to correct end date.
1010 public function testEmptyStartDateFixed() {
1011 unset($this->_params
['start_date'], $this->_params
['is_override']);
1012 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1013 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1014 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1015 $this->assertEquals('2009-01-21', $result['join_date']);
1016 $this->assertEquals('2008-03-01', $result['start_date']);
1017 $this->assertEquals('2009-12-21', $result['end_date']);
1021 * Test that if membership start date is not set it defaults to correct end date
1024 public function testEmptyStartEndDateFixedOneYear() {
1025 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1026 $this->callAPISuccess('membership_type', 'create', array('id' => $this->_membershipTypeID2
, 'duration_interval' => 1));
1027 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1028 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1029 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1030 $this->assertEquals('2009-01-21', $result['join_date']);
1031 $this->assertEquals('2008-03-01', $result['start_date']);
1032 $this->assertEquals('2010-02-28', $result['end_date']);
1036 * Test that if membership start date is not set it defaults to correct end date for fixed multi year memberships.
1038 public function testEmptyStartEndDateFixedMultiYear() {
1039 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1040 $this->callAPISuccess('membership_type', 'create', array('id' => $this->_membershipTypeID2
, 'duration_interval' => 5));
1041 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1042 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1043 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1044 $this->assertEquals('2009-01-21', $result['join_date']);
1045 $this->assertEquals('2008-03-01', $result['start_date']);
1046 $this->assertEquals('2014-02-28', $result['end_date']);
1050 * Test correct end and start dates are calculated for fixed multi year memberships.
1052 * The empty start date is calculated to be the start_date (1 Jan prior to the join_date - so 1 Jan 15)
1054 * In this set our start date is after the start day and before the rollover day so we don't get an extra year
1055 * and we end one day before the rollover day. Start day is 1 Jan so we end on 31 Dec
1056 * and we add on 4 years rather than 5 because we are not after the rollover day - so we calculate 31 Dec 2019
1058 public function testFixedMultiYearDateSetTwoEmptyStartEndDate() {
1059 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1061 $this->callAPISuccess('membership_type', 'create', array(
1062 'id' => $this->_membershipTypeID2
,
1063 'duration_interval' => 5,
1065 'fixed_period_start_day' => '101',
1067 'fixed_period_rollover_day' => '1101',
1069 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1071 'join_date' => '28-Jan 2015',
1073 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1074 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1075 $this->assertEquals('2015-01-28', $result['join_date']);
1076 $this->assertEquals('2015-01-01', $result['start_date']);
1077 $this->assertEquals('2019-12-31', $result['end_date']);
1081 * Test that correct end date is calculated for fixed multi year memberships and start date is not changed.
1083 * In this set our start date is after the start day and before the rollover day so we don't get an extra year
1084 * and we end one day before the rollover day. Start day is 1 Jan so we end on 31 Dec
1085 * and we add on 4 years rather than 5 because we are not after the rollover day - so we calculate 31 Dec 2019
1087 public function testFixedMultiYearDateSetTwoEmptyEndDate() {
1088 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1090 $this->callAPISuccess('membership_type', 'create', array(
1091 'id' => $this->_membershipTypeID2
,
1092 'duration_interval' => 5,
1094 'fixed_period_start_day' => '101',
1096 'fixed_period_rollover_day' => '1101',
1098 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1100 'start_date' => '28-Jan 2015',
1101 'join_date' => '28-Jan 2015',
1103 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1104 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1105 $this->assertEquals('2015-01-28', $result['join_date']);
1106 $this->assertEquals('2015-01-28', $result['start_date']);
1107 $this->assertEquals('2019-12-31', $result['end_date']);
1111 * Test correct end and start dates are calculated for fixed multi year memberships.
1113 * The empty start date is calculated to be the start_date (1 Jan prior to the join_date - so 1 Jan 15)
1115 * In this set our start date is after the start day and before the rollover day so we don't get an extra year
1116 * and we end one day before the rollover day. Start day is 1 Jan so we end on 31 Dec
1117 * and we add on <1 years rather than > 1 because we are not after the rollover day - so we calculate 31 Dec 2015
1119 public function testFixedSingleYearDateSetTwoEmptyStartEndDate() {
1120 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1122 $this->callAPISuccess('membership_type', 'create', array(
1123 'id' => $this->_membershipTypeID2
,
1124 'duration_interval' => 1,
1126 'fixed_period_start_day' => '101',
1128 'fixed_period_rollover_day' => '1101',
1130 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1132 'join_date' => '28-Jan 2015',
1134 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1135 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1136 $this->assertEquals('2015-01-28', $result['join_date']);
1137 $this->assertEquals('2015-01-01', $result['start_date']);
1138 $this->assertEquals('2015-12-31', $result['end_date']);
1142 * Test correct end date for fixed single year memberships is calculated and start_date is not changed.
1144 * In this set our start date is after the start day and before the rollover day so we don't get an extra year
1145 * and we end one day before the rollover day. Start day is 1 Jan so we end on 31 Dec
1146 * and we add on <1 years rather than > 1 because we are not after the rollover day - so we calculate 31 Dec 2015
1148 public function testFixedSingleYearDateSetTwoEmptyEndDate() {
1149 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1151 $this->callAPISuccess('membership_type', 'create', array(
1152 'id' => $this->_membershipTypeID2
,
1153 'duration_interval' => 1,
1155 'fixed_period_start_day' => '101',
1157 'fixed_period_rollover_day' => '1101',
1159 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1161 'start_date' => '28-Jan 2015',
1162 'join_date' => '28-Jan 2015',
1164 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1165 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1166 $this->assertEquals('2015-01-28', $result['join_date']);
1167 $this->assertEquals('2015-01-28', $result['start_date']);
1168 $this->assertEquals('2015-12-31', $result['end_date']);
1172 * Test that correct end date is calculated for fixed multi year memberships and start date is not changed.
1174 * In this set our start date is after the start day and after the rollover day so we do get an extra year
1175 * and we end one day before the rollover day. Start day is 1 Nov so we end on 31 Oct
1176 * and we add on 1 year we are after the rollover day - so we calculate 31 Oct 2016
1178 public function testFixedSingleYearDateSetThreeEmptyEndDate() {
1179 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1181 $this->callAPISuccess('membership_type', 'create', array(
1182 'id' => $this->_membershipTypeID2
,
1183 'duration_interval' => 1,
1185 'fixed_period_start_day' => '1101',
1187 'fixed_period_rollover_day' => '101',
1189 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1191 'start_date' => '28-Jan 2015',
1192 'join_date' => '28-Jan 2015',
1194 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1195 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1196 $this->assertEquals('2015-01-28', $result['join_date']);
1197 $this->assertEquals('2015-01-28', $result['start_date']);
1198 $this->assertEquals('2016-10-31', $result['end_date']);
1202 * Test correct end and start dates are calculated for fixed multi year memberships.
1204 * The empty start date is calculated to be the start_date (1 Nov prior to the join_date - so 1 Nov 14)
1206 * In this set our start date is after the start day and after the rollover day so we do get an extra year
1207 * and we end one day before the rollover day. Start day is 1 Nov so we end on 31 Oct
1208 * and we add on 1 year we are after the rollover day - so we calculate 31 Oct 2016
1210 public function testFixedSingleYearDateSetThreeEmptyStartEndDate() {
1211 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1213 $this->callAPISuccess('membership_type', 'create', array(
1214 'id' => $this->_membershipTypeID2
,
1215 'duration_interval' => 1,
1217 'fixed_period_start_day' => '1101',
1219 'fixed_period_rollover_day' => '101',
1221 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1223 'join_date' => '28-Jan 2015',
1225 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1226 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1227 $this->assertEquals('2015-01-28', $result['join_date']);
1228 $this->assertEquals('2014-11-01', $result['start_date']);
1229 $this->assertEquals('2016-10-31', $result['end_date']);
1233 * Test that correct end date is calculated for fixed multi year memberships and start date is not changed.
1235 * In this set our start date is after the start day and after the rollover day so we do get an extra year
1236 * and we end one day before the rollover day. Start day is 1 Nov so we end on 31 Oct
1237 * and we add on 5 years we are after the rollover day - so we calculate 31 Oct 2020
1239 public function testFixedMultiYearDateSetThreeEmptyEndDate() {
1240 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1242 $this->callAPISuccess('membership_type', 'create', array(
1243 'id' => $this->_membershipTypeID2
,
1244 'duration_interval' => 5,
1246 'fixed_period_start_day' => '1101',
1248 'fixed_period_rollover_day' => '101',
1250 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1252 'start_date' => '28-Jan 2015',
1253 'join_date' => '28-Jan 2015',
1255 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1256 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1257 $this->assertEquals('2015-01-28', $result['join_date']);
1258 $this->assertEquals('2015-01-28', $result['start_date']);
1259 $this->assertEquals('2020-10-31', $result['end_date']);
1263 * Test correct end and start dates are calculated for fixed multi year memberships.
1265 * The empty start date is calculated to be the start_date (1 Nov prior to the join_date - so 1 Nov 14)
1267 * The empty start date is calculated to be the start_date (1 Nov prior to the join_date - so 1 Nov 14)
1268 * In this set our join date is after the start day and after the rollover day so we do get an extra year
1269 * and we end one day before the rollover day. Start day is 1 Nov so we end on 31 Oct
1270 * and we add on 5 years we are after the rollover day - so we calculate 31 Oct 2020
1272 public function testFixedMultiYearDateSetThreeEmptyStartEndDate() {
1273 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1275 $this->callAPISuccess('membership_type', 'create', array(
1276 'id' => $this->_membershipTypeID2
,
1277 'duration_interval' => 5,
1279 'fixed_period_start_day' => '1101',
1281 'fixed_period_rollover_day' => '101',
1283 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1285 'join_date' => '28-Jan 2015',
1287 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1288 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1289 $this->assertEquals('2015-01-28', $result['join_date']);
1290 $this->assertEquals('2014-11-01', $result['start_date']);
1291 $this->assertEquals('2020-10-31', $result['end_date']);
1295 * Test that if membership start date is not set it defaults to correct end date for fixed single year memberships.
1297 public function testEmptyStartDateRolling() {
1298 unset($this->_params
['start_date'], $this->_params
['is_override']);
1299 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1300 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1301 $this->assertEquals('2009-01-21', $result['join_date']);
1302 $this->assertEquals('2009-01-21', $result['start_date']);
1303 $this->assertEquals('2009-12-21', $result['end_date']);
1307 * Test that if membership end date is not set it defaults to correct end date.
1310 public function testEmptyEndDateFixed() {
1311 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1312 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1313 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1314 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1315 $this->assertEquals('2009-01-21', $result['join_date']);
1316 $this->assertEquals('2008-03-01', $result['start_date']);
1317 $this->assertEquals('2010-02-28', $result['end_date']);
1321 * Test that if membership end date is not set it defaults to correct end date.
1324 public function testEmptyEndDateRolling() {
1325 unset($this->_params
['is_override'], $this->_params
['end_date']);
1326 $this->_params
['membership_type_id'] = $this->_membershipTypeID
;
1327 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1328 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1329 $this->assertEquals('2009-01-21', $result['join_date']);
1330 $this->assertEquals('2009-01-21', $result['start_date']);
1331 $this->assertEquals('2010-01-20', $result['end_date']);
1336 * Test that if dates are set they not over-ridden if id is passed in
1338 public function testMembershipDatesNotOverridden() {
1339 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1340 unset($this->_params
['end_date'], $this->_params
['start_date']);
1341 $this->_params
['id'] = $result['id'];
1342 $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1343 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1344 $this->assertEquals('2009-01-21', $result['join_date']);
1345 $this->assertEquals('2009-01-21', $result['start_date']);
1346 $this->assertEquals('2009-12-21', $result['end_date']);