3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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-2016 |
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 +--------------------------------------------------------------------+
55 * Class contains api test cases for "civicrm_relationship_type"
59 class api_v3_RelationshipTypeTest
extends CiviUnitTestCase
{
62 protected $_relTypeID;
63 protected $_apiversion = 3;
65 public function setUp() {
68 $this->_cId_a
= $this->individualCreate();
69 $this->_cId_b
= $this->organizationCreate();
72 public function tearDown() {
74 $tablesToTruncate = array(
76 'civicrm_relationship_type',
78 $this->quickCleanup($tablesToTruncate);
81 ///////////////// civicrm_relationship_type_add methods
86 public function testRelationshipTypeCreateWithoutName() {
87 $relTypeParams = array(
88 'contact_type_a' => 'Individual',
89 'contact_type_b' => 'Organization',
91 $result = $this->callAPIFailure('relationship_type', 'create', $relTypeParams,
92 'Mandatory key(s) missing from params array: name_a_b, name_b_a'
97 * Check with no contact type.
99 public function testRelationshipTypeCreateWithoutContactType() {
100 $relTypeParams = array(
101 'name_a_b' => 'Relation 1 without contact type',
102 'name_b_a' => 'Relation 2 without contact type',
104 $result = $this->callAPIFailure('relationship_type', 'create', $relTypeParams,
105 'Mandatory key(s) missing from params array: contact_type_a, contact_type_b'
110 * Create relationship type.
112 public function testRelationshipTypeCreate() {
114 'name_a_b' => 'Relation 1 for relationship type create',
115 'name_b_a' => 'Relation 2 for relationship type create',
116 'contact_type_a' => 'Individual',
117 'contact_type_b' => 'Organization',
122 $result = $this->callAPIAndDocument('relationship_type', 'create', $params, __FUNCTION__
, __FILE__
);
123 $this->assertNotNull($result['values'][0]['id']);
124 unset($params['sequential']);
125 //assertDBState compares expected values in $result to actual values in the DB
126 $this->assertDBState('CRM_Contact_DAO_RelationshipType', $result['id'], $params);
130 * Test using example code.
132 public function testRelationshipTypeCreateExample() {
133 require_once 'api/v3/examples/RelationshipType/Create.php';
134 $result = relationship_type_create_example();
135 $expectedResult = relationship_type_create_expectedresult();
136 $this->assertAPISuccess($result);
140 * Check if required fields are not passed.
142 public function testRelationshipTypeDeleteWithoutRequired() {
144 'name_b_a' => 'Relation 2 delete without required',
145 'contact_type_b' => 'Individual',
150 $result = $this->callAPIFailure('relationship_type', 'delete', $params);
151 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
155 * Check with incorrect required fields.
157 public function testRelationshipTypeDeleteWithIncorrectData() {
160 'name_b_a' => 'Relation 2 delete with incorrect',
161 'description' => 'Testing relationship type',
162 'contact_type_a' => 'Individual',
163 'contact_type_b' => 'Individual',
167 $result = $this->callAPIFailure('relationship_type', 'delete', $params,
168 'Invalid value for relationship type ID'
173 * Check relationship type delete.
175 public function testRelationshipTypeDelete() {
176 $id = $this->_relationshipTypeCreate();
177 // create sample relationship type.
181 $result = $this->callAPIAndDocument('relationship_type', 'delete', $params, __FUNCTION__
, __FILE__
);
182 $this->assertAPIDeleted('relationship_type', $id);
185 ///////////////// civicrm_relationship_type_update
188 * Check with empty array.
190 public function testRelationshipTypeUpdateEmpty() {
192 $result = $this->callAPIFailure('relationship_type', 'create', $params);
193 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name_a_b, name_b_a, contact_type_a, contact_type_b');
197 * Check with no contact type.
199 public function testRelationshipTypeUpdateWithoutContactType() {
200 // create sample relationship type.
201 $this->_relTypeID
= $this->_relationshipTypeCreate();
203 $relTypeParams = array(
204 'id' => $this->_relTypeID
,
205 'name_a_b' => 'Test 1',
206 'name_b_a' => 'Test 2',
207 'description' => 'Testing relationship type',
212 $result = $this->callAPISuccess('relationship_type', 'create', $relTypeParams);
213 $this->assertNotNull($result['id']);
214 // assertDBState compares expected values in $result to actual values in the DB
215 $this->assertDBState('CRM_Contact_DAO_RelationshipType', $result['id'], $relTypeParams);
219 * Check with all parameters.
221 public function testRelationshipTypeUpdate() {
222 // create sample relationship type.
223 $this->_relTypeID
= $this->_relationshipTypeCreate();
226 'id' => $this->_relTypeID
,
227 'name_a_b' => 'Test 1 for update',
228 'name_b_a' => 'Test 2 for update',
229 'description' => 'SUNIL PAWAR relationship type',
230 'contact_type_a' => 'Individual',
231 'contact_type_b' => 'Individual',
236 $result = $this->callAPISuccess('relationship_type', 'create', $params);
237 $this->assertNotNull($result['id']);
239 // assertDBState compares expected values in $result to actual values in the DB
240 $this->assertDBState('CRM_Contact_DAO_RelationshipType', $result['id'], $params);
243 ///////////////// civicrm_relationship_types_get methods
246 * Check with empty array.
248 public function testRelationshipTypesGetEmptyParams() {
249 $firstRelTypeParams = array(
250 'name_a_b' => 'Relation 27 for create',
251 'name_b_a' => 'Relation 28 for create',
252 'description' => 'Testing relationship type',
253 'contact_type_a' => 'Individual',
254 'contact_type_b' => 'Organization',
259 $first = $this->callAPISuccess('RelationshipType', 'Create', $firstRelTypeParams);
261 $secondRelTypeParams = array(
262 'name_a_b' => 'Relation 25 for create',
263 'name_b_a' => 'Relation 26 for create',
264 'description' => 'Testing relationship type second',
265 'contact_type_a' => 'Individual',
266 'contact_type_b' => 'Organization',
270 $second = $this->callAPISuccess('RelationshipType', 'Create', $secondRelTypeParams);
271 $results = $this->callAPISuccess('relationship_type', 'get', array());
273 $this->assertEquals(2, $results['count']);
277 * Check with params Not Array.
279 public function testRelationshipTypesGetParamsNotArray() {
281 $results = $this->callAPIFailure('relationship_type', 'get', 'string');
285 * Check with valid params array.
287 public function testRelationshipTypesGet() {
288 $firstRelTypeParams = array(
289 'name_a_b' => 'Relation 30 for create',
290 'name_b_a' => 'Relation 31 for create',
291 'description' => 'Testing relationship type',
292 'contact_type_a' => 'Individual',
293 'contact_type_b' => 'Organization',
298 $first = $this->callAPISuccess('RelationshipType', 'Create', $firstRelTypeParams);
300 $secondRelTypeParams = array(
301 'name_a_b' => 'Relation 32 for create',
302 'name_b_a' => 'Relation 33 for create',
303 'description' => 'Testing relationship type second',
304 'contact_type_a' => 'Individual',
305 'contact_type_b' => 'Organization',
309 $second = $this->callAPISuccess('RelationshipType', 'Create', $secondRelTypeParams);
312 'name_a_b' => 'Relation 32 for create',
313 'name_b_a' => 'Relation 33 for create',
314 'description' => 'Testing relationship type second',
316 $results = $this->callAPISuccess('relationship_type', 'get', $params);
318 $this->assertEquals(1, $results['count'], ' in line ' . __LINE__
);
319 $this->assertEquals(1, $results['values'][$results['id']]['is_active'], ' in line ' . __LINE__
);
323 * Create relationship type.
324 * @param null $params
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);