3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
32 * Test APIv3 civicrm_entity_tag_* functions
34 * @package CiviCRM_APIv3
35 * @subpackage API_Core
38 require_once 'CiviTest/CiviUnitTestCase.php';
39 class api_v3_EntityTagTest
extends CiviUnitTestCase
{
41 protected $_individualID;
42 protected $_householdID;
43 protected $_organizationID;
45 protected $_apiversion = 3;
47 protected $_entity = 'entity_tag';
53 $this->_individualID
= $this->individualCreate();
54 $this->_tag
= $this->tagCreate();
55 $this->_tagID
= $this->_tag
['id'];
56 $this->_householdID
= $this->houseHoldCreate();
57 $this->_organizationID
= $this->organizationCreate();
61 $this->quickCleanup(array('civicrm_tag', 'civicrm_entity_tag'));
64 function testAddEmptyParams() {
65 $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params = array(),
66 'contact_id is a required field'
70 function testAddWithoutTagID() {
72 'contact_id' => $this->_individualID
,
74 $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params,
75 'tag_id is a required field'
79 function testAddWithoutContactID() {
81 'tag_id' => $this->_tagID
,
83 $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params,
84 'contact_id is a required field');
87 function testContactEntityTagCreate() {
89 'contact_id' => $this->_individualID
,
90 'tag_id' => $this->_tagID
,
93 $result = $this->callAPIAndDocument('entity_tag', 'create', $params, __FUNCTION__
, __FILE__
);
94 $this->assertEquals($result['added'], 1);
97 function testAddDouble() {
98 $individualId = $this->_individualID
;
99 $organizationId = $this->_organizationID
;
100 $tagID = $this->_tagID
;
102 'contact_id' => $individualId,
106 $result = $this->callAPISuccess('entity_tag', 'create', $params);
108 $this->assertEquals($result['added'], 1);
111 'contact_id_i' => $individualId,
112 'contact_id_o' => $organizationId,
116 $result = $this->callAPISuccess('entity_tag', 'create', $params);
117 $this->assertEquals($result['added'], 1);
118 $this->assertEquals($result['not_added'], 1);
121 ///////////////// civicrm_entity_tag_get methods
122 function testGetNoEntityID() {
123 $ContactId = $this->_individualID
;
124 $tagID = $this->_tagID
;
126 'contact_id' => $ContactId,
130 $individualEntity = $this->callAPISuccess('entity_tag', 'create', $params);
131 $this->assertEquals($individualEntity['added'], 1);
132 $result = $this->callAPISuccess($this->_entity
, 'get', array('sequential' => 1, 'tag_id' => $tagID));
133 $this->assertEquals($ContactId, $result['values'][0]['entity_id']);
136 function testIndividualEntityTagGet() {
137 $contactId = $this->_individualID
;
138 $tagID = $this->_tagID
;
140 'contact_id' => $contactId,
144 $individualEntity = $this->callAPIAndDocument('entity_tag', 'create', $params, __FUNCTION__
, __FILE__
);
145 $this->assertEquals($individualEntity['added'], 1);
147 $paramsEntity = array(
148 'contact_id' => $contactId,
150 $entity = $this->callAPISuccess('entity_tag', 'get', $paramsEntity);
153 function testHouseholdEntityGet() {
154 $ContactId = $this->_householdID
;
155 $tagID = $this->_tagID
;
157 'contact_id' => $ContactId,
161 $householdEntity = $this->callAPISuccess('entity_tag', 'create', $params);
162 $this->assertEquals($householdEntity['added'], 1);
165 function testOrganizationEntityGet() {
166 $ContactId = $this->_organizationID
;
167 $tagID = $this->_tagID
;
169 'contact_id' => $ContactId,
173 $organizationEntity = $this->callAPISuccess('entity_tag', 'create', $params);
174 $this->assertEquals($organizationEntity['added'], 1);
176 $paramsEntity = array('contact_id' => $ContactId);
177 $entity = $this->callAPISuccess('entity_tag', 'get', $paramsEntity);
180 ///////////////// civicrm_entity_tag_Delete methods
181 function testEntityTagDeleteNoTagId() {
182 $entityTagParams = array(
183 'contact_id_i' => $this->_individualID
,
184 'contact_id_h' => $this->_householdID
,
185 'tag_id' => $this->_tagID
,
187 $this->entityTagAdd($entityTagParams);
190 'contact_id_i' => $this->_individualID
,
191 'contact_id_h' => $this->_householdID
,
194 $result = $this->callAPIFailure('entity_tag', 'delete', $params,
195 'tag_id is a required field'
199 function testEntityTagDeleteINDHH() {
200 $entityTagParams = array(
201 'contact_id_i' => $this->_individualID
,
202 'contact_id_h' => $this->_householdID
,
203 'tag_id' => $this->_tagID
,
205 $this->entityTagAdd($entityTagParams);
208 'contact_id_i' => $this->_individualID
,
209 'contact_id_h' => $this->_householdID
,
210 'tag_id' => $this->_tagID
,
213 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
215 $this->assertEquals($result['removed'], 2);
218 function testEntityTagDeleteHH() {
219 $entityTagParams = array(
220 'contact_id_i' => $this->_individualID
,
221 'contact_id_h' => $this->_householdID
,
222 'tag_id' => $this->_tagID
,
224 $this->entityTagAdd($entityTagParams);
227 'contact_id_h' => $this->_householdID
,
228 'tag_id' => $this->_tagID
,
231 $result = $this->callAPIAndDocument('entity_tag', 'delete', $params, __FUNCTION__
, __FILE__
);
232 $this->assertEquals($result['removed'], 1);
235 function testEntityTagDeleteHHORG() {
236 $entityTagParams = array(
237 'contact_id_i' => $this->_individualID
,
238 'contact_id_h' => $this->_householdID
,
239 'tag_id' => $this->_tagID
,
241 $this->entityTagAdd($entityTagParams);
244 'contact_id_h' => $this->_householdID
,
245 'contact_id_o' => $this->_organizationID
,
246 'tag_id' => $this->_tagID
,
249 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
250 $this->assertEquals($result['removed'], 1);
251 $this->assertEquals($result['not_removed'], 1);
254 ///////////////// civicrm_tag_entities_get methods
256 function testCommonContactEntityTagAdd() {
258 'contact_id' => $this->_individualID
,
259 'tag_id' => $this->_tagID
,
262 $individualEntity = $this->callAPISuccess('entity_tag', 'create', $params);
263 $this->assertEquals($individualEntity['added'], 1);
267 function testEntityTagCommonDeleteINDHH() {
268 $entityTagParams = array(
269 'contact_id_i' => $this->_individualID
,
270 'contact_id_h' => $this->_householdID
,
271 'tag_id' => $this->_tagID
,
273 $this->entityTagAdd($entityTagParams);
276 'contact_id_i' => $this->_individualID
,
277 'contact_id_h' => $this->_householdID
,
278 'tag_id' => $this->_tagID
,
281 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
282 $this->assertEquals($result['removed'], 2);
285 function testEntityTagCommonDeleteHH() {
286 $entityTagParams = array(
287 'contact_id_i' => $this->_individualID
,
288 'contact_id_h' => $this->_householdID
,
289 'tag_id' => $this->_tagID
,
291 $this->entityTagAdd($entityTagParams);
294 'contact_id_h' => $this->_householdID
,
295 'tag_id' => $this->_tagID
,
298 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
299 $this->assertEquals($result['removed'], 1);
302 function testEntityTagCommonDeleteHHORG() {
303 $entityTagParams = array(
304 'contact_id_i' => $this->_individualID
,
305 'contact_id_h' => $this->_householdID
,
306 'tag_id' => $this->_tagID
,
308 $this->entityTagAdd($entityTagParams);
311 'contact_id_h' => $this->_householdID
,
312 'contact_id_o' => $this->_organizationID
,
313 'tag_id' => $this->_tagID
,
316 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
317 $this->assertEquals($result['removed'], 1);
318 $this->assertEquals($result['not_removed'], 1);