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