3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
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 * Class api_v3_MembershipTest
38 class api_v3_MembershipTest
extends CiviUnitTestCase
{
39 protected $_apiversion;
40 protected $_contactID;
41 protected $_membershipID;
42 protected $_membershipID2;
43 protected $_membershipID3;
44 protected $_membershipTypeID;
45 protected $_membershipTypeID2;
46 protected $_membershipStatusID;
53 public function setUp() {
55 $this->_apiversion
= 3;
56 $this->_contactID
= $this->individualCreate();
57 $this->_membershipTypeID
= $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID
));
58 $this->_membershipTypeID2
= $this->membershipTypeCreate(array(
59 'period_type' => 'fixed',
61 'fixed_period_start_day' => '301',
63 'fixed_period_rollover_day' => '1111',
65 $this->_membershipStatusID
= $this->membershipStatusCreate('test status');
67 CRM_Member_PseudoConstant
::membershipType(NULL, TRUE);
68 CRM_Member_PseudoConstant
::membershipStatus(NULL, NULL, 'name', TRUE);
69 CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name');
71 $this->_entity
= 'Membership';
72 $this->_params
= array(
73 'contact_id' => $this->_contactID
,
74 'membership_type_id' => $this->_membershipTypeID
,
75 'join_date' => '2009-01-21',
76 'start_date' => '2009-01-21',
77 'end_date' => '2009-12-21',
78 'source' => 'Payment',
80 'status_id' => $this->_membershipStatusID
,
85 * Clean up after tests.
89 public function tearDown() {
90 $this->quickCleanup(array(
92 'civicrm_membership_payment',
93 'civicrm_membership_log',
97 $this->membershipStatusDelete($this->_membershipStatusID
);
98 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID2
));
99 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID
));
100 $this->contactDelete($this->_contactID
);
105 * Test membership deletion.
107 public function testMembershipDelete() {
108 $membershipID = $this->contactMembershipCreate($this->_params
);
109 $this->assertDBRowExist('CRM_Member_DAO_Membership', $membershipID);
111 'id' => $membershipID,
113 $this->callAPIAndDocument('membership', 'delete', $params, __FUNCTION__
, __FILE__
);
114 $this->assertDBRowNotExist('CRM_Member_DAO_Membership', $membershipID);
117 public function testMembershipDeleteEmpty() {
118 $this->callAPIFailure('membership', 'delete', array());
121 public function testMembershipDeleteInvalidID() {
122 $this->callAPIFailure('membership', 'delete', array('id' => 'blah'));
126 * Test civicrm_membership_delete() with invalid Membership Id.
128 public function testMembershipDeleteWithInvalidMembershipId() {
129 $membershipId = 'membership';
130 $this->callAPIFailure('membership', 'delete', $membershipId);
134 * Test membership get.
136 public function testContactMembershipsGet() {
137 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
138 $this->callAPISuccess('membership', 'get', array());
139 $this->callAPISuccess('Membership', 'Delete', array('id' => $this->_membershipID
));
143 * Test civicrm_membership_get with params not array.
145 * Gets treated as contact_id, memberships expected.
147 public function testGetWithParamsContactId() {
148 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
150 'contact_id' => $this->_contactID
,
152 $membership = $this->callAPISuccess('membership', 'get', $params);
154 $result = $membership['values'][$this->_membershipID
];
155 $this->callAPISuccess('Membership', 'Delete', array(
156 'id' => $this->_membershipID
,
158 $this->assertEquals($result['contact_id'], $this->_contactID
, "In line " . __LINE__
);
159 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID
, "In line " . __LINE__
);
160 $this->assertEquals($result['status_id'], $this->_membershipStatusID
, "In line " . __LINE__
);
161 $this->assertEquals($result['join_date'], '2009-01-21', "In line " . __LINE__
);
162 $this->assertEquals($result['start_date'], '2009-01-21', "In line " . __LINE__
);
163 $this->assertEquals($result['end_date'], '2009-12-21', "In line " . __LINE__
);
164 $this->assertEquals($result['source'], 'Payment', "In line " . __LINE__
);
165 $this->assertEquals($result['is_override'], 1, "In line " . __LINE__
);
169 * Test civicrm_membership_get with params not array.
171 * Gets treated as contact_id, memberships expected.
173 public function testGetInSyntax() {
174 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
175 $this->_membershipID2
= $this->contactMembershipCreate($this->_params
);
176 $this->_membershipID3
= $this->contactMembershipCreate($this->_params
);
178 'id' => array('IN' => array($this->_membershipID
, $this->_membershipID3
)),
180 $membership = $this->callAPISuccess('membership', 'get', $params);
181 $this->assertEquals(2, $membership['count']);
182 $this->assertEquals(array($this->_membershipID
, $this->_membershipID3
), array_keys($membership['values']));
184 'id' => array('NOT IN' => array($this->_membershipID
, $this->_membershipID3
)),
186 $membership = $this->callAPISuccess('membership', 'get', $params);
187 $this->assertEquals(1, $membership['count']);
188 $this->assertEquals(array($this->_membershipID2
), array_keys($membership['values']));
192 * Test civicrm_membership_get with params not array.
193 * Gets treated as contact_id, memberships expected.
195 public function testGetInSyntaxOnContactID() {
196 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
197 $contact2 = $this->individualCreate();
198 $contact3 = $this->individualCreate(array('first_name' => 'Scout', 'last_name' => 'Canine'));
199 $this->_membershipID2
= $this->contactMembershipCreate(array_merge($this->_params
, array('contact_id' => $contact2)));
200 $this->_membershipID3
= $this->contactMembershipCreate(array_merge($this->_params
, array('contact_id' => $contact3)));
202 'contact_id' => array('IN' => array($this->_contactID
, $contact3)),
204 $membership = $this->callAPISuccess('membership', 'get', $params);
205 $this->assertEquals(2, $membership['count']);
206 $this->assertEquals(array($this->_membershipID
, $this->_membershipID3
), array_keys($membership['values']));
208 'contact_id' => array('NOT IN' => array($this->_contactID
, $contact3)),
210 $membership = $this->callAPISuccess('membership', 'get', $params);
211 $this->assertEquals(1, $membership['count']);
212 $this->assertEquals(array($this->_membershipID2
), array_keys($membership['values']));
216 * Test civicrm_membership_get with params not array.
218 * Gets treated as contact_id, memberships expected.
220 public function testGetWithParamsMemberShipTypeId() {
221 $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
223 'membership_type_id' => $this->_membershipTypeID
,
225 $membership = $this->callAPISuccess('membership', 'get', $params);
226 $this->callAPISuccess('Membership', 'Delete', array(
227 'id' => $membership['id'],
229 $result = $membership['values'][$membership['id']];
230 $this->assertEquals($result['contact_id'], $this->_contactID
);
231 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID
);
232 $this->assertEquals($result['status_id'], $this->_membershipStatusID
);
233 $this->assertEquals($result['join_date'], '2009-01-21');
234 $this->assertEquals($result['start_date'], '2009-01-21');
235 $this->assertEquals($result['end_date'], '2009-12-21');
236 $this->assertEquals($result['source'], 'Payment');
237 $this->assertEquals($result['is_override'], 1);
238 $this->assertEquals($result['id'], $membership['id']);
242 * Test civicrm_membership_get with params not array.
243 * Gets treated as contact_id, memberships expected.
245 public function testGetWithParamsMemberShipTypeIdContactID() {
246 $params = $this->_params
;
247 $this->callAPISuccess($this->_entity
, 'create', $params);
248 $params['membership_type_id'] = $this->_membershipTypeID2
;
249 $this->callAPISuccess($this->_entity
, 'create', $params);
250 $this->callAPISuccessGetCount('membership', array('contact_id' => $this->_contactID
), 2);
252 'membership_type_id' => $this->_membershipTypeID
,
253 'contact_id' => $this->_contactID
,
255 $result = $this->callAPISuccess('membership', 'getsingle', $params);
256 $this->assertEquals($result['contact_id'], $this->_contactID
);
257 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID
);
260 'membership_type_id' => $this->_membershipTypeID2
,
261 'contact_id' => $this->_contactID
,
263 $result = $this->callAPISuccess('membership', 'getsingle', $params);
264 $this->assertEquals($result['contact_id'], $this->_contactID
);
265 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID2
);
269 * Check with complete array + custom field.
271 * Note that the test is written on purpose without any
272 * variables specific to participant so it can be replicated into other entities
273 * and / or moved to the automated test suite
275 public function testGetWithParamsMemberShipIdAndCustom() {
276 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
278 $params = $this->_params
;
279 $params['custom_' . $ids['custom_field_id']] = "custom string";
281 $result = $this->callAPISuccess($this->_entity
, 'create', $params);
283 $getParams = array('membership_type_id' => $params['membership_type_id']);
284 $check = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
);
285 $this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
287 $this->callAPISuccess('Membership', 'Delete', array(
288 'id' => $result['id'],
293 * Test civicrm_membership_get with proper params.
294 * Memberships expected.
296 public function testGet() {
297 $membershipID = $this->contactMembershipCreate($this->_params
);
299 'contact_id' => $this->_contactID
,
302 $membership = $this->callAPISuccess('membership', 'get', $params);
303 $result = $membership['values'][$membershipID];
304 $this->callAPISuccess('Membership', 'Delete', array(
305 'id' => $membership['id'],
307 $this->assertEquals($result['join_date'], '2009-01-21');
308 $this->assertEquals($result['contact_id'], $this->_contactID
);
309 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID
);
310 $this->assertEquals($result['status_id'], $this->_membershipStatusID
);
312 $this->assertEquals($result['start_date'], '2009-01-21');
313 $this->assertEquals($result['end_date'], '2009-12-21');
314 $this->assertEquals($result['source'], 'Payment');
315 $this->assertEquals($result['is_override'], 1);
320 * Test civicrm_membership_get with proper params.
321 * Memberships expected.
323 public function testGetWithId() {
324 $membershipID = $this->contactMembershipCreate($this->_params
);
326 'contact_id' => $this->_contactID
,
327 'id' => $this->_membershipID
,
330 $result = $this->callAPISuccess('membership', 'get', $params);
331 $this->assertEquals($membershipID, $result['id']);
333 'contact_id' => $this->_contactID
,
334 'membership_id' => $this->_membershipID
,
335 'return' => 'membership_id',
337 $result = $this->callAPISuccess('membership', 'get', $params);
338 $this->assertEquals($membershipID, $result['id']);
342 * Test civicrm_membership_get for only active.
343 * Memberships expected.
345 public function testGetOnlyActive() {
346 $description = "Demonstrates use of 'filter' active_only' param.";
347 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
349 'contact_id' => $this->_contactID
,
353 $membership = $this->callAPISuccess('membership', 'get', $params);
354 $this->assertEquals($membership['values'][$this->_membershipID
]['status_id'], $this->_membershipStatusID
);
355 $this->assertEquals($membership['values'][$this->_membershipID
]['contact_id'], $this->_contactID
);
357 'contact_id' => $this->_contactID
,
363 $membership = $this->callAPIAndDocument('membership', 'get', $params, __FUNCTION__
, __FILE__
, $description, 'FilterIsCurrent');
364 $this->assertEquals($membership['values'][$this->_membershipID
]['status_id'], $this->_membershipStatusID
);
365 $this->assertEquals($membership['values'][$this->_membershipID
]['contact_id'], $this->_contactID
);
367 $this->callAPISuccess('Membership', 'Delete', array('id' => $this->_membershipID
));
371 * Test civicrm_membership_get for non exist contact.
374 public function testGetNoContactExists() {
376 'contact_id' => 55555,
379 $membership = $this->callAPISuccess('membership', 'get', $params);
380 $this->assertEquals($membership['count'], 0);
384 * Test civicrm_membership_get with relationship.
387 public function testGetWithRelationship() {
388 $membershipOrgId = $this->organizationCreate(NULL);
389 $memberContactId = $this->individualCreate();
391 $relTypeParams = array(
392 'name_a_b' => 'Relation 1',
393 'name_b_a' => 'Relation 2',
394 'description' => 'Testing relationship type',
395 'contact_type_a' => 'Organization',
396 'contact_type_b' => 'Individual',
400 $relTypeID = $this->relationshipTypeCreate($relTypeParams);
403 'name' => 'test General',
404 'duration_unit' => 'year',
405 'duration_interval' => 1,
406 'period_type' => 'rolling',
407 'member_of_contact_id' => $membershipOrgId,
409 'financial_type_id' => 1,
410 'relationship_type_id' => $relTypeID,
411 'relationship_direction' => 'b_a',
414 $memType = $this->callAPISuccess('membership_type', 'create', $params);
417 'contact_id' => $memberContactId,
418 'membership_type_id' => $memType['id'],
419 'join_date' => '2009-01-21',
420 'start_date' => '2009-01-21',
421 'end_date' => '2009-12-21',
422 'source' => 'Payment',
424 'status_id' => $this->_membershipStatusID
,
426 $membershipID = $this->contactMembershipCreate($params);
429 'contact_id' => $memberContactId,
430 'membership_type_id' => $memType['id'],
433 $result = $this->callAPISuccess('membership', 'get', $params);
435 $membership = $result['values'][$membershipID];
436 $this->assertEquals($this->_membershipStatusID
, $membership['status_id']);
437 $this->callAPISuccess('Membership', 'Delete', array(
438 'id' => $membership['id'],
440 $this->membershipTypeDelete(array('id' => $memType['id']));
441 $this->relationshipTypeDelete($relTypeID);
442 $this->contactDelete($membershipOrgId);
443 $this->contactDelete($memberContactId);
447 * Test civicrm_membership_create with relationships.
448 * create/get Memberships.
450 * Test suite for CRM-14758: API ( contact, create ) does not always create related membership
451 * and max_related property for Membership_Type and Membership entities
453 public function testCreateWithRelationship() {
454 // Create membership type: inherited through employment, max_related = 2
456 'name_a_b' => 'Employee of',
458 $result = $this->callAPISuccess('relationship_type', 'get', $params);
459 $relationshipTypeId = $result['id'];
460 $membershipOrgId = $this->organizationCreate();
462 'name' => 'Corporate Membership',
463 'duration_unit' => 'year',
464 'duration_interval' => 1,
465 'period_type' => 'rolling',
466 'member_of_contact_id' => $membershipOrgId,
468 'financial_type_id' => 1,
469 'relationship_type_id' => $relationshipTypeId,
470 'relationship_direction' => 'b_a',
474 $result = $this->callAPISuccess('membership_type', 'create', $params);
475 $membershipTypeId = $result['id'];
477 // Create employer and first employee
478 $employerId[0] = $this->organizationCreate(array(), 1);
479 $memberContactId[0] = $this->individualCreate(array('employer_id' => $employerId[0]), 0);
481 // Create organization's membership
483 'contact_id' => $employerId[0],
484 'membership_type_id' => $membershipTypeId,
485 'source' => 'Test suite',
486 'start_date' => date('Y-m-d'),
487 'end_date' => "+1 year",
489 $OrganizationMembershipID = $this->contactMembershipCreate($params);
491 // Check that the employee inherited the membership
493 'contact_id' => $memberContactId[0],
494 'membership_type_id' => $membershipTypeId,
497 $result = $this->callAPISuccess('membership', 'get', $params);
499 $this->assertEquals(1, $result['count']);
500 $result = $result['values'][$result['id']];
501 $this->assertEquals($OrganizationMembershipID, $result['owner_membership_id']);
503 // Create second employee
504 $memberContactId[1] = $this->individualCreate(array('employer_id' => $employerId[0]), 1);
506 // Check that the employee inherited the membership
508 'contact_id' => $memberContactId[1],
509 'membership_type_id' => $membershipTypeId,
511 $result = $this->callAPISuccess('membership', 'get', $params);
512 // If it fails here CRM-14758 is not fixed
513 $this->assertEquals(1, $result['count']);
514 $result = $result['values'][$result['id']];
515 $this->assertEquals($OrganizationMembershipID, $result['owner_membership_id']);
517 // Create third employee
518 $memberContactId[2] = $this->individualCreate(array('employer_id' => $employerId[0]), 2);
520 // Check that employee does NOT inherit the membership (max_related = 2)
522 'contact_id' => $memberContactId[2],
523 'membership_type_id' => $membershipTypeId,
525 $result = $this->callAPISuccess('membership', 'get', $params);
526 $this->assertEquals(0, $result['count']);
528 // Increase max_related for the employer's membership
530 'id' => $OrganizationMembershipID,
533 $this->contactMembershipCreate($params);
535 // Check that the employee inherited the membership
537 'contact_id' => $memberContactId[2],
538 'membership_type_id' => $membershipTypeId,
540 $result = $this->callAPISuccess('membership', 'get', $params);
541 $this->assertEquals(1, $result['count']);
542 $result = $result['values'][$result['id']];
543 $this->assertEquals($OrganizationMembershipID, $result['owner_membership_id']);
545 // First employee moves to a new job
546 $employerId[1] = $this->organizationCreate(array(), 2);
548 'id' => $memberContactId[0],
549 'employer_id' => $employerId[1],
551 $this->callAPISuccess('contact', 'create', $params);
553 // Check that employee does NO LONGER inherit the membership
555 'contact_id' => $memberContactId[0],
556 'membership_type_id' => $membershipTypeId,
558 $result = $this->callAPISuccess('membership', 'get', $params);
559 $this->assertEquals(0, $result['count']);
561 // Set up params for enable/disable checks
562 $relationship1 = $this->callAPISuccess('relationship', 'get', array('contact_id_a' => $memberContactId[1]));
564 'contact_id' => $memberContactId[1],
565 'membership_type_id' => $membershipTypeId,
568 // Deactivate relationship using create and assert membership is not inherited
569 $this->callAPISuccess('relationship', 'create', array('id' => $relationship1['id'], 'is_active' => 0));
570 $result = $this->callAPISuccess('membership', 'get', $params);
571 $this->assertEquals(0, $result['count']);
573 // Re-enable relationship using create and assert membership is inherited
574 $this->callAPISuccess('relationship', 'create', array('id' => $relationship1['id'], 'is_active' => 1));
575 $result = $this->callAPISuccess('membership', 'get', $params);
576 $this->assertEquals(1, $result['count']);
578 // Deactivate relationship using setvalue and assert membership is not inherited
579 $this->callAPISuccess('relationship', 'setvalue', array('id' => $relationship1['id'], 'field' => 'is_active', 'value' => 0));
580 $result = $this->callAPISuccess('membership', 'get', $params);
581 $this->assertEquals(0, $result['count']);
583 // Re-enable relationship using setvalue and assert membership is inherited
584 $this->callAPISuccess('relationship', 'setvalue', array('id' => $relationship1['id'], 'field' => 'is_active', 'value' => 1));
585 $result = $this->callAPISuccess('membership', 'get', $params);
586 $this->assertEquals(1, $result['count']);
588 // Delete relationship and assert membership is not inherited
589 $this->callAPISuccess('relationship', 'delete', array('id' => $relationship1['id']));
590 $result = $this->callAPISuccess('membership', 'get', $params);
591 $this->assertEquals(0, $result['count']);
593 // Tear down - reverse of creation to be safe
594 $this->contactDelete($memberContactId[2]);
595 $this->contactDelete($memberContactId[1]);
596 $this->contactDelete($memberContactId[0]);
597 $this->contactDelete($employerId[1]);
598 $this->contactDelete($employerId[0]);
599 $this->membershipTypeDelete(array('id' => $membershipTypeId));
600 $this->contactDelete($membershipOrgId);
604 * We are checking for no e-notices + only id & end_date returned
606 public function testMembershipGetWithReturn() {
607 $this->contactMembershipCreate($this->_params
);
608 $result = $this->callAPISuccess('membership', 'get', array('return' => 'end_date'));
609 foreach ($result['values'] as $membership) {
610 $this->assertEquals(array('end_date', 'id'), array_keys($membership));
613 ///////////////// civicrm_membership_create methods
616 * Test civicrm_contact_memberships_create with empty params.
619 public function testCreateWithEmptyParams() {
621 $this->callAPIFailure('membership', 'create', $params);
625 * If is_overide is passed in status must also be passed in.
627 public function testCreateOverrideNoStatus() {
628 $params = $this->_params
;
629 unset($params['status_id']);
630 $this->callAPIFailure('membership', 'create', $params);
633 public function testMembershipCreateMissingRequired() {
635 'membership_type_id' => '1',
636 'join_date' => '2006-01-21',
637 'start_date' => '2006-01-21',
638 'end_date' => '2006-12-21',
639 'source' => 'Payment',
643 $this->callAPIFailure('membership', 'create', $params);
646 public function testMembershipCreate() {
648 'contact_id' => $this->_contactID
,
649 'membership_type_id' => $this->_membershipTypeID
,
650 'join_date' => '2006-01-21',
651 'start_date' => '2006-01-21',
652 'end_date' => '2006-12-21',
653 'source' => 'Payment',
655 'status_id' => $this->_membershipStatusID
,
658 $result = $this->callAPIAndDocument('membership', 'create', $params, __FUNCTION__
, __FILE__
);
659 $this->getAndCheck($params, $result['id'], $this->_entity
);
660 $this->assertNotNull($result['id']);
661 $this->assertEquals($this->_contactID
, $result['values'][$result['id']]['contact_id'], " in line " . __LINE__
);
662 $this->assertEquals($result['id'], $result['values'][$result['id']]['id'], " in line " . __LINE__
);
666 * Check for useful message if contact doesn't exist
668 public function testMembershipCreateWithInvalidContact() {
671 'membership_type_id' => $this->_membershipTypeID
,
672 'join_date' => '2006-01-21',
673 'start_date' => '2006-01-21',
674 'end_date' => '2006-12-21',
675 'source' => 'Payment',
677 'status_id' => $this->_membershipStatusID
,
680 $this->callAPIFailure('membership', 'create', $params,
681 'contact_id is not valid : 999'
685 public function testMembershipCreateWithInvalidStatus() {
686 $params = $this->_params
;
687 $params['status_id'] = 999;
688 $this->callAPIFailure('membership', 'create', $params,
689 "'999' is not a valid option for field status_id"
693 public function testMembershipCreateWithInvalidType() {
694 $params = $this->_params
;
695 $params['membership_type_id'] = 999;
697 $this->callAPIFailure('membership', 'create', $params,
698 "'999' is not a valid option for field membership_type_id"
703 * Check with complete array + custom field
704 * Note that the test is written on purpose without any
705 * variables specific to participant so it can be replicated into other entities
706 * and / or moved to the automated test suite
708 public function testCreateWithCustom() {
709 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
711 $params = $this->_params
;
712 $params['custom_' . $ids['custom_field_id']] = "custom string";
714 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
, NULL, 'CreateWithCustomData');
715 $check = $this->callAPISuccess($this->_entity
, 'get', array(
716 'id' => $result['id'],
717 'contact_id' => $this->_contactID
,
719 $this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
723 * Search on custom field value.
725 public function testSearchWithCustomDataCRM16036() {
726 // Create a custom field on membership
727 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
729 // Create a new membership, but don't assign anything to the custom field.
730 $params = $this->_params
;
731 $result = $this->callAPIAndDocument(
738 'SearchWithCustomData');
740 // search memberships with CRM-16036 as custom field value.
741 // Since we did not touch the custom field of any membership,
742 // this should not return any results.
743 $check = $this->callAPISuccess($this->_entity
, 'get', array(
744 'custom_' . $ids['custom_field_id'] => "CRM-16036",
748 $this->callAPISuccess($this->_entity
, 'delete', array(
749 'id' => $result['id'],
753 $this->assertEquals(0, $check['count']);
757 * Test civicrm_contact_memberships_create with membership id (edit
761 public function testMembershipCreateWithId() {
762 $membershipID = $this->contactMembershipCreate($this->_params
);
764 'id' => $membershipID,
765 'contact_id' => $this->_contactID
,
766 'membership_type_id' => $this->_membershipTypeID
,
767 'join_date' => '2006-01-21',
768 'start_date' => '2006-01-21',
769 'end_date' => '2006-12-21',
770 'source' => 'Payment',
772 'status_id' => $this->_membershipStatusID
,
775 $result = $this->callAPISuccess('membership', 'create', $params);
776 $this->callAPISuccess('Membership', 'Delete', array(
777 'id' => $result['id'],
779 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
783 * Test civicrm_contact_memberships_create with membership id (edit
787 public function testMembershipCreateUpdateWithIdNoContact() {
788 $membershipID = $this->contactMembershipCreate($this->_params
);
790 'id' => $membershipID,
791 'membership_type_id' => $this->_membershipTypeID
,
792 'contact_id' => $this->_contactID
,
793 'join_date' => '2006-01-21',
794 'start_date' => '2006-01-21',
795 'end_date' => '2006-12-21',
796 'source' => 'Payment',
798 'status_id' => $this->_membershipStatusID
,
801 $result = $this->callAPISuccess('membership', 'create', $params);
802 $this->callAPISuccess('Membership', 'Delete', array(
803 'id' => $result['id'],
806 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
810 * Test civicrm_contact_memberships_create with membership id (edit
814 public function testMembershipCreateUpdateWithIdNoDates() {
815 $membershipID = $this->contactMembershipCreate($this->_params
);
817 'id' => $membershipID,
818 'contact_id' => $this->_contactID
,
819 'membership_type_id' => $this->_membershipTypeID
,
820 'source' => 'Payment',
822 'status_id' => $this->_membershipStatusID
,
825 $result = $this->callAPISuccess('membership', 'create', $params);
826 $this->callAPISuccess('Membership', 'Delete', array(
827 'id' => $result['id'],
829 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
833 * Test civicrm_contact_memberships_create with membership id (edit
837 public function testMembershipCreateUpdateWithIdNoDatesNoType() {
838 $membershipID = $this->contactMembershipCreate($this->_params
);
840 'id' => $membershipID,
841 'source' => 'not much here',
842 'contact_id' => $this->_contactID
,
844 'status_id' => $this->_membershipStatusID
,
847 $result = $this->callAPISuccess('membership', 'create', $params);
848 $this->callAPISuccess('Membership', 'Delete', array(
849 'id' => $result['id'],
851 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
855 * Test civicrm_contact_memberships_create with membership id (edit
859 public function testMembershipCreateUpdateWithIDAndSource() {
860 $membershipID = $this->contactMembershipCreate($this->_params
);
862 'id' => $membershipID,
863 'source' => 'changed',
864 'contact_id' => $this->_contactID
,
865 'status_id' => $this->_membershipStatusID
,
866 'membership_type_id' => $this->_membershipTypeID
,
867 'skipStatusCal' => 1,
869 $result = $this->callAPISuccess('membership', 'create', $params);
870 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
871 $this->callAPISuccess('Membership', 'Delete', array(
872 'id' => $result['id'],
877 * Change custom field using update.
879 public function testUpdateWithCustom() {
880 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
882 $params = $this->_params
;
883 $params['custom_' . $ids['custom_field_id']] = "custom string";
884 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
, NULL, 'UpdateCustomData');
885 $result = $this->callAPISuccess($this->_entity
, 'create', array(
886 'id' => $result['id'],
887 'custom_' . $ids['custom_field_id'] => "new custom",
889 $check = $this->callAPISuccess($this->_entity
, 'get', array(
890 'id' => $result['id'],
891 'contact_id' => $this->_contactID
,
894 $this->assertEquals("new custom", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
895 $this->callAPISuccess('Membership', 'Delete', array(
896 'id' => $check['id'],
899 $this->customFieldDelete($ids['custom_field_id']);
900 $this->customGroupDelete($ids['custom_group_id']);
904 * per CRM-15746 check that the id can be altered in an update hook
906 public function testMembershipUpdateCreateHookCRM15746() {
907 $this->hookClass
->setHook('civicrm_pre', array($this, 'hook_civicrm_pre_update_create_membership'));
908 $result = $this->callAPISuccess('membership', 'create', $this->_params
);
909 $this->callAPISuccess('membership', 'create', array('id' => $result['id'], 'end_date' => '1 year ago'));
910 $this->callAPISuccessGetCount('membership', array(), 2);
911 $this->hookClass
->reset();
912 $this->callAPISuccess('membership', 'create', array('id' => $result['id'], 'end_date' => '1 year ago'));
913 $this->callAPISuccessGetCount('membership', array(), 2);
917 * Custom hook for update membership.
920 * @param object $objectName
922 * @param array $params
926 public function hook_civicrm_pre_update_create_membership($op, $objectName, $id, &$params) {
927 if ($objectName == 'Membership' && $op == 'edit') {
928 $existingMembership = $this->callAPISuccessGetSingle('membership', array('id' => $params['id']));
929 unset($params['id'], $params['membership_id']);
930 $params['join_date'] = $params['membership_start_date'] = $params['start_date'] = date('Ymd000000', strtotime($existingMembership['start_date']));
931 $params = array_merge($existingMembership, $params);
932 $params['id'] = NULL;
937 * Test civicrm_contact_memberships_create Invalid membership data.
940 public function testMembershipCreateInvalidMemData() {
941 //membership_contact_id as string
943 'membership_contact_id' => 'Invalid',
944 'membership_type_id' => $this->_membershipTypeID
,
945 'join_date' => '2011-01-21',
946 'start_date' => '2010-01-21',
947 'end_date' => '2008-12-21',
948 'source' => 'Payment',
950 'status_id' => $this->_membershipStatusID
,
953 $this->callAPIFailure('membership', 'create', $params);
955 //membership_contact_id which is no in contact table
956 $params['membership_contact_id'] = 999;
957 $this->callAPIFailure('membership', 'create', $params);
960 unset($params['membership_contact_id']);
961 $params['join_date'] = "invalid";
962 $this->callAPIFailure('Membership', 'Create', $params);
966 * Test civicrm_contact_memberships_create with membership_contact_id
970 public function testMembershipCreateWithMemContact() {
972 'membership_contact_id' => $this->_contactID
,
973 'membership_type_id' => $this->_membershipTypeID
,
974 'join_date' => '2011-01-21',
975 'start_date' => '2010-01-21',
976 'end_date' => '2008-12-21',
977 'source' => 'Payment',
979 'status_id' => $this->_membershipStatusID
,
982 $result = $this->callAPISuccess('membership', 'create', $params);
984 $this->callAPISuccess('Membership', 'Delete', array(
985 'id' => $result['id'],
990 * Test civicrm_contact_memberships_create with membership_contact_id
994 public function testMembershipCreateValidMembershipTypeString() {
996 'membership_contact_id' => $this->_contactID
,
997 'membership_type_id' => 'General',
998 'join_date' => '2011-01-21',
999 'start_date' => '2010-01-21',
1000 'end_date' => '2008-12-21',
1001 'source' => 'Payment',
1003 'status_id' => $this->_membershipStatusID
,
1006 $result = $this->callAPISuccess('membership', 'create', $params);
1007 $this->assertEquals($this->_membershipTypeID
, $result['values'][$result['id']]['membership_type_id']);
1008 $this->callAPISuccess('Membership', 'Delete', array(
1009 'id' => $result['id'],
1014 * Test civicrm_contact_memberships_create with membership_contact_id
1018 public function testMembershipCreateInValidMembershipTypeString() {
1020 'membership_contact_id' => $this->_contactID
,
1021 'membership_type_id' => 'invalid',
1022 'join_date' => '2011-01-21',
1023 'start_date' => '2010-01-21',
1024 'end_date' => '2008-12-21',
1025 'source' => 'Payment',
1027 'status_id' => $this->_membershipStatusID
,
1030 $this->callAPIFailure('membership', 'create', $params);
1034 * Test that if membership join date is not set it defaults to today.
1036 public function testEmptyJoinDate() {
1037 unset($this->_params
['join_date'], $this->_params
['is_override']);
1038 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1039 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1040 $this->assertEquals(date('Y-m-d', strtotime('now')), $result['join_date']);
1041 $this->assertEquals('2009-01-21', $result['start_date']);
1042 $this->assertEquals('2009-12-21', $result['end_date']);
1046 * Test that if membership start date is not set it defaults to correct end date.
1049 public function testEmptyStartDateFixed() {
1050 unset($this->_params
['start_date'], $this->_params
['is_override']);
1051 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1052 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1053 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1054 $this->assertEquals('2009-01-21', $result['join_date']);
1055 $this->assertEquals('2008-03-01', $result['start_date']);
1056 $this->assertEquals('2009-12-21', $result['end_date']);
1060 * Test that if membership start date is not set it defaults to correct end date
1063 public function testEmptyStartEndDateFixedOneYear() {
1064 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1065 $this->callAPISuccess('membership_type', 'create', array('id' => $this->_membershipTypeID2
, 'duration_interval' => 1));
1066 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1067 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1068 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1069 $this->assertEquals('2009-01-21', $result['join_date']);
1070 $this->assertEquals('2008-03-01', $result['start_date']);
1071 $this->assertEquals('2010-02-28', $result['end_date']);
1075 * Test that if membership start date is not set it defaults to correct end date for fixed multi year memberships.
1077 public function testEmptyStartEndDateFixedMultiYear() {
1078 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1079 $this->callAPISuccess('membership_type', 'create', array('id' => $this->_membershipTypeID2
, 'duration_interval' => 5));
1080 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1081 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1082 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1083 $this->assertEquals('2009-01-21', $result['join_date']);
1084 $this->assertEquals('2008-03-01', $result['start_date']);
1085 $this->assertEquals('2014-02-28', $result['end_date']);
1089 * Test correct end and start dates are calculated for fixed multi year memberships.
1091 * The empty start date is calculated to be the start_date (1 Jan prior to the join_date - so 1 Jan 15)
1093 * In this set our start date is after the start day and before the rollover day so we don't get an extra year
1094 * and we end one day before the rollover day. Start day is 1 Jan so we end on 31 Dec
1095 * and we add on 4 years rather than 5 because we are not after the rollover day - so we calculate 31 Dec 2019
1097 public function testFixedMultiYearDateSetTwoEmptyStartEndDate() {
1098 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1100 $this->callAPISuccess('membership_type', 'create', array(
1101 'id' => $this->_membershipTypeID2
,
1102 'duration_interval' => 5,
1104 'fixed_period_start_day' => '101',
1106 'fixed_period_rollover_day' => '1101',
1108 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1110 'join_date' => '28-Jan 2015',
1112 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1113 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1114 $this->assertEquals('2015-01-28', $result['join_date']);
1115 $this->assertEquals('2015-01-01', $result['start_date']);
1116 $this->assertEquals('2019-12-31', $result['end_date']);
1120 * Test that correct end date is calculated for fixed multi year memberships and start date is not changed.
1122 * In this set our start date is after the start day and before the rollover day so we don't get an extra year
1123 * and we end one day before the rollover day. Start day is 1 Jan so we end on 31 Dec
1124 * and we add on 4 years rather than 5 because we are not after the rollover day - so we calculate 31 Dec 2019
1126 public function testFixedMultiYearDateSetTwoEmptyEndDate() {
1127 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1129 $this->callAPISuccess('membership_type', 'create', array(
1130 'id' => $this->_membershipTypeID2
,
1131 'duration_interval' => 5,
1133 'fixed_period_start_day' => '101',
1135 'fixed_period_rollover_day' => '1101',
1137 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1139 'start_date' => '28-Jan 2015',
1140 'join_date' => '28-Jan 2015',
1142 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1143 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1144 $this->assertEquals('2015-01-28', $result['join_date']);
1145 $this->assertEquals('2015-01-28', $result['start_date']);
1146 $this->assertEquals('2019-12-31', $result['end_date']);
1150 * Test correct end and start dates are calculated for fixed multi year memberships.
1152 * The empty start date is calculated to be the start_date (1 Jan prior to the join_date - so 1 Jan 15)
1154 * In this set our start date is after the start day and before the rollover day so we don't get an extra year
1155 * and we end one day before the rollover day. Start day is 1 Jan so we end on 31 Dec
1156 * and we add on <1 years rather than > 1 because we are not after the rollover day - so we calculate 31 Dec 2015
1158 public function testFixedSingleYearDateSetTwoEmptyStartEndDate() {
1159 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1161 $this->callAPISuccess('membership_type', 'create', array(
1162 'id' => $this->_membershipTypeID2
,
1163 'duration_interval' => 1,
1165 'fixed_period_start_day' => '101',
1167 'fixed_period_rollover_day' => '1101',
1169 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1171 'join_date' => '28-Jan 2015',
1173 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1174 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1175 $this->assertEquals('2015-01-28', $result['join_date']);
1176 $this->assertEquals('2015-01-01', $result['start_date']);
1177 $this->assertEquals('2015-12-31', $result['end_date']);
1181 * Test correct end date for fixed single year memberships is calculated and start_date is not changed.
1183 * In this set our start date is after the start day and before the rollover day so we don't get an extra year
1184 * and we end one day before the rollover day. Start day is 1 Jan so we end on 31 Dec
1185 * and we add on <1 years rather than > 1 because we are not after the rollover day - so we calculate 31 Dec 2015
1187 public function testFixedSingleYearDateSetTwoEmptyEndDate() {
1188 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1190 $this->callAPISuccess('membership_type', 'create', array(
1191 'id' => $this->_membershipTypeID2
,
1192 'duration_interval' => 1,
1194 'fixed_period_start_day' => '101',
1196 'fixed_period_rollover_day' => '1101',
1198 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1200 'start_date' => '28-Jan 2015',
1201 'join_date' => '28-Jan 2015',
1203 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1204 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1205 $this->assertEquals('2015-01-28', $result['join_date']);
1206 $this->assertEquals('2015-01-28', $result['start_date']);
1207 $this->assertEquals('2015-12-31', $result['end_date']);
1211 * Test that correct end date is calculated for fixed multi year memberships and start date is not changed.
1213 * In this set our start date is after the start day and after the rollover day so we do get an extra year
1214 * and we end one day before the rollover day. Start day is 1 Nov so we end on 31 Oct
1215 * and we add on 1 year we are after the rollover day - so we calculate 31 Oct 2016
1217 public function testFixedSingleYearDateSetThreeEmptyEndDate() {
1218 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1220 $this->callAPISuccess('membership_type', 'create', array(
1221 'id' => $this->_membershipTypeID2
,
1222 'duration_interval' => 1,
1224 'fixed_period_start_day' => '1101',
1226 'fixed_period_rollover_day' => '101',
1228 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1230 'start_date' => '28-Jan 2015',
1231 'join_date' => '28-Jan 2015',
1233 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1234 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1235 $this->assertEquals('2015-01-28', $result['join_date']);
1236 $this->assertEquals('2015-01-28', $result['start_date']);
1237 $this->assertEquals('2016-10-31', $result['end_date']);
1241 * Test correct end and start dates are calculated for fixed multi year memberships.
1243 * The empty start date is calculated to be the start_date (1 Nov prior to the join_date - so 1 Nov 14)
1245 * In this set our start date is after the start day and after the rollover day so we do get an extra year
1246 * and we end one day before the rollover day. Start day is 1 Nov so we end on 31 Oct
1247 * and we add on 1 year we are after the rollover day - so we calculate 31 Oct 2016
1249 public function testFixedSingleYearDateSetThreeEmptyStartEndDate() {
1250 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1252 $this->callAPISuccess('membership_type', 'create', array(
1253 'id' => $this->_membershipTypeID2
,
1254 'duration_interval' => 1,
1256 'fixed_period_start_day' => '1101',
1258 'fixed_period_rollover_day' => '101',
1260 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1262 'join_date' => '28-Jan 2015',
1264 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1265 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1266 $this->assertEquals('2015-01-28', $result['join_date']);
1267 $this->assertEquals('2014-11-01', $result['start_date']);
1268 $this->assertEquals('2016-10-31', $result['end_date']);
1272 * Test that correct end date is calculated for fixed multi year memberships and start date is not changed.
1274 * In this set our start date is after the start day and after the rollover day so we do get an extra year
1275 * and we end one day before the rollover day. Start day is 1 Nov so we end on 31 Oct
1276 * and we add on 5 years we are after the rollover day - so we calculate 31 Oct 2020
1278 public function testFixedMultiYearDateSetThreeEmptyEndDate() {
1279 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1281 $this->callAPISuccess('membership_type', 'create', array(
1282 'id' => $this->_membershipTypeID2
,
1283 'duration_interval' => 5,
1285 'fixed_period_start_day' => '1101',
1287 'fixed_period_rollover_day' => '101',
1289 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1291 'start_date' => '28-Jan 2015',
1292 'join_date' => '28-Jan 2015',
1294 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1295 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1296 $this->assertEquals('2015-01-28', $result['join_date']);
1297 $this->assertEquals('2015-01-28', $result['start_date']);
1298 $this->assertEquals('2020-10-31', $result['end_date']);
1302 * Test correct end and start dates are calculated for fixed multi year memberships.
1304 * The empty start date is calculated to be the start_date (1 Nov prior to the join_date - so 1 Nov 14)
1306 * The empty start date is calculated to be the start_date (1 Nov prior to the join_date - so 1 Nov 14)
1307 * In this set our join date is after the start day and after the rollover day so we do get an extra year
1308 * and we end one day before the rollover day. Start day is 1 Nov so we end on 31 Oct
1309 * and we add on 5 years we are after the rollover day - so we calculate 31 Oct 2020
1311 public function testFixedMultiYearDateSetThreeEmptyStartEndDate() {
1312 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1314 $this->callAPISuccess('membership_type', 'create', array(
1315 'id' => $this->_membershipTypeID2
,
1316 'duration_interval' => 5,
1318 'fixed_period_start_day' => '1101',
1320 'fixed_period_rollover_day' => '101',
1322 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1324 'join_date' => '28-Jan 2015',
1326 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1327 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1328 $this->assertEquals('2015-01-28', $result['join_date']);
1329 $this->assertEquals('2014-11-01', $result['start_date']);
1330 $this->assertEquals('2020-10-31', $result['end_date']);
1334 * Test that if membership start date is not set it defaults to correct end date for fixed single year memberships.
1336 public function testEmptyStartDateRolling() {
1337 unset($this->_params
['start_date'], $this->_params
['is_override']);
1338 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1339 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1340 $this->assertEquals('2009-01-21', $result['join_date']);
1341 $this->assertEquals('2009-01-21', $result['start_date']);
1342 $this->assertEquals('2009-12-21', $result['end_date']);
1346 * Test that if membership end date is not set it defaults to correct end date.
1349 public function testEmptyEndDateFixed() {
1350 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1351 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1352 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1353 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1354 $this->assertEquals('2009-01-21', $result['join_date']);
1355 $this->assertEquals('2008-03-01', $result['start_date']);
1356 $this->assertEquals('2010-02-28', $result['end_date']);
1360 * Test that if membership end date is not set it defaults to correct end date.
1363 public function testEmptyEndDateRolling() {
1364 unset($this->_params
['is_override'], $this->_params
['end_date']);
1365 $this->_params
['membership_type_id'] = $this->_membershipTypeID
;
1366 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1367 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1368 $this->assertEquals('2009-01-21', $result['join_date']);
1369 $this->assertEquals('2009-01-21', $result['start_date']);
1370 $this->assertEquals('2010-01-20', $result['end_date']);
1375 * Test that if dates are set they not over-ridden if id is passed in
1377 public function testMembershipDatesNotOverridden() {
1378 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1379 unset($this->_params
['end_date'], $this->_params
['start_date']);
1380 $this->_params
['id'] = $result['id'];
1381 $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1382 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1383 $this->assertEquals('2009-01-21', $result['join_date']);
1384 $this->assertEquals('2009-01-21', $result['start_date']);
1385 $this->assertEquals('2009-12-21', $result['end_date']);
1390 * Test that all membership types are returned when getoptions is called.
1392 * This test locks in current behaviour where types for all domains are returned. It should possibly be domain
1393 * specific but that should only be done in conjunction with adding a hook to allow that to be altered as the
1394 * multisite use case expects the master domain to be able to see all sites.
1398 public function testGetOptionsMembershipTypeID() {
1399 $options = $this->callAPISuccess('Membership', 'getoptions', array('field' => 'membership_type_id'));
1400 $this->assertEquals('General', array_pop($options['values']));
1401 $this->assertEquals('General', array_pop($options['values']));
1402 $this->assertEquals(NULL, array_pop($options['values']));