phpcs - Fix error, "CONST keyword must be lowercase; expected const but found CONST"
[civicrm-core.git] / tests / phpunit / api / v3 / EntityTagTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26*/
27
28require_once 'CiviTest/CiviUnitTestCase.php';
29
30
31/**
32 * Test APIv3 civicrm_entity_tag_* functions
33 *
34 * @package CiviCRM_APIv3
35 * @subpackage API_Core
36 */
37
38require_once 'CiviTest/CiviUnitTestCase.php';
4cbe18b8
EM
39
40/**
41 * Class api_v3_EntityTagTest
42 */
6a488035
TO
43class api_v3_EntityTagTest extends CiviUnitTestCase {
44
45 protected $_individualID;
46 protected $_householdID;
47 protected $_organizationID;
48 protected $_tagID;
fc928539 49 protected $_apiversion = 3;
6a488035 50 protected $_tag;
283c85e9 51 protected $_entity = 'entity_tag';
b7c9bc4c 52
6a488035
TO
53
54 function setUp() {
55 parent::setUp();
56b010a3 56 $this->useTransaction(TRUE);
6a488035 57
e4d5f1e2 58 $this->_individualID = $this->individualCreate();
fb32de45 59 $this->_tag = $this->tagCreate();
6a488035 60 $this->_tagID = $this->_tag['id'];
678fbf79 61 $this->_householdID = $this->houseHoldCreate();
62 $this->_organizationID = $this->organizationCreate();
6a488035
TO
63 }
64
6a488035 65 function testAddEmptyParams() {
fc928539 66 $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params = array(),
67 'contact_id is a required field'
68 );
6a488035
TO
69 }
70
71 function testAddWithoutTagID() {
72 $params = array(
73 'contact_id' => $this->_individualID,
6a488035 74 );
fc928539 75 $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params,
76 'tag_id is a required field'
77 );
6a488035
TO
78 }
79
80 function testAddWithoutContactID() {
81 $params = array(
82 'tag_id' => $this->_tagID,
6a488035 83 );
fc928539 84 $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params,
85 'contact_id is a required field');
6a488035
TO
86 }
87
88 function testContactEntityTagCreate() {
89 $params = array(
90 'contact_id' => $this->_individualID,
91 'tag_id' => $this->_tagID,
6a488035
TO
92 );
93
fc928539 94 $result = $this->callAPIAndDocument('entity_tag', 'create', $params, __FUNCTION__, __FILE__);
6a488035
TO
95 $this->assertEquals($result['added'], 1);
96 }
97
98 function testAddDouble() {
99 $individualId = $this->_individualID;
100 $organizationId = $this->_organizationID;
101 $tagID = $this->_tagID;
102 $params = array(
103 'contact_id' => $individualId,
104 'tag_id' => $tagID,
6a488035
TO
105 );
106
fc928539 107 $result = $this->callAPISuccess('entity_tag', 'create', $params);
6a488035 108
6a488035
TO
109 $this->assertEquals($result['added'], 1);
110
111 $params = array(
112 'contact_id_i' => $individualId,
113 'contact_id_o' => $organizationId,
114 'tag_id' => $tagID,
6a488035
TO
115 );
116
fc928539 117 $result = $this->callAPISuccess('entity_tag', 'create', $params);
6a488035
TO
118 $this->assertEquals($result['added'], 1);
119 $this->assertEquals($result['not_added'], 1);
120 }
121
122 ///////////////// civicrm_entity_tag_get methods
283c85e9 123 function testGetNoEntityID() {
6a488035
TO
124 $ContactId = $this->_individualID;
125 $tagID = $this->_tagID;
126 $params = array(
127 'contact_id' => $ContactId,
128 'tag_id' => $tagID,
6a488035
TO
129 );
130
fc928539 131 $individualEntity = $this->callAPISuccess('entity_tag', 'create', $params);
6a488035 132 $this->assertEquals($individualEntity['added'], 1);
283c85e9 133 $result = $this->callAPISuccess($this->_entity, 'get', array('sequential' => 1, 'tag_id' => $tagID));
134 $this->assertEquals($ContactId, $result['values'][0]['entity_id']);
6a488035
TO
135 }
136
137 function testIndividualEntityTagGet() {
138 $contactId = $this->_individualID;
139 $tagID = $this->_tagID;
140 $params = array(
141 'contact_id' => $contactId,
142 'tag_id' => $tagID,
6a488035
TO
143 );
144
fb32de45 145 $individualEntity = $this->callAPIAndDocument('entity_tag', 'create', $params, __FUNCTION__, __FILE__);
6a488035
TO
146 $this->assertEquals($individualEntity['added'], 1);
147
148 $paramsEntity = array(
149 'contact_id' => $contactId,
6a488035 150 );
fc928539 151 $entity = $this->callAPISuccess('entity_tag', 'get', $paramsEntity);
6a488035
TO
152 }
153
6a488035
TO
154 function testHouseholdEntityGet() {
155 $ContactId = $this->_householdID;
156 $tagID = $this->_tagID;
157 $params = array(
158 'contact_id' => $ContactId,
159 'tag_id' => $tagID,
6a488035
TO
160 );
161
fc928539 162 $householdEntity = $this->callAPISuccess('entity_tag', 'create', $params);
6a488035 163 $this->assertEquals($householdEntity['added'], 1);
6a488035
TO
164 }
165
6a488035
TO
166 function testOrganizationEntityGet() {
167 $ContactId = $this->_organizationID;
168 $tagID = $this->_tagID;
169 $params = array(
170 'contact_id' => $ContactId,
171 'tag_id' => $tagID,
6a488035
TO
172 );
173
fc928539 174 $organizationEntity = $this->callAPISuccess('entity_tag', 'create', $params);
6a488035
TO
175 $this->assertEquals($organizationEntity['added'], 1);
176
177 $paramsEntity = array('contact_id' => $ContactId);
fc928539 178 $entity = $this->callAPISuccess('entity_tag', 'get', $paramsEntity);
6a488035
TO
179 }
180
283c85e9 181 ///////////////// civicrm_entity_tag_Delete methods
182 function testEntityTagDeleteNoTagId() {
6a488035
TO
183 $entityTagParams = array(
184 'contact_id_i' => $this->_individualID,
185 'contact_id_h' => $this->_householdID,
186 'tag_id' => $this->_tagID,
6a488035
TO
187 );
188 $this->entityTagAdd($entityTagParams);
189
190 $params = array(
191 'contact_id_i' => $this->_individualID,
192 'contact_id_h' => $this->_householdID,
6a488035
TO
193 );
194
fc928539 195 $result = $this->callAPIFailure('entity_tag', 'delete', $params,
196 'tag_id is a required field'
197 );
6a488035
TO
198 }
199
283c85e9 200 function testEntityTagDeleteINDHH() {
6a488035
TO
201 $entityTagParams = array(
202 'contact_id_i' => $this->_individualID,
203 'contact_id_h' => $this->_householdID,
204 'tag_id' => $this->_tagID,
6a488035
TO
205 );
206 $this->entityTagAdd($entityTagParams);
207
208 $params = array(
209 'contact_id_i' => $this->_individualID,
210 'contact_id_h' => $this->_householdID,
211 'tag_id' => $this->_tagID,
6a488035
TO
212 );
213
fc928539 214 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
6a488035 215
6a488035
TO
216 $this->assertEquals($result['removed'], 2);
217 }
218
219 function testEntityTagDeleteHH() {
220 $entityTagParams = array(
221 'contact_id_i' => $this->_individualID,
222 'contact_id_h' => $this->_householdID,
223 'tag_id' => $this->_tagID,
6a488035
TO
224 );
225 $this->entityTagAdd($entityTagParams);
226
227 $params = array(
228 'contact_id_h' => $this->_householdID,
229 'tag_id' => $this->_tagID,
6a488035
TO
230 );
231
fc928539 232 $result = $this->callAPIAndDocument('entity_tag', 'delete', $params, __FUNCTION__, __FILE__);
6a488035
TO
233 $this->assertEquals($result['removed'], 1);
234 }
235
283c85e9 236 function testEntityTagDeleteHHORG() {
6a488035
TO
237 $entityTagParams = array(
238 'contact_id_i' => $this->_individualID,
239 'contact_id_h' => $this->_householdID,
240 'tag_id' => $this->_tagID,
6a488035
TO
241 );
242 $this->entityTagAdd($entityTagParams);
243
244 $params = array(
245 'contact_id_h' => $this->_householdID,
246 'contact_id_o' => $this->_organizationID,
247 'tag_id' => $this->_tagID,
6a488035
TO
248 );
249
fc928539 250 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
6a488035
TO
251 $this->assertEquals($result['removed'], 1);
252 $this->assertEquals($result['not_removed'], 1);
253 }
254
6a488035
TO
255 ///////////////// civicrm_tag_entities_get methods
256
6a488035
TO
257 function testCommonContactEntityTagAdd() {
258 $params = array(
259 'contact_id' => $this->_individualID,
260 'tag_id' => $this->_tagID,
6a488035
TO
261 );
262
fc928539 263 $individualEntity = $this->callAPISuccess('entity_tag', 'create', $params);
6a488035
TO
264 $this->assertEquals($individualEntity['added'], 1);
265 }
266
6a488035 267
283c85e9 268 function testEntityTagCommonDeleteINDHH() {
6a488035
TO
269 $entityTagParams = array(
270 'contact_id_i' => $this->_individualID,
271 'contact_id_h' => $this->_householdID,
272 'tag_id' => $this->_tagID,
6a488035
TO
273 );
274 $this->entityTagAdd($entityTagParams);
275
276 $params = array(
277 'contact_id_i' => $this->_individualID,
278 'contact_id_h' => $this->_householdID,
279 'tag_id' => $this->_tagID,
6a488035
TO
280 );
281
fc928539 282 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
6a488035
TO
283 $this->assertEquals($result['removed'], 2);
284 }
285
283c85e9 286 function testEntityTagCommonDeleteHH() {
6a488035
TO
287 $entityTagParams = array(
288 'contact_id_i' => $this->_individualID,
289 'contact_id_h' => $this->_householdID,
290 'tag_id' => $this->_tagID,
6a488035
TO
291 );
292 $this->entityTagAdd($entityTagParams);
293
294 $params = array(
295 'contact_id_h' => $this->_householdID,
296 'tag_id' => $this->_tagID,
6a488035
TO
297 );
298
fc928539 299 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
6a488035
TO
300 $this->assertEquals($result['removed'], 1);
301 }
302
283c85e9 303 function testEntityTagCommonDeleteHHORG() {
6a488035
TO
304 $entityTagParams = array(
305 'contact_id_i' => $this->_individualID,
306 'contact_id_h' => $this->_householdID,
307 'tag_id' => $this->_tagID,
6a488035
TO
308 );
309 $this->entityTagAdd($entityTagParams);
310
311 $params = array(
312 'contact_id_h' => $this->_householdID,
313 'contact_id_o' => $this->_organizationID,
314 'tag_id' => $this->_tagID,
6a488035
TO
315 );
316
fc928539 317 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
6a488035
TO
318 $this->assertEquals($result['removed'], 1);
319 $this->assertEquals($result['not_removed'], 1);
320 }
321}
322