<?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';
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';
'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 creation
*/
$params['id'] = $result['id'];
$this->callAPISuccess('relationship', 'delete', $params);
}
+
/**
* Ensure disabling works
*/
$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
*/
if ($key == 'note') {
continue;
}
- if($key == 'end_date'){
+ if ($key == 'end_date') {
$this->assertTrue(empty($values[$key]));
continue;
}
'is_active' => 1,
);
-
$result = $this->callAPISuccess('CustomField', 'create', $params);
$customField = NULL;
}
public function testGetIsCurrent() {
- $rel2Params =array(
+ $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
*/
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
*/
* an incorrect one
*/
public function testGetRelationshipByTypeDAO() {
- $this->ids['relationship'] = $this->callAPISuccess($this->_entity, 'create', array('format.only_id' => TRUE,) + $this->_params);
+ $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,
$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(
$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(
$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(
* an incorrect one
*/
public function testGetRelationshipByMembershipTypeReciprocal() {
- $created = $this->callAPISuccess($this->_entity, 'create', $this->_params);
+ $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(
$this->callAPISuccess($this->_entity, 'create', array('id' => $relationship['id'], 'is_active' => 0));
$this->callAPISuccess($this->_entity, 'create', array('id' => $relationship['id'], 'is_active' => 1));
}
+
}