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;
38 protected $_cId_b2;// second org
39 protected $_relTypeID;
40 protected $_ids = array();
41 protected $_customGroupId = NULL;
42 protected $_customFieldId = NULL;
44 public $_eNoticeCompliant = FALSE;
48 'name' => 'Relationship Create',
49 'description' => 'Test all Relationship Create API methods.',
50 'group' => 'CiviCRM API Tests',
56 $this->_apiversion
= 3;
57 $this->_cId_a
= $this->individualCreate(NULL);
58 $this->_cId_b
= $this->organizationCreate();
59 $this->_cId_b2
= $this->organizationCreate(array('organization_name' => ' Org 2'));
60 $this->_entity
= 'relationship';
61 //Create a relationship type
62 $relTypeParams = array(
63 'name_a_b' => 'Relation 1 for delete',
64 'name_b_a' => 'Relation 2 for delete',
65 'description' => 'Testing relationship type',
66 'contact_type_a' => 'Individual',
67 'contact_type_b' => 'Organization',
70 'version' => $this->_apiversion
,
72 $this->_relTypeID
= $this->relationshipTypeCreate($relTypeParams);
73 $this->_params
= array(
74 'contact_id_a' => $this->_cId_a
,
75 'contact_id_b' => $this->_cId_b
,
76 'relationship_type_id' => $this->_relTypeID
,
77 'start_date' => '2008-12-20',
79 'version' => $this->_apiversion
,
85 $this->quickCleanup(array('civicrm_relationship'));
86 $this->relationshipTypeDelete($this->_relTypeID
);
87 $this->contactDelete($this->_cId_a
);
88 $this->contactDelete($this->_cId_b
);
91 ///////////////// civicrm_relationship_create methods
94 * check with empty array
96 function testRelationshipCreateEmpty() {
97 $params = array('version' => $this->_apiversion
);
98 $this->callAPIFailure('relationship', 'create', $params);
102 * check with No array
104 function testRelationshipCreateParamsNotArray() {
105 $params = 'relationship_type_id = 5';
106 $this->callAPIFailure('relationship', 'create', $params);
110 * check if required fields are not passed
112 function testRelationshipCreateWithoutRequired() {
114 'start_date' => array('d' => '10', 'M' => '1', 'Y' => '2008'),
115 'end_date' => array('d' => '10', 'M' => '1', 'Y' => '2009'),
119 $this->callAPIFailure('relationship', 'create', $params);
123 * check with incorrect required fields
125 function testRelationshipCreateWithIncorrectData() {
128 'contact_id_a' => $this->_cId_a
,
129 'contact_id_b' => $this->_cId_b
,
130 'relationship_type_id' => 'Breaking Relationship',
134 $this->callAPIFailure('relationship', 'create', $params);
136 //contact id is not an integer
138 'contact_id_a' => 'invalid',
139 'contact_id_b' => $this->_cId_b
,
140 'relationship_type_id' => $this->_relTypeID
,
141 'start_date' => array('d' => '10', 'M' => '1', 'Y' => '2008'),
144 $this->callAPIFailure('relationship', 'create', $params);
146 //contact id does not exists
147 $params['contact_id_a'] = 999;
148 $this->callAPIFailure('relationship', 'create', $params);
151 $params['contact_id_a'] = $this->_cId_a
;
152 $params['start_date'] = array('d' => '1', 'M' => '1');
153 $this->callAPIFailure('relationship', 'create', $params);
157 * check relationship creation with invalid Relationship
159 function testRelationshipCreatInvalidRelationship() {
160 // both the contact of type Individual
162 'contact_id_a' => $this->_cId_a
,
163 'contact_id_b' => $this->_cId_a
,
164 'relationship_type_id' => $this->_relTypeID
,
165 'start_date' => '2008-01-10',
170 $this->callAPIFailure('relationship', 'create', $params);
172 // both the contact of type Organization
174 'contact_id_a' => $this->_cId_b
,
175 'contact_id_b' => $this->_cId_b
,
176 'relationship_type_id' => $this->_relTypeID
,
177 'start_date' => '2008-01-10',
182 $this->callAPIFailure('relationship', 'create', $params);
186 * check relationship already exists
188 function testRelationshipCreateAlreadyExists() {
190 'contact_id_a' => $this->_cId_a
,
191 'contact_id_b' => $this->_cId_b
,
192 'relationship_type_id' => $this->_relTypeID
,
193 'start_date' => '2008-12-20', 'end_date' => NULL,
195 'version' => $this->_apiversion
,
197 $relationship = civicrm_api('relationship', 'create', $params);
200 'contact_id_a' => $this->_cId_a
,
201 'contact_id_b' => $this->_cId_b
,
202 'relationship_type_id' => $this->_relTypeID
,
203 'start_date' => '2008-12-20',
206 $result = $this->callAPIFailure('relationship', 'create', $params);
207 $this->assertEquals($result['error_message'], 'Relationship already exists');
209 $params['id'] = $relationship['id'];
210 $result = civicrm_api('relationship', 'delete', $params);
214 * check relationship already exists
216 function testRelationshipCreateUpdateAlreadyExists() {
218 'contact_id_a' => $this->_cId_a
,
219 'contact_id_b' => $this->_cId_b
,
220 'relationship_type_id' => $this->_relTypeID
,
221 'start_date' => '2008-12-20',
224 'version' => $this->_apiversion
,
226 $relationship = civicrm_api('relationship', 'create', $params);
229 'id' => $relationship['id'],
231 'version' => $this->_apiversion
,
234 $result = civicrm_api('relationship', 'create', $params);
235 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
236 $result = civicrm_api('relationship', 'get', $params);
237 $this->assertEquals(0, $result['values'][$result['id']]['is_active'], 'in line ' . __LINE__
);
238 $params['id'] = $relationship['id'];
239 $result = civicrm_api('relationship', 'delete', $params);
243 * checkupdate doesn't reset stuff badly - CRM-11789
245 function testRelationshipCreateUpdateDoesntMangle() {
247 'contact_id_a' => $this->_cId_a
,
248 'contact_id_b' => $this->_cId_b
,
249 'relationship_type_id' => $this->_relTypeID
,
250 'start_date' => '2008-12-20',
253 'is_permission_a_b' => 1,
254 'description' => 'my desc',
255 'version' => $this->_apiversion
,
257 $relationship = civicrm_api('relationship', 'create', $params);
259 $updateparams = array(
260 'id' => $relationship['id'],
261 'version' => $this->_apiversion
,
262 'relationship_type_id' => $this->_relTypeID
,
264 $result = civicrm_api('relationship', 'create', $updateparams);
266 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
267 //make sure the orig params didn't get changed
268 $this->getAndCheck($params, $relationship['id'], 'relationship');
275 * check relationship creation
277 function testRelationshipCreate() {
279 'contact_id_a' => $this->_cId_a
,
280 'contact_id_b' => $this->_cId_b
,
281 'relationship_type_id' => $this->_relTypeID
,
282 'start_date' => '2010-10-30',
283 'end_date' => '2010-12-30',
286 'version' => $this->_apiversion
,
289 $result = civicrm_api('relationship', 'create', $params);
290 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
291 $this->assertEquals(0, $result['is_error'], 'in line ' . __LINE__
);
292 $this->assertNotNull($result['id'], 'in line ' . __LINE__
);
293 $relationParams = array(
294 'id' => $result['id'],
297 // assertDBState compares expected values in $result to actual values in the DB
298 $this->assertDBState('CRM_Contact_DAO_Relationship', $result['id'], $relationParams);
299 $result = civicrm_api('relationship', 'get', array('version' => 3, 'id' => $result['id']));
300 $values = $result['values'][$result['id']];
301 foreach ($params as $key => $value) {
302 if ($key == 'version' ||
$key == 'note') {
305 $this->assertEquals($value, $values[$key], $key . " doesn't match " . print_r($values, TRUE) . 'in line' . __LINE__
);
307 $params['id'] = $result['id'];
308 civicrm_api('relationship', 'delete', $params);
312 * check relationship creation
314 function testRelationshipCreateEmptyEndDate() {
316 'contact_id_a' => $this->_cId_a
,
317 'contact_id_b' => $this->_cId_b
,
318 'relationship_type_id' => $this->_relTypeID
,
319 'start_date' => '2010-10-30',
323 'version' => $this->_apiversion
,
326 $result = civicrm_api('relationship', 'create', $params);
328 $this->assertEquals(0, $result['is_error'], 'in line ' . __LINE__
);
329 $this->assertNotNull($result['id'], 'in line ' . __LINE__
);
330 $relationParams = array(
331 'id' => $result['id'],
334 // assertDBState compares expected values in $result to actual values in the DB
335 $this->assertDBState('CRM_Contact_DAO_Relationship', $result['id'], $relationParams);
336 $result = civicrm_api('relationship', 'get', array('version' => 3, 'id' => $result['id']));
337 $values = $result['values'][$result['id']];
338 foreach ($params as $key => $value) {
339 if ($key == 'version' ||
$key == 'note') {
342 if($key == 'end_date'){
343 $this->assertTrue(empty($values[$key]));
346 $this->assertEquals($value, $values[$key], $key . " doesn't match " . print_r($values, TRUE) . 'in line' . __LINE__
);
348 $params['id'] = $result['id'];
349 civicrm_api('relationship', 'delete', $params);
353 * check relationship creation with custom data
355 function testRelationshipCreateWithCustomData() {
356 $customGroup = $this->createCustomGroup();
357 $this->_ids
= $this->createCustomField();
358 //few custom Values for comparing
359 $custom_params = array(
360 "custom_{$this->_ids[0]}" => 'Hello! this is custom data for relationship',
361 "custom_{$this->_ids[1]}" => 'Y',
362 "custom_{$this->_ids[2]}" => '2009-07-11 00:00:00',
363 "custom_{$this->_ids[3]}" => 'http://example.com',
367 'contact_id_a' => $this->_cId_a
,
368 'contact_id_b' => $this->_cId_b
,
369 'relationship_type_id' => $this->_relTypeID
,
370 'start_date' => '2008-12-20',
372 'version' => $this->_apiversion
,
374 $params = array_merge($params, $custom_params);
375 $result = civicrm_api('relationship', 'create', $params);
377 $this->assertNotNull($result['id']);
378 $relationParams = array(
379 'id' => $result['id'],
381 // assertDBState compares expected values in $result to actual values in the DB
382 $this->assertDBState('CRM_Contact_DAO_Relationship', $result['id'], $relationParams);
384 $params['id'] = $result['id'];
385 $result = civicrm_api('relationship', 'delete', $params);
386 $this->relationshipTypeDelete($this->_relTypeID
);
390 * check with complete array + custom field
391 * Note that the test is written on purpose without any
392 * variables specific to participant so it can be replicated into other entities
393 * and / or moved to the automated test suite
395 function testGetWithCustom() {
396 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
398 $params = $this->_params
;
399 $params['custom_' . $ids['custom_field_id']] = "custom string";
401 $result = civicrm_api($this->_entity
, 'create', $params);
402 $this->assertEquals($result['id'], $result['values'][$result['id']]['id']);
404 $this->assertAPISuccess($result, ' in line ' . __LINE__
);
405 $getParams = array('version' => 3, 'id' => $result['id']);
406 $check = civicrm_api($this->_entity
, 'get', $getParams);
407 $this->documentMe($getParams, $check, __FUNCTION__
, __FILE__
);
408 $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
410 $this->customFieldDelete($ids['custom_field_id']);
411 $this->customGroupDelete($ids['custom_group_id']);
414 function createCustomGroup() {
416 'title' => 'Custom Group',
417 'extends' => array('Relationship'),
422 'version' => $this->_apiversion
,
424 $customGroup = civicrm_api('custom_group', 'create', $params);
425 $this->_customGroupId
= $customGroup['id'];
426 return $customGroup['id'];
429 function createCustomField() {
432 'custom_group_id' => $this->_customGroupId
,
433 'label' => 'Enter text about relationship',
434 'html_type' => 'Text',
435 'data_type' => 'String',
436 'default_value' => 'xyz',
439 'is_searchable' => 0,
441 'version' => $this->_apiversion
,
445 $result = civicrm_api('CustomField', 'create', $params);
448 $ids[] = $customField['result']['customFieldId'];
450 $optionValue[] = array(
456 $optionValue[] = array(
462 $optionValue[] = array(
470 'label' => 'Pick Color',
471 'html_type' => 'Select',
472 'data_type' => 'String',
475 'is_searchable' => 0,
477 'option_values' => $optionValue,
478 'custom_group_id' => $this->_customGroupId
,
479 'version' => $this->_apiversion
,
482 $customField = civicrm_api('custom_field', 'create', $params);
483 $ids[] = $customField['id'];
486 'custom_group_id' => $this->_customGroupId
,
487 'name' => 'test_date',
488 'label' => 'test_date',
489 'html_type' => 'Select Date',
490 'data_type' => 'Date',
491 'default_value' => '20090711',
494 'is_searchable' => 0,
496 'version' => $this->_apiversion
,
499 $customField = civicrm_api('custom_field', 'create', $params);
501 $ids[] = $customField['id'];
503 'custom_group_id' => $this->_customGroupId
,
504 'name' => 'test_link',
505 'label' => 'test_link',
506 'html_type' => 'Link',
507 'data_type' => 'Link',
508 'default_value' => 'http://civicrm.org',
511 'is_searchable' => 0,
513 'version' => $this->_apiversion
,
516 $customField = civicrm_api('custom_field', 'create', $params);
517 $ids[] = $customField['id'];
521 ///////////////// civicrm_relationship_delete methods
524 * check with empty array
526 function testRelationshipDeleteEmpty() {
527 $params = array('version' => $this->_apiversion
);
528 $result = $this->callAPIFailure('relationship', 'delete', $params);
529 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
533 * check if required fields are not passed
535 function testRelationshipDeleteWithoutRequired() {
537 'start_date' => '2008-12-20',
538 'end_date' => '2009-12-20',
542 $result = $this->callAPIFailure('relationship', 'delete', $params);
543 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
547 * check with incorrect required fields
549 function testRelationshipDeleteWithIncorrectData() {
551 'contact_id_a' => $this->_cId_a
,
552 'contact_id_b' => $this->_cId_b
,
553 'relationship_type_id' => 'Breaking Relationship',
554 'version' => $this->_apiversion
,
557 $result = $this->callAPIFailure('relationship', 'delete', $params);
558 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id', 'in line ' . __LINE__
);
560 $params['id'] = "Invalid";
561 $result = $this->callAPIFailure('relationship', 'delete', $params);
562 $this->assertEquals($result['error_message'], 'Invalid value for relationship ID', 'in line ' . __LINE__
);
566 * check relationship creation
568 function testRelationshipDelete() {
570 'contact_id_a' => $this->_cId_a
,
571 'contact_id_b' => $this->_cId_b
,
572 'relationship_type_id' => $this->_relTypeID
,
573 'start_date' => '2008-12-20',
575 'version' => $this->_apiversion
,
578 $result = civicrm_api('relationship', 'create', $params);
579 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
580 $this->assertNotNull($result['id']);
582 //Delete relationship
584 $params['id'] = $result['id'];
586 $result = civicrm_api('relationship', 'delete', $params);
587 $this->relationshipTypeDelete($this->_relTypeID
);
590 ///////////////// civicrm_relationship_update methods
593 * check with empty array
595 function testRelationshipUpdateEmpty() {
596 $result = $this->callAPIFailure('relationship', 'create', array());
597 $this->assertEquals('Mandatory key(s) missing from params array: contact_id_a, contact_id_b, relationship_type_id', $result['error_message'], 'In line ' . __LINE__
);
601 * check if required fields are not passed
605 * check relationship update
607 function testRelationshipCreateDuplicate() {
609 'contact_id_a' => $this->_cId_a
,
610 'contact_id_b' => $this->_cId_b
,
611 'relationship_type_id' => $this->_relTypeID
,
612 'start_date' => '20081214',
613 'end_date' => '20091214',
615 'version' => $this->_apiversion
,
618 $result = civicrm_api('relationship', 'create', $relParams);
620 $this->assertNotNull($result['id'], 'In line ' . __LINE__
);
621 $this->_relationID
= $result['id'];
624 'contact_id_a' => $this->_cId_a
,
625 'contact_id_b' => $this->_cId_b
,
626 'relationship_type_id' => $this->_relTypeID
,
627 'start_date' => '20081214',
628 'end_date' => '20091214', 'is_active' => 0,
629 'version' => $this->_apiversion
,
632 $result = $this->callAPIFailure('relationship', 'create', $params);
633 $this->assertEquals($result['error_message'], 'Relationship already exists', 'In line ' . __LINE__
);
635 //delete created relationship
637 'id' => $this->_relationID
,
638 'version' => $this->_apiversion
,
641 $result = civicrm_api('relationship', 'delete', $params);
642 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
644 //delete created relationship type
645 $this->relationshipTypeDelete($this->_relTypeID
);
649 * check with valid params array.
651 function testRelationshipsGet() {
653 'contact_id_a' => $this->_cId_a
,
654 'contact_id_b' => $this->_cId_b
,
655 'relationship_type_id' => $this->_relTypeID
,
656 'start_date' => '2011-01-01',
657 'end_date' => '2013-01-01',
659 'version' => $this->_apiversion
,
662 $result = civicrm_api('relationship', 'create', $relParams);
666 'contact_id' => $this->_cId_b
,
667 'version' => $this->_apiversion
,
669 $result = civicrm_api('relationship', 'get', $params);
671 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
672 $this->assertEquals($result['count'], 1, 'in line ' . __LINE__
);
674 'contact_id_a' => $this->_cId_a
,
675 'version' => $this->_apiversion
,
677 $result = civicrm_api('relationship', 'get', $params);
678 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
679 $this->assertEquals($result['count'], 1, 'in line ' . __LINE__
);
680 // contact_id_a is wrong so should be no matches
682 'contact_id_a' => $this->_cId_b
,
683 'version' => $this->_apiversion
,
685 $result = civicrm_api('relationship', 'get', $params);
686 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
687 $this->assertEquals($result['count'], 0, 'in line ' . __LINE__
);
691 * check with valid params array.
692 * (The get function will behave differently without 'contact_id' passed
694 function testRelationshipsGetGeneric() {
696 'contact_id_a' => $this->_cId_a
,
697 'contact_id_b' => $this->_cId_b
,
698 'relationship_type_id' => $this->_relTypeID
,
699 'start_date' => '2011-01-01',
700 'end_date' => '2013-01-01',
702 'version' => $this->_apiversion
,
705 $result = civicrm_api('relationship', 'create', $relParams);
709 'contact_id_b' => $this->_cId_b
,
710 'version' => $this->_apiversion
,
712 $result = civicrm_api('relationship', 'get', $params);
713 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
716 function testGetIsCurrent() {
718 'contact_id_a' => $this->_cId_a
,
719 'contact_id_b' => $this->_cId_b2
,
720 'relationship_type_id' => $this->_relTypeID
,
721 'start_date' => '2008-12-20',
723 'version' => $this->_apiversion
,
725 $rel2 = civicrm_api('relationship', 'create', $rel2Params);
726 $this->assertAPISuccess($rel2);
727 $rel1 = civicrm_api('relationship', 'create', $this->_params
);
728 $this->assertAPISuccess($rel1);
730 'version' => $this->_apiversion
,
731 'filters' => array('is_current' => 1)
733 $description = "demonstrates is_current filter";
734 $subfile = 'filterIsCurrent';
735 //no relationship has been created
736 $result = civicrm_api('relationship', 'get', $getParams);
737 $this->documentMe($getParams, $result, __FUNCTION__
, __FILE__
, $description, $subfile);
738 $this->assertEquals($result['count'], 1);
739 $this->AssertEquals($rel1['id'], $result['id']);
741 // now try not started
742 $rel2Params['is_active'] =1;
743 $rel2Params['start_date'] ='tomorrow';
744 $rel2 = civicrm_api('relationship', 'create', $rel2Params);
745 $result = civicrm_api('relationship', 'get', $getParams);
746 $this->assertEquals($result['count'], 1);
747 $this->AssertEquals($rel1['id'], $result['id']);
750 $rel2Params['is_active'] =1;
751 $rel2Params['start_date'] ='last week';
752 $rel2Params['end_date'] ='yesterday';
753 $rel2 = civicrm_api('relationship', 'create', $rel2Params);
756 * Test using various operators
758 function testGetTypeOperators() {
759 $relTypeParams = array(
760 'name_a_b' => 'Relation 3 for delete',
761 'name_b_a' => 'Relation 6 for delete',
762 'description' => 'Testing relationship type 2',
763 'contact_type_a' => 'Individual',
764 'contact_type_b' => 'Organization',
767 'version' => $this->_apiversion
,
769 $relationType2 = $this->relationshipTypeCreate($relTypeParams);
770 $relTypeParams = array(
771 'name_a_b' => 'Relation 8 for delete',
772 'name_b_a' => 'Relation 9 for delete',
773 'description' => 'Testing relationship type 7',
774 'contact_type_a' => 'Individual',
775 'contact_type_b' => 'Organization',
778 'version' => $this->_apiversion
,
780 $relationType3 = $this->relationshipTypeCreate($relTypeParams);
782 $relTypeParams = array(
783 'name_a_b' => 'Relation 6 for delete',
784 'name_b_a' => 'Relation 88for delete',
785 'description' => 'Testing relationship type 00',
786 'contact_type_a' => 'Individual',
787 'contact_type_b' => 'Organization',
790 'version' => $this->_apiversion
,
792 $relationType4 = $this->relationshipTypeCreate($relTypeParams);
794 $rel1 = civicrm_api('relationship', 'create', $this->_params
);
795 $this->assertAPISuccess($rel1);
796 $rel2 = civicrm_api('relationship', 'create', array_merge($this->_params
,
797 array('relationship_type_id' => $relationType2,)));
798 $this->assertAPISuccess($rel2);
799 $rel3 = civicrm_api('relationship', 'create', array_merge($this->_params
,
800 array('relationship_type_id' => $relationType3,)));
801 $this->assertAPISuccess($rel3);
802 $rel4 = civicrm_api('relationship', 'create', array_merge($this->_params
,
803 array('relationship_type_id' => $relationType4,)));
804 $this->assertAPISuccess($rel4);
807 'version' => $this->_apiversion
,
808 'relationship_type_id' => array('IN' => array($relationType2, $relationType3))
812 $description = "demonstrates use of IN filter";
813 $subfile = 'INRelationshipType';
815 $result = civicrm_api('relationship', 'get', $getParams);
816 $this->documentMe($getParams, $result, __FUNCTION__
, __FILE__
, $description, $subfile);
817 $this->assertEquals($result['count'], 2);
818 $this->AssertEquals(array($rel2['id'], $rel3['id']), array_keys($result['values']));
820 $description = "demonstrates use of NOT IN filter";
821 $subfile = 'NotInRelationshipType';
823 'version' => $this->_apiversion
,
824 'relationship_type_id' => array('NOT IN' => array($relationType2, $relationType3))
826 $result = civicrm_api('relationship', 'get', $getParams);
827 $this->documentMe($getParams, $result, __FUNCTION__
, __FILE__
, $description, $subfile);
828 $this->assertEquals($result['count'], 2);
829 $this->AssertEquals(array($rel1['id'], $rel4['id']), array_keys($result['values']));
831 $description = "demonstrates use of BETWEEN filter";
832 $subfile = 'BetweenRelationshipType';
834 'version' => $this->_apiversion
,
835 'relationship_type_id' => array('BETWEEN' => array($relationType2, $relationType4))
837 $result = civicrm_api('relationship', 'get', $getParams);
838 $this->documentMe($getParams, $result, __FUNCTION__
, __FILE__
, $description, $subfile);
839 $this->assertEquals($result['count'], 3);
840 $this->AssertEquals(array($rel2['id'], $rel3['id'], $rel4['id']), array_keys($result['values']));
842 $description = "demonstrates use of Not BETWEEN filter";
843 $subfile = 'NotBetweenRelationshipType';
845 'version' => $this->_apiversion
,
846 'relationship_type_id' => array('NOT BETWEEN' => array($relationType2, $relationType4))
848 $result = civicrm_api('relationship', 'get', $getParams);
849 $this->documentMe($getParams, $result, __FUNCTION__
, __FILE__
, $description, $subfile);
850 $this->assertEquals($result['count'], 1);
851 $this->AssertEquals(array($rel1['id'],), array_keys($result['values']));
855 * check with invalid relationshipType Id
857 function testRelationshipTypeAddInvalidId() {
858 $relTypeParams = array(
860 'name_a_b' => 'Relation 1 for delete',
861 'name_b_a' => 'Relation 2 for delete',
862 'contact_type_a' => 'Individual',
863 'contact_type_b' => 'Organization',
865 $result = $this->callAPIFailure('relationship_type', 'create', $relTypeParams);
866 $this->assertEquals('id is not a valid integer', $result['error_message'], 'in line ' . __LINE__
);
869 ///////////////// civicrm_get_relationships
872 * check with invalid data
874 function testGetRelationshipInvalidData() {
875 $contact_a = array('contact_id' => $this->_cId_a
);
876 $contact_b = array('contact_id' => $this->_cId_b
);
878 //no relationship has been created
879 $result = civicrm_api('relationship', 'get', $contact_a, $contact_b, NULL, 'asc');
880 $this->assertAPIFailure($result);
884 * check with valid data with contact_b
886 function testGetRelationshipWithContactB() {
888 'contact_id_a' => $this->_cId_a
,
889 'contact_id_b' => $this->_cId_b
,
890 'relationship_type_id' => $this->_relTypeID
,
891 'start_date' => '2011-01-01',
892 'end_date' => '2013-01-01',
894 'version' => $this->_apiversion
,
897 $relationship = civicrm_api('relationship', 'create', $relParams);
900 'contact_id' => $this->_cId_a
,
901 'version' => $this->_apiversion
,
904 $result = civicrm_api('relationship', 'get', $contacts);
905 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
906 $this->assertGreaterThan(0, $result['count'], 'in line ' . __LINE__
);
908 'id' => $relationship['id'],
909 'version' => $this->_apiversion
,
911 $result = civicrm_api('relationship', 'delete', $params);
912 $this->relationshipTypeDelete($this->_relTypeID
);
916 * check with valid data with relationshipTypes
918 function testGetRelationshipWithRelTypes() {
920 'contact_id_a' => $this->_cId_a
,
921 'contact_id_b' => $this->_cId_b
,
922 'relationship_type_id' => $this->_relTypeID
,
923 'start_date' => '2011-01-01',
924 'end_date' => '2013-01-01',
926 'version' => $this->_apiversion
,
929 $relationship = civicrm_api('relationship', 'create', $relParams);
932 'contact_id' => $this->_cId_a
,
933 'version' => $this->_apiversion
,
936 $result = civicrm_api('relationship', 'get', $contact_a);
938 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
941 'id' => $relationship['id'],
942 'version' => $this->_apiversion
,
944 $result = civicrm_api('relationship', 'delete', $params);
945 $this->relationshipTypeDelete($this->_relTypeID
);