3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 +--------------------------------------------------------------------+
30 | CiviCRM version 4.7 |
31 +--------------------------------------------------------------------+
32 | Copyright CiviCRM LLC (c) 2004-2015 |
33 +--------------------------------------------------------------------+
34 | This file is a part of CiviCRM. |
36 | CiviCRM is free software; you can copy, modify, and distribute it |
37 | under the terms of the GNU Affero General Public License |
38 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
40 | CiviCRM is distributed in the hope that it will be useful, but |
41 | WITHOUT ANY WARRANTY; without even the implied warranty of |
42 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
43 | See the GNU Affero General Public License for more details. |
45 | You should have received a copy of the GNU Affero General Public |
46 | License and the CiviCRM Licensing Exception along |
47 | with this program; if not, contact CiviCRM LLC |
48 | at info[AT]civicrm[DOT]org. If you have questions about the |
49 | GNU Affero General Public License or the licensing of CiviCRM, |
50 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
51 +--------------------------------------------------------------------+
54 require_once 'CiviTest/CiviUnitTestCase.php';
57 * Class contains api test cases for "civicrm_relationship_type"
60 class api_v3_RelationshipTypeTest
extends CiviUnitTestCase
{
63 protected $_relTypeID;
64 protected $_apiversion = 3;
66 public function setUp() {
69 $this->_cId_a
= $this->individualCreate();
70 $this->_cId_b
= $this->organizationCreate();
73 public function tearDown() {
75 $tablesToTruncate = array(
77 'civicrm_relationship_type',
79 $this->quickCleanup($tablesToTruncate);
82 ///////////////// civicrm_relationship_type_add methods
87 public function testRelationshipTypeCreateWithoutName() {
88 $relTypeParams = array(
89 'contact_type_a' => 'Individual',
90 'contact_type_b' => 'Organization',
92 $result = $this->callAPIFailure('relationship_type', 'create', $relTypeParams,
93 'Mandatory key(s) missing from params array: name_a_b, name_b_a'
98 * Check with no contact type.
100 public function testRelationshipTypeCreateWithoutContactType() {
101 $relTypeParams = array(
102 'name_a_b' => 'Relation 1 without contact type',
103 'name_b_a' => 'Relation 2 without contact type',
105 $result = $this->callAPIFailure('relationship_type', 'create', $relTypeParams,
106 'Mandatory key(s) missing from params array: contact_type_a, contact_type_b'
111 * Create relationship type.
113 public function testRelationshipTypeCreate() {
115 'name_a_b' => 'Relation 1 for relationship type create',
116 'name_b_a' => 'Relation 2 for relationship type create',
117 'contact_type_a' => 'Individual',
118 'contact_type_b' => 'Organization',
123 $result = $this->callAPIAndDocument('relationship_type', 'create', $params, __FUNCTION__
, __FILE__
);
124 $this->assertNotNull($result['values'][0]['id']);
125 unset($params['sequential']);
126 //assertDBState compares expected values in $result to actual values in the DB
127 $this->assertDBState('CRM_Contact_DAO_RelationshipType', $result['id'], $params);
131 * Test using example code.
133 public function testRelationshipTypeCreateExample() {
134 require_once 'api/v3/examples/RelationshipType/Create.php';
135 $result = relationship_type_create_example();
136 $expectedResult = relationship_type_create_expectedresult();
137 $this->assertAPISuccess($result);
141 * Check if required fields are not passed.
143 public function testRelationshipTypeDeleteWithoutRequired() {
145 'name_b_a' => 'Relation 2 delete without required',
146 'contact_type_b' => 'Individual',
151 $result = $this->callAPIFailure('relationship_type', 'delete', $params);
152 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
156 * Check with incorrect required fields.
158 public function testRelationshipTypeDeleteWithIncorrectData() {
161 'name_b_a' => 'Relation 2 delete with incorrect',
162 'description' => 'Testing relationship type',
163 'contact_type_a' => 'Individual',
164 'contact_type_b' => 'Individual',
168 $result = $this->callAPIFailure('relationship_type', 'delete', $params,
169 'Invalid value for relationship type ID'
174 * Check relationship type delete.
176 public function testRelationshipTypeDelete() {
177 $id = $this->_relationshipTypeCreate();
178 // create sample relationship type.
182 $result = $this->callAPIAndDocument('relationship_type', 'delete', $params, __FUNCTION__
, __FILE__
);
183 $this->assertAPIDeleted('relationship_type', $id);
186 ///////////////// civicrm_relationship_type_update
189 * Check with empty array.
191 public function testRelationshipTypeUpdateEmpty() {
193 $result = $this->callAPIFailure('relationship_type', 'create', $params);
194 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name_a_b, name_b_a, contact_type_a, contact_type_b');
198 * Check with no contact type.
200 public function testRelationshipTypeUpdateWithoutContactType() {
201 // create sample relationship type.
202 $this->_relTypeID
= $this->_relationshipTypeCreate();
204 $relTypeParams = array(
205 'id' => $this->_relTypeID
,
206 'name_a_b' => 'Test 1',
207 'name_b_a' => 'Test 2',
208 'description' => 'Testing relationship type',
213 $result = $this->callAPISuccess('relationship_type', 'create', $relTypeParams);
214 $this->assertNotNull($result['id']);
215 // assertDBState compares expected values in $result to actual values in the DB
216 $this->assertDBState('CRM_Contact_DAO_RelationshipType', $result['id'], $relTypeParams);
220 * Check with all parameters.
222 public function testRelationshipTypeUpdate() {
223 // create sample relationship type.
224 $this->_relTypeID
= $this->_relationshipTypeCreate();
227 'id' => $this->_relTypeID
,
228 'name_a_b' => 'Test 1 for update',
229 'name_b_a' => 'Test 2 for update',
230 'description' => 'SUNIL PAWAR relationship type',
231 'contact_type_a' => 'Individual',
232 'contact_type_b' => 'Individual',
237 $result = $this->callAPISuccess('relationship_type', 'create', $params);
238 $this->assertNotNull($result['id']);
240 // assertDBState compares expected values in $result to actual values in the DB
241 $this->assertDBState('CRM_Contact_DAO_RelationshipType', $result['id'], $params);
244 ///////////////// civicrm_relationship_types_get methods
247 * Check with empty array.
249 public function testRelationshipTypesGetEmptyParams() {
250 $firstRelTypeParams = array(
251 'name_a_b' => 'Relation 27 for create',
252 'name_b_a' => 'Relation 28 for create',
253 'description' => 'Testing relationship type',
254 'contact_type_a' => 'Individual',
255 'contact_type_b' => 'Organization',
260 $first = $this->callAPISuccess('RelationshipType', 'Create', $firstRelTypeParams);
262 $secondRelTypeParams = array(
263 'name_a_b' => 'Relation 25 for create',
264 'name_b_a' => 'Relation 26 for create',
265 'description' => 'Testing relationship type second',
266 'contact_type_a' => 'Individual',
267 'contact_type_b' => 'Organization',
271 $second = $this->callAPISuccess('RelationshipType', 'Create', $secondRelTypeParams);
272 $results = $this->callAPISuccess('relationship_type', 'get', array());
274 $this->assertEquals(2, $results['count']);
278 * Check with params Not Array.
280 public function testRelationshipTypesGetParamsNotArray() {
282 $results = $this->callAPIFailure('relationship_type', 'get', 'string');
286 * Check with valid params array.
288 public function testRelationshipTypesGet() {
289 $firstRelTypeParams = array(
290 'name_a_b' => 'Relation 30 for create',
291 'name_b_a' => 'Relation 31 for create',
292 'description' => 'Testing relationship type',
293 'contact_type_a' => 'Individual',
294 'contact_type_b' => 'Organization',
299 $first = $this->callAPISuccess('RelationshipType', 'Create', $firstRelTypeParams);
301 $secondRelTypeParams = array(
302 'name_a_b' => 'Relation 32 for create',
303 'name_b_a' => 'Relation 33 for create',
304 'description' => 'Testing relationship type second',
305 'contact_type_a' => 'Individual',
306 'contact_type_b' => 'Organization',
310 $second = $this->callAPISuccess('RelationshipType', 'Create', $secondRelTypeParams);
313 'name_a_b' => 'Relation 32 for create',
314 'name_b_a' => 'Relation 33 for create',
315 'description' => 'Testing relationship type second',
317 $results = $this->callAPISuccess('relationship_type', 'get', $params);
319 $this->assertEquals(1, $results['count'], ' in line ' . __LINE__
);
320 $this->assertEquals(1, $results['values'][$results['id']]['is_active'], ' in line ' . __LINE__
);
324 * Create relationship type.
325 * @param null $params
328 public function _relationshipTypeCreate($params = NULL) {
329 if (!is_array($params) ||
empty($params)) {
331 'name_a_b' => 'Relation 1 for create',
332 'name_b_a' => 'Relation 2 for create',
333 'description' => 'Testing relationship type',
334 'contact_type_a' => 'Individual',
335 'contact_type_b' => 'Organization',
341 return $this->relationshipTypeCreate($params);