4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.5 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
30 +--------------------------------------------------------------------+
31 | CiviCRM version 4.5 |
32 +--------------------------------------------------------------------+
33 | Copyright CiviCRM LLC (c) 2004-2014 |
34 +--------------------------------------------------------------------+
35 | This file is a part of CiviCRM. |
37 | CiviCRM is free software; you can copy, modify, and distribute it |
38 | under the terms of the GNU Affero General Public License |
39 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
41 | CiviCRM is distributed in the hope that it will be useful, but |
42 | WITHOUT ANY WARRANTY; without even the implied warranty of |
43 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
44 | See the GNU Affero General Public License for more details. |
46 | You should have received a copy of the GNU Affero General Public |
47 | License and the CiviCRM Licensing Exception along |
48 | with this program; if not, contact CiviCRM LLC |
49 | at info[AT]civicrm[DOT]org. If you have questions about the |
50 | GNU Affero General Public License or the licensing of CiviCRM, |
51 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
52 +--------------------------------------------------------------------+
55 require_once 'CiviTest/CiviUnitTestCase.php';
58 * Class contains api test cases for "civicrm_relationship_type"
61 class api_v3_RelationshipTypeTest
extends CiviUnitTestCase
{
64 protected $_relTypeID;
65 protected $_apiversion = 3;
72 'name' => 'RelationshipType Create',
73 'description' => 'Test all RelationshipType Create API methods.',
74 'group' => 'CiviCRM API Tests',
81 $this->_cId_a
= $this->individualCreate();
82 $this->_cId_b
= $this->organizationCreate();
87 $tablesToTruncate = array(
89 'civicrm_relationship_type',
91 $this->quickCleanup($tablesToTruncate);
94 ///////////////// civicrm_relationship_type_add methods
99 function testRelationshipTypeCreateWithoutName() {
100 $relTypeParams = array(
101 'contact_type_a' => 'Individual',
102 'contact_type_b' => 'Organization',
104 $result = $this->callAPIFailure('relationship_type', 'create', $relTypeParams,
105 'Mandatory key(s) missing from params array: name_a_b, name_b_a'
110 * check with no contact type
112 function testRelationshipTypeCreateWithoutContactType() {
113 $relTypeParams = array(
114 'name_a_b' => 'Relation 1 without contact type',
115 'name_b_a' => 'Relation 2 without contact type',
117 $result = $this->callAPIFailure('relationship_type', 'create', $relTypeParams,
118 'Mandatory key(s) missing from params array: contact_type_a, contact_type_b'
123 * create relationship type
125 function testRelationshipTypeCreate() {
127 'name_a_b' => 'Relation 1 for relationship type create',
128 'name_b_a' => 'Relation 2 for relationship type create',
129 'contact_type_a' => 'Individual',
130 'contact_type_b' => 'Organization',
135 $result = $this->callAPIAndDocument('relationship_type', 'create', $params, __FUNCTION__
, __FILE__
);
136 $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__
);
137 unset($params['sequential']);
138 //assertDBState compares expected values in $result to actual values in the DB
139 $this->assertDBState('CRM_Contact_DAO_RelationshipType', $result['id'], $params);
143 * Test using example code
145 function testRelationshipTypeCreateExample() {
146 require_once 'api/v3/examples/RelationshipType/Create.php';
147 $result = relationship_type_create_example();
148 $expectedResult = relationship_type_create_expectedresult();
149 $this->assertAPISuccess($result);
153 * check if required fields are not passed
155 function testRelationshipTypeDeleteWithoutRequired() {
157 'name_b_a' => 'Relation 2 delete without required',
158 'contact_type_b' => 'Individual',
163 $result = $this->callAPIFailure('relationship_type', 'delete', $params);
164 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
168 * check with incorrect required fields
170 function testRelationshipTypeDeleteWithIncorrectData() {
173 'name_b_a' => 'Relation 2 delete with incorrect',
174 'description' => 'Testing relationship type',
175 'contact_type_a' => 'Individual',
176 'contact_type_b' => 'Individual',
180 $result = $this->callAPIFailure('relationship_type', 'delete', $params,
181 'Invalid value for relationship type ID'
186 * check relationship type delete
188 function testRelationshipTypeDelete() {
189 $id = $this->_relationshipTypeCreate();
190 // create sample relationship type.
194 $result = $this->callAPIAndDocument('relationship_type', 'delete', $params, __FUNCTION__
, __FILE__
);
195 $this->assertAPIDeleted('relationship_type', $id);
198 ///////////////// civicrm_relationship_type_update
201 * check with empty array
203 function testRelationshipTypeUpdateEmpty() {
205 $result = $this->callAPIFailure('relationship_type', 'create', $params);
206 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name_a_b, name_b_a, contact_type_a, contact_type_b');
210 * check with no contact type
212 function testRelationshipTypeUpdateWithoutContactType() {
213 // create sample relationship type.
214 $this->_relTypeID
= $this->_relationshipTypeCreate();
216 $relTypeParams = array(
217 'id' => $this->_relTypeID
,
218 'name_a_b' => 'Test 1',
219 'name_b_a' => 'Test 2',
220 'description' => 'Testing relationship type',
225 $result = $this->callAPISuccess('relationship_type', 'create', $relTypeParams);
226 $this->assertNotNull($result['id']);
227 // assertDBState compares expected values in $result to actual values in the DB
228 $this->assertDBState('CRM_Contact_DAO_RelationshipType', $result['id'], $relTypeParams);
232 * check with all parameters
234 function testRelationshipTypeUpdate() {
235 // create sample relationship type.
236 $this->_relTypeID
= $this->_relationshipTypeCreate();
239 'id' => $this->_relTypeID
,
240 'name_a_b' => 'Test 1 for update',
241 'name_b_a' => 'Test 2 for update',
242 'description' => 'SUNIL PAWAR relationship type',
243 'contact_type_a' => 'Individual',
244 'contact_type_b' => 'Individual',
249 $result = $this->callAPISuccess('relationship_type', 'create', $params);
250 $this->assertNotNull($result['id']);
252 // assertDBState compares expected values in $result to actual values in the DB
253 $this->assertDBState('CRM_Contact_DAO_RelationshipType', $result['id'], $params);
256 ///////////////// civicrm_relationship_types_get methods
259 * check with empty array
261 function testRelationshipTypesGetEmptyParams() {
262 $firstRelTypeParams = array(
263 'name_a_b' => 'Relation 27 for create',
264 'name_b_a' => 'Relation 28 for create',
265 'description' => 'Testing relationship type',
266 'contact_type_a' => 'Individual',
267 'contact_type_b' => 'Organization',
272 $first = $this->callAPISuccess('RelationshipType', 'Create', $firstRelTypeParams);
274 $secondRelTypeParams = array(
275 'name_a_b' => 'Relation 25 for create',
276 'name_b_a' => 'Relation 26 for create',
277 'description' => 'Testing relationship type second',
278 'contact_type_a' => 'Individual',
279 'contact_type_b' => 'Organization',
283 $second = $this->callAPISuccess('RelationshipType', 'Create', $secondRelTypeParams);
284 $results = $this->callAPISuccess('relationship_type', 'get', array());
286 $this->assertEquals(2, $results['count']);
290 * check with params Not Array.
292 function testRelationshipTypesGetParamsNotArray() {
294 $results = $this->callAPIFailure('relationship_type', 'get', 'string');
298 * check with valid params array.
300 function testRelationshipTypesGet() {
301 $firstRelTypeParams = array(
302 'name_a_b' => 'Relation 30 for create',
303 'name_b_a' => 'Relation 31 for create',
304 'description' => 'Testing relationship type',
305 'contact_type_a' => 'Individual',
306 'contact_type_b' => 'Organization',
311 $first = $this->callAPISuccess('RelationshipType', 'Create', $firstRelTypeParams);
313 $secondRelTypeParams = array(
314 'name_a_b' => 'Relation 32 for create',
315 'name_b_a' => 'Relation 33 for create',
316 'description' => 'Testing relationship type second',
317 'contact_type_a' => 'Individual',
318 'contact_type_b' => 'Organization',
322 $second = $this->callAPISuccess('RelationshipType', 'Create', $secondRelTypeParams);
325 'name_a_b' => 'Relation 32 for create',
326 'name_b_a' => 'Relation 33 for create',
327 'description' => 'Testing relationship type second',
329 $results = $this->callAPISuccess('relationship_type', 'get', $params);
331 $this->assertEquals(1, $results['count'], ' in line ' . __LINE__
);
332 $this->assertEquals(1, $results['values'][$results['id']]['is_active'], ' in line ' . __LINE__
);
336 * create relationship type.
338 function _relationshipTypeCreate($params = NULL) {
339 if (!is_array($params) ||
empty($params)) {
341 'name_a_b' => 'Relation 1 for create',
342 'name_b_a' => 'Relation 2 for create',
343 'description' => 'Testing relationship type',
344 'contact_type_a' => 'Individual',
345 'contact_type_b' => 'Organization',
351 return $this->relationshipTypeCreate($params);