3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Test APIv3 civicrm_membership functions
31 * @package CiviCRM_APIv3
32 * @subpackage API_Member
36 require_once 'CiviTest/CiviUnitTestCase.php';
38 class api_v3_MembershipTest
extends CiviUnitTestCase
{
39 protected $_apiversion;
40 protected $_contactID;
41 protected $_membershipTypeID;
42 protected $_membershipStatusID;
43 protected $__membershipID;
46 public $_eNoticeCompliant = TRUE;
48 public function setUp() {
49 // Connect to the database
51 $this->_apiversion
= 3;
52 $this->_contactID
= $this->individualCreate();
53 $this->_membershipTypeID
= $this->membershipTypeCreate($this->_contactID
);
54 $this->_membershipStatusID
= $this->membershipStatusCreate('test status');
56 require_once 'CRM/Member/PseudoConstant.php';
57 CRM_Member_PseudoConstant
::membershipType(NULL, TRUE);
58 CRM_Member_PseudoConstant
::membershipStatus(NULL, NULL, 'name', TRUE);
59 CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name');
61 $this->_entity
= 'Membership';
62 $this->_params
= array(
63 'contact_id' => $this->_contactID
,
64 'membership_type_id' => $this->_membershipTypeID
,
65 'join_date' => '2009-01-21',
66 'start_date' => '2009-01-21',
67 'end_date' => '2009-12-21',
68 'source' => 'Payment',
70 'status_id' => $this->_membershipStatusID
,
76 $this->quickCleanup(array(
78 'civicrm_membership_payment')
80 $this->membershipStatusDelete($this->_membershipStatusID
);
81 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID
));
82 $this->contactDelete($this->_contactID
);
87 * Test civicrm_membership_delete()
89 function testMembershipDelete() {
90 $membershipID = $this->contactMembershipCreate($this->_params
);
92 'id' => $membershipID,
93 'version' => $this->_apiversion
,
95 $result = civicrm_api('membership', 'delete', $params);
96 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
97 $this->assertAPISuccess($result, "In line " . __LINE__
);
100 function testMembershipDeleteEmpty() {
102 $result = civicrm_api('membership', 'delete', $params);
103 $this->assertAPIFailure($result);
106 function testMembershipDeleteInvalidID() {
107 $params = array('version' => $this->_apiversion
, 'id' => 'blah');
108 $result = civicrm_api('membership', 'delete', $params);
109 $this->assertAPIFailure($result);
113 * Test civicrm_membership_delete() with invalid Membership Id
115 function testMembershipDeleteWithInvalidMembershipId() {
116 $membershipId = 'membership';
117 $result = civicrm_api('membership', 'delete', $membershipId);
118 $this->assertAPIFailure($result,
119 "In line " . __LINE__
124 * All other methods calls MembershipType and MembershipContact
125 * api, but putting simple test methods to control existence of
126 * these methods for backwards compatibility, also verifying basic
127 * behaviour is the same as new methods.
129 function testContactMembershipsGet() {
130 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
131 $params = array('version' => $this->_apiversion
);
132 $result = civicrm_api('membership', 'get', $params);
133 $this->assertEquals(0, $result['is_error'], "In line " . __LINE__
);
134 $result = civicrm_api('Membership', 'Delete', array(
135 'id' => $this->_membershipID
,
136 'version' => $this->_apiversion
,
141 * Test civicrm_membership_get with params not array.
142 * Gets treated as contact_id, memberships expected.
144 function testGetWithParamsContactId() {
145 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
147 'contact_id' => $this->_contactID
,
148 'version' => $this->_apiversion
,
150 $membership = civicrm_api('membership', 'get', $params);
152 $result = $membership['values'][$this->_membershipID
];
153 civicrm_api('Membership', 'Delete', array(
154 'id' => $this->_membershipID
,
155 'version' => $this->_apiversion
,
157 $this->assertEquals($result['contact_id'], $this->_contactID
, "In line " . __LINE__
);
158 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID
, "In line " . __LINE__
);
159 $this->assertEquals($result['status_id'], $this->_membershipStatusID
, "In line " . __LINE__
);
160 $this->assertEquals($result['join_date'], '2009-01-21', "In line " . __LINE__
);
161 $this->assertEquals($result['start_date'], '2009-01-21', "In line " . __LINE__
);
162 $this->assertEquals($result['end_date'], '2009-12-21', "In line " . __LINE__
);
163 $this->assertEquals($result['source'], 'Payment', "In line " . __LINE__
);
164 $this->assertEquals($result['is_override'], 1, "In line " . __LINE__
);
168 * Test civicrm_membership_get with params not array.
169 * Gets treated as contact_id, memberships expected.
171 function testGetWithParamsMemberShipTypeId() {
172 $result = civicrm_api($this->_entity
, 'create', $this->_params
);
174 'membership_type_id' => $this->_membershipTypeID
,
175 'version' => $this->_apiversion
,
177 $membership = civicrm_api('membership', 'get', $params);
178 $result = civicrm_api('Membership', 'Delete', array(
179 'id' => $membership['id'],
180 'version' => $this->_apiversion
,
182 $result = $membership['values'][$membership['id']];
183 $this->assertEquals($result['contact_id'], $this->_contactID
, "In line " . __LINE__
);
184 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID
, "In line " . __LINE__
);
185 $this->assertEquals($result['status_id'], $this->_membershipStatusID
, "In line " . __LINE__
);
186 $this->assertEquals($result['join_date'], '2009-01-21', "In line " . __LINE__
);
187 $this->assertEquals($result['start_date'], '2009-01-21', "In line " . __LINE__
);
188 $this->assertEquals($result['end_date'], '2009-12-21', "In line " . __LINE__
);
189 $this->assertEquals($result['source'], 'Payment', "In line " . __LINE__
);
190 $this->assertEquals($result['is_override'], 1, "In line " . __LINE__
);
191 $this->assertEquals($result['id'], $membership['id']);
195 * Test civicrm_membership_get with params not array.
196 * Gets treated as contact_id, memberships expected.
198 function testGetWithNonExistantMemberShipTypeId() {
199 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
201 'membership_type_id' => 465653,
202 'version' => $this->_apiversion
,
204 $result = civicrm_api('membership', 'get', $params);
205 civicrm_api('Membership', 'Delete', array(
206 'id' => $this->_membershipID
,
207 'version' => $this->_apiversion
,
210 $this->assertAPISuccess($result, "In line " . __LINE__
);
211 $this->assertEquals($result['count'], 0, "In line " . __LINE__
);
212 civicrm_api('Membership', 'Delete', array(
213 'id' => $this->_membershipID
,
214 'version' => $this->_apiversion
,
219 * check with complete array + custom field
220 * Note that the test is written on purpose without any
221 * variables specific to participant so it can be replicated into other entities
222 * and / or moved to the automated test suite
224 function testGetWithParamsMemberShipIdAndCustom() {
225 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
227 $params = $this->_params
;
228 $params['custom_' . $ids['custom_field_id']] = "custom string";
230 $result = civicrm_api($this->_entity
, 'create', $params);
232 $this->assertAPISuccess($result, ' in line ' . __LINE__
);
233 $getParams = array('version' => 3, 'membership_type_id' => $params['membership_type_id']);
234 $check = civicrm_api($this->_entity
, 'get', $getParams);
235 $this->documentMe($getParams, $check, __FUNCTION__
, __FILE__
);
236 $this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
238 $this->customFieldDelete($ids['custom_field_id']);
239 $this->customGroupDelete($ids['custom_group_id']);
240 $result = civicrm_api('Membership', 'Delete', array(
241 'id' => $result['id'],
242 'version' => $this->_apiversion
,
247 * Test civicrm_membership_get with proper params.
248 * Memberships expected.
251 $membershipID = $this->contactMembershipCreate($this->_params
);
253 'contact_id' => $this->_contactID
,
254 'version' => $this->_apiversion
,
257 $membership = civicrm_api('membership', 'get', $params);
258 //$this->documentMe($params,$membership,__FUNCTION__,__FILE__);
259 $result = $membership['values'][$membershipID];
260 civicrm_api('Membership', 'Delete', array(
261 'id' => $membership['id'],
262 'version' => $this->_apiversion
,
264 $this->assertEquals($result['join_date'], '2009-01-21', "In line " . __LINE__
);
265 $this->assertEquals($result['contact_id'], $this->_contactID
, "In line " . __LINE__
);
266 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID
, "In line " . __LINE__
);
267 $this->assertEquals($result['status_id'], $this->_membershipStatusID
, "In line " . __LINE__
);
269 $this->assertEquals($result['start_date'], '2009-01-21', "In line " . __LINE__
);
270 $this->assertEquals($result['end_date'], '2009-12-21', "In line " . __LINE__
);
271 $this->assertEquals($result['source'], 'Payment', "In line " . __LINE__
);
272 $this->assertEquals($result['is_override'], 1, "In line " . __LINE__
);
277 * Test civicrm_membership_get with proper params.
278 * Memberships expected.
280 function testGetWithId() {
281 $membershipID = $this->contactMembershipCreate($this->_params
);
283 'contact_id' => $this->_contactID
,
284 'version' => $this->_apiversion
,
285 'id' => $this->__membershipID
,
288 $result = civicrm_api('membership', 'get', $params);
289 $this->assertAPISuccess($result);
290 $this->assertEquals($membershipID, $result['id']);
292 'contact_id' => $this->_contactID
,
293 'version' => $this->_apiversion
,
294 'membership_id' => $this->__membershipID
,
295 'return' => 'membership_id',
297 $result = civicrm_api('membership', 'get', $params);
298 $this->assertAPISuccess($result);
299 $this->assertEquals($membershipID, $result['id']);
300 civicrm_api('Membership', 'Delete', array(
301 'id' => $result['id'],
302 'version' => $this->_apiversion
,
307 * Test civicrm_membership_get for only active.
308 * Memberships expected.
310 function testGetOnlyActive() {
311 $description = "Demonstrates use of 'filter' active_only' param";
312 $this->_membershipID
= $this->contactMembershipCreate($this->_params
);
313 $subfile = 'filterIsCurrent';
315 'contact_id' => $this->_contactID
,
317 'version' => $this->_apiversion
,
320 $membership = civicrm_api('membership', 'get', $params);
321 $result = $membership['values'][$this->_membershipID
];
322 $this->assertEquals($membership['values'][$this->_membershipID
]['status_id'], $this->_membershipStatusID
, "In line " . __LINE__
);
323 $this->assertEquals($membership['values'][$this->_membershipID
]['contact_id'], $this->_contactID
, "In line " . __LINE__
);
325 'contact_id' => $this->_contactID
,
329 'version' => $this->_apiversion
,
332 $membership = civicrm_api('membership', 'get', $params);
333 $this->documentMe($params, $membership, __FUNCTION__
, __FILE__
, $description, $subfile);
334 $result = $membership['values'][$this->_membershipID
];
335 $this->assertEquals($membership['values'][$this->_membershipID
]['status_id'], $this->_membershipStatusID
, "In line " . __LINE__
);
336 $this->assertEquals($membership['values'][$this->_membershipID
]['contact_id'], $this->_contactID
, "In line " . __LINE__
);
339 $result = civicrm_api('Membership', 'Delete', array(
340 'id' => $this->_membershipID
,
341 'version' => $this->_apiversion
,
346 * Test civicrm_membership_get for non exist contact.
349 function testGetNoContactExists() {
351 'contact_id' => 55555,
352 'version' => $this->_apiversion
,
355 $membership = civicrm_api('membership', 'get', $params);
356 $this->assertEquals($membership['count'], 0, "In line " . __LINE__
);
360 * Test civicrm_membership_get with relationship.
363 function testGetWithRelationship() {
364 $membershipOrgId = $this->organizationCreate(NULL);
365 $memberContactId = $this->individualCreate(NULL);
367 $relTypeParams = array(
368 'name_a_b' => 'Relation 1',
369 'name_b_a' => 'Relation 2',
370 'description' => 'Testing relationship type',
371 'contact_type_a' => 'Organization',
372 'contact_type_b' => 'Individual',
375 'version' => $this->_apiversion
,
377 $relTypeID = $this->relationshipTypeCreate($relTypeParams);
380 'name' => 'test General',
381 'duration_unit' => 'year',
382 'duration_interval' => 1,
383 'period_type' => 'rolling',
384 'member_of_contact_id' => $membershipOrgId,
386 'financial_type_id' => 1,
387 'relationship_type_id' => $relTypeID,
388 'relationship_direction' => 'b_a',
390 'version' => $this->_apiversion
,
392 $memType = civicrm_api('membership_type', 'create', $params);
395 'contact_id' => $memberContactId,
396 'membership_type_id' => $memType['id'],
397 'join_date' => '2009-01-21',
398 'start_date' => '2009-01-21',
399 'end_date' => '2009-12-21',
400 'source' => 'Payment',
402 'status_id' => $this->_membershipStatusID
,
403 'version' => $this->_apiversion
,
405 $membershipID = $this->contactMembershipCreate($params);
408 'contact_id' => $memberContactId,
409 'membership_type_id' => $memType['id'],
410 'version' => $this->_apiversion
,
413 $result = civicrm_api('membership', 'get', $params);
415 $membership = $result['values'][$membershipID];
416 $this->assertEquals($this->_membershipStatusID
, $membership['status_id'],
417 "In line " . __LINE__
419 $result = civicrm_api('Membership', 'Delete', array(
420 'id' => $membership['id'],
421 'version' => $this->_apiversion
,
423 $this->membershipTypeDelete(array('id' => $memType['id']));
424 $this->relationshipTypeDelete($relTypeID);
425 $this->contactDelete($membershipOrgId);
426 $this->contactDelete($memberContactId);
429 ///////////////// civicrm_membership_create methods
432 * Test civicrm_contact_memberships_create with empty params.
435 function testCreateWithEmptyParams() {
437 $result = civicrm_api('membership', 'create', $params);
438 $this->assertAPIFailure($result);
442 * Test civicrm_contact_memberships_create with params with wrong type.
445 function testCreateWithParamsString() {
446 $params = 'a string';
447 $result = civicrm_api('membership', 'create', $params);
448 $this->assertAPIFailure($result,
449 "In line " . __LINE__
453 * If is_overide is passed in status must also be passed in
455 function testCreateOverrideNoStatus() {
456 $params = $this->_params
;
457 unset($params['status_id']);
458 $result = civicrm_api('membership', 'create', $params);
459 $this->assertAPIFailure($result,
460 "In line " . __LINE__
464 function testMembershipCreateMissingRequired() {
466 'membership_type_id' => '1',
467 'join_date' => '2006-01-21',
468 'start_date' => '2006-01-21',
469 'end_date' => '2006-12-21',
470 'source' => 'Payment',
472 'version' => $this->_apiversion
,
475 $result = civicrm_api('membership', 'create', $params);
476 $this->assertAPIFailure($result);
479 function testMembershipCreate() {
481 'contact_id' => $this->_contactID
,
482 'membership_type_id' => $this->_membershipTypeID
,
483 'join_date' => '2006-01-21',
484 'start_date' => '2006-01-21',
485 'end_date' => '2006-12-21',
486 'source' => 'Payment',
488 'status_id' => $this->_membershipStatusID
,
489 'version' => $this->_apiversion
,
492 $result = civicrm_api('membership', 'create', $params);
493 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
494 $this->getAndCheck($params, $result['id'], $this->_entity
);
495 $this->assertAPISuccess($result);
496 $this->assertNotNull($result['id']);
497 $this->assertEquals($this->_contactID
, $result['values'][$result['id']]['contact_id'], " in line " . __LINE__
);
498 $this->assertEquals($result['id'], $result['values'][$result['id']]['id'], " in line " . __LINE__
);
501 * Check for useful message if contact doesn't exist
503 function testMembershipCreateWithInvalidContact() {
506 'membership_type_id' => $this->_membershipTypeID
,
507 'join_date' => '2006-01-21',
508 'start_date' => '2006-01-21',
509 'end_date' => '2006-12-21',
510 'source' => 'Payment',
512 'status_id' => $this->_membershipStatusID
,
513 'version' => $this->_apiversion
,
516 $result = civicrm_api('membership', 'create', $params);
517 $this->assertEquals('contact_id is not valid : 999', $result['error_message']);
519 function testMembershipCreateWithInvalidStatus() {
520 $params = $this->_params
;
521 $params['status_id'] = 999;
523 $result = civicrm_api('membership', 'create', $params);
524 $this->assertEquals('status_id is not valid : 999', $result['error_message']);
527 function testMembershipCreateWithInvalidType() {
528 $params = $this->_params
;
529 $params['membership_type_id'] = 999;
531 $result = civicrm_api('membership', 'create', $params);
532 $this->assertEquals('membership_type_id is not valid : 999', $result['error_message']);
536 * check with complete array + custom field
537 * Note that the test is written on purpose without any
538 * variables specific to participant so it can be replicated into other entities
539 * and / or moved to the automated test suite
541 function testCreateWithCustom() {
542 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
544 $params = $this->_params
;
545 $params['custom_' . $ids['custom_field_id']] = "custom string";
547 $result = civicrm_api($this->_entity
, 'create', $params);
548 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
549 $this->assertAPISuccess($result, ' in line ' . __LINE__
);
551 $check = civicrm_api($this->_entity
, 'get', array('version' => 3, 'id' => $result['id'], 'contact_id' => $this->_contactID
));
552 $this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
553 $this->customFieldDelete($ids['custom_field_id']);
554 $this->customGroupDelete($ids['custom_group_id']);
555 civicrm_api('Membership', 'Delete', array(
556 'id' => $result['id'],
557 'version' => $this->_apiversion
,
562 * Test civicrm_contact_memberships_create with membership id (edit
566 function testMembershipCreateWithId() {
567 $membershipID = $this->contactMembershipCreate($this->_params
);
569 'id' => $membershipID,
570 'contact_id' => $this->_contactID
,
571 'membership_type_id' => $this->_membershipTypeID
,
572 'join_date' => '2006-01-21',
573 'start_date' => '2006-01-21',
574 'end_date' => '2006-12-21',
575 'source' => 'Payment',
577 'status_id' => $this->_membershipStatusID
,
578 'version' => $this->_apiversion
,
581 $result = civicrm_api('membership', 'create', $params);
582 civicrm_api('Membership', 'Delete', array(
583 'id' => $result['id'],
584 'version' => $this->_apiversion
,
586 $this->assertAPISuccess($result, "in line " . __LINE__
);
587 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
591 * Test civicrm_contact_memberships_create with membership id (edit
595 function testMembershipCreateUpdateWithIdNoContact() {
596 $membershipID = $this->contactMembershipCreate($this->_params
);
598 'id' => $membershipID,
599 'membership_type_id' => $this->_membershipTypeID
,
600 'contact_id' => $this->_contactID
,
601 'join_date' => '2006-01-21',
602 'start_date' => '2006-01-21',
603 'end_date' => '2006-12-21',
604 'source' => 'Payment',
606 'status_id' => $this->_membershipStatusID
,
607 'version' => $this->_apiversion
,
610 $result = civicrm_api('membership', 'create', $params);
611 civicrm_api('Membership', 'Delete', array(
612 'id' => $result['id'],
613 'version' => $this->_apiversion
,
615 $this->assertAPISuccess($result, "in line " . __LINE__
);
616 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
620 * Test civicrm_contact_memberships_create with membership id (edit
624 function testMembershipCreateUpdateWithIdNoDates() {
625 $membershipID = $this->contactMembershipCreate($this->_params
);
627 'id' => $membershipID,
628 'contact_id' => $this->_contactID
,
629 'membership_type_id' => $this->_membershipTypeID
,
630 'source' => 'Payment',
632 'status_id' => $this->_membershipStatusID
,
633 'version' => $this->_apiversion
,
636 $result = civicrm_api('membership', 'create', $params);
637 civicrm_api('Membership', 'Delete', array(
638 'id' => $result['id'],
639 'version' => $this->_apiversion
,
641 $this->assertAPISuccess($result, "in line " . __LINE__
);
642 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
646 * Test civicrm_contact_memberships_create with membership id (edit
650 function testMembershipCreateUpdateWithIdNoDatesNoType() {
651 $membershipID = $this->contactMembershipCreate($this->_params
);
653 'id' => $membershipID,
654 'source' => 'not much here',
655 'contact_id' => $this->_contactID
,
657 'status_id' => $this->_membershipStatusID
,
658 'version' => $this->_apiversion
,
661 $result = civicrm_api('membership', 'create', $params);
662 civicrm_api('Membership', 'Delete', array(
663 'id' => $result['id'],
664 'version' => $this->_apiversion
,
666 $this->assertAPISuccess($result, "in line " . __LINE__
);
667 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
671 * Test civicrm_contact_memberships_create with membership id (edit
675 function testMembershipCreateUpdateWithIDAndSource() {
676 $membershipID = $this->contactMembershipCreate($this->_params
);
678 'id' => $membershipID,
679 'source' => 'changed',
680 'contact_id' => $this->_contactID
,
681 'status_id' => $this->_membershipStatusID
,
682 'version' => $this->_apiversion
,
683 'membership_type_id' => $this->_membershipTypeID
,
684 'skipStatusCal' => 1,
686 $result = civicrm_api('membership', 'create', $params);
687 $this->assertAPISuccess($result, "in line " . __LINE__
);
688 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__
);
689 civicrm_api('Membership', 'Delete', array(
690 'id' => $result['id'],
691 'version' => $this->_apiversion
,
696 * change custom field using update
698 function testUpdateWithCustom() {
699 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
701 $params = $this->_params
;
702 $params['custom_' . $ids['custom_field_id']] = "custom string";
703 $result = civicrm_api($this->_entity
, 'create', $params);
705 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
706 $this->assertAPISuccess($result, ' in line ' . __LINE__
);
707 $result = civicrm_api($this->_entity
, 'create', array('id' => $result['id'], 'version' => 3, 'custom_' . $ids['custom_field_id'] => "new custom"));
708 $this->assertAPISuccess($result, ' in line ' . __LINE__
);
709 $check = civicrm_api($this->_entity
, 'get', array('version' => 3, 'id' => $result['id'], 'contact_id' => $this->_contactID
));
711 $this->assertEquals("new custom", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
712 $delete = civicrm_api('Membership', 'Delete', array(
713 'id' => $check['id'],
714 'version' => $this->_apiversion
,
717 $this->customFieldDelete($ids['custom_field_id']);
718 $this->customGroupDelete($ids['custom_group_id']);
722 * Test civicrm_contact_memberships_create Invalid membership data
725 function testMembershipCreateInvalidMemData() {
726 //membership_contact_id as string
728 'membership_contact_id' => 'Invalid',
729 'membership_type_id' => $this->_membershipTypeID
,
730 'join_date' => '2011-01-21',
731 'start_date' => '2010-01-21',
732 'end_date' => '2008-12-21',
733 'source' => 'Payment',
735 'status_id' => $this->_membershipStatusID
,
736 'version' => $this->_apiversion
,
739 $result = civicrm_api('membership', 'create', $params);
740 $this->assertAPIFailure($result, "in line " . __LINE__
);
742 //membership_contact_id which is no in contact table
743 $params['membership_contact_id'] = 999;
744 $result = civicrm_api('membership', 'create', $params);
745 $this->assertAPIFailure($result, "in line " . __LINE__
);
748 unset($params['membership_contact_id']);
749 $params['join_date'] = "invalid";
750 $result = civicrm_api('Membership', 'Create', $params);
751 $this->assertAPIFailure($result, "in line " . __LINE__
);
755 * Test civicrm_contact_memberships_create with membership_contact_id
759 function testMembershipCreateWithMemContact() {
761 'membership_contact_id' => $this->_contactID
,
762 'membership_type_id' => $this->_membershipTypeID
,
763 'join_date' => '2011-01-21',
764 'start_date' => '2010-01-21',
765 'end_date' => '2008-12-21',
766 'source' => 'Payment',
768 'status_id' => $this->_membershipStatusID
,
769 'version' => $this->_apiversion
,
772 $result = civicrm_api('membership', 'create', $params);
774 $this->assertAPISuccess($result, ' in line ' . __LINE__
);
775 $result = civicrm_api('Membership', 'Delete', array(
776 'id' => $result['id'],
777 'version' => $this->_apiversion
,
781 ///////////////// civicrm_membership_delete methods