3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 public $_eNoticeCompliant = TRUE;
52 $this->_individualID
= $this->individualCreate(NULL);
53 $this->_tag
= $this->tagCreate(NULL);
54 $this->_tagID
= $this->_tag
['id'];
55 $this->_householdID
= $this->houseHoldCreate(NULL);
56 $this->_organizationID
= $this->organizationCreate(NULL);
60 $this->quickCleanup(array('civicrm_tag', 'civicrm_entity_tag'));
63 function testAddEmptyParams() {
64 $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params = array(),
65 'contact_id is a required field'
69 function testAddWithoutTagID() {
71 'contact_id' => $this->_individualID
,
73 $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params,
74 'tag_id is a required field'
78 function testAddWithoutContactID() {
80 'tag_id' => $this->_tagID
,
82 $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params,
83 'contact_id is a required field');
86 function testContactEntityTagCreate() {
88 'contact_id' => $this->_individualID
,
89 'tag_id' => $this->_tagID
,
92 $result = $this->callAPIAndDocument('entity_tag', 'create', $params, __FUNCTION__
, __FILE__
);
93 $this->assertEquals($result['added'], 1);
96 function testAddDouble() {
97 $individualId = $this->_individualID
;
98 $organizationId = $this->_organizationID
;
99 $tagID = $this->_tagID
;
101 'contact_id' => $individualId,
105 $result = $this->callAPISuccess('entity_tag', 'create', $params);
107 $this->assertEquals($result['added'], 1);
110 'contact_id_i' => $individualId,
111 'contact_id_o' => $organizationId,
115 $result = $this->callAPISuccess('entity_tag', 'create', $params);
116 $this->assertEquals($result['added'], 1);
117 $this->assertEquals($result['not_added'], 1);
120 ///////////////// civicrm_entity_tag_get methods
121 function testGetWrongParamsType() {
122 $ContactId = $this->_individualID
;
123 $tagID = $this->_tagID
;
125 'contact_id' => $ContactId,
129 $individualEntity = $this->callAPISuccess('entity_tag', 'create', $params);
130 $this->assertEquals($individualEntity['added'], 1);
133 function testIndividualEntityTagGetWithoutContactID() {
134 $paramsEntity = array();
135 $entity = $this->callAPIFailure('entity_tag', 'get', $paramsEntity,
136 'Mandatory key(s) missing from params array: entity_id'
140 function testIndividualEntityTagGet() {
141 $contactId = $this->_individualID
;
142 $tagID = $this->_tagID
;
144 'contact_id' => $contactId,
148 $individualEntity = $this->callAPISuccess('entity_tag', 'create', $params);
149 $this->assertEquals($individualEntity['added'], 1);
151 $paramsEntity = array(
152 'contact_id' => $contactId,
154 $entity = $this->callAPISuccess('entity_tag', 'get', $paramsEntity);
157 function testHouseholdEntityGetWithoutContactID() {
158 $entity = $this->callAPIFailure('entity_tag', 'get', array());
161 function testHouseholdEntityGet() {
162 $ContactId = $this->_householdID
;
163 $tagID = $this->_tagID
;
165 'contact_id' => $ContactId,
169 $householdEntity = $this->callAPISuccess('entity_tag', 'create', $params);
170 $this->assertEquals($householdEntity['added'], 1);
173 function testOrganizationEntityGetWithoutContactID() {
174 $entity = $this->callAPIFailure('entity_tag', 'get', array());
177 function testOrganizationEntityGet() {
178 $ContactId = $this->_organizationID
;
179 $tagID = $this->_tagID
;
181 'contact_id' => $ContactId,
185 $organizationEntity = $this->callAPISuccess('entity_tag', 'create', $params);
186 $this->assertEquals($organizationEntity['added'], 1);
188 $paramsEntity = array('contact_id' => $ContactId);
189 $entity = $this->callAPISuccess('entity_tag', 'get', $paramsEntity);
192 ///////////////// civicrm_entity_tag_remove methods
193 function testEntityTagRemoveNoTagId() {
194 $entityTagParams = array(
195 'contact_id_i' => $this->_individualID
,
196 'contact_id_h' => $this->_householdID
,
197 'tag_id' => $this->_tagID
,
199 $this->entityTagAdd($entityTagParams);
202 'contact_id_i' => $this->_individualID
,
203 'contact_id_h' => $this->_householdID
,
206 $result = $this->callAPIFailure('entity_tag', 'delete', $params,
207 'tag_id is a required field'
211 function testEntityTagRemoveINDHH() {
212 $entityTagParams = array(
213 'contact_id_i' => $this->_individualID
,
214 'contact_id_h' => $this->_householdID
,
215 'tag_id' => $this->_tagID
,
217 $this->entityTagAdd($entityTagParams);
220 'contact_id_i' => $this->_individualID
,
221 'contact_id_h' => $this->_householdID
,
222 'tag_id' => $this->_tagID
,
225 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
227 $this->assertEquals($result['removed'], 2);
230 function testEntityTagDeleteHH() {
231 $entityTagParams = array(
232 'contact_id_i' => $this->_individualID
,
233 'contact_id_h' => $this->_householdID
,
234 'tag_id' => $this->_tagID
,
236 $this->entityTagAdd($entityTagParams);
239 'contact_id_h' => $this->_householdID
,
240 'tag_id' => $this->_tagID
,
243 $result = $this->callAPIAndDocument('entity_tag', 'delete', $params, __FUNCTION__
, __FILE__
);
244 $this->assertEquals($result['removed'], 1);
247 function testEntityTagRemoveHHORG() {
248 $entityTagParams = array(
249 'contact_id_i' => $this->_individualID
,
250 'contact_id_h' => $this->_householdID
,
251 'tag_id' => $this->_tagID
,
253 $this->entityTagAdd($entityTagParams);
256 'contact_id_h' => $this->_householdID
,
257 'contact_id_o' => $this->_organizationID
,
258 'tag_id' => $this->_tagID
,
261 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
262 $this->assertEquals($result['removed'], 1);
263 $this->assertEquals($result['not_removed'], 1);
266 ///////////////// civicrm_tag_entities_get methods
268 function testCommonContactEntityTagAdd() {
270 'contact_id' => $this->_individualID
,
271 'tag_id' => $this->_tagID
,
274 $individualEntity = $this->callAPISuccess('entity_tag', 'create', $params);
275 $this->assertEquals($individualEntity['added'], 1);
279 function testEntityTagCommonRemoveINDHH() {
280 $entityTagParams = array(
281 'contact_id_i' => $this->_individualID
,
282 'contact_id_h' => $this->_householdID
,
283 'tag_id' => $this->_tagID
,
285 $this->entityTagAdd($entityTagParams);
288 'contact_id_i' => $this->_individualID
,
289 'contact_id_h' => $this->_householdID
,
290 'tag_id' => $this->_tagID
,
293 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
294 $this->assertEquals($result['removed'], 2);
297 function testEntityTagCommonRemoveHH() {
298 $entityTagParams = array(
299 'contact_id_i' => $this->_individualID
,
300 'contact_id_h' => $this->_householdID
,
301 'tag_id' => $this->_tagID
,
303 $this->entityTagAdd($entityTagParams);
306 'contact_id_h' => $this->_householdID
,
307 'tag_id' => $this->_tagID
,
310 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
311 $this->assertEquals($result['removed'], 1);
314 function testEntityTagCommonRemoveHHORG() {
315 $entityTagParams = array(
316 'contact_id_i' => $this->_individualID
,
317 'contact_id_h' => $this->_householdID
,
318 'tag_id' => $this->_tagID
,
320 $this->entityTagAdd($entityTagParams);
323 'contact_id_h' => $this->_householdID
,
324 'contact_id_o' => $this->_organizationID
,
325 'tag_id' => $this->_tagID
,
328 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
329 $this->assertEquals($result['removed'], 1);
330 $this->assertEquals($result['not_removed'], 1);