<?php
/**
- +--------------------------------------------------------------------+
- | CiviCRM version 4.6 |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM. |
- | |
- | CiviCRM is free software; you can copy, modify, and distribute it |
- | under the terms of the GNU Affero General Public License |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
- | |
- | CiviCRM is distributed in the hope that it will be useful, but |
- | WITHOUT ANY WARRANTY; without even the implied warranty of |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
- | See the GNU Affero General Public License for more details. |
- | |
- | You should have received a copy of the GNU Affero General Public |
- | License and the CiviCRM Licensing Exception along |
- | with this program; if not, contact CiviCRM LLC |
- | at info[AT]civicrm[DOT]org. If you have questions about the |
- | GNU Affero General Public License or the licensing of CiviCRM, |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing |
- +--------------------------------------------------------------------+
-*/
+ * +--------------------------------------------------------------------+
+ * | CiviCRM version 4.6 |
+ * +--------------------------------------------------------------------+
+ * | Copyright CiviCRM LLC (c) 2004-2014 |
+ * +--------------------------------------------------------------------+
+ * | This file is a part of CiviCRM. |
+ * | |
+ * | CiviCRM is free software; you can copy, modify, and distribute it |
+ * | under the terms of the GNU Affero General Public License |
+ * | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
+ * | |
+ * | CiviCRM is distributed in the hope that it will be useful, but |
+ * | WITHOUT ANY WARRANTY; without even the implied warranty of |
+ * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
+ * | See the GNU Affero General Public License for more details. |
+ * | |
+ * | You should have received a copy of the GNU Affero General Public |
+ * | License and the CiviCRM Licensing Exception along |
+ * | with this program; if not, contact CiviCRM LLC |
+ * | at info[AT]civicrm[DOT]org. If you have questions about the |
+ * | GNU Affero General Public License or the licensing of CiviCRM, |
+ * | see the CiviCRM license FAQ at http://civicrm.org/licensing |
+ * +--------------------------------------------------------------------+
+ */
require_once 'CiviTest/CiviUnitTestCase.php';
protected $_entity;
- /**
- * @return array
- */
- function get_info() {
- return array(
- 'name' => 'Relationship Create',
- 'description' => 'Test all Relationship Create API methods.',
- 'group' => 'CiviCRM API Tests',
- );
- }
-
- function setUp() {
+ public function setUp() {
parent::setUp();
$this->_cId_a = $this->individualCreate();
- $this->_cId_a_2 = $this->individualCreate(array('last_name' => 'c2', 'email' => 'c@w.com', 'contact_type' => 'Individual'));
+ $this->_cId_a_2 = $this->individualCreate(array(
+ 'last_name' => 'c2',
+ 'email' => 'c@w.com',
+ 'contact_type' => 'Individual',
+ ));
$this->_cId_b = $this->organizationCreate();
$this->_cId_b2 = $this->organizationCreate(array('organization_name' => ' Org 2'));
$this->_entity = 'relationship';
}
- function tearDown() {
+ public function tearDown() {
$this->contactDelete($this->_cId_a);
$this->contactDelete($this->_cId_a_2);
$this->contactDelete($this->_cId_b);
/**
* Check with empty array
*/
- function testRelationshipCreateEmpty() {
+ public function testRelationshipCreateEmpty() {
$this->callAPIFailure('relationship', 'create', array());
}
/**
* Check if required fields are not passed
*/
- function testRelationshipCreateWithoutRequired() {
+ public function testRelationshipCreateWithoutRequired() {
$params = array(
'start_date' => array('d' => '10', 'M' => '1', 'Y' => '2008'),
'end_date' => array('d' => '10', 'M' => '1', 'Y' => '2009'),
/**
* Check with incorrect required fields
*/
- function testRelationshipCreateWithIncorrectData() {
+ public function testRelationshipCreateWithIncorrectData() {
$params = array(
'contact_id_a' => $this->_cId_a,
/**
* Check relationship creation with invalid Relationship
*/
- function testRelationshipCreatInvalidRelationship() {
+ public function testRelationshipCreatInvalidRelationship() {
// both the contact of type Individual
$params = array(
'contact_id_a' => $this->_cId_a,
/**
* Check relationship already exists
*/
- function testRelationshipCreateAlreadyExists() {
+ public function testRelationshipCreateAlreadyExists() {
$params = array(
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
'relationship_type_id' => $this->_relTypeID,
- 'start_date' => '2008-12-20', 'end_date' => NULL,
+ 'start_date' => '2008-12-20',
+ 'end_date' => NULL,
'is_active' => 1,
);
$relationship = $this->callAPISuccess('relationship', 'create', $params);
/**
* Check relationship already exists
*/
- function testRelationshipCreateUpdateAlreadyExists() {
+ public function testRelationshipCreateUpdateAlreadyExists() {
$params = array(
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
/**
* Checkupdate doesn't reset stuff badly - CRM-11789
*/
- function testRelationshipCreateUpdateDoesntMangle() {
+ public function testRelationshipCreateUpdateDoesntMangle() {
$params = array(
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
}
-
/**
* Check relationship creation
*/
- function testRelationshipCreate() {
+ public function testRelationshipCreate() {
$params = array(
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
$params['id'] = $result['id'];
$this->callAPISuccess('relationship', 'delete', $params);
}
+
/**
* Ensure disabling works
*/
- function testRelationshipUpdate() {
+ public function testRelationshipUpdate() {
$result = $this->callAPISuccess('relationship', 'create', $this->_params);
$relID = $result['id'];
$result = $this->callAPISuccess('relationship', 'create', array('id' => $relID, 'description' => 'blah'));
$this->assertEquals($relID, $result['id']);
+
$this->assertEquals('blah', $result['values'][$result['id']]['description']);
+
$result = $this->callAPISuccess('relationship', 'create', array('id' => $relID, 'is_permission_b_a' => 1));
$this->assertEquals(1, $result['values'][$result['id']]['is_permission_b_a']);
$result = $this->callAPISuccess('relationship', 'create', array('id' => $result['id'], 'is_active' => 0));
+ $result = $this->callAPISuccess('relationship', 'get', array('id' => $result['id']));
$this->assertEquals(0, $result['values'][$result['id']]['is_active']);
$this->assertEquals('blah', $result['values'][$result['id']]['description']);
$this->assertEquals(1, $result['values'][$result['id']]['is_permission_b_a']);
}
+
/**
* Check relationship creation
*/
- function testRelationshipCreateEmptyEndDate() {
+ public function testRelationshipCreateEmptyEndDate() {
$params = array(
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
if ($key == 'note') {
continue;
}
- if($key == 'end_date'){
+ if ($key == 'end_date') {
$this->assertTrue(empty($values[$key]));
continue;
}
/**
* Check relationship creation with custom data
*/
- function testRelationshipCreateWithCustomData() {
+ public function testRelationshipCreateWithCustomData() {
$customGroup = $this->createCustomGroup();
$this->_ids = $this->createCustomField();
//few custom Values for comparing
* variables specific to participant so it can be replicated into other entities
* and / or moved to the automated test suite
*/
- function testGetWithCustom() {
+ public function testGetWithCustom() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
$params = $this->_params;
/**
* @return mixed
*/
- function createCustomGroup() {
+ public function createCustomGroup() {
$params = array(
'title' => 'Custom Group',
'extends' => array('Relationship'),
/**
* @return array
*/
- function createCustomField() {
+ public function createCustomField() {
$ids = array();
$params = array(
'custom_group_id' => $this->_customGroupId,
'is_active' => 1,
);
-
$result = $this->callAPISuccess('CustomField', 'create', $params);
$customField = NULL;
/**
* Check with empty array
*/
- function testRelationshipDeleteEmpty() {
+ public function testRelationshipDeleteEmpty() {
$params = array();
$result = $this->callAPIFailure('relationship', 'delete', $params, 'Mandatory key(s) missing from params array: id');
}
/**
* Check if required fields are not passed
*/
- function testRelationshipDeleteWithoutRequired() {
+ public function testRelationshipDeleteWithoutRequired() {
$params = array(
'start_date' => '2008-12-20',
'end_date' => '2009-12-20',
/**
* Check with incorrect required fields
*/
- function testRelationshipDeleteWithIncorrectData() {
+ public function testRelationshipDeleteWithIncorrectData() {
$params = array(
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
/**
* Check relationship creation
*/
- function testRelationshipDelete() {
+ public function testRelationshipDelete() {
$params = array(
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
/**
* Check with empty array
*/
- function testRelationshipUpdateEmpty() {
+ public function testRelationshipUpdateEmpty() {
$result = $this->callAPIFailure('relationship', 'create', array(),
'Mandatory key(s) missing from params array: contact_id_a, contact_id_b, relationship_type_id');
}
/**
* Check relationship update
*/
- function testRelationshipCreateDuplicate() {
+ public function testRelationshipCreateDuplicate() {
$relParams = array(
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
/**
* Check with valid params array.
*/
- function testRelationshipsGet() {
+ public function testRelationshipsGet() {
$relParams = array(
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
* Check with valid params array.
* (The get function will behave differently without 'contact_id' passed
*/
- function testRelationshipsGetGeneric() {
+ public function testRelationshipsGetGeneric() {
$relParams = array(
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
$result = $this->callAPISuccess('relationship', 'get', $params);
}
- function testGetIsCurrent() {
- $rel2Params =array(
+ public function testGetIsCurrent() {
+ $rel2Params = array(
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b2,
'relationship_type_id' => $this->_relTypeID,
$rel1 = $this->callAPISuccess('relationship', 'create', $this->_params);
$getParams = array(
- 'filters' => array('is_current' => 1)
+ 'filters' => array('is_current' => 1),
);
$description = "demonstrates is_current filter";
$subfile = 'filterIsCurrent';
$this->AssertEquals($rel1['id'], $result['id']);
// now try not started
- $rel2Params['is_active'] =1;
- $rel2Params['start_date'] ='tomorrow';
+ $rel2Params['is_active'] = 1;
+ $rel2Params['start_date'] = 'tomorrow';
$rel2 = $this->callAPISuccess('relationship', 'create', $rel2Params);
$result = $this->callAPISuccess('relationship', 'get', $getParams);
$this->assertEquals($result['count'], 1);
$this->AssertEquals($rel1['id'], $result['id']);
// now try finished
- $rel2Params['is_active'] =1;
- $rel2Params['start_date'] ='last week';
- $rel2Params['end_date'] ='yesterday';
+ $rel2Params['is_active'] = 1;
+ $rel2Params['start_date'] = 'last week';
+ $rel2Params['end_date'] = 'yesterday';
$rel2 = $this->callAPISuccess('relationship', 'create', $rel2Params);
}
+
/*
* Test using various operators
*/
- function testGetTypeOperators() {
+ public function testGetTypeOperators() {
$relTypeParams = array(
- 'name_a_b' => 'Relation 3 for delete',
- 'name_b_a' => 'Relation 6 for delete',
- 'description' => 'Testing relationship type 2',
- 'contact_type_a' => 'Individual',
- 'contact_type_b' => 'Organization',
- 'is_reserved' => 1,
- 'is_active' => 1,
+ 'name_a_b' => 'Relation 3 for delete',
+ 'name_b_a' => 'Relation 6 for delete',
+ 'description' => 'Testing relationship type 2',
+ 'contact_type_a' => 'Individual',
+ 'contact_type_b' => 'Organization',
+ 'is_reserved' => 1,
+ 'is_active' => 1,
);
$relationType2 = $this->relationshipTypeCreate($relTypeParams);
$relTypeParams = array(
- 'name_a_b' => 'Relation 8 for delete',
- 'name_b_a' => 'Relation 9 for delete',
- 'description' => 'Testing relationship type 7',
- 'contact_type_a' => 'Individual',
- 'contact_type_b' => 'Organization',
- 'is_reserved' => 1,
- 'is_active' => 1,
+ 'name_a_b' => 'Relation 8 for delete',
+ 'name_b_a' => 'Relation 9 for delete',
+ 'description' => 'Testing relationship type 7',
+ 'contact_type_a' => 'Individual',
+ 'contact_type_b' => 'Organization',
+ 'is_reserved' => 1,
+ 'is_active' => 1,
);
$relationType3 = $this->relationshipTypeCreate($relTypeParams);
$relTypeParams = array(
- 'name_a_b' => 'Relation 6 for delete',
- 'name_b_a' => 'Relation 88for delete',
- 'description' => 'Testing relationship type 00',
- 'contact_type_a' => 'Individual',
- 'contact_type_b' => 'Organization',
- 'is_reserved' => 1,
- 'is_active' => 1,
+ 'name_a_b' => 'Relation 6 for delete',
+ 'name_b_a' => 'Relation 88for delete',
+ 'description' => 'Testing relationship type 00',
+ 'contact_type_a' => 'Individual',
+ 'contact_type_b' => 'Organization',
+ 'is_reserved' => 1,
+ 'is_active' => 1,
);
$relationType4 = $this->relationshipTypeCreate($relTypeParams);
$rel1 = $this->callAPISuccess('relationship', 'create', $this->_params);
$rel2 = $this->callAPISuccess('relationship', 'create', array_merge($this->_params,
- array('relationship_type_id' => $relationType2,)));
+ array('relationship_type_id' => $relationType2)));
$rel3 = $this->callAPISuccess('relationship', 'create', array_merge($this->_params,
- array('relationship_type_id' => $relationType3,)));
+ array('relationship_type_id' => $relationType3)));
$rel4 = $this->callAPISuccess('relationship', 'create', array_merge($this->_params,
- array('relationship_type_id' => $relationType4,)));
+ array('relationship_type_id' => $relationType4)));
$getParams = array(
- 'relationship_type_id' => array('IN' => array($relationType2, $relationType3))
+ 'relationship_type_id' => array('IN' => array($relationType2, $relationType3)),
);
$description = "demonstrates use of IN filter";
$description = "demonstrates use of NOT IN filter";
$subfile = 'NotInRelationshipType';
$getParams = array(
- 'relationship_type_id' => array('NOT IN' => array($relationType2, $relationType3))
+ 'relationship_type_id' => array('NOT IN' => array($relationType2, $relationType3)),
);
$result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals($result['count'], 2);
$description = "demonstrates use of BETWEEN filter";
$subfile = 'BetweenRelationshipType';
$getParams = array(
- 'relationship_type_id' => array('BETWEEN' => array($relationType2, $relationType4))
+ 'relationship_type_id' => array('BETWEEN' => array($relationType2, $relationType4)),
);
$result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals($result['count'], 3);
$description = "demonstrates use of Not BETWEEN filter";
$subfile = 'NotBetweenRelationshipType';
$getParams = array(
- 'relationship_type_id' => array('NOT BETWEEN' => array($relationType2, $relationType4))
+ 'relationship_type_id' => array('NOT BETWEEN' => array($relationType2, $relationType4)),
);
$result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals($result['count'], 1);
- $this->AssertEquals(array($rel1['id'],), array_keys($result['values']));
+ $this->AssertEquals(array($rel1['id']), array_keys($result['values']));
}
+
/**
* Check with invalid relationshipType Id
*/
- function testRelationshipTypeAddInvalidId() {
+ public function testRelationshipTypeAddInvalidId() {
$relTypeParams = array(
'id' => 'invalid',
'name_a_b' => 'Relation 1 for delete',
/**
* Check with valid data with contact_b
*/
- function testGetRelationshipWithContactB() {
+ public function testGetRelationshipWithContactB() {
$relParams = array(
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
/**
* Check with valid data with relationshipTypes
*/
- function testGetRelationshipWithRelTypes() {
+ public function testGetRelationshipWithRelTypes() {
$relParams = array(
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
* We should get 1 result without or with correct relationship type id & 0 with
* an incorrect one
*/
- function testGetRelationshipByTypeReciprocal() {
+ public function testGetRelationshipByTypeReciprocal() {
$created = $this->callAPISuccess($this->_entity, 'create', $this->_params);
$result = $this->callAPISuccess($this->_entity, 'get', array(
'contact_id' => $this->_cId_a,
* We should get 1 result without or with correct relationship type id & 0 with
* an incorrect one
*/
- function testGetRelationshipByTypeDAO() {
- $this->ids['relationship'] = $this->callAPISuccess($this->_entity, 'create', array('format.only_id' => TRUE,) + $this->_params);
+ public function testGetRelationshipByTypeDAO() {
+ $this->ids['relationship'] = $this->callAPISuccess($this->_entity, 'create', array('format.only_id' => TRUE) + $this->_params);
$result = $this->callAPISuccess($this->_entity, 'getcount', array(
- 'contact_id_a' => $this->_cId_a,),
- 1);
+ 'contact_id_a' => $this->_cId_a,
+ ),
+ 1);
$result = $this->callAPISuccess($this->_entity, 'get', array(
'contact_id_a' => $this->_cId_a,
'relationship_type_id' => $this->_relTypeID,
* We should get 1 result without or with correct relationship type id & 0 with
* an incorrect one
*/
- function testGetRelationshipByTypeArrayDAO() {
+ public function testGetRelationshipByTypeArrayDAO() {
$created = $this->callAPISuccess($this->_entity, 'create', $this->_params);
$org3 = $this->organizationCreate();
$relType2 = 5; // lets just assume built in ones aren't being messed with!
$this->callAPISuccess($this->_entity, 'create',
array_merge($this->_params, array(
'relationship_type_id' => $relType2,
- 'contact_id_b' => $this->_cId_b2))
+ 'contact_id_b' => $this->_cId_b2,
+ ))
);
//relationshp 3
$this->callAPISuccess($this->_entity, 'create',
array_merge($this->_params, array(
'relationship_type_id' => $relType3,
- 'contact_id_b' => $org3))
+ 'contact_id_b' => $org3,
+ ))
);
$result = $this->callAPISuccess($this->_entity, 'get', array(
* We should get 1 result without or with correct relationship type id & 0 with
* an incorrect one
*/
- function testGetRelationshipByTypeArrayReciprocal() {
+ public function testGetRelationshipByTypeArrayReciprocal() {
$created = $this->callAPISuccess($this->_entity, 'create', $this->_params);
$org3 = $this->organizationCreate();
$relType2 = 5; // lets just assume built in ones aren't being messed with!
$this->callAPISuccess($this->_entity, 'create',
array_merge($this->_params, array(
'relationship_type_id' => $relType2,
- 'contact_id_b' => $this->_cId_b2))
+ 'contact_id_b' => $this->_cId_b2,
+ ))
);
//relationshp 3
$this->callAPISuccess($this->_entity, 'create',
array_merge($this->_params, array(
'relationship_type_id' => $relType3,
- 'contact_id_b' => $org3))
+ 'contact_id_b' => $org3,
+ ))
);
$result = $this->callAPISuccess($this->_entity, 'get', array(
* We should get 1 result without or with correct relationship type id & 0 with
* an incorrect one
*/
- function testGetRelationshipByMembershipTypeDAO() {
+ public function testGetRelationshipByMembershipTypeDAO() {
$created = $this->callAPISuccess($this->_entity, 'create', $this->_params);
$org3 = $this->organizationCreate();
$this->callAPISuccess($this->_entity, 'create',
array_merge($this->_params, array(
'relationship_type_id' => $relType2,
- 'contact_id_b' => $this->_cId_b2))
+ 'contact_id_b' => $this->_cId_b2,
+ ))
);
//relationshp 3
$this->callAPISuccess($this->_entity, 'create',
array_merge($this->_params, array(
'relationship_type_id' => $relType3,
- 'contact_id_b' => $org3))
+ 'contact_id_b' => $org3,
+ ))
);
//relationshp 4 with reveral
array_merge($this->_params, array(
'relationship_type_id' => $relType1,
'contact_id_a' => $this->_cId_a,
- 'contact_id_b' => $this->_cId_a_2))
+ 'contact_id_b' => $this->_cId_a_2,
+ ))
);
$result = $this->callAPISuccess($this->_entity, 'get', array(
* We should get 1 result without or with correct relationship type id & 0 with
* an incorrect one
*/
- function testGetRelationshipByMembershipTypeReciprocal() {
- $created = $this->callAPISuccess($this->_entity, 'create', $this->_params);
+ public function testGetRelationshipByMembershipTypeReciprocal() {
+ $created = $this->callAPISuccess($this->_entity, 'create', $this->_params);
$org3 = $this->organizationCreate();
$relType2 = 5; // lets just assume built in ones aren't being messed with!
$this->callAPISuccess($this->_entity, 'create',
array_merge($this->_params, array(
'relationship_type_id' => $relType2,
- 'contact_id_b' => $this->_cId_b2))
+ 'contact_id_b' => $this->_cId_b2,
+ ))
);
//relationshp 3
$this->callAPISuccess($this->_entity, 'create',
array_merge($this->_params, array(
'relationship_type_id' => $relType3,
- 'contact_id_b' => $org3))
+ 'contact_id_b' => $org3,
+ ))
);
//relationshp 4 with reveral
array_merge($this->_params, array(
'relationship_type_id' => $relType1,
'contact_id_a' => $this->_cId_a,
- 'contact_id_b' => $this->_cId_a_2))
+ 'contact_id_b' => $this->_cId_a_2,
+ ))
);
$result = $this->callAPISuccess($this->_entity, 'get', array(
/**
* Check for enotices on enable & disable as reported in CRM-14350
*/
- function testSetActive() {
+ public function testSetActive() {
$relationship = $this->callAPISuccess($this->_entity, 'create', $this->_params);
$this->callAPISuccess($this->_entity, 'create', array('id' => $relationship['id'], 'is_active' => 0));
$this->callAPISuccess($this->_entity, 'create', array('id' => $relationship['id'], 'is_active' => 1));