Merge pull request #14326 from civicrm/5.14
[civicrm-core.git] / tests / phpunit / api / v3 / RelationshipTest.php
1 <?php
2 /**
3 * +--------------------------------------------------------------------+
4 * | CiviCRM version 5 |
5 * +--------------------------------------------------------------------+
6 * | Copyright CiviCRM LLC (c) 2004-2019 |
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 * Class contains api test cases for "civicrm_relationship"
30 * @group headless
31 */
32 class api_v3_RelationshipTest extends CiviUnitTestCase {
33
34 use CRMTraits_Custom_CustomDataTrait;
35
36 protected $_apiversion = 3;
37 protected $_cId_a;
38 /**
39 * Second individual.
40 *
41 * @var int
42 */
43 protected $_cId_a_2;
44 protected $_cId_b;
45 /**
46 * Second organization contact.
47 *
48 * @var int
49 */
50 protected $_cId_b2;
51 protected $_relTypeID;
52 protected $_ids = [];
53 protected $_customFieldId = NULL;
54 protected $_params;
55
56 protected $entity;
57
58 /**
59 * Set up function.
60 */
61 public function setUp() {
62 parent::setUp();
63 $this->_cId_a = $this->individualCreate();
64 $this->_cId_a_2 = $this->individualCreate(array(
65 'last_name' => 'c2',
66 'email' => 'c@w.com',
67 'contact_type' => 'Individual',
68 ));
69 $this->_cId_b = $this->organizationCreate();
70 $this->_cId_b2 = $this->organizationCreate(array('organization_name' => ' Org 2'));
71 $this->entity = 'Relationship';
72 //Create a relationship type.
73 $relTypeParams = array(
74 'name_a_b' => 'Relation 1 for delete',
75 'name_b_a' => 'Relation 2 for delete',
76 'description' => 'Testing relationship type',
77 'contact_type_a' => 'Individual',
78 'contact_type_b' => 'Organization',
79 'is_reserved' => 1,
80 'is_active' => 1,
81 );
82
83 $this->_relTypeID = $this->relationshipTypeCreate($relTypeParams);
84 $this->_params = array(
85 'contact_id_a' => $this->_cId_a,
86 'contact_id_b' => $this->_cId_b,
87 'relationship_type_id' => $this->_relTypeID,
88 'start_date' => '2008-12-20',
89 'is_active' => 1,
90 );
91
92 }
93
94 /**
95 * Tear down function.
96 *
97 * @throws \Exception
98 */
99 public function tearDown() {
100 $this->contactDelete($this->_cId_a);
101 $this->contactDelete($this->_cId_a_2);
102 $this->contactDelete($this->_cId_b);
103 $this->contactDelete($this->_cId_b2);
104 $this->quickCleanup(array('civicrm_relationship'), TRUE);
105 $this->relationshipTypeDelete($this->_relTypeID);
106 }
107
108 /**
109 * Check with empty array.
110 */
111 public function testRelationshipCreateEmpty() {
112 $this->callAPIFailure('relationship', 'create', array());
113 }
114
115 /**
116 * Test Current Employer is correctly set.
117 */
118 public function testCurrentEmployerRelationship() {
119 $employerRelationshipID = $this->callAPISuccessGetValue('RelationshipType', array(
120 'return' => "id",
121 'name_b_a' => "Employer Of",
122 ));
123 $employerRelationship = $this->callAPISuccess('Relationship', 'create', array(
124 'contact_id_a' => $this->_cId_a,
125 'contact_id_b' => $this->_cId_b,
126 'relationship_type_id' => $employerRelationshipID,
127 ));
128 $params = array($this->_cId_a => $this->_cId_b);
129 CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($params);
130
131 //Check if current employer is correctly set.
132 $employer = $this->callAPISuccessGetValue('Contact', array(
133 'return' => "current_employer",
134 'id' => $this->_cId_a,
135 ));
136 $organisation = $this->callAPISuccessGetValue('Contact', array(
137 'return' => "sort_name",
138 'id' => $this->_cId_b,
139 ));
140 $this->assertEquals($employer, $organisation);
141
142 //Update relationship type
143 $update = $this->callAPISuccess('Relationship', 'create', array(
144 'id' => $employerRelationship['id'],
145 'relationship_type_id' => $this->_relTypeID,
146 ));
147 $employeeContact = $this->callAPISuccessGetSingle('Contact', array(
148 'return' => array("current_employer"),
149 'id' => $this->_cId_a,
150 ));
151 //current employer should be removed.
152 $this->assertEmpty($employeeContact['current_employer']);
153 }
154
155 /**
156 * Check if required fields are not passed.
157 */
158 public function testRelationshipCreateWithoutRequired() {
159 $params = array(
160 'start_date' => array('d' => '10', 'M' => '1', 'Y' => '2008'),
161 'end_date' => array('d' => '10', 'M' => '1', 'Y' => '2009'),
162 'is_active' => 1,
163 );
164
165 $this->callAPIFailure('relationship', 'create', $params);
166 }
167
168 /**
169 * Check with incorrect required fields.
170 */
171 public function testRelationshipCreateWithIncorrectData() {
172
173 $params = array(
174 'contact_id_a' => $this->_cId_a,
175 'contact_id_b' => $this->_cId_b,
176 'relationship_type_id' => 'Breaking Relationship',
177 );
178
179 $this->callAPIFailure('relationship', 'create', $params);
180
181 //contact id is not an integer
182 $params = array(
183 'contact_id_a' => 'invalid',
184 'contact_id_b' => $this->_cId_b,
185 'relationship_type_id' => $this->_relTypeID,
186 'start_date' => array('d' => '10', 'M' => '1', 'Y' => '2008'),
187 'is_active' => 1,
188 );
189 $this->callAPIFailure('relationship', 'create', $params);
190
191 // Contact id does not exist.
192 $params['contact_id_a'] = 999;
193 $this->callAPIFailure('relationship', 'create', $params);
194
195 //invalid date
196 $params['contact_id_a'] = $this->_cId_a;
197 $params['start_date'] = array('d' => '1', 'M' => '1');
198 $this->callAPIFailure('relationship', 'create', $params);
199 }
200
201 /**
202 * Check relationship creation with invalid Relationship.
203 */
204 public function testRelationshipCreateInvalidRelationship() {
205 // Both have the contact type Individual.
206 $params = array(
207 'contact_id_a' => $this->_cId_a,
208 'contact_id_b' => $this->_cId_a,
209 'relationship_type_id' => $this->_relTypeID,
210 'start_date' => '2008-01-10',
211 'is_active' => 1,
212 );
213
214 $this->callAPIFailure('relationship', 'create', $params);
215
216 // both the contact of type Organization
217 $params = array(
218 'contact_id_a' => $this->_cId_b,
219 'contact_id_b' => $this->_cId_b,
220 'relationship_type_id' => $this->_relTypeID,
221 'start_date' => '2008-01-10',
222 'is_active' => 1,
223 );
224
225 $this->callAPIFailure('relationship', 'create', $params);
226 }
227
228 /**
229 * Check relationship already exists.
230 */
231 public function testRelationshipCreateAlreadyExists() {
232 $params = array(
233 'contact_id_a' => $this->_cId_a,
234 'contact_id_b' => $this->_cId_b,
235 'relationship_type_id' => $this->_relTypeID,
236 'start_date' => '2008-12-20',
237 'end_date' => NULL,
238 'is_active' => 1,
239 );
240 $relationship = $this->callAPISuccess('relationship', 'create', $params);
241
242 $params = array(
243 'contact_id_a' => $this->_cId_a,
244 'contact_id_b' => $this->_cId_b,
245 'relationship_type_id' => $this->_relTypeID,
246 'start_date' => '2008-12-20',
247 'is_active' => 1,
248 );
249 $this->callAPIFailure('relationship', 'create', $params, 'Duplicate Relationship');
250
251 $params['id'] = $relationship['id'];
252 $this->callAPISuccess('relationship', 'delete', $params);
253 }
254
255 /**
256 * Check relationship already exists.
257 */
258 public function testRelationshipCreateUpdateAlreadyExists() {
259 $params = array(
260 'contact_id_a' => $this->_cId_a,
261 'contact_id_b' => $this->_cId_b,
262 'relationship_type_id' => $this->_relTypeID,
263 'start_date' => '2008-12-20',
264 'end_date' => NULL,
265 'is_active' => 1,
266
267 );
268 $relationship = $this->callAPISuccess('relationship', 'create', $params);
269 $params = array(
270 'id' => $relationship['id'],
271 'is_active' => 0,
272 'debug' => 1,
273 );
274 $this->callAPISuccess('relationship', 'create', $params);
275 $this->callAPISuccess('relationship', 'get', $params);
276 $params['id'] = $relationship['id'];
277 $this->callAPISuccess('relationship', 'delete', $params);
278 }
279
280 /**
281 * Check update doesn't reset stuff badly - CRM-11789.
282 */
283 public function testRelationshipCreateUpdateDoesNotMangle() {
284 $params = array(
285 'contact_id_a' => $this->_cId_a,
286 'contact_id_b' => $this->_cId_b,
287 'relationship_type_id' => $this->_relTypeID,
288 'start_date' => '2008-12-20',
289 'is_active' => 1,
290 'is_permission_a_b' => 1,
291 'description' => 'my desc',
292 );
293 $relationship = $this->callAPISuccess('relationship', 'create', $params);
294
295 $updateParams = array(
296 'id' => $relationship['id'],
297 'relationship_type_id' => $this->_relTypeID,
298 );
299 $this->callAPISuccess('relationship', 'create', $updateParams);
300
301 //make sure the orig params didn't get changed
302 $this->getAndCheck($params, $relationship['id'], 'relationship');
303
304 }
305
306 /**
307 * Check relationship creation.
308 */
309 public function testRelationshipCreate() {
310 $params = array(
311 'contact_id_a' => $this->_cId_a,
312 'contact_id_b' => $this->_cId_b,
313 'relationship_type_id' => $this->_relTypeID,
314 'start_date' => '2010-10-30',
315 'end_date' => '2010-12-30',
316 'is_active' => 1,
317 'note' => 'note',
318 );
319
320 $result = $this->callAPIAndDocument('relationship', 'create', $params, __FUNCTION__, __FILE__);
321 $this->assertNotNull($result['id']);
322 $relationParams = array(
323 'id' => $result['id'],
324 );
325
326 // assertDBState compares expected values in $result to actual values in the DB
327 $this->assertDBState('CRM_Contact_DAO_Relationship', $result['id'], $relationParams);
328 $result = $this->callAPISuccess('relationship', 'get', array('id' => $result['id']));
329 $values = $result['values'][$result['id']];
330 foreach ($params as $key => $value) {
331 if ($key == 'note') {
332 continue;
333 }
334 $this->assertEquals($value, $values[$key], $key . " doesn't match " . print_r($values, TRUE));
335 }
336 $params['id'] = $result['id'];
337 $this->callAPISuccess('relationship', 'delete', $params);
338 }
339
340 /**
341 * Ensure disabling works.
342 */
343 public function testRelationshipUpdate() {
344 $result = $this->callAPISuccess('relationship', 'create', $this->_params);
345 $relID = $result['id'];
346 $result = $this->callAPISuccess('relationship', 'create', array('id' => $relID, 'description' => 'blah'));
347 $this->assertEquals($relID, $result['id']);
348
349 $this->assertEquals('blah', $result['values'][$result['id']]['description']);
350
351 $result = $this->callAPISuccess('relationship', 'create', array('id' => $relID, 'is_permission_b_a' => 1));
352 $this->assertEquals(1, $result['values'][$result['id']]['is_permission_b_a']);
353 $result = $this->callAPISuccess('relationship', 'create', array('id' => $result['id'], 'is_active' => 0));
354 $result = $this->callAPISuccess('relationship', 'get', array('id' => $result['id']));
355 $this->assertEquals(0, $result['values'][$result['id']]['is_active']);
356 $this->assertEquals('blah', $result['values'][$result['id']]['description']);
357 $this->assertEquals(1, $result['values'][$result['id']]['is_permission_b_a']);
358 }
359
360 /**
361 * Check relationship creation.
362 */
363 public function testRelationshipCreateEmptyEndDate() {
364 $params = array(
365 'contact_id_a' => $this->_cId_a,
366 'contact_id_b' => $this->_cId_b,
367 'relationship_type_id' => $this->_relTypeID,
368 'start_date' => '2010-10-30',
369 'end_date' => '',
370 'is_active' => 1,
371 'note' => 'note',
372 );
373
374 $result = $this->callAPISuccess('relationship', 'create', $params);
375 $this->assertNotNull($result['id']);
376 $relationParams = array(
377 'id' => $result['id'],
378 );
379
380 // assertDBState compares expected values in $result to actual values in the DB
381 $this->assertDBState('CRM_Contact_DAO_Relationship', $result['id'], $relationParams);
382 $result = $this->callAPISuccess('relationship', 'get', array('id' => $result['id']));
383 $values = $result['values'][$result['id']];
384 foreach ($params as $key => $value) {
385 if ($key == 'note') {
386 continue;
387 }
388 if ($key == 'end_date') {
389 $this->assertTrue(empty($values[$key]));
390 continue;
391 }
392 $this->assertEquals($value, $values[$key], $key . " doesn't match " . print_r($values, TRUE) . 'in line' . __LINE__);
393 }
394 $params['id'] = $result['id'];
395 $this->callAPISuccess('relationship', 'delete', $params);
396 }
397
398 /**
399 * Check relationship creation with custom data.
400 */
401 public function testRelationshipCreateEditWithCustomData() {
402 $this->createCustomGroupWithFieldsOfAllTypes();
403 //few custom Values for comparing
404 $custom_params = [
405 $this->getCustomFieldName('text') => 'Hello! this is custom data for relationship',
406 $this->getCustomFieldName('select_string') => 'Y',
407 $this->getCustomFieldName('select_date') => '2009-07-11 00:00:00',
408 $this->getCustomFieldName('link') => 'http://example.com',
409 ];
410
411 $params = [
412 'contact_id_a' => $this->_cId_a,
413 'contact_id_b' => $this->_cId_b,
414 'relationship_type_id' => $this->_relTypeID,
415 'start_date' => '2008-12-20',
416 'is_active' => 1,
417 ];
418 $params = array_merge($params, $custom_params);
419 $result = $this->callAPISuccess('relationship', 'create', $params);
420
421 $relationParams = ['id' => $result['id']];
422 $this->assertDBState('CRM_Contact_DAO_Relationship', $result['id'], $relationParams);
423
424 //Test Edit of custom field from the form.
425 $getParams = array('id' => $result['id']);
426 $updateParams = array_merge($getParams, array(
427 $this->getCustomFieldName('text') => 'Edited Text Value',
428 'relationship_type_id' => $this->_relTypeID . '_b_a',
429 'related_contact_id' => $this->_cId_a,
430 ));
431 $reln = new CRM_Contact_Form_Relationship();
432 $reln->_action = CRM_Core_Action::UPDATE;
433 $reln->_relationshipId = $result['id'];
434 $reln->submit($updateParams);
435
436 $check = $this->callAPISuccess('relationship', 'get', $getParams);
437 $this->assertEquals("Edited Text Value", $check['values'][$check['id']][$this->getCustomFieldName('text')]);
438
439 $params['id'] = $result['id'];
440 $this->callAPISuccess('relationship', 'delete', $params);
441 $this->relationshipTypeDelete($this->_relTypeID);
442 }
443
444 /**
445 * Check with complete array + custom field
446 * Note that the test is written on purpose without any
447 * variables specific to participant so it can be replicated into other entities
448 * and / or moved to the automated test suite
449 */
450 public function testGetWithCustom() {
451 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
452
453 $params = $this->_params;
454 $params['custom_' . $ids['custom_field_id']] = "custom string";
455
456 $result = $this->callAPISuccess($this->entity, 'create', $params);
457 $this->assertEquals($result['id'], $result['values'][$result['id']]['id']);
458
459 $getParams = array('id' => $result['id']);
460 $check = $this->callAPIAndDocument($this->entity, 'get', $getParams, __FUNCTION__, __FILE__);
461 $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
462
463 $this->customFieldDelete($ids['custom_field_id']);
464 $this->customGroupDelete($ids['custom_group_id']);
465 }
466
467 /**
468 * Check with empty array.
469 */
470 public function testRelationshipDeleteEmpty() {
471 $this->callAPIFailure('relationship', 'delete', array(), 'Mandatory key(s) missing from params array: id');
472 }
473
474 /**
475 * Check if required fields are not passed.
476 */
477 public function testRelationshipDeleteWithoutRequired() {
478 $params = array(
479 'start_date' => '2008-12-20',
480 'end_date' => '2009-12-20',
481 'is_active' => 1,
482 );
483
484 $this->callAPIFailure('relationship', 'delete', $params, 'Mandatory key(s) missing from params array: id');
485 }
486
487 /**
488 * Check with incorrect required fields.
489 */
490 public function testRelationshipDeleteWithIncorrectData() {
491 $params = array(
492 'contact_id_a' => $this->_cId_a,
493 'contact_id_b' => $this->_cId_b,
494 'relationship_type_id' => 'Breaking Relationship',
495 );
496
497 $this->callAPIFailure('relationship', 'delete', $params, 'Mandatory key(s) missing from params array: id');
498
499 $params['id'] = "Invalid";
500 $this->callAPIFailure('relationship', 'delete', $params, 'id is not a valid integer');
501 }
502
503 /**
504 * Check relationship creation.
505 */
506 public function testRelationshipDelete() {
507 $params = array(
508 'contact_id_a' => $this->_cId_a,
509 'contact_id_b' => $this->_cId_b,
510 'relationship_type_id' => $this->_relTypeID,
511 'start_date' => '2008-12-20',
512 'is_active' => 1,
513 );
514
515 $result = $this->callAPISuccess('relationship', 'create', $params);
516 $params = array('id' => $result['id']);
517 $this->callAPIAndDocument('relationship', 'delete', $params, __FUNCTION__, __FILE__);
518 $this->relationshipTypeDelete($this->_relTypeID);
519 }
520
521 ///////////////// civicrm_relationship_update methods
522
523 /**
524 * Check with empty array.
525 */
526 public function testRelationshipUpdateEmpty() {
527 $this->callAPIFailure('relationship', 'create', array(),
528 'Mandatory key(s) missing from params array: contact_id_a, contact_id_b, relationship_type_id');
529 }
530
531 /**
532 * Check if required fields are not passed.
533 */
534
535 /**
536 * Check relationship update.
537 */
538 public function testRelationshipCreateDuplicate() {
539 $relParams = array(
540 'contact_id_a' => $this->_cId_a,
541 'contact_id_b' => $this->_cId_b,
542 'relationship_type_id' => $this->_relTypeID,
543 'start_date' => '20081214',
544 'end_date' => '20091214',
545 'is_active' => 1,
546 );
547
548 $result = $this->callAPISuccess('relationship', 'create', $relParams);
549
550 $this->assertNotNull($result['id']);
551
552 $params = array(
553 'contact_id_a' => $this->_cId_a,
554 'contact_id_b' => $this->_cId_b,
555 'relationship_type_id' => $this->_relTypeID,
556 'start_date' => '20081214',
557 'end_date' => '20091214',
558 'is_active' => 0,
559 );
560
561 $this->callAPIFailure('relationship', 'create', $params, 'Duplicate Relationship');
562
563 $this->callAPISuccess('relationship', 'delete', array('id' => $result['id']));
564 $this->relationshipTypeDelete($this->_relTypeID);
565 }
566
567 /**
568 * CRM-13725 - Two relationships of same type with same start and end date
569 * should be OK if the custom field values differ.
570 */
571 public function testRelationshipCreateDuplicateWithCustomFields() {
572 $this->createCustomGroupWithFieldsOfAllTypes();
573
574 $custom_params_1 = array(
575 $this->getCustomFieldName('text') => 'Hello! this is custom data for relationship',
576 $this->getCustomFieldName('select_string') => 'Y',
577 $this->getCustomFieldName('select_date') => '2009-07-11 00:00:00',
578 $this->getCustomFieldName('link') => 'http://example.com',
579 );
580
581 $custom_params_2 = array(
582 $this->getCustomFieldName('text') => 'Hello! this is other custom data',
583 $this->getCustomFieldName('select_string') => 'Y',
584 $this->getCustomFieldName('select_date') => '2009-07-11 00:00:00',
585 $this->getCustomFieldName('link') => 'http://example.org',
586 );
587
588 $params = array(
589 'contact_id_a' => $this->_cId_a,
590 'contact_id_b' => $this->_cId_b,
591 'relationship_type_id' => $this->_relTypeID,
592 'start_date' => '2008-12-20',
593 'is_active' => 1,
594 );
595
596 $params_1 = array_merge($params, $custom_params_1);
597 $params_2 = array_merge($params, $custom_params_2);
598
599 $result_1 = $this->callAPISuccess('relationship', 'create', $params_1);
600 $result_2 = $this->callAPISuccess('relationship', 'create', $params_2);
601
602 $this->assertNotNull($result_2['id']);
603 $this->assertEquals(0, $result_2['is_error']);
604
605 $this->relationshipTypeDelete($this->_relTypeID);
606 }
607
608 /**
609 * CRM-13725 - Two relationships of same type with same start and end date
610 * should be OK if the custom field values differ. In this case, the
611 * existing relationship does not have custom values, but the new one
612 * does.
613 */
614 public function testRelationshipCreateDuplicateWithCustomFields2() {
615 $this->createCustomGroupWithFieldsOfAllTypes();
616
617 $custom_params_2 = array(
618 $this->getCustomFieldName('text') => 'Hello! this is other custom data',
619 $this->getCustomFieldName('select_string') => 'Y',
620 $this->getCustomFieldName('select_date') => '2009-07-11 00:00:00',
621 $this->getCustomFieldName('link') => 'http://example.org',
622 );
623
624 $params_1 = [
625 'contact_id_a' => $this->_cId_a,
626 'contact_id_b' => $this->_cId_b,
627 'relationship_type_id' => $this->_relTypeID,
628 'start_date' => '2008-12-20',
629 'is_active' => 1,
630 ];
631
632 $params_2 = array_merge($params_1, $custom_params_2);
633
634 $this->callAPISuccess('relationship', 'create', $params_1);
635 $result_2 = $this->callAPISuccess('relationship', 'create', $params_2);
636
637 $this->assertNotNull($result_2['id']);
638 $this->assertEquals(0, $result_2['is_error']);
639
640 $this->relationshipTypeDelete($this->_relTypeID);
641 }
642
643 /**
644 * CRM-13725 - Two relationships of same type with same start and end date
645 * should be OK if the custom field values differ. In this case, the
646 * existing relationship does have custom values, but the new one
647 * does not.
648 */
649 public function testRelationshipCreateDuplicateWithCustomFields3() {
650 $this->createCustomGroupWithFieldsOfAllTypes();
651
652 $custom_params_1 = [
653 $this->getCustomFieldName('text') => 'Hello! this is other custom data',
654 $this->getCustomFieldName('select_string') => 'Y',
655 $this->getCustomFieldName('select_date') => '2009-07-11 00:00:00',
656 $this->getCustomFieldName('link') => 'http://example.org',
657 ];
658
659 $params_2 = array(
660 'contact_id_a' => $this->_cId_a,
661 'contact_id_b' => $this->_cId_b,
662 'relationship_type_id' => $this->_relTypeID,
663 'start_date' => '2008-12-20',
664 'is_active' => 1,
665 );
666
667 $params_1 = array_merge($params_2, $custom_params_1);
668
669 $this->callAPISuccess('relationship', 'create', $params_1);
670 $result_2 = $this->callAPISuccess('relationship', 'create', $params_2);
671
672 $this->assertNotNull($result_2['id']);
673 $this->assertEquals(0, $result_2['is_error']);
674
675 $this->relationshipTypeDelete($this->_relTypeID);
676 }
677
678 /**
679 * Check with valid params array.
680 */
681 public function testRelationshipsGet() {
682 $relParams = array(
683 'contact_id_a' => $this->_cId_a,
684 'contact_id_b' => $this->_cId_b,
685 'relationship_type_id' => $this->_relTypeID,
686 'start_date' => '2011-01-01',
687 'end_date' => '2013-01-01',
688 'is_active' => 1,
689 );
690
691 $this->callAPISuccess('relationship', 'create', $relParams);
692
693 //get relationship
694 $params = array(
695 'contact_id' => $this->_cId_b,
696 );
697 $result = $this->callAPISuccess('relationship', 'get', $params);
698 $this->assertEquals($result['count'], 1);
699 $params = array(
700 'contact_id_a' => $this->_cId_a,
701 );
702 $result = $this->callAPISuccess('relationship', 'get', $params);
703 $this->assertEquals($result['count'], 1);
704 // contact_id_a is wrong so should be no matches
705 $params = array(
706 'contact_id_a' => $this->_cId_b,
707 );
708 $result = $this->callAPISuccess('relationship', 'get', $params);
709 $this->assertEquals($result['count'], 0);
710 }
711
712 /**
713 * Chain Relationship.get and to Contact.get.
714 */
715 public function testRelationshipGetWithChainedCall() {
716 // Create a relationship.
717 $createResult = $this->callAPISuccess('relationship', 'create', $this->_params);
718 $id = $createResult['id'];
719
720 // Try to retrieve it using chaining.
721 $params = array(
722 'relationship_type_id' => $this->_relTypeID,
723 'id' => $id,
724 'api.Contact.get' => array(
725 'id' => '$value.contact_id_b',
726 ),
727 );
728
729 $result = $this->callAPISuccess('relationship', 'get', $params);
730
731 $this->assertEquals(1, $result['count']);
732 $relationship = CRM_Utils_Array::first($result['values']);
733 $this->assertEquals(1, $relationship['api.Contact.get']['count']);
734 $contact = CRM_Utils_Array::first($relationship['api.Contact.get']['values']);
735 $this->assertEquals($this->_cId_b, $contact['id']);
736 }
737
738 /**
739 * Chain Contact.get to Relationship.get and again to Contact.get.
740 */
741 public function testRelationshipGetInChainedCall() {
742 // Create a relationship.
743 $this->callAPISuccess('relationship', 'create', $this->_params);
744
745 // Try to retrieve it using chaining.
746 $params = array(
747 'id' => $this->_cId_a,
748 'api.Relationship.get' => array(
749 'relationship_type_id' => $this->_relTypeID,
750 'contact_id_a' => '$value.id',
751 'api.Contact.get' => array(
752 'id' => '$value.contact_id_b',
753 ),
754 ),
755 );
756
757 $result = $this->callAPISuccess('contact', 'get', $params);
758 $this->assertEquals(1, $result['count']);
759 $contact = CRM_Utils_Array::first($result['values']);
760 $this->assertEquals(1, $contact['api.Relationship.get']['count']);
761 $relationship = CRM_Utils_Array::first($contact['api.Relationship.get']['values']);
762 $this->assertEquals(1, $relationship['api.Contact.get']['count']);
763 $contact = CRM_Utils_Array::first($relationship['api.Contact.get']['values']);
764 $this->assertEquals($this->_cId_b, $contact['id']);
765 }
766
767 /**
768 * Check with valid params array.
769 * (The get function will behave differently without 'contact_id' passed
770 */
771 public function testRelationshipsGetGeneric() {
772 $relParams = array(
773 'contact_id_a' => $this->_cId_a,
774 'contact_id_b' => $this->_cId_b,
775 'relationship_type_id' => $this->_relTypeID,
776 'start_date' => '2011-01-01',
777 'end_date' => '2013-01-01',
778 'is_active' => 1,
779 );
780
781 $this->callAPISuccess('relationship', 'create', $relParams);
782
783 //get relationship
784 $params = array(
785 'contact_id_b' => $this->_cId_b,
786 );
787 $this->callAPISuccess('relationship', 'get', $params);
788 }
789
790 /**
791 * Test retrieving only current relationships.
792 */
793 public function testGetIsCurrent() {
794 $rel2Params = array(
795 'contact_id_a' => $this->_cId_a,
796 'contact_id_b' => $this->_cId_b2,
797 'relationship_type_id' => $this->_relTypeID,
798 'start_date' => '2008-12-20',
799 'is_active' => 0,
800 );
801 $this->callAPISuccess('relationship', 'create', $rel2Params);
802 $rel1 = $this->callAPISuccess('relationship', 'create', $this->_params);
803
804 $getParams = array(
805 'filters' => array('is_current' => 1),
806 );
807 $description = "Demonstrates is_current filter.";
808 $subfile = 'filterIsCurrent';
809 //no relationship has been created
810 $result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__, __FILE__, $description, $subfile);
811 $this->assertEquals($result['count'], 1);
812 $this->AssertEquals($rel1['id'], $result['id']);
813
814 // now try not started
815 $rel2Params['is_active'] = 1;
816 $rel2Params['start_date'] = 'tomorrow';
817 $this->callAPISuccess('relationship', 'create', $rel2Params);
818 $result = $this->callAPISuccess('relationship', 'get', $getParams);
819 $this->assertEquals($result['count'], 1);
820 $this->AssertEquals($rel1['id'], $result['id']);
821
822 // now try finished
823 $rel2Params['is_active'] = 1;
824 $rel2Params['start_date'] = 'last week';
825 $rel2Params['end_date'] = 'yesterday';
826 $this->callAPISuccess('relationship', 'create', $rel2Params);
827 }
828
829 /**
830 * Test using various operators.
831 */
832 public function testGetTypeOperators() {
833 $relTypeParams = array(
834 'name_a_b' => 'Relation 3 for delete',
835 'name_b_a' => 'Relation 6 for delete',
836 'description' => 'Testing relationship type 2',
837 'contact_type_a' => 'Individual',
838 'contact_type_b' => 'Organization',
839 'is_reserved' => 1,
840 'is_active' => 1,
841 );
842 $relationType2 = $this->relationshipTypeCreate($relTypeParams);
843 $relTypeParams = array(
844 'name_a_b' => 'Relation 8 for delete',
845 'name_b_a' => 'Relation 9 for delete',
846 'description' => 'Testing relationship type 7',
847 'contact_type_a' => 'Individual',
848 'contact_type_b' => 'Organization',
849 'is_reserved' => 1,
850 'is_active' => 1,
851 );
852 $relationType3 = $this->relationshipTypeCreate($relTypeParams);
853
854 $relTypeParams = array(
855 'name_a_b' => 'Relation 6 for delete',
856 'name_b_a' => 'Relation 88for delete',
857 'description' => 'Testing relationship type 00',
858 'contact_type_a' => 'Individual',
859 'contact_type_b' => 'Organization',
860 'is_reserved' => 1,
861 'is_active' => 1,
862 );
863 $relationType4 = $this->relationshipTypeCreate($relTypeParams);
864
865 $rel1 = $this->callAPISuccess('relationship', 'create', $this->_params);
866 $rel2 = $this->callAPISuccess('relationship', 'create', array_merge($this->_params,
867 array('relationship_type_id' => $relationType2)));
868 $rel3 = $this->callAPISuccess('relationship', 'create', array_merge($this->_params,
869 array('relationship_type_id' => $relationType3)));
870 $rel4 = $this->callAPISuccess('relationship', 'create', array_merge($this->_params,
871 array('relationship_type_id' => $relationType4)));
872
873 $getParams = array(
874 'relationship_type_id' => array('IN' => array($relationType2, $relationType3)),
875 );
876
877 $description = "Demonstrates use of IN filter.";
878 $subfile = 'INRelationshipType';
879
880 $result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__, __FILE__, $description, $subfile);
881 $this->assertEquals($result['count'], 2);
882 $this->AssertEquals(array($rel2['id'], $rel3['id']), array_keys($result['values']));
883
884 $description = "Demonstrates use of NOT IN filter.";
885 $subfile = 'NotInRelationshipType';
886 $getParams = array(
887 'relationship_type_id' => array('NOT IN' => array($relationType2, $relationType3)),
888 );
889 $result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__, __FILE__, $description, $subfile);
890 $this->assertEquals($result['count'], 2);
891 $this->AssertEquals(array($rel1['id'], $rel4['id']), array_keys($result['values']));
892
893 $description = "Demonstrates use of BETWEEN filter.";
894 $subfile = 'BetweenRelationshipType';
895 $getParams = array(
896 'relationship_type_id' => array('BETWEEN' => array($relationType2, $relationType4)),
897 );
898 $result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__, __FILE__, $description, $subfile);
899 $this->assertEquals($result['count'], 3);
900 $this->AssertEquals(array($rel2['id'], $rel3['id'], $rel4['id']), array_keys($result['values']));
901
902 $description = "Demonstrates use of Not BETWEEN filter.";
903 $subfile = 'NotBetweenRelationshipType';
904 $getParams = array(
905 'relationship_type_id' => array('NOT BETWEEN' => array($relationType2, $relationType4)),
906 );
907 $result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__, __FILE__, $description, $subfile);
908 $this->assertEquals($result['count'], 1);
909 $this->AssertEquals(array($rel1['id']), array_keys($result['values']));
910
911 }
912
913 /**
914 * Check with invalid relationshipType Id.
915 */
916 public function testRelationshipTypeAddInvalidId() {
917 $relTypeParams = array(
918 'id' => 'invalid',
919 'name_a_b' => 'Relation 1 for delete',
920 'name_b_a' => 'Relation 2 for delete',
921 'contact_type_a' => 'Individual',
922 'contact_type_b' => 'Organization',
923 );
924 $this->callAPIFailure('relationship_type', 'create', $relTypeParams,
925 'id is not a valid integer');
926 }
927
928 /**
929 * Check with valid data with contact_b.
930 */
931 public function testGetRelationshipWithContactB() {
932 $relParams = array(
933 'contact_id_a' => $this->_cId_a,
934 'contact_id_b' => $this->_cId_b,
935 'relationship_type_id' => $this->_relTypeID,
936 'start_date' => '2011-01-01',
937 'end_date' => '2013-01-01',
938 'is_active' => 1,
939 );
940
941 $relationship = $this->callAPISuccess('relationship', 'create', $relParams);
942
943 $contacts = array(
944 'contact_id' => $this->_cId_a,
945 );
946
947 $result = $this->callAPISuccess('relationship', 'get', $contacts);
948 $this->assertGreaterThan(0, $result['count']);
949 $params = array(
950 'id' => $relationship['id'],
951 );
952 $this->callAPISuccess('relationship', 'delete', $params);
953 $this->relationshipTypeDelete($this->_relTypeID);
954 }
955
956 /**
957 * Check with valid data with relationshipTypes.
958 */
959 public function testGetRelationshipWithRelTypes() {
960 $relParams = array(
961 'contact_id_a' => $this->_cId_a,
962 'contact_id_b' => $this->_cId_b,
963 'relationship_type_id' => $this->_relTypeID,
964 'start_date' => '2011-01-01',
965 'end_date' => '2013-01-01',
966 'is_active' => 1,
967 );
968
969 $relationship = $this->callAPISuccess('relationship', 'create', $relParams);
970
971 $contact_a = array(
972 'contact_id' => $this->_cId_a,
973 );
974 $this->callAPISuccess('relationship', 'get', $contact_a);
975
976 $params = array(
977 'id' => $relationship['id'],
978 );
979 $this->callAPISuccess('relationship', 'delete', $params);
980 $this->relationshipTypeDelete($this->_relTypeID);
981 }
982
983 /**
984 * Checks that passing in 'contact_id' + a relationship type
985 * will filter by relationship type (relationships go in both directions)
986 * as relationship api does a reciprocal check if contact_id provided
987 *
988 * We should get 1 result without or with correct relationship type id & 0 with
989 * an incorrect one
990 */
991 public function testGetRelationshipByTypeReciprocal() {
992 $created = $this->callAPISuccess($this->entity, 'create', $this->_params);
993 $result = $this->callAPISuccess($this->entity, 'get', array(
994 'contact_id' => $this->_cId_a,
995 'relationship_type_id' => $this->_relTypeID,
996 ));
997 $this->assertEquals(1, $result['count']);
998 $result = $this->callAPISuccess($this->entity, 'get', array(
999 'contact_id' => $this->_cId_a,
1000 'relationship_type_id' => $this->_relTypeID + 1,
1001 ));
1002 $this->assertEquals(0, $result['count']);
1003 $this->callAPISuccess($this->entity, 'delete', array('id' => $created['id']));
1004 }
1005
1006 /**
1007 * Checks that passing in 'contact_id_b' + a relationship type
1008 * will filter by relationship type for contact b
1009 *
1010 * We should get 1 result without or with correct relationship type id & 0 with
1011 * an incorrect one
1012 */
1013 public function testGetRelationshipByTypeDAO() {
1014 $this->_ids['relationship'] = $this->callAPISuccess($this->entity, 'create', array('format.only_id' => TRUE) +
1015 $this->_params);
1016 $this->callAPISuccess($this->entity, 'getcount', array(
1017 'contact_id_a' => $this->_cId_a,
1018 ), 1);
1019 $result = $this->callAPISuccess($this->entity, 'get', array(
1020 'contact_id_a' => $this->_cId_a,
1021 'relationship_type_id' => $this->_relTypeID,
1022 ));
1023 $this->assertEquals(1, $result['count']);
1024 $result = $this->callAPISuccess($this->entity, 'get', array(
1025 'contact_id_a' => $this->_cId_a,
1026 'relationship_type_id' => $this->_relTypeID + 1,
1027 ));
1028 $this->assertEquals(0, $result['count']);
1029 }
1030
1031 /**
1032 * Checks that passing in 'contact_id_b' + a relationship type
1033 * will filter by relationship type for contact b
1034 *
1035 * We should get 1 result without or with correct relationship type id & 0 with
1036 * an incorrect one
1037 */
1038 public function testGetRelationshipByTypeArrayDAO() {
1039 $this->callAPISuccess($this->entity, 'create', $this->_params);
1040 $org3 = $this->organizationCreate();
1041 // lets just assume built in ones aren't being messed with!
1042 $relType2 = 5;
1043 // lets just assume built in ones aren't being messed with!
1044 $relType3 = 6;
1045
1046 // Relationship 2.
1047 $this->callAPISuccess($this->entity, 'create',
1048 array_merge($this->_params, array(
1049 'relationship_type_id' => $relType2,
1050 'contact_id_b' => $this->_cId_b2,
1051 ))
1052 );
1053
1054 // Relationship 3.
1055 $this->callAPISuccess($this->entity, 'create',
1056 array_merge($this->_params, array(
1057 'relationship_type_id' => $relType3,
1058 'contact_id_b' => $org3,
1059 ))
1060 );
1061
1062 $result = $this->callAPISuccess($this->entity, 'get', array(
1063 'contact_id_a' => $this->_cId_a,
1064 'relationship_type_id' => array('IN' => array($this->_relTypeID, $relType3)),
1065 ));
1066
1067 $this->assertEquals(2, $result['count']);
1068 foreach ($result['values'] as $key => $value) {
1069 $this->assertTrue(in_array($value['relationship_type_id'], array($this->_relTypeID, $relType3)));
1070 }
1071 }
1072
1073 /**
1074 * Checks that passing in 'contact_id_b' + a relationship type
1075 * will filter by relationship type for contact b
1076 *
1077 * We should get 1 result without or with correct relationship type id & 0 with
1078 * an incorrect one
1079 */
1080 public function testGetRelationshipByTypeArrayReciprocal() {
1081 $this->callAPISuccess($this->entity, 'create', $this->_params);
1082 $org3 = $this->organizationCreate();
1083 // lets just assume built in ones aren't being messed with!
1084 $relType2 = 5;
1085 $relType3 = 6;
1086
1087 // Relationship 2.
1088 $this->callAPISuccess($this->entity, 'create',
1089 array_merge($this->_params, array(
1090 'relationship_type_id' => $relType2,
1091 'contact_id_b' => $this->_cId_b2,
1092 ))
1093 );
1094
1095 // Relationship 3.
1096 $this->callAPISuccess($this->entity, 'create',
1097 array_merge($this->_params, array(
1098 'relationship_type_id' => $relType3,
1099 'contact_id_b' => $org3,
1100 ))
1101 );
1102
1103 $result = $this->callAPISuccess($this->entity, 'get', array(
1104 'contact_id' => $this->_cId_a,
1105 'relationship_type_id' => array('IN' => array($this->_relTypeID, $relType3)),
1106 ));
1107
1108 $this->assertEquals(2, $result['count']);
1109 foreach ($result['values'] as $key => $value) {
1110 $this->assertTrue(in_array($value['relationship_type_id'], array($this->_relTypeID, $relType3)));
1111 }
1112 }
1113
1114 /**
1115 * Test relationship get by membership type.
1116 *
1117 * Checks that passing in 'contact_id_b' + a relationship type
1118 * will filter by relationship type for contact b
1119 *
1120 * We should get 1 result without or with correct relationship type id & 0 with
1121 * an incorrect one
1122 */
1123 public function testGetRelationshipByMembershipTypeDAO() {
1124 $this->callAPISuccess($this->entity, 'create', $this->_params);
1125 $org3 = $this->organizationCreate();
1126
1127 // lets just assume built in ones aren't being messed with!
1128 $relType2 = 5;
1129 // lets just assume built in ones aren't being messed with!
1130 $relType3 = 6;
1131 $relType1 = 1;
1132 $memberType = $this->membershipTypeCreate(array(
1133 'relationship_type_id' => CRM_Core_DAO::VALUE_SEPARATOR . $relType1 . CRM_Core_DAO::VALUE_SEPARATOR . $relType3 . CRM_Core_DAO::VALUE_SEPARATOR,
1134 'relationship_direction' => CRM_Core_DAO::VALUE_SEPARATOR . 'a_b' . CRM_Core_DAO::VALUE_SEPARATOR . 'b_a' . CRM_Core_DAO::VALUE_SEPARATOR,
1135 ));
1136
1137 // Relationship 2.
1138 $this->callAPISuccess($this->entity, 'create',
1139 array_merge($this->_params, array(
1140 'relationship_type_id' => $relType2,
1141 'contact_id_b' => $this->_cId_b2,
1142 ))
1143 );
1144
1145 // Relationship 3.
1146 $this->callAPISuccess($this->entity, 'create',
1147 array_merge($this->_params, array(
1148 'relationship_type_id' => $relType3,
1149 'contact_id_b' => $org3,
1150 ))
1151 );
1152
1153 // Relationship 4 with reversal.
1154 $this->callAPISuccess($this->entity, 'create',
1155 array_merge($this->_params, array(
1156 'relationship_type_id' => $relType1,
1157 'contact_id_a' => $this->_cId_a,
1158 'contact_id_b' => $this->_cId_a_2,
1159 ))
1160 );
1161
1162 $result = $this->callAPISuccess($this->entity, 'get', array(
1163 'contact_id_a' => $this->_cId_a,
1164 'membership_type_id' => $memberType,
1165 ));
1166 // although our contact has more than one relationship we have passed them in as contact_id_a & can't get reciprocal
1167 $this->assertEquals(1, $result['count']);
1168 foreach ($result['values'] as $key => $value) {
1169 $this->assertTrue(in_array($value['relationship_type_id'], array($relType1)));
1170 }
1171 }
1172
1173 /**
1174 * Checks that passing in 'contact_id_b' + a relationship type
1175 * will filter by relationship type for contact b
1176 *
1177 * We should get 1 result without or with correct relationship type id & 0 with
1178 * an incorrect one
1179 */
1180 public function testGetRelationshipByMembershipTypeReciprocal() {
1181 $this->callAPISuccess($this->entity, 'create', $this->_params);
1182 $org3 = $this->organizationCreate();
1183
1184 // Let's just assume built in ones aren't being messed with!
1185 $relType2 = 5;
1186 $relType3 = 6;
1187 $relType1 = 1;
1188 $memberType = $this->membershipTypeCreate(array(
1189 'relationship_type_id' => CRM_Core_DAO::VALUE_SEPARATOR . $relType1 . CRM_Core_DAO::VALUE_SEPARATOR . $relType3 . CRM_Core_DAO::VALUE_SEPARATOR,
1190 'relationship_direction' => CRM_Core_DAO::VALUE_SEPARATOR . 'a_b' . CRM_Core_DAO::VALUE_SEPARATOR . 'b_a' . CRM_Core_DAO::VALUE_SEPARATOR,
1191 ));
1192
1193 // Relationship 2.
1194 $this->callAPISuccess($this->entity, 'create',
1195 array_merge($this->_params, array(
1196 'relationship_type_id' => $relType2,
1197 'contact_id_b' => $this->_cId_b2,
1198 ))
1199 );
1200
1201 // Relationship 4.
1202 $this->callAPISuccess($this->entity, 'create',
1203 array_merge($this->_params, array(
1204 'relationship_type_id' => $relType3,
1205 'contact_id_b' => $org3,
1206 ))
1207 );
1208
1209 // Relationship 4 with reversal.
1210 $this->callAPISuccess($this->entity, 'create',
1211 array_merge($this->_params, array(
1212 'relationship_type_id' => $relType1,
1213 'contact_id_a' => $this->_cId_a,
1214 'contact_id_b' => $this->_cId_a_2,
1215 ))
1216 );
1217
1218 $result = $this->callAPISuccess($this->entity, 'get', array(
1219 'contact_id' => $this->_cId_a,
1220 'membership_type_id' => $memberType,
1221 ));
1222 // Although our contact has more than one relationship we have passed them in as contact_id_a & can't get reciprocal
1223 $this->assertEquals(2, $result['count']);
1224
1225 foreach ($result['values'] as $key => $value) {
1226 $this->assertTrue(in_array($value['relationship_type_id'], array($relType1, $relType3)));
1227 }
1228 }
1229
1230 /**
1231 * Check for e-notices on enable & disable as reported in CRM-14350
1232 */
1233 public function testSetActive() {
1234 $relationship = $this->callAPISuccess($this->entity, 'create', $this->_params);
1235 $this->callAPISuccess($this->entity, 'create', array('id' => $relationship['id'], 'is_active' => 0));
1236 $this->callAPISuccess($this->entity, 'create', array('id' => $relationship['id'], 'is_active' => 1));
1237 }
1238
1239 /**
1240 * Test creating related memberships.
1241 */
1242 public function testCreateRelatedMembership() {
1243 $relatedMembershipType = $this->callAPISuccess('MembershipType', 'create', array(
1244 'name' => 'Membership with Related',
1245 'member_of_contact_id' => 1,
1246 'financial_type_id' => 1,
1247 'minimum_fee' => 0.00,
1248 'duration_unit' => 'year',
1249 'duration_interval' => 1,
1250 'period_type' => 'rolling',
1251 'relationship_type_id' => $this->_relTypeID,
1252 'relationship_direction' => 'b_a',
1253 'visibility' => 'Public',
1254 'auto_renew' => 0,
1255 'is_active' => 1,
1256 'domain_id' => CRM_Core_Config::domainID(),
1257 ));
1258 $originalMembership = $this->callAPISuccess('Membership', 'create', array(
1259 'membership_type_id' => $relatedMembershipType['id'],
1260 'contact_id' => $this->_cId_b,
1261 ));
1262 $this->callAPISuccess('Relationship', 'create', array(
1263 'relationship_type_id' => $this->_relTypeID,
1264 'contact_id_a' => $this->_cId_a,
1265 'contact_id_b' => $this->_cId_b,
1266 ));
1267 $contactAMembership = $this->callAPISuccessGetSingle('membership', array('contact_id' => $this->_cId_a));
1268 $this->assertEquals($originalMembership['id'], $contactAMembership['owner_membership_id']);
1269
1270 // Adding a relationship with a future start date should NOT create a membership
1271 $this->callAPISuccess('Relationship', 'create', array(
1272 'relationship_type_id' => $this->_relTypeID,
1273 'contact_id_a' => $this->_cId_a_2,
1274 'contact_id_b' => $this->_cId_b,
1275 'start_date' => 'now + 1 week',
1276 ));
1277 $this->callAPISuccessGetCount('membership', array('contact_id' => $this->_cId_a_2), 0);
1278
1279 // Deleting the organization should cause the related membership to be deleted.
1280 $this->callAPISuccess('contact', 'delete', array('id' => $this->_cId_b));
1281 $this->callAPISuccessGetCount('membership', array('contact_id' => $this->_cId_a), 0);
1282 }
1283
1284 }