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