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 = TRUE;
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'), TRUE);
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',
226 $relationship = $this->callAPISuccess('relationship', 'create', $params);
228 'id' => $relationship['id'],
232 $result = $this->callAPISuccess('relationship', 'create', $params);
233 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
234 $result = $this->callAPISuccess('relationship', 'get', $params);
235 $params['id'] = $relationship['id'];
236 $result = $this->callAPISuccess('relationship', 'delete', $params);
240 * checkupdate doesn't reset stuff badly - CRM-11789
242 function testRelationshipCreateUpdateDoesntMangle() {
244 'contact_id_a' => $this->_cId_a
,
245 'contact_id_b' => $this->_cId_b
,
246 'relationship_type_id' => $this->_relTypeID
,
247 'start_date' => '2008-12-20',
249 'is_permission_a_b' => 1,
250 'description' => 'my desc',
251 'version' => $this->_apiversion
,
253 $relationship = $this->callAPISuccess('relationship', 'create', $params);
255 $updateparams = array(
256 'id' => $relationship['id'],
257 'version' => $this->_apiversion
,
258 'relationship_type_id' => $this->_relTypeID
,
260 $result = $this->callAPISuccess('relationship', 'create', $updateparams);
262 //make sure the orig params didn't get changed
263 $this->getAndCheck($params, $relationship['id'], 'relationship');
270 * check relationship creation
272 function testRelationshipCreate() {
274 'contact_id_a' => $this->_cId_a
,
275 'contact_id_b' => $this->_cId_b
,
276 'relationship_type_id' => $this->_relTypeID
,
277 'start_date' => '2010-10-30',
278 'end_date' => '2010-12-30',
283 $result = $this->callAPIAndDocument('relationship', 'create', $params, __FUNCTION__
, __FILE__
);
284 $this->assertNotNull($result['id'], 'in line ' . __LINE__
);
285 $relationParams = array(
286 'id' => $result['id'],
289 // assertDBState compares expected values in $result to actual values in the DB
290 $this->assertDBState('CRM_Contact_DAO_Relationship', $result['id'], $relationParams);
291 $result = $this->callAPISuccess('relationship', 'get', array('version' => 3, 'id' => $result['id']));
292 $values = $result['values'][$result['id']];
293 foreach ($params as $key => $value) {
294 if ($key == 'version' ||
$key == 'note') {
297 $this->assertEquals($value, $values[$key], $key . " doesn't match " . print_r($values, TRUE) . 'in line' . __LINE__
);
299 $params['id'] = $result['id'];
300 $this->callAPISuccess('relationship', 'delete', $params);
304 * check relationship creation
306 function testRelationshipCreateEmptyEndDate() {
308 'contact_id_a' => $this->_cId_a
,
309 'contact_id_b' => $this->_cId_b
,
310 'relationship_type_id' => $this->_relTypeID
,
311 'start_date' => '2010-10-30',
315 'version' => $this->_apiversion
,
318 $result = $this->callAPISuccess('relationship', 'create', $params);
319 $this->assertNotNull($result['id'], 'in line ' . __LINE__
);
320 $relationParams = array(
321 'id' => $result['id'],
324 // assertDBState compares expected values in $result to actual values in the DB
325 $this->assertDBState('CRM_Contact_DAO_Relationship', $result['id'], $relationParams);
326 $result = $this->callAPISuccess('relationship', 'get', array('id' => $result['id']));
327 $values = $result['values'][$result['id']];
328 foreach ($params as $key => $value) {
329 if ($key == 'version' ||
$key == 'note') {
332 if($key == 'end_date'){
333 $this->assertTrue(empty($values[$key]));
336 $this->assertEquals($value, $values[$key], $key . " doesn't match " . print_r($values, TRUE) . 'in line' . __LINE__
);
338 $params['id'] = $result['id'];
339 $this->callAPISuccess('relationship', 'delete', $params);
343 * check relationship creation with custom data
345 function testRelationshipCreateWithCustomData() {
346 $customGroup = $this->createCustomGroup();
347 $this->_ids
= $this->createCustomField();
348 //few custom Values for comparing
349 $custom_params = array(
350 "custom_{$this->_ids[0]}" => 'Hello! this is custom data for relationship',
351 "custom_{$this->_ids[1]}" => 'Y',
352 "custom_{$this->_ids[2]}" => '2009-07-11 00:00:00',
353 "custom_{$this->_ids[3]}" => 'http://example.com',
357 'contact_id_a' => $this->_cId_a
,
358 'contact_id_b' => $this->_cId_b
,
359 'relationship_type_id' => $this->_relTypeID
,
360 'start_date' => '2008-12-20',
362 'version' => $this->_apiversion
,
364 $params = array_merge($params, $custom_params);
365 $result = $this->callAPISuccess('relationship', 'create', $params);
367 $relationParams = array(
368 'id' => $result['id'],
370 // assertDBState compares expected values in $result to actual values in the DB
371 $this->assertDBState('CRM_Contact_DAO_Relationship', $result['id'], $relationParams);
373 $params['id'] = $result['id'];
374 $result = $this->callAPISuccess('relationship', 'delete', $params);
375 $this->relationshipTypeDelete($this->_relTypeID
);
379 * check with complete array + custom field
380 * Note that the test is written on purpose without any
381 * variables specific to participant so it can be replicated into other entities
382 * and / or moved to the automated test suite
384 function testGetWithCustom() {
385 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, __FILE__
);
387 $params = $this->_params
;
388 $params['custom_' . $ids['custom_field_id']] = "custom string";
390 $result = $this->callAPISuccess($this->_entity
, 'create', $params);
391 $this->assertEquals($result['id'], $result['values'][$result['id']]['id']);
393 $getParams = array('version' => 3, 'id' => $result['id']);
394 $check = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
);
395 $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__
);
397 $this->customFieldDelete($ids['custom_field_id']);
398 $this->customGroupDelete($ids['custom_group_id']);
401 function createCustomGroup() {
403 'title' => 'Custom Group',
404 'extends' => array('Relationship'),
409 'version' => $this->_apiversion
,
411 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
412 $this->_customGroupId
= $customGroup['id'];
413 return $customGroup['id'];
416 function createCustomField() {
419 'custom_group_id' => $this->_customGroupId
,
420 'label' => 'Enter text about relationship',
421 'html_type' => 'Text',
422 'data_type' => 'String',
423 'default_value' => 'xyz',
426 'is_searchable' => 0,
428 'version' => $this->_apiversion
,
432 $result = $this->callAPISuccess('CustomField', 'create', $params);
435 $ids[] = $customField['result']['customFieldId'];
437 $optionValue[] = array(
443 $optionValue[] = array(
449 $optionValue[] = array(
457 'label' => 'Pick Color',
458 'html_type' => 'Select',
459 'data_type' => 'String',
462 'is_searchable' => 0,
464 'option_values' => $optionValue,
465 'custom_group_id' => $this->_customGroupId
,
466 'version' => $this->_apiversion
,
469 $customField = $this->callAPISuccess('custom_field', 'create', $params);
470 $ids[] = $customField['id'];
473 'custom_group_id' => $this->_customGroupId
,
474 'name' => 'test_date',
475 'label' => 'test_date',
476 'html_type' => 'Select Date',
477 'data_type' => 'Date',
478 'default_value' => '20090711',
481 'is_searchable' => 0,
483 'version' => $this->_apiversion
,
486 $customField = $this->callAPISuccess('custom_field', 'create', $params);
488 $ids[] = $customField['id'];
490 'custom_group_id' => $this->_customGroupId
,
491 'name' => 'test_link',
492 'label' => 'test_link',
493 'html_type' => 'Link',
494 'data_type' => 'Link',
495 'default_value' => 'http://civicrm.org',
498 'is_searchable' => 0,
500 'version' => $this->_apiversion
,
503 $customField = $this->callAPISuccess('custom_field', 'create', $params);
504 $ids[] = $customField['id'];
508 ///////////////// civicrm_relationship_delete methods
511 * check with empty array
513 function testRelationshipDeleteEmpty() {
514 $params = array('version' => $this->_apiversion
);
515 $result = $this->callAPIFailure('relationship', 'delete', $params);
516 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
520 * check if required fields are not passed
522 function testRelationshipDeleteWithoutRequired() {
524 'start_date' => '2008-12-20',
525 'end_date' => '2009-12-20',
529 $result = $this->callAPIFailure('relationship', 'delete', $params);
530 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
534 * check with incorrect required fields
536 function testRelationshipDeleteWithIncorrectData() {
538 'contact_id_a' => $this->_cId_a
,
539 'contact_id_b' => $this->_cId_b
,
540 'relationship_type_id' => 'Breaking Relationship',
541 'version' => $this->_apiversion
,
544 $result = $this->callAPIFailure('relationship', 'delete', $params);
545 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id', 'in line ' . __LINE__
);
547 $params['id'] = "Invalid";
548 $result = $this->callAPIFailure('relationship', 'delete', $params);
549 $this->assertEquals($result['error_message'], 'Invalid value for relationship ID', 'in line ' . __LINE__
);
553 * check relationship creation
555 function testRelationshipDelete() {
557 'contact_id_a' => $this->_cId_a
,
558 'contact_id_b' => $this->_cId_b
,
559 'relationship_type_id' => $this->_relTypeID
,
560 'start_date' => '2008-12-20',
562 'version' => $this->_apiversion
,
565 $result = $this->callAPISuccess('relationship', 'create', $params);
567 //Delete relationship
569 $params['id'] = $result['id'];
571 $result = $this->callAPIAndDocument('relationship', 'delete', $params, __FUNCTION__
, __FILE__
);
572 $this->relationshipTypeDelete($this->_relTypeID
);
575 ///////////////// civicrm_relationship_update methods
578 * check with empty array
580 function testRelationshipUpdateEmpty() {
581 $result = $this->callAPIFailure('relationship', 'create', array());
582 $this->assertEquals('Mandatory key(s) missing from params array: contact_id_a, contact_id_b, relationship_type_id', $result['error_message'], 'In line ' . __LINE__
);
586 * check if required fields are not passed
590 * check relationship update
592 function testRelationshipCreateDuplicate() {
594 'contact_id_a' => $this->_cId_a
,
595 'contact_id_b' => $this->_cId_b
,
596 'relationship_type_id' => $this->_relTypeID
,
597 'start_date' => '20081214',
598 'end_date' => '20091214',
602 $result = $this->callAPISuccess('relationship', 'create', $relParams);
604 $this->assertNotNull($result['id'], 'In line ' . __LINE__
);
605 $this->_relationID
= $result['id'];
608 'contact_id_a' => $this->_cId_a
,
609 'contact_id_b' => $this->_cId_b
,
610 'relationship_type_id' => $this->_relTypeID
,
611 'start_date' => '20081214',
612 'end_date' => '20091214', 'is_active' => 0,
613 'version' => $this->_apiversion
,
616 $result = $this->callAPIFailure('relationship', 'create', $params);
617 $this->assertEquals($result['error_message'], 'Relationship already exists', 'In line ' . __LINE__
);
619 //delete created relationship
621 'id' => $this->_relationID
,
622 'version' => $this->_apiversion
,
625 $result = civicrm_api('relationship', 'delete', $params);
626 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
628 //delete created relationship type
629 $this->relationshipTypeDelete($this->_relTypeID
);
633 * check with valid params array.
635 function testRelationshipsGet() {
637 'contact_id_a' => $this->_cId_a
,
638 'contact_id_b' => $this->_cId_b
,
639 'relationship_type_id' => $this->_relTypeID
,
640 'start_date' => '2011-01-01',
641 'end_date' => '2013-01-01',
643 'version' => $this->_apiversion
,
646 $result = civicrm_api('relationship', 'create', $relParams);
650 'contact_id' => $this->_cId_b
,
652 $result = $this->callAPISuccess('relationship', 'get', $params);
653 $this->assertEquals($result['count'], 1, 'in line ' . __LINE__
);
655 'contact_id_a' => $this->_cId_a
,
657 $result = $this->callAPISuccess('relationship', 'get', $params);
658 $this->assertEquals($result['count'], 1, 'in line ' . __LINE__
);
659 // contact_id_a is wrong so should be no matches
661 'contact_id_a' => $this->_cId_b
,
662 'version' => $this->_apiversion
,
664 $result = $this->callAPISuccess('relationship', 'get', $params);
665 $this->assertEquals($result['count'], 0, 'in line ' . __LINE__
);
669 * check with valid params array.
670 * (The get function will behave differently without 'contact_id' passed
672 function testRelationshipsGetGeneric() {
674 'contact_id_a' => $this->_cId_a
,
675 'contact_id_b' => $this->_cId_b
,
676 'relationship_type_id' => $this->_relTypeID
,
677 'start_date' => '2011-01-01',
678 'end_date' => '2013-01-01',
680 'version' => $this->_apiversion
,
683 $result = $this->callAPISuccess('relationship', 'create', $relParams);
687 'contact_id_b' => $this->_cId_b
,
689 $result = $this->callAPISuccess('relationship', 'get', $params);
692 function testGetIsCurrent() {
694 'contact_id_a' => $this->_cId_a
,
695 'contact_id_b' => $this->_cId_b2
,
696 'relationship_type_id' => $this->_relTypeID
,
697 'start_date' => '2008-12-20',
700 $rel2 = $this->callAPISuccess('relationship', 'create', $rel2Params);
701 $rel1 = $this->callAPISuccess('relationship', 'create', $this->_params
);
704 'filters' => array('is_current' => 1)
706 $description = "demonstrates is_current filter";
707 $subfile = 'filterIsCurrent';
708 //no relationship has been created
709 $result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__
, __FILE__
, $description, $subfile);
710 $this->assertEquals($result['count'], 1);
711 $this->AssertEquals($rel1['id'], $result['id']);
713 // now try not started
714 $rel2Params['is_active'] =1;
715 $rel2Params['start_date'] ='tomorrow';
716 $rel2 = $this->callAPISuccess('relationship', 'create', $rel2Params);
717 $result = $this->callAPISuccess('relationship', 'get', $getParams);
718 $this->assertEquals($result['count'], 1);
719 $this->AssertEquals($rel1['id'], $result['id']);
722 $rel2Params['is_active'] =1;
723 $rel2Params['start_date'] ='last week';
724 $rel2Params['end_date'] ='yesterday';
725 $rel2 = $this->callAPISuccess('relationship', 'create', $rel2Params);
728 * Test using various operators
730 function testGetTypeOperators() {
731 $relTypeParams = array(
732 'name_a_b' => 'Relation 3 for delete',
733 'name_b_a' => 'Relation 6 for delete',
734 'description' => 'Testing relationship type 2',
735 'contact_type_a' => 'Individual',
736 'contact_type_b' => 'Organization',
739 'version' => $this->_apiversion
,
741 $relationType2 = $this->relationshipTypeCreate($relTypeParams);
742 $relTypeParams = array(
743 'name_a_b' => 'Relation 8 for delete',
744 'name_b_a' => 'Relation 9 for delete',
745 'description' => 'Testing relationship type 7',
746 'contact_type_a' => 'Individual',
747 'contact_type_b' => 'Organization',
750 'version' => $this->_apiversion
,
752 $relationType3 = $this->relationshipTypeCreate($relTypeParams);
754 $relTypeParams = array(
755 'name_a_b' => 'Relation 6 for delete',
756 'name_b_a' => 'Relation 88for delete',
757 'description' => 'Testing relationship type 00',
758 'contact_type_a' => 'Individual',
759 'contact_type_b' => 'Organization',
762 'version' => $this->_apiversion
,
764 $relationType4 = $this->relationshipTypeCreate($relTypeParams);
766 $rel1 = $this->callAPISuccess('relationship', 'create', $this->_params
);
767 $rel2 = $this->callAPISuccess('relationship', 'create', array_merge($this->_params
,
768 array('relationship_type_id' => $relationType2,)));
769 $rel3 = $this->callAPISuccess('relationship', 'create', array_merge($this->_params
,
770 array('relationship_type_id' => $relationType3,)));
771 $rel4 = $this->callAPISuccess('relationship', 'create', array_merge($this->_params
,
772 array('relationship_type_id' => $relationType4,)));
775 'relationship_type_id' => array('IN' => array($relationType2, $relationType3))
778 $description = "demonstrates use of IN filter";
779 $subfile = 'INRelationshipType';
781 $result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__
, __FILE__
, $description, $subfile);
782 $this->assertEquals($result['count'], 2);
783 $this->AssertEquals(array($rel2['id'], $rel3['id']), array_keys($result['values']));
785 $description = "demonstrates use of NOT IN filter";
786 $subfile = 'NotInRelationshipType';
788 'relationship_type_id' => array('NOT IN' => array($relationType2, $relationType3))
790 $result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__
, __FILE__
, $description, $subfile);
791 $this->assertEquals($result['count'], 2);
792 $this->AssertEquals(array($rel1['id'], $rel4['id']), array_keys($result['values']));
794 $description = "demonstrates use of BETWEEN filter";
795 $subfile = 'BetweenRelationshipType';
797 'relationship_type_id' => array('BETWEEN' => array($relationType2, $relationType4))
799 $result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__
, __FILE__
, $description, $subfile);
800 $this->assertEquals($result['count'], 3);
801 $this->AssertEquals(array($rel2['id'], $rel3['id'], $rel4['id']), array_keys($result['values']));
803 $description = "demonstrates use of Not BETWEEN filter";
804 $subfile = 'NotBetweenRelationshipType';
806 'version' => $this->_apiversion
,
807 'relationship_type_id' => array('NOT BETWEEN' => array($relationType2, $relationType4))
809 $result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__
, __FILE__
, $description, $subfile);
810 $this->assertEquals($result['count'], 1);
811 $this->AssertEquals(array($rel1['id'],), array_keys($result['values']));
815 * check with invalid relationshipType Id
817 function testRelationshipTypeAddInvalidId() {
818 $relTypeParams = array(
820 'name_a_b' => 'Relation 1 for delete',
821 'name_b_a' => 'Relation 2 for delete',
822 'contact_type_a' => 'Individual',
823 'contact_type_b' => 'Organization',
825 $result = $this->callAPIFailure('relationship_type', 'create', $relTypeParams);
826 $this->assertEquals('id is not a valid integer', $result['error_message'], 'in line ' . __LINE__
);
830 * check with valid data with contact_b
832 function testGetRelationshipWithContactB() {
834 'contact_id_a' => $this->_cId_a
,
835 'contact_id_b' => $this->_cId_b
,
836 'relationship_type_id' => $this->_relTypeID
,
837 'start_date' => '2011-01-01',
838 'end_date' => '2013-01-01',
842 $relationship = $this->callAPISuccess('relationship', 'create', $relParams);
845 'contact_id' => $this->_cId_a
,
848 $result = $this->callAPISuccess('relationship', 'get', $contacts);
849 $this->assertGreaterThan(0, $result['count'], 'in line ' . __LINE__
);
851 'id' => $relationship['id'],
853 $result = $this->callAPISuccess('relationship', 'delete', $params);
854 $this->relationshipTypeDelete($this->_relTypeID
);
858 * check with valid data with relationshipTypes
860 function testGetRelationshipWithRelTypes() {
862 'contact_id_a' => $this->_cId_a
,
863 'contact_id_b' => $this->_cId_b
,
864 'relationship_type_id' => $this->_relTypeID
,
865 'start_date' => '2011-01-01',
866 'end_date' => '2013-01-01',
870 $relationship = $this->callAPISuccess('relationship', 'create', $relParams);
873 'contact_id' => $this->_cId_a
,
875 $result = $this->callAPISuccess('relationship', 'get', $contact_a);
878 'id' => $relationship['id'],
880 $result = $this->callAPISuccess('relationship', 'delete', $params);
881 $this->relationshipTypeDelete($this->_relTypeID
);