4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
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.3 |
32 +--------------------------------------------------------------------+
33 | Copyright CiviCRM LLC (c) 2004-2013 |
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;
66 public $_eNoticeCompliant = TRUE;
69 'name' => 'RelationshipType Create',
70 'description' => 'Test all RelationshipType Create API methods.',
71 'group' => 'CiviCRM API Tests',
78 $this->_apiversion
= 3;
79 $this->_cId_a
= $this->individualCreate(NULL);
80 $this->_cId_b
= $this->organizationCreate(NULL);
85 $tablesToTruncate = array(
87 'civicrm_relationship_type',
89 $this->quickCleanup($tablesToTruncate);
92 ///////////////// civicrm_relationship_type_add methods
97 function testRelationshipTypeCreateWithoutName() {
98 $relTypeParams = array(
99 'contact_type_a' => 'Individual',
100 'contact_type_b' => 'Organization',
101 'version' => $this->_apiversion
,
103 $result = civicrm_api('relationship_type', 'create', $relTypeParams);
105 $this->assertEquals($result['is_error'], 1);
106 $this->assertEquals($result['error_message'],
107 'Mandatory key(s) missing from params array: name_a_b, name_b_a'
112 * check with no contact type
114 function testRelationshipTypeCreateWithoutContactType() {
115 $relTypeParams = array(
116 'name_a_b' => 'Relation 1 without contact type',
117 'name_b_a' => 'Relation 2 without contact type',
118 'version' => $this->_apiversion
,
120 $result = civicrm_api('relationship_type', 'create', $relTypeParams);
122 $this->assertEquals($result['is_error'], 1);
123 $this->assertEquals($result['error_message'],
124 'Mandatory key(s) missing from params array: contact_type_a, contact_type_b'
129 * create relationship type
131 function testRelationshipTypeCreate() {
133 'name_a_b' => 'Relation 1 for relationship type create',
134 'name_b_a' => 'Relation 2 for relationship type create',
135 'contact_type_a' => 'Individual',
136 'contact_type_b' => 'Organization',
139 'version' => $this->_apiversion
,
142 $result = civicrm_api('relationship_type', 'create', $params);
143 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
144 $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__
);
145 unset($params['version']);
146 unset($params['sequential']);
147 //assertDBState compares expected values in $result to actual values in the DB
148 $this->assertDBState('CRM_Contact_DAO_RelationshipType', $result['id'], $params);
152 * Test using example code
154 function testRelationshipTypeCreateExample() {
155 require_once 'api/v3/examples/RelationshipTypeCreate.php';
156 $result = relationship_type_create_example();
157 $expectedResult = relationship_type_create_expectedresult();
158 $this->assertEquals($result['is_error'], 0);
161 ///////////////// civicrm_relationship_type_delete methods
164 * check with empty array
166 function testRelationshipTypeDeleteEmpty() {
168 $result = civicrm_api('relationship_type', 'delete', $params);
170 $this->assertEquals($result['is_error'], 1);
174 * check with No array
176 function testRelationshipTypeDeleteParamsNotArray() {
177 $params = 'name_a_b = Test1';
178 $result = civicrm_api('relationship_type', 'delete', $params);
180 $this->assertEquals($result['is_error'], 1);
184 * check if required fields are not passed
186 function testRelationshipTypeDeleteWithoutRequired() {
188 'name_b_a' => 'Relation 2 delete without required',
189 'contact_type_b' => 'Individual',
194 $result = civicrm_api('relationship_type', 'delete', $params);
196 $this->assertEquals($result['is_error'], 1);
197 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, id');
201 * check with incorrect required fields
203 function testRelationshipTypeDeleteWithIncorrectData() {
206 'name_b_a' => 'Relation 2 delete with incorrect',
207 'description' => 'Testing relationship type',
208 'contact_type_a' => 'Individual',
209 'contact_type_b' => 'Individual',
212 'version' => $this->_apiversion
,
215 $result = civicrm_api('relationship_type', 'delete', $params);
217 $this->assertEquals($result['is_error'], 1);
218 $this->assertEquals($result['error_message'], 'Invalid value for relationship type ID');
222 * check relationship type delete
224 function testRelationshipTypeDelete() {
225 $rel = $this->_relationshipTypeCreate();
226 // create sample relationship type.
229 'version' => $this->_apiversion
,
231 $result = civicrm_api('relationship_type', 'delete', $params);
232 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
233 $this->assertEquals($result['is_error'], 0);
236 ///////////////// civicrm_relationship_type_update
239 * check with empty array
241 function testRelationshipTypeUpdateEmpty() {
243 $result = civicrm_api('relationship_type', 'create', $params);
245 $this->assertEquals($result['is_error'], 1);
246 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, name_a_b, name_b_a, contact_type_a, contact_type_b');
250 * check with No array
252 function testRelationshipTypeUpdateParamsNotArray() {
253 $params = 'name_a_b = Relation 1';
254 $result = civicrm_api('relationship_type', 'create', $params);
256 $this->assertEquals($result['is_error'], 1);
257 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
261 * check with no contact type
263 function testRelationshipTypeUpdateWithoutContactType() {
264 // create sample relationship type.
265 $this->_relTypeID
= $this->_relationshipTypeCreate(NULL);
267 $relTypeParams = array(
268 'id' => $this->_relTypeID
,
269 'name_a_b' => 'Test 1',
270 'name_b_a' => 'Test 2',
271 'description' => 'Testing relationship type',
274 'version' => $this->_apiversion
,
277 $result = civicrm_api('relationship_type', 'create', $relTypeParams);
278 $this->assertNotNull($result['id']);
279 unset($relTypeParams['version']);
280 // assertDBState compares expected values in $result to actual values in the DB
281 $this->assertDBState('CRM_Contact_DAO_RelationshipType', $result['id'], $relTypeParams);
285 * check with all parameters
287 function testRelationshipTypeUpdate() {
288 // create sample relationship type.
289 $this->_relTypeID
= $this->_relationshipTypeCreate(NULL);
292 'id' => $this->_relTypeID
,
293 'name_a_b' => 'Test 1 for update',
294 'name_b_a' => 'Test 2 for update',
295 'description' => 'SUNIL PAWAR relationship type',
296 'contact_type_a' => 'Individual',
297 'contact_type_b' => 'Individual',
300 'version' => $this->_apiversion
,
303 $result = civicrm_api('relationship_type', 'create', $params);
304 $this->assertNotNull($result['id']);
305 unset($params['version']);
306 // assertDBState compares expected values in $result to actual values in the DB
307 $this->assertDBState('CRM_Contact_DAO_RelationshipType', $result['id'], $params);
310 ///////////////// civicrm_relationship_types_get methods
313 * check with empty array
315 function testRelationshipTypesGetEmptyParams() {
316 $firstRelTypeParams = array(
317 'name_a_b' => 'Relation 27 for create',
318 'name_b_a' => 'Relation 28 for create',
319 'description' => 'Testing relationship type',
320 'contact_type_a' => 'Individual',
321 'contact_type_b' => 'Organization',
324 'version' => $this->_apiversion
,
327 $first = civicrm_api('RelationshipType', 'Create', $firstRelTypeParams);
329 $secondRelTypeParams = array(
330 'name_a_b' => 'Relation 25 for create',
331 'name_b_a' => 'Relation 26 for create',
332 'description' => 'Testing relationship type second',
333 'contact_type_a' => 'Individual',
334 'contact_type_b' => 'Organization',
337 'version' => $this->_apiversion
,
339 $second = civicrm_api('RelationshipType', 'Create', $secondRelTypeParams);
340 $results = civicrm_api('relationship_type', 'get', array(
341 'version' => $this->_apiversion
,
344 $this->assertEquals(2, $results['count']);
345 $this->assertEquals(0, $results['is_error']);
349 * check with params Not Array.
351 function testRelationshipTypesGetParamsNotArray() {
353 $results = civicrm_api('relationship_type', 'get', 'string');
354 $this->assertEquals(1, $results['is_error']);
358 * check with valid params array.
360 function testRelationshipTypesGet() {
361 $firstRelTypeParams = array(
362 'name_a_b' => 'Relation 30 for create',
363 'name_b_a' => 'Relation 31 for create',
364 'description' => 'Testing relationship type',
365 'contact_type_a' => 'Individual',
366 'contact_type_b' => 'Organization',
369 'version' => $this->_apiversion
,
372 $first = civicrm_api('RelationshipType', 'Create', $firstRelTypeParams);
374 $secondRelTypeParams = array(
375 'name_a_b' => 'Relation 32 for create',
376 'name_b_a' => 'Relation 33 for create',
377 'description' => 'Testing relationship type second',
378 'contact_type_a' => 'Individual',
379 'contact_type_b' => 'Organization',
382 'version' => $this->_apiversion
,
384 $second = civicrm_api('RelationshipType', 'Create', $secondRelTypeParams);
387 'name_a_b' => 'Relation 32 for create',
388 'name_b_a' => 'Relation 33 for create',
389 'description' => 'Testing relationship type second',
390 'version' => $this->_apiversion
,
392 $results = civicrm_api('relationship_type', 'get', $params);
394 $this->assertEquals(0, $results['is_error'], ' in line ' . __LINE__
);
395 $this->assertEquals(1, $results['count'], ' in line ' . __LINE__
);
396 $this->assertEquals(1, $results['values'][$results['id']]['is_active'], ' in line ' . __LINE__
);
400 * create relationship type.
402 function _relationshipTypeCreate($params = NULL) {
403 if (!is_array($params) ||
empty($params)) {
405 'name_a_b' => 'Relation 1 for create',
406 'name_b_a' => 'Relation 2 for create',
407 'description' => 'Testing relationship type',
408 'contact_type_a' => 'Individual',
409 'contact_type_b' => 'Organization',
412 'version' => API_LATEST_VERSION
,
416 return $this->relationshipTypeCreate($params);