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
35 require_once 'CiviTest/CiviUnitTestCase.php';
38 * Class api_v3_MembershipTest
40 class api_v3_MembershipTest
extends CiviUnitTestCase
{
41 protected $_apiversion;
42 protected $_contactID;
43 protected $_membershipID;
44 protected $_membershipID2;
45 protected $_membershipID3;
46 protected $_membershipTypeID;
47 protected $_membershipTypeID2;
48 protected $_membershipStatusID;
55 public function setUp() {
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
,
87 * Clean up after tests.
91 public function tearDown() {
92 $this->quickCleanup(array(
94 'civicrm_membership_payment',
95 'civicrm_membership_log',
99 $this->membershipStatusDelete($this->_membershipStatusID
);
100 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID2
));
101 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID
));
102 $this->contactDelete($this->_contactID
);
107 * Test membership deletion.
109 public function testMembershipDelete() {
110 $membershipID = $this->contactMembershipCreate($this->_params
);
111 $this->assertDBRowExist('CRM_Member_DAO_Membership', $membershipID);
113 'id' => $membershipID,
115 $this->callAPIAndDocument('membership', 'delete', $params, __FUNCTION__
, __FILE__
);
116 $this->assertDBRowNotExist('CRM_Member_DAO_Membership', $membershipID);
119 public function testMembershipDeleteEmpty() {
120 $this->callAPIFailure('membership', 'delete', array());
123 public function testMembershipDeleteInvalidID() {
124 $this->callAPIFailure('membership', 'delete', array('id' => 'blah'));
128 * Test civicrm_membership_delete() with invalid Membership Id.
130 public function testMembershipDeleteWithInvalidMembershipId() {
131 $membershipId = 'membership';
132 $this->callAPIFailure('membership', 'delete', $membershipId);
136 * Test membership get.
138 public function testContactMembershipsGet() {
139 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
140 $this->callAPISuccess('membership', 'get', array());
141 $this->callAPISuccess('Membership', 'Delete', array('id' => $this->_membershipID
));
145 * Test civicrm_membership_get with params not array.
147 * Gets treated as contact_id, memberships expected.
149 public function testGetWithParamsContactId() {
150 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
152 'contact_id' => $this->_contactID
,
154 $membership = $this->callAPISuccess('membership', 'get', $params);
156 $result = $membership['values'][$this->_membershipID
];
157 $this->callAPISuccess('Membership', 'Delete', array(
158 'id' => $this->_membershipID
,
160 $this->assertEquals($result['contact_id'], $this->_contactID
, "In line " . __LINE__
);
161 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID
, "In line " . __LINE__
);
162 $this->assertEquals($result['status_id'], $this->_membershipStatusID
, "In line " . __LINE__
);
163 $this->assertEquals($result['join_date'], '2009-01-21', "In line " . __LINE__
);
164 $this->assertEquals($result['start_date'], '2009-01-21', "In line " . __LINE__
);
165 $this->assertEquals($result['end_date'], '2009-12-21', "In line " . __LINE__
);
166 $this->assertEquals($result['source'], 'Payment', "In line " . __LINE__
);
167 $this->assertEquals($result['is_override'], 1, "In line " . __LINE__
);
171 * Test civicrm_membership_get with params not array.
173 * Gets treated as contact_id, memberships expected.
175 public function testGetInSyntax() {
176 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
177 $this->_membershipID2
= $this->contactMembershipCreate($this->_params
);
178 $this->_membershipID3
= $this->contactMembershipCreate($this->_params
);
180 'id' => array('IN' => array($this->_membershipID
, $this->_membershipID3
)),
182 $membership = $this->callAPISuccess('membership', 'get', $params);
183 $this->assertEquals(2, $membership['count']);
184 $this->assertEquals(array($this->_membershipID
, $this->_membershipID3
), array_keys($membership['values']));
186 'id' => array('NOT IN' => array($this->_membershipID
, $this->_membershipID3
)),
188 $membership = $this->callAPISuccess('membership', 'get', $params);
189 $this->assertEquals(1, $membership['count']);
190 $this->assertEquals(array($this->_membershipID2
), array_keys($membership['values']));
194 * Test civicrm_membership_get with params not array.
195 * Gets treated as contact_id, memberships expected.
197 public function testGetInSyntaxOnContactID() {
198 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
199 $contact2 = $this->individualCreate();
200 $contact3 = $this->individualCreate(array('first_name' => 'Scout', 'last_name' => 'Canine'));
201 $this->_membershipID2
= $this->contactMembershipCreate(array_merge($this->_params
, array('contact_id' => $contact2)));
202 $this->_membershipID3
= $this->contactMembershipCreate(array_merge($this->_params
, array('contact_id' => $contact3)));
204 'contact_id' => array('IN' => array($this->_contactID
, $contact3)),
206 $membership = $this->callAPISuccess('membership', 'get', $params);
207 $this->assertEquals(2, $membership['count']);
208 $this->assertEquals(array($this->_membershipID
, $this->_membershipID3
), array_keys($membership['values']));
210 'contact_id' => array('NOT IN' => array($this->_contactID
, $contact3)),
212 $membership = $this->callAPISuccess('membership', 'get', $params);
213 $this->assertEquals(1, $membership['count']);
214 $this->assertEquals(array($this->_membershipID2
), array_keys($membership['values']));
218 * Test civicrm_membership_get with params not array.
220 * Gets treated as contact_id, memberships expected.
222 public function testGetWithParamsMemberShipTypeId() {
223 $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
225 'membership_type_id' => $this->_membershipTypeID
,
227 $membership = $this->callAPISuccess('membership', 'get', $params);
228 $this->callAPISuccess('Membership', 'Delete', array(
229 'id' => $membership['id'],
231 $result = $membership['values'][$membership['id']];
232 $this->assertEquals($result['contact_id'], $this->_contactID
);
233 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID
);
234 $this->assertEquals($result['status_id'], $this->_membershipStatusID
);
235 $this->assertEquals($result['join_date'], '2009-01-21');
236 $this->assertEquals($result['start_date'], '2009-01-21');
237 $this->assertEquals($result['end_date'], '2009-12-21');
238 $this->assertEquals($result['source'], 'Payment');
239 $this->assertEquals($result['is_override'], 1);
240 $this->assertEquals($result['id'], $membership['id']);
244 * Test civicrm_membership_get with params not array.
245 * Gets treated as contact_id, memberships expected.
247 public function testGetWithParamsMemberShipTypeIdContactID() {
248 $params = $this->_params
;
249 $this->callAPISuccess($this->_entity
, 'create', $params);
250 $params['membership_type_id'] = $this->_membershipTypeID2
;
251 $this->callAPISuccess($this->_entity
, 'create', $params);
252 $this->callAPISuccessGetCount('membership', array('contact_id' => $this->_contactID
), 2);
254 'membership_type_id' => $this->_membershipTypeID
,
255 'contact_id' => $this->_contactID
,
257 $result = $this->callAPISuccess('membership', 'getsingle', $params);
258 $this->assertEquals($result['contact_id'], $this->_contactID
);
259 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID
);
262 'membership_type_id' => $this->_membershipTypeID2
,
263 'contact_id' => $this->_contactID
,
265 $result = $this->callAPISuccess('membership', 'getsingle', $params);
266 $this->assertEquals($result['contact_id'], $this->_contactID
);
267 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID2
);
271 * Check with complete array + custom field.
273 * Note that the test is written on purpose without any
274 * variables specific to participant so it can be replicated into other entities
275 * and / or moved to the automated test suite
277 public function testGetWithParamsMemberShipIdAndCustom() {
278 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
280 $params = $this->_params
;
281 $params['custom_' . $ids['custom_field_id']] = "custom string";
283 $result = $this->callAPISuccess($this->_entity
, 'create', $params);
285 $getParams = array('membership_type_id' => $params['membership_type_id']);
286 $check = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
);
287 $this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
289 $this->callAPISuccess('Membership', 'Delete', array(
290 'id' => $result['id'],
295 * Test civicrm_membership_get with proper params.
296 * Memberships expected.
298 public function testGet() {
299 $membershipID = $this->contactMembershipCreate($this->_params
);
301 'contact_id' => $this->_contactID
,
304 $membership = $this->callAPISuccess('membership', 'get', $params);
305 $result = $membership['values'][$membershipID];
306 $this->callAPISuccess('Membership', 'Delete', array(
307 'id' => $membership['id'],
309 $this->assertEquals($result['join_date'], '2009-01-21');
310 $this->assertEquals($result['contact_id'], $this->_contactID
);
311 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID
);
312 $this->assertEquals($result['status_id'], $this->_membershipStatusID
);
314 $this->assertEquals($result['start_date'], '2009-01-21');
315 $this->assertEquals($result['end_date'], '2009-12-21');
316 $this->assertEquals($result['source'], 'Payment');
317 $this->assertEquals($result['is_override'], 1);
322 * Test civicrm_membership_get with proper params.
323 * Memberships expected.
325 public function testGetWithId() {
326 $membershipID = $this->contactMembershipCreate($this->_params
);
328 'contact_id' => $this->_contactID
,
329 'id' => $this->_membershipID
,
332 $result = $this->callAPISuccess('membership', 'get', $params);
333 $this->assertEquals($membershipID, $result['id']);
335 'contact_id' => $this->_contactID
,
336 'membership_id' => $this->_membershipID
,
337 'return' => 'membership_id',
339 $result = $this->callAPISuccess('membership', 'get', $params);
340 $this->assertEquals($membershipID, $result['id']);
344 * Test civicrm_membership_get for only active.
345 * Memberships expected.
347 public function testGetOnlyActive() {
348 $description = "Demonstrates use of 'filter' active_only' param.";
349 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
351 'contact_id' => $this->_contactID
,
355 $membership = $this->callAPISuccess('membership', 'get', $params);
356 $this->assertEquals($membership['values'][$this->_membershipID
]['status_id'], $this->_membershipStatusID
);
357 $this->assertEquals($membership['values'][$this->_membershipID
]['contact_id'], $this->_contactID
);
359 'contact_id' => $this->_contactID
,
365 $membership = $this->callAPIAndDocument('membership', 'get', $params, __FUNCTION__
, __FILE__
, $description, 'FilterIsCurrent');
366 $this->assertEquals($membership['values'][$this->_membershipID
]['status_id'], $this->_membershipStatusID
);
367 $this->assertEquals($membership['values'][$this->_membershipID
]['contact_id'], $this->_contactID
);
369 $this->callAPISuccess('Membership', 'Delete', array('id' => $this->_membershipID
));
373 * Test civicrm_membership_get for non exist contact.
376 public function testGetNoContactExists() {
378 'contact_id' => 55555,
381 $membership = $this->callAPISuccess('membership', 'get', $params);
382 $this->assertEquals($membership['count'], 0);
386 * Test civicrm_membership_get with relationship.
389 public function testGetWithRelationship() {
390 $membershipOrgId = $this->organizationCreate(NULL);
391 $memberContactId = $this->individualCreate();
393 $relTypeParams = array(
394 'name_a_b' => 'Relation 1',
395 'name_b_a' => 'Relation 2',
396 'description' => 'Testing relationship type',
397 'contact_type_a' => 'Organization',
398 'contact_type_b' => 'Individual',
402 $relTypeID = $this->relationshipTypeCreate($relTypeParams);
405 'name' => 'test General',
406 'duration_unit' => 'year',
407 'duration_interval' => 1,
408 'period_type' => 'rolling',
409 'member_of_contact_id' => $membershipOrgId,
411 'financial_type_id' => 1,
412 'relationship_type_id' => $relTypeID,
413 'relationship_direction' => 'b_a',
416 $memType = $this->callAPISuccess('membership_type', 'create', $params);
419 'contact_id' => $memberContactId,
420 'membership_type_id' => $memType['id'],
421 'join_date' => '2009-01-21',
422 'start_date' => '2009-01-21',
423 'end_date' => '2009-12-21',
424 'source' => 'Payment',
426 'status_id' => $this->_membershipStatusID
,
428 $membershipID = $this->contactMembershipCreate($params);
431 'contact_id' => $memberContactId,
432 'membership_type_id' => $memType['id'],
435 $result = $this->callAPISuccess('membership', 'get', $params);
437 $membership = $result['values'][$membershipID];
438 $this->assertEquals($this->_membershipStatusID
, $membership['status_id']);
439 $this->callAPISuccess('Membership', 'Delete', array(
440 'id' => $membership['id'],
442 $this->membershipTypeDelete(array('id' => $memType['id']));
443 $this->relationshipTypeDelete($relTypeID);
444 $this->contactDelete($membershipOrgId);
445 $this->contactDelete($memberContactId);
449 * Test civicrm_membership_create with relationships.
450 * create/get Memberships.
452 * Test suite for CRM-14758: API ( contact, create ) does not always create related membership
453 * and max_related property for Membership_Type and Membership entities
455 public function testCreateWithRelationship() {
456 // Create membership type: inherited through employment, max_related = 2
458 'name_a_b' => 'Employee of',
460 $result = $this->callAPISuccess('relationship_type', 'get', $params);
461 $relationshipTypeId = $result['id'];
462 $membershipOrgId = $this->organizationCreate();
464 'name' => 'Corporate Membership',
465 'duration_unit' => 'year',
466 'duration_interval' => 1,
467 'period_type' => 'rolling',
468 'member_of_contact_id' => $membershipOrgId,
470 'financial_type_id' => 1,
471 'relationship_type_id' => $relationshipTypeId,
472 'relationship_direction' => 'b_a',
476 $result = $this->callAPISuccess('membership_type', 'create', $params);
477 $membershipTypeId = $result['id'];
479 // Create employer and first employee
480 $employerId[0] = $this->organizationCreate(array(), 1);
481 $memberContactId[0] = $this->individualCreate(array('employer_id' => $employerId[0]), 0);
483 // Create organization's membership
485 'contact_id' => $employerId[0],
486 'membership_type_id' => $membershipTypeId,
487 'source' => 'Test suite',
488 'start_date' => date('Y-m-d'),
489 'end_date' => "+1 year",
491 $OrganizationMembershipID = $this->contactMembershipCreate($params);
493 // Check that the employee inherited the membership
495 'contact_id' => $memberContactId[0],
496 'membership_type_id' => $membershipTypeId,
499 $result = $this->callAPISuccess('membership', 'get', $params);
501 $this->assertEquals(1, $result['count']);
502 $result = $result['values'][$result['id']];
503 $this->assertEquals($OrganizationMembershipID, $result['owner_membership_id']);
505 // Create second employee
506 $memberContactId[1] = $this->individualCreate(array('employer_id' => $employerId[0]), 1);
508 // Check that the employee inherited the membership
510 'contact_id' => $memberContactId[1],
511 'membership_type_id' => $membershipTypeId,
513 $result = $this->callAPISuccess('membership', 'get', $params);
514 // If it fails here CRM-14758 is not fixed
515 $this->assertEquals(1, $result['count']);
516 $result = $result['values'][$result['id']];
517 $this->assertEquals($OrganizationMembershipID, $result['owner_membership_id']);
519 // Create third employee
520 $memberContactId[2] = $this->individualCreate(array('employer_id' => $employerId[0]), 2);
522 // Check that employee does NOT inherit the membership (max_related = 2)
524 'contact_id' => $memberContactId[2],
525 'membership_type_id' => $membershipTypeId,
527 $result = $this->callAPISuccess('membership', 'get', $params);
528 $this->assertEquals(0, $result['count']);
530 // Increase max_related for the employer's membership
532 'id' => $OrganizationMembershipID,
535 $this->contactMembershipCreate($params);
537 // Check that the employee inherited the membership
539 'contact_id' => $memberContactId[2],
540 'membership_type_id' => $membershipTypeId,
542 $result = $this->callAPISuccess('membership', 'get', $params);
543 $this->assertEquals(1, $result['count']);
544 $result = $result['values'][$result['id']];
545 $this->assertEquals($OrganizationMembershipID, $result['owner_membership_id']);
547 // First employee moves to a new job
548 $employerId[1] = $this->organizationCreate(array(), 2);
550 'id' => $memberContactId[0],
551 'employer_id' => $employerId[1],
553 $this->callAPISuccess('contact', 'create', $params);
555 // Check that employee does NO LONGER inherit the membership
557 'contact_id' => $memberContactId[0],
558 'membership_type_id' => $membershipTypeId,
560 $result = $this->callAPISuccess('membership', 'get', $params);
561 $this->assertEquals(0, $result['count']);
563 // Set up params for enable/disable checks
564 $relationship1 = $this->callAPISuccess('relationship', 'get', array('contact_id_a' => $memberContactId[1]));
566 'contact_id' => $memberContactId[1],
567 'membership_type_id' => $membershipTypeId,
570 // Deactivate relationship using create and assert membership is not inherited
571 $this->callAPISuccess('relationship', 'create', array('id' => $relationship1['id'], 'is_active' => 0));
572 $result = $this->callAPISuccess('membership', 'get', $params);
573 $this->assertEquals(0, $result['count']);
575 // Re-enable relationship using create and assert membership is inherited
576 $this->callAPISuccess('relationship', 'create', array('id' => $relationship1['id'], 'is_active' => 1));
577 $result = $this->callAPISuccess('membership', 'get', $params);
578 $this->assertEquals(1, $result['count']);
580 // Deactivate relationship using setvalue and assert membership is not inherited
581 $this->callAPISuccess('relationship', 'setvalue', array('id' => $relationship1['id'], 'field' => 'is_active', 'value' => 0));
582 $result = $this->callAPISuccess('membership', 'get', $params);
583 $this->assertEquals(0, $result['count']);
585 // Re-enable relationship using setvalue and assert membership is inherited
586 $this->callAPISuccess('relationship', 'setvalue', array('id' => $relationship1['id'], 'field' => 'is_active', 'value' => 1));
587 $result = $this->callAPISuccess('membership', 'get', $params);
588 $this->assertEquals(1, $result['count']);
590 // Delete relationship and assert membership is not inherited
591 $this->callAPISuccess('relationship', 'delete', array('id' => $relationship1['id']));
592 $result = $this->callAPISuccess('membership', 'get', $params);
593 $this->assertEquals(0, $result['count']);
595 // Tear down - reverse of creation to be safe
596 $this->contactDelete($memberContactId[2]);
597 $this->contactDelete($memberContactId[1]);
598 $this->contactDelete($memberContactId[0]);
599 $this->contactDelete($employerId[1]);
600 $this->contactDelete($employerId[0]);
601 $this->membershipTypeDelete(array('id' => $membershipTypeId));
602 $this->contactDelete($membershipOrgId);
606 * We are checking for no e-notices + only id & end_date returned
608 public function testMembershipGetWithReturn() {
609 $this->contactMembershipCreate($this->_params
);
610 $result = $this->callAPISuccess('membership', 'get', array('return' => 'end_date'));
611 foreach ($result['values'] as $membership) {
612 $this->assertEquals(array('end_date', 'membership_end_date', 'id'), array_keys($membership));
615 ///////////////// civicrm_membership_create methods
618 * Test civicrm_contact_memberships_create with empty params.
621 public function testCreateWithEmptyParams() {
623 $this->callAPIFailure('membership', 'create', $params);
627 * If is_overide is passed in status must also be passed in.
629 public function testCreateOverrideNoStatus() {
630 $params = $this->_params
;
631 unset($params['status_id']);
632 $this->callAPIFailure('membership', 'create', $params);
635 public function testMembershipCreateMissingRequired() {
637 'membership_type_id' => '1',
638 'join_date' => '2006-01-21',
639 'start_date' => '2006-01-21',
640 'end_date' => '2006-12-21',
641 'source' => 'Payment',
645 $this->callAPIFailure('membership', 'create', $params);
648 public function testMembershipCreate() {
650 'contact_id' => $this->_contactID
,
651 'membership_type_id' => $this->_membershipTypeID
,
652 'join_date' => '2006-01-21',
653 'start_date' => '2006-01-21',
654 'end_date' => '2006-12-21',
655 'source' => 'Payment',
657 'status_id' => $this->_membershipStatusID
,
660 $result = $this->callAPIAndDocument('membership', 'create', $params, __FUNCTION__
, __FILE__
);
661 $this->getAndCheck($params, $result['id'], $this->_entity
);
662 $this->assertNotNull($result['id']);
663 $this->assertEquals($this->_contactID
, $result['values'][$result['id']]['contact_id'], " in line " . __LINE__
);
664 $this->assertEquals($result['id'], $result['values'][$result['id']]['id'], " in line " . __LINE__
);
668 * Check for useful message if contact doesn't exist
670 public function testMembershipCreateWithInvalidContact() {
673 'membership_type_id' => $this->_membershipTypeID
,
674 'join_date' => '2006-01-21',
675 'start_date' => '2006-01-21',
676 'end_date' => '2006-12-21',
677 'source' => 'Payment',
679 'status_id' => $this->_membershipStatusID
,
682 $this->callAPIFailure('membership', 'create', $params,
683 'contact_id is not valid : 999'
687 public function testMembershipCreateWithInvalidStatus() {
688 $params = $this->_params
;
689 $params['status_id'] = 999;
690 $this->callAPIFailure('membership', 'create', $params,
691 "'999' is not a valid option for field status_id"
695 public function testMembershipCreateWithInvalidType() {
696 $params = $this->_params
;
697 $params['membership_type_id'] = 999;
699 $this->callAPIFailure('membership', 'create', $params,
700 "'999' is not a valid option for field membership_type_id"
705 * Check with complete array + custom field
706 * Note that the test is written on purpose without any
707 * variables specific to participant so it can be replicated into other entities
708 * and / or moved to the automated test suite
710 public function testCreateWithCustom() {
711 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
713 $params = $this->_params
;
714 $params['custom_' . $ids['custom_field_id']] = "custom string";
716 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
, NULL, 'CreateWithCustomData');
717 $check = $this->callAPISuccess($this->_entity
, 'get', array(
718 'id' => $result['id'],
719 'contact_id' => $this->_contactID
,
721 $this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
725 * Search on custom field value.
727 public function testSearchWithCustomDataCRM16036() {
728 // Create a custom field on membership
729 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
731 // Create a new membership, but don't assign anything to the custom field.
732 $params = $this->_params
;
733 $result = $this->callAPIAndDocument(
740 'SearchWithCustomData');
742 // search memberships with CRM-16036 as custom field value.
743 // Since we did not touch the custom field of any membership,
744 // this should not return any results.
745 $check = $this->callAPISuccess($this->_entity
, 'get', array(
746 'custom_' . $ids['custom_field_id'] => "CRM-16036",
750 $this->callAPISuccess($this->_entity
, 'delete', array(
751 'id' => $result['id'],
755 $this->assertEquals(0, $check['count']);
759 * Test civicrm_contact_memberships_create with membership id (edit
763 public function testMembershipCreateWithId() {
764 $membershipID = $this->contactMembershipCreate($this->_params
);
766 'id' => $membershipID,
767 'contact_id' => $this->_contactID
,
768 'membership_type_id' => $this->_membershipTypeID
,
769 'join_date' => '2006-01-21',
770 'start_date' => '2006-01-21',
771 'end_date' => '2006-12-21',
772 'source' => 'Payment',
774 'status_id' => $this->_membershipStatusID
,
777 $result = $this->callAPISuccess('membership', 'create', $params);
778 $this->callAPISuccess('Membership', 'Delete', array(
779 'id' => $result['id'],
781 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
785 * Test civicrm_contact_memberships_create with membership id (edit
789 public function testMembershipCreateUpdateWithIdNoContact() {
790 $membershipID = $this->contactMembershipCreate($this->_params
);
792 'id' => $membershipID,
793 'membership_type_id' => $this->_membershipTypeID
,
794 'contact_id' => $this->_contactID
,
795 'join_date' => '2006-01-21',
796 'start_date' => '2006-01-21',
797 'end_date' => '2006-12-21',
798 'source' => 'Payment',
800 'status_id' => $this->_membershipStatusID
,
803 $result = $this->callAPISuccess('membership', 'create', $params);
804 $this->callAPISuccess('Membership', 'Delete', array(
805 'id' => $result['id'],
808 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
812 * Test civicrm_contact_memberships_create with membership id (edit
816 public function testMembershipCreateUpdateWithIdNoDates() {
817 $membershipID = $this->contactMembershipCreate($this->_params
);
819 'id' => $membershipID,
820 'contact_id' => $this->_contactID
,
821 'membership_type_id' => $this->_membershipTypeID
,
822 'source' => 'Payment',
824 'status_id' => $this->_membershipStatusID
,
827 $result = $this->callAPISuccess('membership', 'create', $params);
828 $this->callAPISuccess('Membership', 'Delete', array(
829 'id' => $result['id'],
831 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
835 * Test civicrm_contact_memberships_create with membership id (edit
839 public function testMembershipCreateUpdateWithIdNoDatesNoType() {
840 $membershipID = $this->contactMembershipCreate($this->_params
);
842 'id' => $membershipID,
843 'source' => 'not much here',
844 'contact_id' => $this->_contactID
,
846 'status_id' => $this->_membershipStatusID
,
849 $result = $this->callAPISuccess('membership', 'create', $params);
850 $this->callAPISuccess('Membership', 'Delete', array(
851 'id' => $result['id'],
853 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
857 * Test civicrm_contact_memberships_create with membership id (edit
861 public function testMembershipCreateUpdateWithIDAndSource() {
862 $membershipID = $this->contactMembershipCreate($this->_params
);
864 'id' => $membershipID,
865 'source' => 'changed',
866 'contact_id' => $this->_contactID
,
867 'status_id' => $this->_membershipStatusID
,
868 'membership_type_id' => $this->_membershipTypeID
,
869 'skipStatusCal' => 1,
871 $result = $this->callAPISuccess('membership', 'create', $params);
872 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
873 $this->callAPISuccess('Membership', 'Delete', array(
874 'id' => $result['id'],
879 * Change custom field using update.
881 public function testUpdateWithCustom() {
882 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
884 $params = $this->_params
;
885 $params['custom_' . $ids['custom_field_id']] = "custom string";
886 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
, NULL, 'UpdateCustomData');
887 $result = $this->callAPISuccess($this->_entity
, 'create', array(
888 'id' => $result['id'],
889 'custom_' . $ids['custom_field_id'] => "new custom",
891 $check = $this->callAPISuccess($this->_entity
, 'get', array(
892 'id' => $result['id'],
893 'contact_id' => $this->_contactID
,
896 $this->assertEquals("new custom", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
897 $this->callAPISuccess('Membership', 'Delete', array(
898 'id' => $check['id'],
901 $this->customFieldDelete($ids['custom_field_id']);
902 $this->customGroupDelete($ids['custom_group_id']);
906 * per CRM-15746 check that the id can be altered in an update hook
908 public function testMembershipUpdateCreateHookCRM15746() {
909 $this->hookClass
->setHook('civicrm_pre', array($this, 'hook_civicrm_pre_update_create_membership'));
910 $result = $this->callAPISuccess('membership', 'create', $this->_params
);
911 $this->callAPISuccess('membership', 'create', array('id' => $result['id'], 'end_date' => '1 year ago'));
912 $this->callAPISuccessGetCount('membership', array(), 2);
913 $this->hookClass
->reset();
914 $this->callAPISuccess('membership', 'create', array('id' => $result['id'], 'end_date' => '1 year ago'));
915 $this->callAPISuccessGetCount('membership', array(), 2);
919 * Custom hook for update membership.
922 * @param object $objectName
924 * @param array $params
928 public function hook_civicrm_pre_update_create_membership($op, $objectName, $id, &$params) {
929 if ($objectName == 'Membership' && $op == 'edit') {
930 $existingMembership = $this->callAPISuccessGetSingle('membership', array('id' => $params['id']));
931 unset($params['id'], $params['membership_id']);
932 $params['join_date'] = $params['membership_start_date'] = $params['start_date'] = date('Ymd000000', strtotime($existingMembership['start_date']));
933 $params = array_merge($existingMembership, $params);
934 $params['id'] = NULL;
939 * Test civicrm_contact_memberships_create Invalid membership data.
942 public function testMembershipCreateInvalidMemData() {
943 //membership_contact_id as string
945 'membership_contact_id' => 'Invalid',
946 'membership_type_id' => $this->_membershipTypeID
,
947 'join_date' => '2011-01-21',
948 'start_date' => '2010-01-21',
949 'end_date' => '2008-12-21',
950 'source' => 'Payment',
952 'status_id' => $this->_membershipStatusID
,
955 $this->callAPIFailure('membership', 'create', $params);
957 //membership_contact_id which is no in contact table
958 $params['membership_contact_id'] = 999;
959 $this->callAPIFailure('membership', 'create', $params);
962 unset($params['membership_contact_id']);
963 $params['join_date'] = "invalid";
964 $this->callAPIFailure('Membership', 'Create', $params);
968 * Test civicrm_contact_memberships_create with membership_contact_id
972 public function testMembershipCreateWithMemContact() {
974 'membership_contact_id' => $this->_contactID
,
975 'membership_type_id' => $this->_membershipTypeID
,
976 'join_date' => '2011-01-21',
977 'start_date' => '2010-01-21',
978 'end_date' => '2008-12-21',
979 'source' => 'Payment',
981 'status_id' => $this->_membershipStatusID
,
984 $result = $this->callAPISuccess('membership', 'create', $params);
986 $this->callAPISuccess('Membership', 'Delete', array(
987 'id' => $result['id'],
992 * Test civicrm_contact_memberships_create with membership_contact_id
996 public function testMembershipCreateValidMembershipTypeString() {
998 'membership_contact_id' => $this->_contactID
,
999 'membership_type_id' => 'General',
1000 'join_date' => '2011-01-21',
1001 'start_date' => '2010-01-21',
1002 'end_date' => '2008-12-21',
1003 'source' => 'Payment',
1005 'status_id' => $this->_membershipStatusID
,
1008 $result = $this->callAPISuccess('membership', 'create', $params);
1009 $this->assertEquals($this->_membershipTypeID
, $result['values'][$result['id']]['membership_type_id']);
1010 $this->callAPISuccess('Membership', 'Delete', array(
1011 'id' => $result['id'],
1016 * Test civicrm_contact_memberships_create with membership_contact_id
1020 public function testMembershipCreateInValidMembershipTypeString() {
1022 'membership_contact_id' => $this->_contactID
,
1023 'membership_type_id' => 'invalid',
1024 'join_date' => '2011-01-21',
1025 'start_date' => '2010-01-21',
1026 'end_date' => '2008-12-21',
1027 'source' => 'Payment',
1029 'status_id' => $this->_membershipStatusID
,
1032 $this->callAPIFailure('membership', 'create', $params);
1036 * Test that if membership join date is not set it defaults to today.
1038 public function testEmptyJoinDate() {
1039 unset($this->_params
['join_date'], $this->_params
['is_override']);
1040 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1041 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1042 $this->assertEquals(date('Y-m-d', strtotime('now')), $result['join_date']);
1043 $this->assertEquals('2009-01-21', $result['start_date']);
1044 $this->assertEquals('2009-12-21', $result['end_date']);
1048 * Test that if membership start date is not set it defaults to correct end date.
1051 public function testEmptyStartDateFixed() {
1052 unset($this->_params
['start_date'], $this->_params
['is_override']);
1053 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1054 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1055 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1056 $this->assertEquals('2009-01-21', $result['join_date']);
1057 $this->assertEquals('2008-03-01', $result['start_date']);
1058 $this->assertEquals('2009-12-21', $result['end_date']);
1062 * Test that if membership start date is not set it defaults to correct end date
1065 public function testEmptyStartEndDateFixedOneYear() {
1066 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1067 $this->callAPISuccess('membership_type', 'create', array('id' => $this->_membershipTypeID2
, 'duration_interval' => 1));
1068 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1069 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1070 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1071 $this->assertEquals('2009-01-21', $result['join_date']);
1072 $this->assertEquals('2008-03-01', $result['start_date']);
1073 $this->assertEquals('2010-02-28', $result['end_date']);
1077 * Test that if membership start date is not set it defaults to correct end date for fixed multi year memberships.
1079 public function testEmptyStartEndDateFixedMultiYear() {
1080 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1081 $this->callAPISuccess('membership_type', 'create', array('id' => $this->_membershipTypeID2
, 'duration_interval' => 5));
1082 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1083 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1084 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1085 $this->assertEquals('2009-01-21', $result['join_date']);
1086 $this->assertEquals('2008-03-01', $result['start_date']);
1087 $this->assertEquals('2014-02-28', $result['end_date']);
1091 * Test correct end and start dates are calculated for fixed multi year memberships.
1093 * The empty start date is calculated to be the start_date (1 Jan prior to the join_date - so 1 Jan 15)
1095 * In this set our start date is after the start day and before the rollover day so we don't get an extra year
1096 * and we end one day before the rollover day. Start day is 1 Jan so we end on 31 Dec
1097 * and we add on 4 years rather than 5 because we are not after the rollover day - so we calculate 31 Dec 2019
1099 public function testFixedMultiYearDateSetTwoEmptyStartEndDate() {
1100 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1102 $this->callAPISuccess('membership_type', 'create', array(
1103 'id' => $this->_membershipTypeID2
,
1104 'duration_interval' => 5,
1106 'fixed_period_start_day' => '101',
1108 'fixed_period_rollover_day' => '1101',
1110 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1112 'join_date' => '28-Jan 2015',
1114 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1115 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1116 $this->assertEquals('2015-01-28', $result['join_date']);
1117 $this->assertEquals('2015-01-01', $result['start_date']);
1118 $this->assertEquals('2019-12-31', $result['end_date']);
1122 * Test that correct end date is calculated for fixed multi year memberships and start date is not changed.
1124 * In this set our start date is after the start day and before the rollover day so we don't get an extra year
1125 * and we end one day before the rollover day. Start day is 1 Jan so we end on 31 Dec
1126 * and we add on 4 years rather than 5 because we are not after the rollover day - so we calculate 31 Dec 2019
1128 public function testFixedMultiYearDateSetTwoEmptyEndDate() {
1129 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1131 $this->callAPISuccess('membership_type', 'create', array(
1132 'id' => $this->_membershipTypeID2
,
1133 'duration_interval' => 5,
1135 'fixed_period_start_day' => '101',
1137 'fixed_period_rollover_day' => '1101',
1139 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1141 'start_date' => '28-Jan 2015',
1142 'join_date' => '28-Jan 2015',
1144 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1145 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1146 $this->assertEquals('2015-01-28', $result['join_date']);
1147 $this->assertEquals('2015-01-28', $result['start_date']);
1148 $this->assertEquals('2019-12-31', $result['end_date']);
1152 * Test correct end and start dates are calculated for fixed multi year memberships.
1154 * The empty start date is calculated to be the start_date (1 Jan prior to the join_date - so 1 Jan 15)
1156 * In this set our start date is after the start day and before the rollover day so we don't get an extra year
1157 * and we end one day before the rollover day. Start day is 1 Jan so we end on 31 Dec
1158 * and we add on <1 years rather than > 1 because we are not after the rollover day - so we calculate 31 Dec 2015
1160 public function testFixedSingleYearDateSetTwoEmptyStartEndDate() {
1161 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1163 $this->callAPISuccess('membership_type', 'create', array(
1164 'id' => $this->_membershipTypeID2
,
1165 'duration_interval' => 1,
1167 'fixed_period_start_day' => '101',
1169 'fixed_period_rollover_day' => '1101',
1171 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1173 'join_date' => '28-Jan 2015',
1175 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1176 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1177 $this->assertEquals('2015-01-28', $result['join_date']);
1178 $this->assertEquals('2015-01-01', $result['start_date']);
1179 $this->assertEquals('2015-12-31', $result['end_date']);
1183 * Test correct end date for fixed single year memberships is calculated and start_date is not changed.
1185 * In this set our start date is after the start day and before the rollover day so we don't get an extra year
1186 * and we end one day before the rollover day. Start day is 1 Jan so we end on 31 Dec
1187 * and we add on <1 years rather than > 1 because we are not after the rollover day - so we calculate 31 Dec 2015
1189 public function testFixedSingleYearDateSetTwoEmptyEndDate() {
1190 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1192 $this->callAPISuccess('membership_type', 'create', array(
1193 'id' => $this->_membershipTypeID2
,
1194 'duration_interval' => 1,
1196 'fixed_period_start_day' => '101',
1198 'fixed_period_rollover_day' => '1101',
1200 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1202 'start_date' => '28-Jan 2015',
1203 'join_date' => '28-Jan 2015',
1205 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1206 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1207 $this->assertEquals('2015-01-28', $result['join_date']);
1208 $this->assertEquals('2015-01-28', $result['start_date']);
1209 $this->assertEquals('2015-12-31', $result['end_date']);
1213 * Test that correct end date is calculated for fixed multi year memberships and start date is not changed.
1215 * In this set our start date is after the start day and after the rollover day so we do get an extra year
1216 * and we end one day before the rollover day. Start day is 1 Nov so we end on 31 Oct
1217 * and we add on 1 year we are after the rollover day - so we calculate 31 Oct 2016
1219 public function testFixedSingleYearDateSetThreeEmptyEndDate() {
1220 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1222 $this->callAPISuccess('membership_type', 'create', array(
1223 'id' => $this->_membershipTypeID2
,
1224 'duration_interval' => 1,
1226 'fixed_period_start_day' => '1101',
1228 'fixed_period_rollover_day' => '101',
1230 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1232 'start_date' => '28-Jan 2015',
1233 'join_date' => '28-Jan 2015',
1235 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1236 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1237 $this->assertEquals('2015-01-28', $result['join_date']);
1238 $this->assertEquals('2015-01-28', $result['start_date']);
1239 $this->assertEquals('2016-10-31', $result['end_date']);
1243 * Test correct end and start dates are calculated for fixed multi year memberships.
1245 * The empty start date is calculated to be the start_date (1 Nov prior to the join_date - so 1 Nov 14)
1247 * In this set our start date is after the start day and after the rollover day so we do get an extra year
1248 * and we end one day before the rollover day. Start day is 1 Nov so we end on 31 Oct
1249 * and we add on 1 year we are after the rollover day - so we calculate 31 Oct 2016
1251 public function testFixedSingleYearDateSetThreeEmptyStartEndDate() {
1252 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1254 $this->callAPISuccess('membership_type', 'create', array(
1255 'id' => $this->_membershipTypeID2
,
1256 'duration_interval' => 1,
1258 'fixed_period_start_day' => '1101',
1260 'fixed_period_rollover_day' => '101',
1262 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1264 'join_date' => '28-Jan 2015',
1266 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1267 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1268 $this->assertEquals('2015-01-28', $result['join_date']);
1269 $this->assertEquals('2014-11-01', $result['start_date']);
1270 $this->assertEquals('2016-10-31', $result['end_date']);
1274 * Test that correct end date is calculated for fixed multi year memberships and start date is not changed.
1276 * In this set our start date is after the start day and after the rollover day so we do get an extra year
1277 * and we end one day before the rollover day. Start day is 1 Nov so we end on 31 Oct
1278 * and we add on 5 years we are after the rollover day - so we calculate 31 Oct 2020
1280 public function testFixedMultiYearDateSetThreeEmptyEndDate() {
1281 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1283 $this->callAPISuccess('membership_type', 'create', array(
1284 'id' => $this->_membershipTypeID2
,
1285 'duration_interval' => 5,
1287 'fixed_period_start_day' => '1101',
1289 'fixed_period_rollover_day' => '101',
1291 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1293 'start_date' => '28-Jan 2015',
1294 'join_date' => '28-Jan 2015',
1296 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1297 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1298 $this->assertEquals('2015-01-28', $result['join_date']);
1299 $this->assertEquals('2015-01-28', $result['start_date']);
1300 $this->assertEquals('2020-10-31', $result['end_date']);
1304 * Test correct end and start dates are calculated for fixed multi year memberships.
1306 * The empty start date is calculated to be the start_date (1 Nov prior to the join_date - so 1 Nov 14)
1308 * The empty start date is calculated to be the start_date (1 Nov prior to the join_date - so 1 Nov 14)
1309 * In this set our join date is after the start day and after the rollover day so we do get an extra year
1310 * and we end one day before the rollover day. Start day is 1 Nov so we end on 31 Oct
1311 * and we add on 5 years we are after the rollover day - so we calculate 31 Oct 2020
1313 public function testFixedMultiYearDateSetThreeEmptyStartEndDate() {
1314 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1316 $this->callAPISuccess('membership_type', 'create', array(
1317 'id' => $this->_membershipTypeID2
,
1318 'duration_interval' => 5,
1320 'fixed_period_start_day' => '1101',
1322 'fixed_period_rollover_day' => '101',
1324 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1326 'join_date' => '28-Jan 2015',
1328 $result = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, $dates));
1329 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1330 $this->assertEquals('2015-01-28', $result['join_date']);
1331 $this->assertEquals('2014-11-01', $result['start_date']);
1332 $this->assertEquals('2020-10-31', $result['end_date']);
1336 * Test that if membership start date is not set it defaults to correct end date for fixed single year memberships.
1338 public function testEmptyStartDateRolling() {
1339 unset($this->_params
['start_date'], $this->_params
['is_override']);
1340 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1341 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1342 $this->assertEquals('2009-01-21', $result['join_date']);
1343 $this->assertEquals('2009-01-21', $result['start_date']);
1344 $this->assertEquals('2009-12-21', $result['end_date']);
1348 * Test that if membership end date is not set it defaults to correct end date.
1351 public function testEmptyEndDateFixed() {
1352 unset($this->_params
['start_date'], $this->_params
['is_override'], $this->_params
['end_date']);
1353 $this->_params
['membership_type_id'] = $this->_membershipTypeID2
;
1354 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1355 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1356 $this->assertEquals('2009-01-21', $result['join_date']);
1357 $this->assertEquals('2008-03-01', $result['start_date']);
1358 $this->assertEquals('2010-02-28', $result['end_date']);
1362 * Test that if membership end date is not set it defaults to correct end date.
1365 public function testEmptyEndDateRolling() {
1366 unset($this->_params
['is_override'], $this->_params
['end_date']);
1367 $this->_params
['membership_type_id'] = $this->_membershipTypeID
;
1368 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1369 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1370 $this->assertEquals('2009-01-21', $result['join_date']);
1371 $this->assertEquals('2009-01-21', $result['start_date']);
1372 $this->assertEquals('2010-01-20', $result['end_date']);
1377 * Test that if dates are set they not over-ridden if id is passed in
1379 public function testMembershipDatesNotOverridden() {
1380 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1381 unset($this->_params
['end_date'], $this->_params
['start_date']);
1382 $this->_params
['id'] = $result['id'];
1383 $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
1384 $result = $this->callAPISuccess($this->_entity
, 'getsingle', array('id' => $result['id']));
1385 $this->assertEquals('2009-01-21', $result['join_date']);
1386 $this->assertEquals('2009-01-21', $result['start_date']);
1387 $this->assertEquals('2009-12-21', $result['end_date']);
1392 * Test that all membership types are returned when getoptions is called.
1394 * This test locks in current behaviour where types for all domains are returned. It should possibly be domain
1395 * specific but that should only be done in conjunction with adding a hook to allow that to be altered as the
1396 * multisite use case expects the master domain to be able to see all sites.
1400 public function testGetOptionsMembershipTypeID() {
1401 $options = $this->callAPISuccess('Membership', 'getoptions', array('field' => 'membership_type_id'));
1402 $this->assertEquals('General', array_pop($options['values']));
1403 $this->assertEquals('General', array_pop($options['values']));
1404 $this->assertEquals(NULL, array_pop($options['values']));