4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.6 |
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.6 |
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;
67 public function setUp() {
70 $this->_cId_a
= $this->individualCreate();
71 $this->_cId_b
= $this->organizationCreate();
74 public function tearDown() {
76 $tablesToTruncate = array(
78 'civicrm_relationship_type',
80 $this->quickCleanup($tablesToTruncate);
83 ///////////////// civicrm_relationship_type_add methods
88 public function testRelationshipTypeCreateWithoutName() {
89 $relTypeParams = array(
90 'contact_type_a' => 'Individual',
91 'contact_type_b' => 'Organization',
93 $result = $this->callAPIFailure('relationship_type', 'create', $relTypeParams,
94 'Mandatory key(s) missing from params array: name_a_b, name_b_a'
99 * Check with no contact type
101 public function testRelationshipTypeCreateWithoutContactType() {
102 $relTypeParams = array(
103 'name_a_b' => 'Relation 1 without contact type',
104 'name_b_a' => 'Relation 2 without contact type',
106 $result = $this->callAPIFailure('relationship_type', 'create', $relTypeParams,
107 'Mandatory key(s) missing from params array: contact_type_a, contact_type_b'
112 * Create relationship type
114 public function testRelationshipTypeCreate() {
116 'name_a_b' => 'Relation 1 for relationship type create',
117 'name_b_a' => 'Relation 2 for relationship type create',
118 'contact_type_a' => 'Individual',
119 'contact_type_b' => 'Organization',
124 $result = $this->callAPIAndDocument('relationship_type', 'create', $params, __FUNCTION__
, __FILE__
);
125 $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__
);
126 unset($params['sequential']);
127 //assertDBState compares expected values in $result to actual values in the DB
128 $this->assertDBState('CRM_Contact_DAO_RelationshipType', $result['id'], $params);
132 * Test using example code
134 public function testRelationshipTypeCreateExample() {
135 require_once 'api/v3/examples/RelationshipType/Create.php';
136 $result = relationship_type_create_example();
137 $expectedResult = relationship_type_create_expectedresult();
138 $this->assertAPISuccess($result);
142 * Check if required fields are not passed
144 public function testRelationshipTypeDeleteWithoutRequired() {
146 'name_b_a' => 'Relation 2 delete without required',
147 'contact_type_b' => 'Individual',
152 $result = $this->callAPIFailure('relationship_type', 'delete', $params);
153 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
157 * Check with incorrect required fields
159 public function testRelationshipTypeDeleteWithIncorrectData() {
162 'name_b_a' => 'Relation 2 delete with incorrect',
163 'description' => 'Testing relationship type',
164 'contact_type_a' => 'Individual',
165 'contact_type_b' => 'Individual',
169 $result = $this->callAPIFailure('relationship_type', 'delete', $params,
170 'Invalid value for relationship type ID'
175 * Check relationship type delete
177 public function testRelationshipTypeDelete() {
178 $id = $this->_relationshipTypeCreate();
179 // create sample relationship type.
183 $result = $this->callAPIAndDocument('relationship_type', 'delete', $params, __FUNCTION__
, __FILE__
);
184 $this->assertAPIDeleted('relationship_type', $id);
187 ///////////////// civicrm_relationship_type_update
190 * Check with empty array
192 public function testRelationshipTypeUpdateEmpty() {
194 $result = $this->callAPIFailure('relationship_type', 'create', $params);
195 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name_a_b, name_b_a, contact_type_a, contact_type_b');
199 * Check with no contact type
201 public function testRelationshipTypeUpdateWithoutContactType() {
202 // create sample relationship type.
203 $this->_relTypeID
= $this->_relationshipTypeCreate();
205 $relTypeParams = array(
206 'id' => $this->_relTypeID
,
207 'name_a_b' => 'Test 1',
208 'name_b_a' => 'Test 2',
209 'description' => 'Testing relationship type',
214 $result = $this->callAPISuccess('relationship_type', 'create', $relTypeParams);
215 $this->assertNotNull($result['id']);
216 // assertDBState compares expected values in $result to actual values in the DB
217 $this->assertDBState('CRM_Contact_DAO_RelationshipType', $result['id'], $relTypeParams);
221 * Check with all parameters
223 public function testRelationshipTypeUpdate() {
224 // create sample relationship type.
225 $this->_relTypeID
= $this->_relationshipTypeCreate();
228 'id' => $this->_relTypeID
,
229 'name_a_b' => 'Test 1 for update',
230 'name_b_a' => 'Test 2 for update',
231 'description' => 'SUNIL PAWAR relationship type',
232 'contact_type_a' => 'Individual',
233 'contact_type_b' => 'Individual',
238 $result = $this->callAPISuccess('relationship_type', 'create', $params);
239 $this->assertNotNull($result['id']);
241 // assertDBState compares expected values in $result to actual values in the DB
242 $this->assertDBState('CRM_Contact_DAO_RelationshipType', $result['id'], $params);
245 ///////////////// civicrm_relationship_types_get methods
248 * Check with empty array
250 public function testRelationshipTypesGetEmptyParams() {
251 $firstRelTypeParams = array(
252 'name_a_b' => 'Relation 27 for create',
253 'name_b_a' => 'Relation 28 for create',
254 'description' => 'Testing relationship type',
255 'contact_type_a' => 'Individual',
256 'contact_type_b' => 'Organization',
261 $first = $this->callAPISuccess('RelationshipType', 'Create', $firstRelTypeParams);
263 $secondRelTypeParams = array(
264 'name_a_b' => 'Relation 25 for create',
265 'name_b_a' => 'Relation 26 for create',
266 'description' => 'Testing relationship type second',
267 'contact_type_a' => 'Individual',
268 'contact_type_b' => 'Organization',
272 $second = $this->callAPISuccess('RelationshipType', 'Create', $secondRelTypeParams);
273 $results = $this->callAPISuccess('relationship_type', 'get', array());
275 $this->assertEquals(2, $results['count']);
279 * Check with params Not Array.
281 public function testRelationshipTypesGetParamsNotArray() {
283 $results = $this->callAPIFailure('relationship_type', 'get', 'string');
287 * Check with valid params array.
289 public function testRelationshipTypesGet() {
290 $firstRelTypeParams = array(
291 'name_a_b' => 'Relation 30 for create',
292 'name_b_a' => 'Relation 31 for create',
293 'description' => 'Testing relationship type',
294 'contact_type_a' => 'Individual',
295 'contact_type_b' => 'Organization',
300 $first = $this->callAPISuccess('RelationshipType', 'Create', $firstRelTypeParams);
302 $secondRelTypeParams = array(
303 'name_a_b' => 'Relation 32 for create',
304 'name_b_a' => 'Relation 33 for create',
305 'description' => 'Testing relationship type second',
306 'contact_type_a' => 'Individual',
307 'contact_type_b' => 'Organization',
311 $second = $this->callAPISuccess('RelationshipType', 'Create', $secondRelTypeParams);
314 'name_a_b' => 'Relation 32 for create',
315 'name_b_a' => 'Relation 33 for create',
316 'description' => 'Testing relationship type second',
318 $results = $this->callAPISuccess('relationship_type', 'get', $params);
320 $this->assertEquals(1, $results['count'], ' in line ' . __LINE__
);
321 $this->assertEquals(1, $results['values'][$results['id']]['is_active'], ' in line ' . __LINE__
);
325 * Create relationship type.
327 public function _relationshipTypeCreate($params = NULL) {
328 if (!is_array($params) ||
empty($params)) {
330 'name_a_b' => 'Relation 1 for create',
331 'name_b_a' => 'Relation 2 for create',
332 'description' => 'Testing relationship type',
333 'contact_type_a' => 'Individual',
334 'contact_type_b' => 'Organization',
340 return $this->relationshipTypeCreate($params);