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';
41 * Class api_v3_EntityTagTest
43 class api_v3_EntityTagTest
extends CiviUnitTestCase
{
45 protected $_individualID;
46 protected $_householdID;
47 protected $_organizationID;
49 protected $_apiversion = 3;
51 protected $_entity = 'entity_tag';
57 $this->_individualID
= $this->individualCreate();
58 $this->_tag
= $this->tagCreate();
59 $this->_tagID
= $this->_tag
['id'];
60 $this->_householdID
= $this->houseHoldCreate();
61 $this->_organizationID
= $this->organizationCreate();
65 $this->quickCleanup(array('civicrm_tag', 'civicrm_entity_tag'));
68 function testAddEmptyParams() {
69 $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params = array(),
70 'contact_id is a required field'
74 function testAddWithoutTagID() {
76 'contact_id' => $this->_individualID
,
78 $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params,
79 'tag_id is a required field'
83 function testAddWithoutContactID() {
85 'tag_id' => $this->_tagID
,
87 $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params,
88 'contact_id is a required field');
91 function testContactEntityTagCreate() {
93 'contact_id' => $this->_individualID
,
94 'tag_id' => $this->_tagID
,
97 $result = $this->callAPIAndDocument('entity_tag', 'create', $params, __FUNCTION__
, __FILE__
);
98 $this->assertEquals($result['added'], 1);
101 function testAddDouble() {
102 $individualId = $this->_individualID
;
103 $organizationId = $this->_organizationID
;
104 $tagID = $this->_tagID
;
106 'contact_id' => $individualId,
110 $result = $this->callAPISuccess('entity_tag', 'create', $params);
112 $this->assertEquals($result['added'], 1);
115 'contact_id_i' => $individualId,
116 'contact_id_o' => $organizationId,
120 $result = $this->callAPISuccess('entity_tag', 'create', $params);
121 $this->assertEquals($result['added'], 1);
122 $this->assertEquals($result['not_added'], 1);
125 ///////////////// civicrm_entity_tag_get methods
126 function testGetNoEntityID() {
127 $ContactId = $this->_individualID
;
128 $tagID = $this->_tagID
;
130 'contact_id' => $ContactId,
134 $individualEntity = $this->callAPISuccess('entity_tag', 'create', $params);
135 $this->assertEquals($individualEntity['added'], 1);
136 $result = $this->callAPISuccess($this->_entity
, 'get', array('sequential' => 1, 'tag_id' => $tagID));
137 $this->assertEquals($ContactId, $result['values'][0]['entity_id']);
140 function testIndividualEntityTagGet() {
141 $contactId = $this->_individualID
;
142 $tagID = $this->_tagID
;
144 'contact_id' => $contactId,
148 $individualEntity = $this->callAPIAndDocument('entity_tag', 'create', $params, __FUNCTION__
, __FILE__
);
149 $this->assertEquals($individualEntity['added'], 1);
151 $paramsEntity = array(
152 'contact_id' => $contactId,
154 $entity = $this->callAPISuccess('entity_tag', 'get', $paramsEntity);
157 function testHouseholdEntityGet() {
158 $ContactId = $this->_householdID
;
159 $tagID = $this->_tagID
;
161 'contact_id' => $ContactId,
165 $householdEntity = $this->callAPISuccess('entity_tag', 'create', $params);
166 $this->assertEquals($householdEntity['added'], 1);
169 function testOrganizationEntityGet() {
170 $ContactId = $this->_organizationID
;
171 $tagID = $this->_tagID
;
173 'contact_id' => $ContactId,
177 $organizationEntity = $this->callAPISuccess('entity_tag', 'create', $params);
178 $this->assertEquals($organizationEntity['added'], 1);
180 $paramsEntity = array('contact_id' => $ContactId);
181 $entity = $this->callAPISuccess('entity_tag', 'get', $paramsEntity);
184 ///////////////// civicrm_entity_tag_Delete methods
185 function testEntityTagDeleteNoTagId() {
186 $entityTagParams = array(
187 'contact_id_i' => $this->_individualID
,
188 'contact_id_h' => $this->_householdID
,
189 'tag_id' => $this->_tagID
,
191 $this->entityTagAdd($entityTagParams);
194 'contact_id_i' => $this->_individualID
,
195 'contact_id_h' => $this->_householdID
,
198 $result = $this->callAPIFailure('entity_tag', 'delete', $params,
199 'tag_id is a required field'
203 function testEntityTagDeleteINDHH() {
204 $entityTagParams = array(
205 'contact_id_i' => $this->_individualID
,
206 'contact_id_h' => $this->_householdID
,
207 'tag_id' => $this->_tagID
,
209 $this->entityTagAdd($entityTagParams);
212 'contact_id_i' => $this->_individualID
,
213 'contact_id_h' => $this->_householdID
,
214 'tag_id' => $this->_tagID
,
217 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
219 $this->assertEquals($result['removed'], 2);
222 function testEntityTagDeleteHH() {
223 $entityTagParams = array(
224 'contact_id_i' => $this->_individualID
,
225 'contact_id_h' => $this->_householdID
,
226 'tag_id' => $this->_tagID
,
228 $this->entityTagAdd($entityTagParams);
231 'contact_id_h' => $this->_householdID
,
232 'tag_id' => $this->_tagID
,
235 $result = $this->callAPIAndDocument('entity_tag', 'delete', $params, __FUNCTION__
, __FILE__
);
236 $this->assertEquals($result['removed'], 1);
239 function testEntityTagDeleteHHORG() {
240 $entityTagParams = array(
241 'contact_id_i' => $this->_individualID
,
242 'contact_id_h' => $this->_householdID
,
243 'tag_id' => $this->_tagID
,
245 $this->entityTagAdd($entityTagParams);
248 'contact_id_h' => $this->_householdID
,
249 'contact_id_o' => $this->_organizationID
,
250 'tag_id' => $this->_tagID
,
253 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
254 $this->assertEquals($result['removed'], 1);
255 $this->assertEquals($result['not_removed'], 1);
258 ///////////////// civicrm_tag_entities_get methods
260 function testCommonContactEntityTagAdd() {
262 'contact_id' => $this->_individualID
,
263 'tag_id' => $this->_tagID
,
266 $individualEntity = $this->callAPISuccess('entity_tag', 'create', $params);
267 $this->assertEquals($individualEntity['added'], 1);
271 function testEntityTagCommonDeleteINDHH() {
272 $entityTagParams = array(
273 'contact_id_i' => $this->_individualID
,
274 'contact_id_h' => $this->_householdID
,
275 'tag_id' => $this->_tagID
,
277 $this->entityTagAdd($entityTagParams);
280 'contact_id_i' => $this->_individualID
,
281 'contact_id_h' => $this->_householdID
,
282 'tag_id' => $this->_tagID
,
285 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
286 $this->assertEquals($result['removed'], 2);
289 function testEntityTagCommonDeleteHH() {
290 $entityTagParams = array(
291 'contact_id_i' => $this->_individualID
,
292 'contact_id_h' => $this->_householdID
,
293 'tag_id' => $this->_tagID
,
295 $this->entityTagAdd($entityTagParams);
298 'contact_id_h' => $this->_householdID
,
299 'tag_id' => $this->_tagID
,
302 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
303 $this->assertEquals($result['removed'], 1);
306 function testEntityTagCommonDeleteHHORG() {
307 $entityTagParams = array(
308 'contact_id_i' => $this->_individualID
,
309 'contact_id_h' => $this->_householdID
,
310 'tag_id' => $this->_tagID
,
312 $this->entityTagAdd($entityTagParams);
315 'contact_id_h' => $this->_householdID
,
316 'contact_id_o' => $this->_organizationID
,
317 'tag_id' => $this->_tagID
,
320 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
321 $this->assertEquals($result['removed'], 1);
322 $this->assertEquals($result['not_removed'], 1);