3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
31 * Class contains api test cases for "civicrm_relationship"
34 class api_v3_RelationshipTest
extends CiviUnitTestCase
{
35 protected $_apiversion = 3;
38 protected $_cId_b2;// second org
39 protected $_relTypeID;
40 protected $_ids = array();
41 protected $_customGroupId = NULL;
42 protected $_customFieldId = NULL;
44 public $_eNoticeCompliant = TRUE;
48 'name' => 'Relationship Create',
49 'description' => 'Test all Relationship Create API methods.',
50 'group' => 'CiviCRM API Tests',
56 $this->_cId_a
= $this->individualCreate();
57 $this->_cId_b
= $this->organizationCreate();
58 $this->_cId_b2
= $this->organizationCreate(array('organization_name' => ' Org 2'));
59 $this->_entity
= 'relationship';
60 //Create a relationship type
61 $relTypeParams = array(
62 'name_a_b' => 'Relation 1 for delete',
63 'name_b_a' => 'Relation 2 for delete',
64 'description' => 'Testing relationship type',
65 'contact_type_a' => 'Individual',
66 'contact_type_b' => 'Organization',
71 $this->_relTypeID
= $this->relationshipTypeCreate($relTypeParams);
72 $this->_params
= array(
73 'contact_id_a' => $this->_cId_a
,
74 'contact_id_b' => $this->_cId_b
,
75 'relationship_type_id' => $this->_relTypeID
,
76 'start_date' => '2008-12-20',
83 $this->contactDelete($this->_cId_a
);
84 $this->contactDelete($this->_cId_b
);
85 $this->contactDelete($this->_cId_b2
);
86 $this->quickCleanup(array('civicrm_relationship'), TRUE);
87 $this->relationshipTypeDelete($this->_relTypeID
);
90 ///////////////// civicrm_relationship_create methods
93 * check with empty array
95 function testRelationshipCreateEmpty() {
96 $this->callAPIFailure('relationship', 'create', array());
100 * check if required fields are not passed
102 function testRelationshipCreateWithoutRequired() {
104 'start_date' => array('d' => '10', 'M' => '1', 'Y' => '2008'),
105 'end_date' => array('d' => '10', 'M' => '1', 'Y' => '2009'),
109 $this->callAPIFailure('relationship', 'create', $params);
113 * check with incorrect required fields
115 function testRelationshipCreateWithIncorrectData() {
118 'contact_id_a' => $this->_cId_a
,
119 'contact_id_b' => $this->_cId_b
,
120 'relationship_type_id' => 'Breaking Relationship',
123 $this->callAPIFailure('relationship', 'create', $params);
125 //contact id is not an integer
127 'contact_id_a' => 'invalid',
128 'contact_id_b' => $this->_cId_b
,
129 'relationship_type_id' => $this->_relTypeID
,
130 'start_date' => array('d' => '10', 'M' => '1', 'Y' => '2008'),
133 $this->callAPIFailure('relationship', 'create', $params);
135 //contact id does not exists
136 $params['contact_id_a'] = 999;
137 $this->callAPIFailure('relationship', 'create', $params);
140 $params['contact_id_a'] = $this->_cId_a
;
141 $params['start_date'] = array('d' => '1', 'M' => '1');
142 $this->callAPIFailure('relationship', 'create', $params);
146 * check relationship creation with invalid Relationship
148 function testRelationshipCreatInvalidRelationship() {
149 // both the contact of type Individual
151 'contact_id_a' => $this->_cId_a
,
152 'contact_id_b' => $this->_cId_a
,
153 'relationship_type_id' => $this->_relTypeID
,
154 'start_date' => '2008-01-10',
158 $this->callAPIFailure('relationship', 'create', $params);
160 // both the contact of type Organization
162 'contact_id_a' => $this->_cId_b
,
163 'contact_id_b' => $this->_cId_b
,
164 'relationship_type_id' => $this->_relTypeID
,
165 'start_date' => '2008-01-10',
169 $this->callAPIFailure('relationship', 'create', $params);
173 * check relationship already exists
175 function testRelationshipCreateAlreadyExists() {
177 'contact_id_a' => $this->_cId_a
,
178 'contact_id_b' => $this->_cId_b
,
179 'relationship_type_id' => $this->_relTypeID
,
180 'start_date' => '2008-12-20', 'end_date' => NULL,
183 $relationship = $this->callAPISuccess('relationship', 'create', $params);
186 'contact_id_a' => $this->_cId_a
,
187 'contact_id_b' => $this->_cId_b
,
188 'relationship_type_id' => $this->_relTypeID
,
189 'start_date' => '2008-12-20',
192 $result = $this->callAPIFailure('relationship', 'create', $params, 'Relationship already exists');
194 $params['id'] = $relationship['id'];
195 $result = $this->callAPISuccess('relationship', 'delete', $params);
199 * check relationship already exists
201 function testRelationshipCreateUpdateAlreadyExists() {
203 'contact_id_a' => $this->_cId_a
,
204 'contact_id_b' => $this->_cId_b
,
205 'relationship_type_id' => $this->_relTypeID
,
206 'start_date' => '2008-12-20',
211 $relationship = $this->callAPISuccess('relationship', 'create', $params);
213 'id' => $relationship['id'],
217 $result = $this->callAPISuccess('relationship', 'create', $params);
218 $result = $this->callAPISuccess('relationship', 'get', $params);
219 $params['id'] = $relationship['id'];
220 $result = $this->callAPISuccess('relationship', 'delete', $params);
224 * checkupdate doesn't reset stuff badly - CRM-11789
226 function testRelationshipCreateUpdateDoesntMangle() {
228 'contact_id_a' => $this->_cId_a
,
229 'contact_id_b' => $this->_cId_b
,
230 'relationship_type_id' => $this->_relTypeID
,
231 'start_date' => '2008-12-20',
233 'is_permission_a_b' => 1,
234 'description' => 'my desc',
236 $relationship = $this->callAPISuccess('relationship', 'create', $params);
238 $updateparams = array(
239 'id' => $relationship['id'],
240 'relationship_type_id' => $this->_relTypeID
,
242 $result = $this->callAPISuccess('relationship', 'create', $updateparams);
244 //make sure the orig params didn't get changed
245 $this->getAndCheck($params, $relationship['id'], 'relationship');
252 * check relationship creation
254 function testRelationshipCreate() {
256 'contact_id_a' => $this->_cId_a
,
257 'contact_id_b' => $this->_cId_b
,
258 'relationship_type_id' => $this->_relTypeID
,
259 'start_date' => '2010-10-30',
260 'end_date' => '2010-12-30',
265 $result = $this->callAPIAndDocument('relationship', 'create', $params, __FUNCTION__
, __FILE__
);
266 $this->assertNotNull($result['id']);
267 $relationParams = array(
268 'id' => $result['id'],
271 // assertDBState compares expected values in $result to actual values in the DB
272 $this->assertDBState('CRM_Contact_DAO_Relationship', $result['id'], $relationParams);
273 $result = $this->callAPISuccess('relationship', 'get', array('id' => $result['id']));
274 $values = $result['values'][$result['id']];
275 foreach ($params as $key => $value) {
276 if ($key == 'note') {
279 $this->assertEquals($value, $values[$key], $key . " doesn't match " . print_r($values, TRUE));
281 $params['id'] = $result['id'];
282 $this->callAPISuccess('relationship', 'delete', $params);
286 * check relationship creation
288 function testRelationshipCreateEmptyEndDate() {
290 'contact_id_a' => $this->_cId_a
,
291 'contact_id_b' => $this->_cId_b
,
292 'relationship_type_id' => $this->_relTypeID
,
293 'start_date' => '2010-10-30',
299 $result = $this->callAPISuccess('relationship', 'create', $params);
300 $this->assertNotNull($result['id']);
301 $relationParams = array(
302 'id' => $result['id'],
305 // assertDBState compares expected values in $result to actual values in the DB
306 $this->assertDBState('CRM_Contact_DAO_Relationship', $result['id'], $relationParams);
307 $result = $this->callAPISuccess('relationship', 'get', array('id' => $result['id']));
308 $values = $result['values'][$result['id']];
309 foreach ($params as $key => $value) {
310 if ($key == 'note') {
313 if($key == 'end_date'){
314 $this->assertTrue(empty($values[$key]));
317 $this->assertEquals($value, $values[$key], $key . " doesn't match " . print_r($values, TRUE) . 'in line' . __LINE__
);
319 $params['id'] = $result['id'];
320 $this->callAPISuccess('relationship', 'delete', $params);
324 * check relationship creation with custom data
326 function testRelationshipCreateWithCustomData() {
327 $customGroup = $this->createCustomGroup();
328 $this->_ids
= $this->createCustomField();
329 //few custom Values for comparing
330 $custom_params = array(
331 "custom_{$this->_ids[0]}" => 'Hello! this is custom data for relationship',
332 "custom_{$this->_ids[1]}" => 'Y',
333 "custom_{$this->_ids[2]}" => '2009-07-11 00:00:00',
334 "custom_{$this->_ids[3]}" => 'http://example.com',
338 'contact_id_a' => $this->_cId_a
,
339 'contact_id_b' => $this->_cId_b
,
340 'relationship_type_id' => $this->_relTypeID
,
341 'start_date' => '2008-12-20',
344 $params = array_merge($params, $custom_params);
345 $result = $this->callAPISuccess('relationship', 'create', $params);
347 $relationParams = array(
348 'id' => $result['id'],
350 // assertDBState compares expected values in $result to actual values in the DB
351 $this->assertDBState('CRM_Contact_DAO_Relationship', $result['id'], $relationParams);
353 $params['id'] = $result['id'];
354 $result = $this->callAPISuccess('relationship', 'delete', $params);
355 $this->relationshipTypeDelete($this->_relTypeID
);
359 * check with complete array + custom field
360 * Note that the test is written on purpose without any
361 * variables specific to participant so it can be replicated into other entities
362 * and / or moved to the automated test suite
364 function testGetWithCustom() {
365 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
367 $params = $this->_params
;
368 $params['custom_' . $ids['custom_field_id']] = "custom string";
370 $result = $this->callAPISuccess($this->_entity
, 'create', $params);
371 $this->assertEquals($result['id'], $result['values'][$result['id']]['id']);
373 $getParams = array('id' => $result['id']);
374 $check = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
);
375 $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
377 $this->customFieldDelete($ids['custom_field_id']);
378 $this->customGroupDelete($ids['custom_group_id']);
381 function createCustomGroup() {
383 'title' => 'Custom Group',
384 'extends' => array('Relationship'),
390 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
391 $this->_customGroupId
= $customGroup['id'];
392 return $customGroup['id'];
395 function createCustomField() {
398 'custom_group_id' => $this->_customGroupId
,
399 'label' => 'Enter text about relationship',
400 'html_type' => 'Text',
401 'data_type' => 'String',
402 'default_value' => 'xyz',
405 'is_searchable' => 0,
410 $result = $this->callAPISuccess('CustomField', 'create', $params);
413 $ids[] = $customField['result']['customFieldId'];
415 $optionValue[] = array(
421 $optionValue[] = array(
427 $optionValue[] = array(
435 'label' => 'Pick Color',
436 'html_type' => 'Select',
437 'data_type' => 'String',
440 'is_searchable' => 0,
442 'option_values' => $optionValue,
443 'custom_group_id' => $this->_customGroupId
,
446 $customField = $this->callAPISuccess('custom_field', 'create', $params);
447 $ids[] = $customField['id'];
450 'custom_group_id' => $this->_customGroupId
,
451 'name' => 'test_date',
452 'label' => 'test_date',
453 'html_type' => 'Select Date',
454 'data_type' => 'Date',
455 'default_value' => '20090711',
458 'is_searchable' => 0,
462 $customField = $this->callAPISuccess('custom_field', 'create', $params);
464 $ids[] = $customField['id'];
466 'custom_group_id' => $this->_customGroupId
,
467 'name' => 'test_link',
468 'label' => 'test_link',
469 'html_type' => 'Link',
470 'data_type' => 'Link',
471 'default_value' => 'http://civicrm.org',
474 'is_searchable' => 0,
478 $customField = $this->callAPISuccess('custom_field', 'create', $params);
479 $ids[] = $customField['id'];
483 ///////////////// civicrm_relationship_delete methods
486 * check with empty array
488 function testRelationshipDeleteEmpty() {
490 $result = $this->callAPIFailure('relationship', 'delete', $params, 'Mandatory key(s) missing from params array: id');
494 * check if required fields are not passed
496 function testRelationshipDeleteWithoutRequired() {
498 'start_date' => '2008-12-20',
499 'end_date' => '2009-12-20',
503 $result = $this->callAPIFailure('relationship', 'delete', $params, 'Mandatory key(s) missing from params array: id');
507 * check with incorrect required fields
509 function testRelationshipDeleteWithIncorrectData() {
511 'contact_id_a' => $this->_cId_a
,
512 'contact_id_b' => $this->_cId_b
,
513 'relationship_type_id' => 'Breaking Relationship',
516 $result = $this->callAPIFailure('relationship', 'delete', $params, 'Mandatory key(s) missing from params array: id');
518 $params['id'] = "Invalid";
519 $result = $this->callAPIFailure('relationship', 'delete', $params, 'Invalid value for relationship ID');
523 * check relationship creation
525 function testRelationshipDelete() {
527 'contact_id_a' => $this->_cId_a
,
528 'contact_id_b' => $this->_cId_b
,
529 'relationship_type_id' => $this->_relTypeID
,
530 'start_date' => '2008-12-20',
534 $result = $this->callAPISuccess('relationship', 'create', $params);
536 //Delete relationship
538 $params['id'] = $result['id'];
540 $result = $this->callAPIAndDocument('relationship', 'delete', $params, __FUNCTION__
, __FILE__
);
541 $this->relationshipTypeDelete($this->_relTypeID
);
544 ///////////////// civicrm_relationship_update methods
547 * check with empty array
549 function testRelationshipUpdateEmpty() {
550 $result = $this->callAPIFailure('relationship', 'create', array(),
551 'Mandatory key(s) missing from params array: contact_id_a, contact_id_b, relationship_type_id');
555 * check if required fields are not passed
559 * check relationship update
561 function testRelationshipCreateDuplicate() {
563 'contact_id_a' => $this->_cId_a
,
564 'contact_id_b' => $this->_cId_b
,
565 'relationship_type_id' => $this->_relTypeID
,
566 'start_date' => '20081214',
567 'end_date' => '20091214',
571 $result = $this->callAPISuccess('relationship', 'create', $relParams);
573 $this->assertNotNull($result['id']);
574 $this->_relationID
= $result['id'];
577 'contact_id_a' => $this->_cId_a
,
578 'contact_id_b' => $this->_cId_b
,
579 'relationship_type_id' => $this->_relTypeID
,
580 'start_date' => '20081214',
581 'end_date' => '20091214',
585 $result = $this->callAPIFailure('relationship', 'create', $params, 'Relationship already exists');
587 //delete created relationship
589 'id' => $this->_relationID
,
592 $result = $this->callAPISuccess('relationship', 'delete', $params);
594 //delete created relationship type
595 $this->relationshipTypeDelete($this->_relTypeID
);
599 * check with valid params array.
601 function testRelationshipsGet() {
603 'contact_id_a' => $this->_cId_a
,
604 'contact_id_b' => $this->_cId_b
,
605 'relationship_type_id' => $this->_relTypeID
,
606 'start_date' => '2011-01-01',
607 'end_date' => '2013-01-01',
611 $result = $this->callAPISuccess('relationship', 'create', $relParams);
615 'contact_id' => $this->_cId_b
,
617 $result = $this->callAPISuccess('relationship', 'get', $params);
618 $this->assertEquals($result['count'], 1);
620 'contact_id_a' => $this->_cId_a
,
622 $result = $this->callAPISuccess('relationship', 'get', $params);
623 $this->assertEquals($result['count'], 1);
624 // contact_id_a is wrong so should be no matches
626 'contact_id_a' => $this->_cId_b
,
628 $result = $this->callAPISuccess('relationship', 'get', $params);
629 $this->assertEquals($result['count'], 0);
633 * check with valid params array.
634 * (The get function will behave differently without 'contact_id' passed
636 function testRelationshipsGetGeneric() {
638 'contact_id_a' => $this->_cId_a
,
639 'contact_id_b' => $this->_cId_b
,
640 'relationship_type_id' => $this->_relTypeID
,
641 'start_date' => '2011-01-01',
642 'end_date' => '2013-01-01',
646 $result = $this->callAPISuccess('relationship', 'create', $relParams);
650 'contact_id_b' => $this->_cId_b
,
652 $result = $this->callAPISuccess('relationship', 'get', $params);
655 function testGetIsCurrent() {
657 'contact_id_a' => $this->_cId_a
,
658 'contact_id_b' => $this->_cId_b2
,
659 'relationship_type_id' => $this->_relTypeID
,
660 'start_date' => '2008-12-20',
663 $rel2 = $this->callAPISuccess('relationship', 'create', $rel2Params);
664 $rel1 = $this->callAPISuccess('relationship', 'create', $this->_params
);
667 'filters' => array('is_current' => 1)
669 $description = "demonstrates is_current filter";
670 $subfile = 'filterIsCurrent';
671 //no relationship has been created
672 $result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__
, __FILE__
, $description, $subfile);
673 $this->assertEquals($result['count'], 1);
674 $this->AssertEquals($rel1['id'], $result['id']);
676 // now try not started
677 $rel2Params['is_active'] =1;
678 $rel2Params['start_date'] ='tomorrow';
679 $rel2 = $this->callAPISuccess('relationship', 'create', $rel2Params);
680 $result = $this->callAPISuccess('relationship', 'get', $getParams);
681 $this->assertEquals($result['count'], 1);
682 $this->AssertEquals($rel1['id'], $result['id']);
685 $rel2Params['is_active'] =1;
686 $rel2Params['start_date'] ='last week';
687 $rel2Params['end_date'] ='yesterday';
688 $rel2 = $this->callAPISuccess('relationship', 'create', $rel2Params);
691 * Test using various operators
693 function testGetTypeOperators() {
694 $relTypeParams = array(
695 'name_a_b' => 'Relation 3 for delete',
696 'name_b_a' => 'Relation 6 for delete',
697 'description' => 'Testing relationship type 2',
698 'contact_type_a' => 'Individual',
699 'contact_type_b' => 'Organization',
703 $relationType2 = $this->relationshipTypeCreate($relTypeParams);
704 $relTypeParams = array(
705 'name_a_b' => 'Relation 8 for delete',
706 'name_b_a' => 'Relation 9 for delete',
707 'description' => 'Testing relationship type 7',
708 'contact_type_a' => 'Individual',
709 'contact_type_b' => 'Organization',
713 $relationType3 = $this->relationshipTypeCreate($relTypeParams);
715 $relTypeParams = array(
716 'name_a_b' => 'Relation 6 for delete',
717 'name_b_a' => 'Relation 88for delete',
718 'description' => 'Testing relationship type 00',
719 'contact_type_a' => 'Individual',
720 'contact_type_b' => 'Organization',
724 $relationType4 = $this->relationshipTypeCreate($relTypeParams);
726 $rel1 = $this->callAPISuccess('relationship', 'create', $this->_params
);
727 $rel2 = $this->callAPISuccess('relationship', 'create', array_merge($this->_params
,
728 array('relationship_type_id' => $relationType2,)));
729 $rel3 = $this->callAPISuccess('relationship', 'create', array_merge($this->_params
,
730 array('relationship_type_id' => $relationType3,)));
731 $rel4 = $this->callAPISuccess('relationship', 'create', array_merge($this->_params
,
732 array('relationship_type_id' => $relationType4,)));
735 'relationship_type_id' => array('IN' => array($relationType2, $relationType3))
738 $description = "demonstrates use of IN filter";
739 $subfile = 'INRelationshipType';
741 $result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__
, __FILE__
, $description, $subfile);
742 $this->assertEquals($result['count'], 2);
743 $this->AssertEquals(array($rel2['id'], $rel3['id']), array_keys($result['values']));
745 $description = "demonstrates use of NOT IN filter";
746 $subfile = 'NotInRelationshipType';
748 'relationship_type_id' => array('NOT IN' => array($relationType2, $relationType3))
750 $result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__
, __FILE__
, $description, $subfile);
751 $this->assertEquals($result['count'], 2);
752 $this->AssertEquals(array($rel1['id'], $rel4['id']), array_keys($result['values']));
754 $description = "demonstrates use of BETWEEN filter";
755 $subfile = 'BetweenRelationshipType';
757 'relationship_type_id' => array('BETWEEN' => array($relationType2, $relationType4))
759 $result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__
, __FILE__
, $description, $subfile);
760 $this->assertEquals($result['count'], 3);
761 $this->AssertEquals(array($rel2['id'], $rel3['id'], $rel4['id']), array_keys($result['values']));
763 $description = "demonstrates use of Not BETWEEN filter";
764 $subfile = 'NotBetweenRelationshipType';
766 'relationship_type_id' => array('NOT BETWEEN' => array($relationType2, $relationType4))
768 $result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__
, __FILE__
, $description, $subfile);
769 $this->assertEquals($result['count'], 1);
770 $this->AssertEquals(array($rel1['id'],), array_keys($result['values']));
774 * check with invalid relationshipType Id
776 function testRelationshipTypeAddInvalidId() {
777 $relTypeParams = array(
779 'name_a_b' => 'Relation 1 for delete',
780 'name_b_a' => 'Relation 2 for delete',
781 'contact_type_a' => 'Individual',
782 'contact_type_b' => 'Organization',
784 $result = $this->callAPIFailure('relationship_type', 'create', $relTypeParams,
785 'id is not a valid integer');
789 * check with valid data with contact_b
791 function testGetRelationshipWithContactB() {
793 'contact_id_a' => $this->_cId_a
,
794 'contact_id_b' => $this->_cId_b
,
795 'relationship_type_id' => $this->_relTypeID
,
796 'start_date' => '2011-01-01',
797 'end_date' => '2013-01-01',
801 $relationship = $this->callAPISuccess('relationship', 'create', $relParams);
804 'contact_id' => $this->_cId_a
,
807 $result = $this->callAPISuccess('relationship', 'get', $contacts);
808 $this->assertGreaterThan(0, $result['count']);
810 'id' => $relationship['id'],
812 $result = $this->callAPISuccess('relationship', 'delete', $params);
813 $this->relationshipTypeDelete($this->_relTypeID
);
817 * check with valid data with relationshipTypes
819 function testGetRelationshipWithRelTypes() {
821 'contact_id_a' => $this->_cId_a
,
822 'contact_id_b' => $this->_cId_b
,
823 'relationship_type_id' => $this->_relTypeID
,
824 'start_date' => '2011-01-01',
825 'end_date' => '2013-01-01',
829 $relationship = $this->callAPISuccess('relationship', 'create', $relParams);
832 'contact_id' => $this->_cId_a
,
834 $result = $this->callAPISuccess('relationship', 'get', $contact_a);
837 'id' => $relationship['id'],
839 $result = $this->callAPISuccess('relationship', 'delete', $params);
840 $this->relationshipTypeDelete($this->_relTypeID
);
844 * Checks that passing in 'contact_id' + a relationship type
845 * will filter by relationship type (relationships go in both directions)
846 * as relationship api does a reciprocal check if contact_id provided
848 * We should get 1 result without or with correct relationship type id & 0 with
851 function testGetRelationshipByTypeReciprocal() {
852 $created = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
853 $result = $this->callAPISuccess($this->_entity
, 'get', array(
854 'contact_id' => $this->_cId_a
,
855 'relationship_type_id' => $this->_relTypeID
,
857 $this->assertEquals(1, $result['count']);
858 $result = $this->callAPISuccess($this->_entity
, 'get', array(
859 'contact_id' => $this->_cId_a
,
860 'relationship_type_id' => $this->_relTypeID +
1,
862 $this->assertEquals(0, $result['count']);
863 $this->callAPISuccess($this->_entity
, 'delete', array('id' => $created['id']));
867 * Checks that passing in 'contact_id_b' + a relationship type
868 * will filter by relationship type for contact b
870 * We should get 1 result without or with correct relationship type id & 0 with
873 function testGetRelationshipByTypeDAO() {
874 $this->ids
['relationship'] = $this->callAPISuccess($this->_entity
, 'create', array('format.only_id' => TRUE,) +
$this->_params
);
875 $result = $this->callAPISuccess($this->_entity
, 'getcount', array(
876 'contact_id_a' => $this->_cId_a
,),
878 $result = $this->callAPISuccess($this->_entity
, 'get', array(
879 'contact_id_a' => $this->_cId_a
,
880 'relationship_type_id' => $this->_relTypeID
,
882 $this->assertEquals(1, $result['count']);
883 $result = $this->callAPISuccess($this->_entity
, 'get', array(
884 'contact_id_a' => $this->_cId_a
,
885 'relationship_type_id' => $this->_relTypeID +
1,
887 $this->assertEquals(0, $result['count']);
891 * Checks that passing in 'contact_id_b' + a relationship type
892 * will filter by relationship type for contact b
894 * We should get 1 result without or with correct relationship type id & 0 with
897 function testGetRelationshipByTypeArrayDAO() {
898 $created = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
899 $org3 = $this->organizationCreate();
900 $relType2 = 5; // lets just assume built in ones aren't being messed with!
901 $relType3 = 6; // lets just assume built in ones aren't being messed with!
904 $this->callAPISuccess($this->_entity
, 'create',
905 array_merge($this->_params
, array(
906 'relationship_type_id' => $relType2,
907 'contact_id_b' => $this->_cId_b2
))
911 $this->callAPISuccess($this->_entity
, 'create',
912 array_merge($this->_params
, array(
913 'relationship_type_id' => $relType3,
914 'contact_id_b' => $org3))
917 $result = $this->callAPISuccess($this->_entity
, 'get', array(
918 'contact_id_a' => $this->_cId_a
,
919 'relationship_type_id' => array('IN' => array($this->_relTypeID
, $relType3)),
922 $this->assertEquals(2, $result['count']);
923 foreach ($result['values'] as $key => $value) {
924 $this->assertTrue(in_array($value['relationship_type_id'], array($this->_relTypeID
, $relType3)));
929 * Checks that passing in 'contact_id_b' + a relationship type
930 * will filter by relationship type for contact b
932 * We should get 1 result without or with correct relationship type id & 0 with
935 function testGetRelationshipByTypeArrayReciprocal() {
936 $created = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
937 $org3 = $this->organizationCreate();
938 $relType2 = 5; // lets just assume built in ones aren't being messed with!
939 $relType3 = 6; // lets just assume built in ones aren't being messed with!
942 $this->callAPISuccess($this->_entity
, 'create',
943 array_merge($this->_params
, array(
944 'relationship_type_id' => $relType2,
945 'contact_id_b' => $this->_cId_b2
))
949 $this->callAPISuccess($this->_entity
, 'create',
950 array_merge($this->_params
, array(
951 'relationship_type_id' => $relType3,
952 'contact_id_b' => $org3))
955 $result = $this->callAPISuccess($this->_entity
, 'get', array(
956 'contact_id' => $this->_cId_a
,
957 'relationship_type_id' => array('IN' => array($this->_relTypeID
, $relType3)),
960 $this->assertEquals(2, $result['count']);
961 foreach ($result['values'] as $key => $value) {
962 $this->assertTrue(in_array($value['relationship_type_id'], array($this->_relTypeID
, $relType3)));