CRM-13072 upgrade relationship & relationship type tests to pass
[civicrm-core.git] / tests / phpunit / api / v3 / MembershipTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26*/
27
28/**
29 * Test APIv3 civicrm_membership functions
30 *
31 * @package CiviCRM_APIv3
32 * @subpackage API_Member
33 */
34
35
36require_once 'CiviTest/CiviUnitTestCase.php';
37
38class api_v3_MembershipTest extends CiviUnitTestCase {
39 protected $_apiversion;
40 protected $_contactID;
41 protected $_membershipTypeID;
42 protected $_membershipStatusID;
43 protected $__membershipID;
44 protected $_entity;
45 protected $_params;
46 public $_eNoticeCompliant = TRUE;
47
48 public function setUp() {
49 // Connect to the database
50 parent::setUp();
51 $this->_apiversion = 3;
52 $this->_contactID = $this->individualCreate();
53 $this->_membershipTypeID = $this->membershipTypeCreate($this->_contactID);
54 $this->_membershipStatusID = $this->membershipStatusCreate('test status');
55
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');
60
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',
69 'is_override' => 1,
70 'status_id' => $this->_membershipStatusID,
6a488035
TO
71 );
72 }
73
74 function tearDown() {
75 $this->quickCleanup(array(
76 'civicrm_membership',
771f3245 77 'civicrm_membership_payment',
78 'civicrm_membership_log',
79 ),
80 TRUE
6a488035
TO
81 );
82 $this->membershipStatusDelete($this->_membershipStatusID);
83 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID));
84 $this->contactDelete($this->_contactID);
85
86 }
87
88 /**
89 * Test civicrm_membership_delete()
90 */
91 function testMembershipDelete() {
92 $membershipID = $this->contactMembershipCreate($this->_params);
93 $params = array(
94 'id' => $membershipID,
6a488035 95 );
771f3245 96 $result = $this->callAPIAndDocument('membership', 'delete', $params, __FUNCTION__, __FILE__);
6a488035
TO
97 }
98
99 function testMembershipDeleteEmpty() {
100 $params = array();
d0e1eff2 101 $result = $this->callAPIFailure('membership', 'delete', $params);
6a488035
TO
102 }
103
104 function testMembershipDeleteInvalidID() {
771f3245 105 $params = array('id' => 'blah');
d0e1eff2 106 $result = $this->callAPIFailure('membership', 'delete', $params);
6a488035
TO
107 }
108
109 /**
110 * Test civicrm_membership_delete() with invalid Membership Id
111 */
112 function testMembershipDeleteWithInvalidMembershipId() {
113 $membershipId = 'membership';
771f3245 114 $result = $this->callAPIFailure('membership', 'delete', $membershipId);
6a488035
TO
115 }
116
117 /**
118 * All other methods calls MembershipType and MembershipContact
119 * api, but putting simple test methods to control existence of
120 * these methods for backwards compatibility, also verifying basic
121 * behaviour is the same as new methods.
122 */
123 function testContactMembershipsGet() {
124 $this->_membershipID = $this->contactMembershipCreate($this->_params);
771f3245 125 $params = array();
126 $result = $this->callAPISuccess('membership', 'get', $params);
127 $result = $this->callAPISuccess('Membership', 'Delete', array(
6a488035 128 'id' => $this->_membershipID,
771f3245 129 ));
6a488035
TO
130 }
131
132 /**
133 * Test civicrm_membership_get with params not array.
134 * Gets treated as contact_id, memberships expected.
135 */
136 function testGetWithParamsContactId() {
137 $this->_membershipID = $this->contactMembershipCreate($this->_params);
138 $params = array(
139 'contact_id' => $this->_contactID,
6a488035 140 );
771f3245 141 $membership = $this->callAPISuccess('membership', 'get', $params);
6a488035
TO
142
143 $result = $membership['values'][$this->_membershipID];
771f3245 144 $this->callAPISuccess('Membership', 'Delete', array(
6a488035 145 'id' => $this->_membershipID,
6a488035
TO
146 ));
147 $this->assertEquals($result['contact_id'], $this->_contactID, "In line " . __LINE__);
148 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID, "In line " . __LINE__);
149 $this->assertEquals($result['status_id'], $this->_membershipStatusID, "In line " . __LINE__);
150 $this->assertEquals($result['join_date'], '2009-01-21', "In line " . __LINE__);
151 $this->assertEquals($result['start_date'], '2009-01-21', "In line " . __LINE__);
152 $this->assertEquals($result['end_date'], '2009-12-21', "In line " . __LINE__);
153 $this->assertEquals($result['source'], 'Payment', "In line " . __LINE__);
154 $this->assertEquals($result['is_override'], 1, "In line " . __LINE__);
155 }
156
157 /**
158 * Test civicrm_membership_get with params not array.
159 * Gets treated as contact_id, memberships expected.
160 */
161 function testGetWithParamsMemberShipTypeId() {
771f3245 162 $result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
6a488035
TO
163 $params = array(
164 'membership_type_id' => $this->_membershipTypeID,
6a488035 165 );
771f3245 166 $membership = $this->callAPISuccess('membership', 'get', $params);
167 $result = $this->callAPISuccess('Membership', 'Delete', array(
6a488035 168 'id' => $membership['id'],
771f3245 169 ));
6a488035
TO
170 $result = $membership['values'][$membership['id']];
171 $this->assertEquals($result['contact_id'], $this->_contactID, "In line " . __LINE__);
172 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID, "In line " . __LINE__);
173 $this->assertEquals($result['status_id'], $this->_membershipStatusID, "In line " . __LINE__);
174 $this->assertEquals($result['join_date'], '2009-01-21', "In line " . __LINE__);
175 $this->assertEquals($result['start_date'], '2009-01-21', "In line " . __LINE__);
176 $this->assertEquals($result['end_date'], '2009-12-21', "In line " . __LINE__);
177 $this->assertEquals($result['source'], 'Payment', "In line " . __LINE__);
178 $this->assertEquals($result['is_override'], 1, "In line " . __LINE__);
179 $this->assertEquals($result['id'], $membership['id']);
180 }
181
6a488035
TO
182 /**
183 * check with complete array + custom field
184 * Note that the test is written on purpose without any
185 * variables specific to participant so it can be replicated into other entities
186 * and / or moved to the automated test suite
187 */
188 function testGetWithParamsMemberShipIdAndCustom() {
189 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
190
191 $params = $this->_params;
192 $params['custom_' . $ids['custom_field_id']] = "custom string";
193
771f3245 194 $result = $this->callAPISuccess($this->_entity, 'create', $params);
6a488035 195
771f3245 196 $getParams = array('membership_type_id' => $params['membership_type_id']);
197 $check = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
6a488035
TO
198 $this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
199
771f3245 200 $result = $this->callAPISuccess('Membership', 'Delete', array(
6a488035 201 'id' => $result['id'],
771f3245 202 ));
6a488035
TO
203 }
204
205 /**
206 * Test civicrm_membership_get with proper params.
207 * Memberships expected.
208 */
209 function testGet() {
210 $membershipID = $this->contactMembershipCreate($this->_params);
211 $params = array(
212 'contact_id' => $this->_contactID,
6a488035
TO
213 );
214
771f3245 215 $membership = $this->callAPISuccess('membership', 'get', $params);
6a488035 216 $result = $membership['values'][$membershipID];
771f3245 217 $this->callAPISuccess('Membership', 'Delete', array(
6a488035 218 'id' => $membership['id'],
771f3245 219 ));
6a488035
TO
220 $this->assertEquals($result['join_date'], '2009-01-21', "In line " . __LINE__);
221 $this->assertEquals($result['contact_id'], $this->_contactID, "In line " . __LINE__);
222 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID, "In line " . __LINE__);
223 $this->assertEquals($result['status_id'], $this->_membershipStatusID, "In line " . __LINE__);
224
225 $this->assertEquals($result['start_date'], '2009-01-21', "In line " . __LINE__);
226 $this->assertEquals($result['end_date'], '2009-12-21', "In line " . __LINE__);
227 $this->assertEquals($result['source'], 'Payment', "In line " . __LINE__);
228 $this->assertEquals($result['is_override'], 1, "In line " . __LINE__);
229 }
230
231
232 /**
233 * Test civicrm_membership_get with proper params.
234 * Memberships expected.
235 */
236 function testGetWithId() {
237 $membershipID = $this->contactMembershipCreate($this->_params);
238 $params = array(
239 'contact_id' => $this->_contactID,
6a488035
TO
240 'id' => $this->__membershipID,
241 'return' => 'id',
242 );
771f3245 243 $result = $this->callAPISuccess('membership', 'get', $params);
6a488035
TO
244 $this->assertEquals($membershipID, $result['id']);
245 $params = array(
246 'contact_id' => $this->_contactID,
6a488035
TO
247 'membership_id' => $this->__membershipID,
248 'return' => 'membership_id',
249 );
771f3245 250 $result = $this->callAPISuccess('membership', 'get', $params);
6a488035 251 $this->assertEquals($membershipID, $result['id']);
6a488035
TO
252 }
253
254 /**
255 * Test civicrm_membership_get for only active.
256 * Memberships expected.
257 */
258 function testGetOnlyActive() {
259 $description = "Demonstrates use of 'filter' active_only' param";
260 $this->_membershipID = $this->contactMembershipCreate($this->_params);
261 $subfile = 'filterIsCurrent';
262 $params = array(
263 'contact_id' => $this->_contactID,
264 'active_only' => 1,
6a488035
TO
265 );
266
771f3245 267 $membership = $this->callAPISuccess('membership', 'get', $params);
6a488035
TO
268 $result = $membership['values'][$this->_membershipID];
269 $this->assertEquals($membership['values'][$this->_membershipID]['status_id'], $this->_membershipStatusID, "In line " . __LINE__);
270 $this->assertEquals($membership['values'][$this->_membershipID]['contact_id'], $this->_contactID, "In line " . __LINE__);
271 $params = array(
272 'contact_id' => $this->_contactID,
273 'filters' => array(
274 'is_current' => 1,
275 ),
6a488035
TO
276 );
277
771f3245 278 $membership = $this->callAPIAndDocument('membership', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile);
6a488035
TO
279 $result = $membership['values'][$this->_membershipID];
280 $this->assertEquals($membership['values'][$this->_membershipID]['status_id'], $this->_membershipStatusID, "In line " . __LINE__);
281 $this->assertEquals($membership['values'][$this->_membershipID]['contact_id'], $this->_contactID, "In line " . __LINE__);
282
283
771f3245 284 $result = $this->callAPISuccess('Membership', 'Delete', array(
6a488035 285 'id' => $this->_membershipID,
771f3245 286 ));
6a488035
TO
287 }
288
289 /**
290 * Test civicrm_membership_get for non exist contact.
291 * empty Memberships.
292 */
293 function testGetNoContactExists() {
294 $params = array(
295 'contact_id' => 55555,
6a488035
TO
296 );
297
771f3245 298 $membership = $this->callAPISuccess('membership', 'get', $params);
6a488035
TO
299 $this->assertEquals($membership['count'], 0, "In line " . __LINE__);
300 }
301
302 /**
303 * Test civicrm_membership_get with relationship.
304 * get Memberships.
305 */
306 function testGetWithRelationship() {
307 $membershipOrgId = $this->organizationCreate(NULL);
308 $memberContactId = $this->individualCreate(NULL);
309
310 $relTypeParams = array(
311 'name_a_b' => 'Relation 1',
312 'name_b_a' => 'Relation 2',
313 'description' => 'Testing relationship type',
314 'contact_type_a' => 'Organization',
315 'contact_type_b' => 'Individual',
316 'is_reserved' => 1,
317 'is_active' => 1,
6a488035
TO
318 );
319 $relTypeID = $this->relationshipTypeCreate($relTypeParams);
320
321 $params = array(
322 'name' => 'test General',
323 'duration_unit' => 'year',
324 'duration_interval' => 1,
325 'period_type' => 'rolling',
326 'member_of_contact_id' => $membershipOrgId,
327 'domain_id' => 1,
771f3245 328 'financial_type_id' => 1,
6a488035
TO
329 'relationship_type_id' => $relTypeID,
330 'relationship_direction' => 'b_a',
331 'is_active' => 1,
6a488035 332 );
771f3245 333 $memType = $this->callAPISuccess('membership_type', 'create', $params);
6a488035
TO
334
335 $params = array(
336 'contact_id' => $memberContactId,
337 'membership_type_id' => $memType['id'],
338 'join_date' => '2009-01-21',
339 'start_date' => '2009-01-21',
340 'end_date' => '2009-12-21',
341 'source' => 'Payment',
342 'is_override' => 1,
343 'status_id' => $this->_membershipStatusID,
6a488035
TO
344 );
345 $membershipID = $this->contactMembershipCreate($params);
346
347 $params = array(
348 'contact_id' => $memberContactId,
349 'membership_type_id' => $memType['id'],
6a488035
TO
350 );
351
771f3245 352 $result = $this->callAPISuccess('membership', 'get', $params);
6a488035
TO
353
354 $membership = $result['values'][$membershipID];
771f3245 355 $this->assertEquals($this->_membershipStatusID, $membership['status_id']);
356 $result = $this->callAPISuccess('Membership', 'Delete', array(
6a488035 357 'id' => $membership['id'],
6a488035
TO
358 ));
359 $this->membershipTypeDelete(array('id' => $memType['id']));
360 $this->relationshipTypeDelete($relTypeID);
361 $this->contactDelete($membershipOrgId);
362 $this->contactDelete($memberContactId);
363 }
364
365 ///////////////// civicrm_membership_create methods
366
367 /**
368 * Test civicrm_contact_memberships_create with empty params.
369 * Error expected.
370 */
371 function testCreateWithEmptyParams() {
372 $params = array();
d0e1eff2 373 $result = $this->callAPIFailure('membership', 'create', $params);
6a488035
TO
374 }
375
376 /**
6a488035
TO
377 * If is_overide is passed in status must also be passed in
378 */
379 function testCreateOverrideNoStatus() {
380 $params = $this->_params;
381 unset($params['status_id']);
771f3245 382 $result = $this->callAPIFailure('membership', 'create', $params);
6a488035
TO
383 }
384
385 function testMembershipCreateMissingRequired() {
386 $params = array(
387 'membership_type_id' => '1',
388 'join_date' => '2006-01-21',
389 'start_date' => '2006-01-21',
390 'end_date' => '2006-12-21',
391 'source' => 'Payment',
392 'status_id' => '2',
6a488035
TO
393 );
394
d0e1eff2 395 $result = $this->callAPIFailure('membership', 'create', $params);
6a488035
TO
396 }
397
398 function testMembershipCreate() {
399 $params = array(
400 'contact_id' => $this->_contactID,
401 'membership_type_id' => $this->_membershipTypeID,
402 'join_date' => '2006-01-21',
403 'start_date' => '2006-01-21',
404 'end_date' => '2006-12-21',
405 'source' => 'Payment',
406 'is_override' => 1,
407 'status_id' => $this->_membershipStatusID,
6a488035
TO
408 );
409
771f3245 410 $result = $this->callAPIAndDocument('membership', 'create', $params, __FUNCTION__, __FILE__);
6a488035 411 $this->getAndCheck($params, $result['id'], $this->_entity);
6a488035
TO
412 $this->assertNotNull($result['id']);
413 $this->assertEquals($this->_contactID, $result['values'][$result['id']]['contact_id'], " in line " . __LINE__);
414 $this->assertEquals($result['id'], $result['values'][$result['id']]['id'], " in line " . __LINE__);
415 }
416 /*
417 * Check for useful message if contact doesn't exist
418 */
419 function testMembershipCreateWithInvalidContact() {
420 $params = array(
421 'contact_id' => 999,
422 'membership_type_id' => $this->_membershipTypeID,
423 'join_date' => '2006-01-21',
424 'start_date' => '2006-01-21',
425 'end_date' => '2006-12-21',
426 'source' => 'Payment',
427 'is_override' => 1,
428 'status_id' => $this->_membershipStatusID,
6a488035
TO
429 );
430
771f3245 431 $result = $this->callAPIFailure('membership', 'create', $params,
432 'contact_id is not valid : 999'
433 );
6a488035
TO
434 }
435 function testMembershipCreateWithInvalidStatus() {
436 $params = $this->_params;
437 $params['status_id'] = 999;
771f3245 438 $result = $this->callAPIFailure('membership', 'create', $params,
439 "'999' is not a valid option for field status_id"
440 );
6a488035
TO
441 }
442
443 function testMembershipCreateWithInvalidType() {
444 $params = $this->_params;
445 $params['membership_type_id'] = 999;
446
771f3245 447 $result = $this->callAPIFailure('membership', 'create', $params,
448 "'999' is not a valid option for field membership_type_id"
449 );
6a488035
TO
450 }
451
452 /**
453 * check with complete array + custom field
454 * Note that the test is written on purpose without any
455 * variables specific to participant so it can be replicated into other entities
456 * and / or moved to the automated test suite
457 */
458 function testCreateWithCustom() {
459 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
460
461 $params = $this->_params;
462 $params['custom_' . $ids['custom_field_id']] = "custom string";
463
771f3245 464 $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
465 $check = $this->callAPISuccess($this->_entity, 'get', array('id' => $result['id'], 'contact_id' => $this->_contactID));
6a488035 466 $this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
6a488035
TO
467 }
468
469 /**
470 * Test civicrm_contact_memberships_create with membership id (edit
471 * membership).
472 * success expected.
473 */
474 function testMembershipCreateWithId() {
475 $membershipID = $this->contactMembershipCreate($this->_params);
476 $params = array(
477 'id' => $membershipID,
478 'contact_id' => $this->_contactID,
479 'membership_type_id' => $this->_membershipTypeID,
480 'join_date' => '2006-01-21',
481 'start_date' => '2006-01-21',
482 'end_date' => '2006-12-21',
483 'source' => 'Payment',
484 'is_override' => 1,
485 'status_id' => $this->_membershipStatusID,
6a488035
TO
486 );
487
771f3245 488 $result = $this->callAPISuccess('membership', 'create', $params);
489 $this->callAPISuccess('Membership', 'Delete', array(
6a488035 490 'id' => $result['id'],
771f3245 491 ));
6a488035
TO
492 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__);
493 }
494
495 /**
496 * Test civicrm_contact_memberships_create with membership id (edit
497 * membership).
498 * success expected.
499 */
500 function testMembershipCreateUpdateWithIdNoContact() {
501 $membershipID = $this->contactMembershipCreate($this->_params);
502 $params = array(
503 'id' => $membershipID,
504 'membership_type_id' => $this->_membershipTypeID,
505 'contact_id' => $this->_contactID,
506 'join_date' => '2006-01-21',
507 'start_date' => '2006-01-21',
508 'end_date' => '2006-12-21',
509 'source' => 'Payment',
510 'is_override' => 1,
511 'status_id' => $this->_membershipStatusID,
6a488035
TO
512 );
513
771f3245 514 $result = $this->callAPISuccess('membership', 'create', $params);
515 $this->callAPISuccess('Membership', 'Delete', array(
6a488035 516 'id' => $result['id'],
6a488035 517 ));
771f3245 518
6a488035
TO
519 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__);
520 }
521
522 /**
523 * Test civicrm_contact_memberships_create with membership id (edit
524 * membership).
525 * success expected.
526 */
527 function testMembershipCreateUpdateWithIdNoDates() {
528 $membershipID = $this->contactMembershipCreate($this->_params);
529 $params = array(
530 'id' => $membershipID,
531 'contact_id' => $this->_contactID,
532 'membership_type_id' => $this->_membershipTypeID,
533 'source' => 'Payment',
534 'is_override' => 1,
535 'status_id' => $this->_membershipStatusID,
6a488035
TO
536 );
537
771f3245 538 $result = $this->callAPISuccess('membership', 'create', $params);
539 $this->callAPISuccess('Membership', 'Delete', array(
6a488035 540 'id' => $result['id'],
771f3245 541 ));
6a488035
TO
542 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__);
543 }
544
545 /**
546 * Test civicrm_contact_memberships_create with membership id (edit
547 * membership).
548 * success expected.
549 */
550 function testMembershipCreateUpdateWithIdNoDatesNoType() {
551 $membershipID = $this->contactMembershipCreate($this->_params);
552 $params = array(
553 'id' => $membershipID,
554 'source' => 'not much here',
555 'contact_id' => $this->_contactID,
556 'is_override' => 1,
557 'status_id' => $this->_membershipStatusID,
6a488035
TO
558 );
559
771f3245 560 $result = $this->callAPISuccess('membership', 'create', $params);
561 $this->callAPISuccess('Membership', 'Delete', array(
6a488035 562 'id' => $result['id'],
771f3245 563 ));
6a488035
TO
564 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__);
565 }
566
567 /**
568 * Test civicrm_contact_memberships_create with membership id (edit
569 * membership).
570 * success expected.
571 */
572 function testMembershipCreateUpdateWithIDAndSource() {
573 $membershipID = $this->contactMembershipCreate($this->_params);
574 $params = array(
575 'id' => $membershipID,
576 'source' => 'changed',
577 'contact_id' => $this->_contactID,
771f3245 578 'status_id' => $this->_membershipStatusID, 'membership_type_id' => $this->_membershipTypeID,
6a488035
TO
579 'skipStatusCal' => 1,
580 );
771f3245 581 $result = $this->callAPISuccess('membership', 'create', $params);
6a488035 582 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__);
771f3245 583 $this->callAPISuccess('Membership', 'Delete', array(
6a488035 584 'id' => $result['id'],
6a488035
TO
585 ));
586 }
587
588 /**
589 * change custom field using update
590 */
591 function testUpdateWithCustom() {
592 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
593
594 $params = $this->_params;
595 $params['custom_' . $ids['custom_field_id']] = "custom string";
771f3245 596 $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
597 $result = $this->callAPISuccess($this->_entity, 'create', array('id' => $result['id'], 'custom_' . $ids['custom_field_id'] => "new custom"));
598 $check = $this->callAPISuccess($this->_entity, 'get', array('id' => $result['id'], 'contact_id' => $this->_contactID));
6a488035
TO
599
600 $this->assertEquals("new custom", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
771f3245 601 $delete = $this->callAPISuccess('Membership', 'Delete', array(
6a488035 602 'id' => $check['id'],
6a488035
TO
603 ));
604
605 $this->customFieldDelete($ids['custom_field_id']);
606 $this->customGroupDelete($ids['custom_group_id']);
607 }
608
609 /**
610 * Test civicrm_contact_memberships_create Invalid membership data
611 * Error expected.
612 */
613 function testMembershipCreateInvalidMemData() {
614 //membership_contact_id as string
615 $params = array(
616 'membership_contact_id' => 'Invalid',
617 'membership_type_id' => $this->_membershipTypeID,
618 'join_date' => '2011-01-21',
619 'start_date' => '2010-01-21',
620 'end_date' => '2008-12-21',
621 'source' => 'Payment',
622 'is_override' => 1,
771f3245 623 'status_id' => $this->_membershipStatusID, );
6a488035 624
d0e1eff2 625 $result = $this->callAPIFailure('membership', 'create', $params);
6a488035
TO
626
627 //membership_contact_id which is no in contact table
628 $params['membership_contact_id'] = 999;
d0e1eff2 629 $result = $this->callAPIFailure('membership', 'create', $params);
6a488035
TO
630
631 //invalid join date
632 unset($params['membership_contact_id']);
633 $params['join_date'] = "invalid";
d0e1eff2 634 $result = $this->callAPIFailure('Membership', 'Create', $params);
6a488035
TO
635 }
636
637 /**
638 * Test civicrm_contact_memberships_create with membership_contact_id
639 * membership).
640 * Success expected.
641 */
642 function testMembershipCreateWithMemContact() {
643 $params = array(
644 'membership_contact_id' => $this->_contactID,
645 'membership_type_id' => $this->_membershipTypeID,
646 'join_date' => '2011-01-21',
647 'start_date' => '2010-01-21',
648 'end_date' => '2008-12-21',
649 'source' => 'Payment',
650 'is_override' => 1,
651 'status_id' => $this->_membershipStatusID,
6a488035
TO
652 );
653
771f3245 654 $result = $this->callAPISuccess('membership', 'create', $params);
6a488035 655
771f3245 656 $result = $this->callAPISuccess('Membership', 'Delete', array(
6a488035 657 'id' => $result['id'],
771f3245 658 ));
6a488035
TO
659 }
660
661 ///////////////// civicrm_membership_delete methods
662}
663