3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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';
54 public function setUp() {
56 $this->useTransaction(TRUE);
58 $this->_individualID
= $this->individualCreate();
59 $this->_tag
= $this->tagCreate();
60 $this->_tagID
= $this->_tag
['id'];
61 $this->_householdID
= $this->houseHoldCreate();
62 $this->_organizationID
= $this->organizationCreate();
65 public function testAddEmptyParams() {
66 $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params = array(),
67 'contact_id is a required field'
71 public function testAddWithoutTagID() {
73 'contact_id' => $this->_individualID
,
75 $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params,
76 'tag_id is a required field'
80 public function testAddWithoutContactID() {
82 'tag_id' => $this->_tagID
,
84 $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params,
85 'contact_id is a required field');
88 public function testContactEntityTagCreate() {
90 'contact_id' => $this->_individualID
,
91 'tag_id' => $this->_tagID
,
94 $result = $this->callAPIAndDocument('entity_tag', 'create', $params, __FUNCTION__
, __FILE__
);
95 $this->assertEquals($result['added'], 1);
98 public function testAddDouble() {
99 $individualId = $this->_individualID
;
100 $organizationId = $this->_organizationID
;
101 $tagID = $this->_tagID
;
103 'contact_id' => $individualId,
107 $result = $this->callAPISuccess('entity_tag', 'create', $params);
109 $this->assertEquals($result['added'], 1);
112 'contact_id_i' => $individualId,
113 'contact_id_o' => $organizationId,
117 $result = $this->callAPISuccess('entity_tag', 'create', $params);
118 $this->assertEquals($result['added'], 1);
119 $this->assertEquals($result['not_added'], 1);
122 ///////////////// civicrm_entity_tag_get methods
123 public function testGetNoEntityID() {
124 $ContactId = $this->_individualID
;
125 $tagID = $this->_tagID
;
127 'contact_id' => $ContactId,
131 $individualEntity = $this->callAPISuccess('entity_tag', 'create', $params);
132 $this->assertEquals($individualEntity['added'], 1);
133 $result = $this->callAPISuccess($this->_entity
, 'get', array('sequential' => 1, 'tag_id' => $tagID));
134 $this->assertEquals($ContactId, $result['values'][0]['entity_id']);
137 public function testIndividualEntityTagGet() {
138 $contactId = $this->_individualID
;
139 $tagID = $this->_tagID
;
141 'contact_id' => $contactId,
145 $individualEntity = $this->callAPIAndDocument('entity_tag', 'create', $params, __FUNCTION__
, __FILE__
);
146 $this->assertEquals($individualEntity['added'], 1);
148 $paramsEntity = array(
149 'contact_id' => $contactId,
151 $entity = $this->callAPISuccess('entity_tag', 'get', $paramsEntity);
154 public function testHouseholdEntityGet() {
155 $ContactId = $this->_householdID
;
156 $tagID = $this->_tagID
;
158 'contact_id' => $ContactId,
162 $householdEntity = $this->callAPISuccess('entity_tag', 'create', $params);
163 $this->assertEquals($householdEntity['added'], 1);
166 public function testOrganizationEntityGet() {
167 $ContactId = $this->_organizationID
;
168 $tagID = $this->_tagID
;
170 'contact_id' => $ContactId,
174 $organizationEntity = $this->callAPISuccess('entity_tag', 'create', $params);
175 $this->assertEquals($organizationEntity['added'], 1);
177 $paramsEntity = array('contact_id' => $ContactId);
178 $entity = $this->callAPISuccess('entity_tag', 'get', $paramsEntity);
181 ///////////////// civicrm_entity_tag_Delete methods
182 public function testEntityTagDeleteNoTagId() {
183 $entityTagParams = array(
184 'contact_id_i' => $this->_individualID
,
185 'contact_id_h' => $this->_householdID
,
186 'tag_id' => $this->_tagID
,
188 $this->entityTagAdd($entityTagParams);
191 'contact_id_i' => $this->_individualID
,
192 'contact_id_h' => $this->_householdID
,
195 $result = $this->callAPIFailure('entity_tag', 'delete', $params,
196 'tag_id is a required field'
200 public function testEntityTagDeleteINDHH() {
201 $entityTagParams = array(
202 'contact_id_i' => $this->_individualID
,
203 'contact_id_h' => $this->_householdID
,
204 'tag_id' => $this->_tagID
,
206 $this->entityTagAdd($entityTagParams);
209 'contact_id_i' => $this->_individualID
,
210 'contact_id_h' => $this->_householdID
,
211 'tag_id' => $this->_tagID
,
214 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
216 $this->assertEquals($result['removed'], 2);
219 public function testEntityTagDeleteHH() {
220 $entityTagParams = array(
221 'contact_id_i' => $this->_individualID
,
222 'contact_id_h' => $this->_householdID
,
223 'tag_id' => $this->_tagID
,
225 $this->entityTagAdd($entityTagParams);
228 'contact_id_h' => $this->_householdID
,
229 'tag_id' => $this->_tagID
,
232 $result = $this->callAPIAndDocument('entity_tag', 'delete', $params, __FUNCTION__
, __FILE__
);
233 $this->assertEquals($result['removed'], 1);
236 public function testEntityTagDeleteHHORG() {
237 $entityTagParams = array(
238 'contact_id_i' => $this->_individualID
,
239 'contact_id_h' => $this->_householdID
,
240 'tag_id' => $this->_tagID
,
242 $this->entityTagAdd($entityTagParams);
245 'contact_id_h' => $this->_householdID
,
246 'contact_id_o' => $this->_organizationID
,
247 'tag_id' => $this->_tagID
,
250 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
251 $this->assertEquals($result['removed'], 1);
252 $this->assertEquals($result['not_removed'], 1);
255 ///////////////// civicrm_tag_entities_get methods
257 public function testCommonContactEntityTagAdd() {
259 'contact_id' => $this->_individualID
,
260 'tag_id' => $this->_tagID
,
263 $individualEntity = $this->callAPISuccess('entity_tag', 'create', $params);
264 $this->assertEquals($individualEntity['added'], 1);
268 public function testEntityTagCommonDeleteINDHH() {
269 $entityTagParams = array(
270 'contact_id_i' => $this->_individualID
,
271 'contact_id_h' => $this->_householdID
,
272 'tag_id' => $this->_tagID
,
274 $this->entityTagAdd($entityTagParams);
277 'contact_id_i' => $this->_individualID
,
278 'contact_id_h' => $this->_householdID
,
279 'tag_id' => $this->_tagID
,
282 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
283 $this->assertEquals($result['removed'], 2);
286 public function testEntityTagCommonDeleteHH() {
287 $entityTagParams = array(
288 'contact_id_i' => $this->_individualID
,
289 'contact_id_h' => $this->_householdID
,
290 'tag_id' => $this->_tagID
,
292 $this->entityTagAdd($entityTagParams);
295 'contact_id_h' => $this->_householdID
,
296 'tag_id' => $this->_tagID
,
299 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
300 $this->assertEquals($result['removed'], 1);
303 public function testEntityTagCommonDeleteHHORG() {
304 $entityTagParams = array(
305 'contact_id_i' => $this->_individualID
,
306 'contact_id_h' => $this->_householdID
,
307 'tag_id' => $this->_tagID
,
309 $this->entityTagAdd($entityTagParams);
312 'contact_id_h' => $this->_householdID
,
313 'contact_id_o' => $this->_organizationID
,
314 'tag_id' => $this->_tagID
,
317 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
318 $this->assertEquals($result['removed'], 1);
319 $this->assertEquals($result['not_removed'], 1);