4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
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.4 |
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 = 3;
66 public $_eNoticeCompliant = TRUE;
69 'name' => 'RelationshipType Create',
70 'description' => 'Test all RelationshipType Create API methods.',
71 'group' => 'CiviCRM API Tests',
78 $this->_cId_a
= $this->individualCreate();
79 $this->_cId_b
= $this->organizationCreate();
84 $tablesToTruncate = array(
86 'civicrm_relationship_type',
88 $this->quickCleanup($tablesToTruncate);
91 ///////////////// civicrm_relationship_type_add methods
96 function testRelationshipTypeCreateWithoutName() {
97 $relTypeParams = array(
98 'contact_type_a' => 'Individual',
99 'contact_type_b' => 'Organization',
101 $result = $this->callAPIFailure('relationship_type', 'create', $relTypeParams,
102 'Mandatory key(s) missing from params array: name_a_b, name_b_a'
107 * check with no contact type
109 function testRelationshipTypeCreateWithoutContactType() {
110 $relTypeParams = array(
111 'name_a_b' => 'Relation 1 without contact type',
112 'name_b_a' => 'Relation 2 without contact type',
114 $result = $this->callAPIFailure('relationship_type', 'create', $relTypeParams,
115 'Mandatory key(s) missing from params array: contact_type_a, contact_type_b'
120 * create relationship type
122 function testRelationshipTypeCreate() {
124 'name_a_b' => 'Relation 1 for relationship type create',
125 'name_b_a' => 'Relation 2 for relationship type create',
126 'contact_type_a' => 'Individual',
127 'contact_type_b' => 'Organization',
132 $result = $this->callAPIAndDocument('relationship_type', 'create', $params, __FUNCTION__
, __FILE__
);
133 $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__
);
134 unset($params['sequential']);
135 //assertDBState compares expected values in $result to actual values in the DB
136 $this->assertDBState('CRM_Contact_DAO_RelationshipType', $result['id'], $params);
140 * Test using example code
142 function testRelationshipTypeCreateExample() {
143 require_once 'api/v3/examples/RelationshipTypeCreate.php';
144 $result = relationship_type_create_example();
145 $expectedResult = relationship_type_create_expectedresult();
146 $this->assertAPISuccess($result);
150 * check if required fields are not passed
152 function testRelationshipTypeDeleteWithoutRequired() {
154 'name_b_a' => 'Relation 2 delete without required',
155 'contact_type_b' => 'Individual',
160 $result = $this->callAPIFailure('relationship_type', 'delete', $params);
161 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
165 * check with incorrect required fields
167 function testRelationshipTypeDeleteWithIncorrectData() {
170 'name_b_a' => 'Relation 2 delete with incorrect',
171 'description' => 'Testing relationship type',
172 'contact_type_a' => 'Individual',
173 'contact_type_b' => 'Individual',
177 $result = $this->callAPIFailure('relationship_type', 'delete', $params,
178 'Invalid value for relationship type ID'
183 * check relationship type delete
185 function testRelationshipTypeDelete() {
186 $id = $this->_relationshipTypeCreate();
187 // create sample relationship type.
191 $result = $this->callAPIAndDocument('relationship_type', 'delete', $params, __FUNCTION__
, __FILE__
);
192 $this->assertAPIDeleted('relationship_type', $id);
195 ///////////////// civicrm_relationship_type_update
198 * check with empty array
200 function testRelationshipTypeUpdateEmpty() {
202 $result = $this->callAPIFailure('relationship_type', 'create', $params);
203 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name_a_b, name_b_a, contact_type_a, contact_type_b');
207 * check with no contact type
209 function testRelationshipTypeUpdateWithoutContactType() {
210 // create sample relationship type.
211 $this->_relTypeID
= $this->_relationshipTypeCreate();
213 $relTypeParams = array(
214 'id' => $this->_relTypeID
,
215 'name_a_b' => 'Test 1',
216 'name_b_a' => 'Test 2',
217 'description' => 'Testing relationship type',
222 $result = $this->callAPISuccess('relationship_type', 'create', $relTypeParams);
223 $this->assertNotNull($result['id']);
224 // assertDBState compares expected values in $result to actual values in the DB
225 $this->assertDBState('CRM_Contact_DAO_RelationshipType', $result['id'], $relTypeParams);
229 * check with all parameters
231 function testRelationshipTypeUpdate() {
232 // create sample relationship type.
233 $this->_relTypeID
= $this->_relationshipTypeCreate();
236 'id' => $this->_relTypeID
,
237 'name_a_b' => 'Test 1 for update',
238 'name_b_a' => 'Test 2 for update',
239 'description' => 'SUNIL PAWAR relationship type',
240 'contact_type_a' => 'Individual',
241 'contact_type_b' => 'Individual',
246 $result = $this->callAPISuccess('relationship_type', 'create', $params);
247 $this->assertNotNull($result['id']);
249 // assertDBState compares expected values in $result to actual values in the DB
250 $this->assertDBState('CRM_Contact_DAO_RelationshipType', $result['id'], $params);
253 ///////////////// civicrm_relationship_types_get methods
256 * check with empty array
258 function testRelationshipTypesGetEmptyParams() {
259 $firstRelTypeParams = array(
260 'name_a_b' => 'Relation 27 for create',
261 'name_b_a' => 'Relation 28 for create',
262 'description' => 'Testing relationship type',
263 'contact_type_a' => 'Individual',
264 'contact_type_b' => 'Organization',
269 $first = $this->callAPISuccess('RelationshipType', 'Create', $firstRelTypeParams);
271 $secondRelTypeParams = array(
272 'name_a_b' => 'Relation 25 for create',
273 'name_b_a' => 'Relation 26 for create',
274 'description' => 'Testing relationship type second',
275 'contact_type_a' => 'Individual',
276 'contact_type_b' => 'Organization',
280 $second = $this->callAPISuccess('RelationshipType', 'Create', $secondRelTypeParams);
281 $results = $this->callAPISuccess('relationship_type', 'get', array());
283 $this->assertEquals(2, $results['count']);
287 * check with params Not Array.
289 function testRelationshipTypesGetParamsNotArray() {
291 $results = $this->callAPIFailure('relationship_type', 'get', 'string');
295 * check with valid params array.
297 function testRelationshipTypesGet() {
298 $firstRelTypeParams = array(
299 'name_a_b' => 'Relation 30 for create',
300 'name_b_a' => 'Relation 31 for create',
301 'description' => 'Testing relationship type',
302 'contact_type_a' => 'Individual',
303 'contact_type_b' => 'Organization',
308 $first = $this->callAPISuccess('RelationshipType', 'Create', $firstRelTypeParams);
310 $secondRelTypeParams = array(
311 'name_a_b' => 'Relation 32 for create',
312 'name_b_a' => 'Relation 33 for create',
313 'description' => 'Testing relationship type second',
314 'contact_type_a' => 'Individual',
315 'contact_type_b' => 'Organization',
319 $second = $this->callAPISuccess('RelationshipType', 'Create', $secondRelTypeParams);
322 'name_a_b' => 'Relation 32 for create',
323 'name_b_a' => 'Relation 33 for create',
324 'description' => 'Testing relationship type second',
326 $results = $this->callAPISuccess('relationship_type', 'get', $params);
328 $this->assertEquals(1, $results['count'], ' in line ' . __LINE__
);
329 $this->assertEquals(1, $results['values'][$results['id']]['is_active'], ' in line ' . __LINE__
);
333 * create relationship type.
335 function _relationshipTypeCreate($params = NULL) {
336 if (!is_array($params) ||
empty($params)) {
338 'name_a_b' => 'Relation 1 for create',
339 'name_b_a' => 'Relation 2 for create',
340 'description' => 'Testing relationship type',
341 'contact_type_a' => 'Individual',
342 'contact_type_b' => 'Organization',
348 return $this->relationshipTypeCreate($params);