3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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->callAPISuccess('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);
123 * civicrm_entity_tag_get methods.
125 public function testGetNoEntityID() {
126 $ContactId = $this->_individualID
;
127 $tagID = $this->_tagID
;
129 'contact_id' => $ContactId,
133 $individualEntity = $this->callAPISuccess('entity_tag', 'create', $params);
134 $this->assertEquals($individualEntity['added'], 1);
135 $result = $this->callAPISuccess($this->_entity
, 'get', array('sequential' => 1, 'tag_id' => $tagID));
136 $this->assertEquals($ContactId, $result['values'][0]['entity_id']);
139 public function testIndividualEntityTagGet() {
140 $contactId = $this->_individualID
;
141 $tagID = $this->_tagID
;
143 'contact_id' => $contactId,
147 $individualEntity = $this->callAPIAndDocument('entity_tag', 'create', $params, __FUNCTION__
, __FILE__
);
148 $this->assertEquals($individualEntity['added'], 1);
150 $paramsEntity = array(
151 'contact_id' => $contactId,
153 $entity = $this->callAPIAndDocument('entity_tag', 'get', $paramsEntity, __FUNCTION__
, __FILE__
);
156 public function testHouseholdEntityGet() {
157 $ContactId = $this->_householdID
;
158 $tagID = $this->_tagID
;
160 'contact_id' => $ContactId,
164 $householdEntity = $this->callAPISuccess('entity_tag', 'create', $params);
165 $this->assertEquals($householdEntity['added'], 1);
168 public function testOrganizationEntityGet() {
169 $ContactId = $this->_organizationID
;
170 $tagID = $this->_tagID
;
172 'contact_id' => $ContactId,
176 $organizationEntity = $this->callAPISuccess('entity_tag', 'create', $params);
177 $this->assertEquals($organizationEntity['added'], 1);
179 $paramsEntity = array('contact_id' => $ContactId);
180 $entity = $this->callAPISuccess('entity_tag', 'get', $paramsEntity);
184 * civicrm_entity_tag_Delete methods.
186 public function testEntityTagDeleteNoTagId() {
187 $entityTagParams = array(
188 'contact_id_i' => $this->_individualID
,
189 'contact_id_h' => $this->_householdID
,
190 'tag_id' => $this->_tagID
,
192 $this->entityTagAdd($entityTagParams);
195 'contact_id_i' => $this->_individualID
,
196 'contact_id_h' => $this->_householdID
,
199 $result = $this->callAPIFailure('entity_tag', 'delete', $params,
200 'tag_id is a required field'
204 public function testEntityTagDeleteINDHH() {
205 $entityTagParams = array(
206 'contact_id_i' => $this->_individualID
,
207 'contact_id_h' => $this->_householdID
,
208 'tag_id' => $this->_tagID
,
210 $this->entityTagAdd($entityTagParams);
213 'contact_id_i' => $this->_individualID
,
214 'contact_id_h' => $this->_householdID
,
215 'tag_id' => $this->_tagID
,
218 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
220 $this->assertEquals($result['removed'], 2);
223 public function testEntityTagDeleteHH() {
224 $entityTagParams = array(
225 'contact_id_i' => $this->_individualID
,
226 'contact_id_h' => $this->_householdID
,
227 'tag_id' => $this->_tagID
,
229 $this->entityTagAdd($entityTagParams);
232 'contact_id_h' => $this->_householdID
,
233 'tag_id' => $this->_tagID
,
236 $result = $this->callAPIAndDocument('entity_tag', 'delete', $params, __FUNCTION__
, __FILE__
);
237 $this->assertEquals($result['removed'], 1);
240 public function testEntityTagDeleteHHORG() {
241 $entityTagParams = array(
242 'contact_id_i' => $this->_individualID
,
243 'contact_id_h' => $this->_householdID
,
244 'tag_id' => $this->_tagID
,
246 $this->entityTagAdd($entityTagParams);
249 'contact_id_h' => $this->_householdID
,
250 'contact_id_o' => $this->_organizationID
,
251 'tag_id' => $this->_tagID
,
254 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
255 $this->assertEquals($result['removed'], 1);
256 $this->assertEquals($result['not_removed'], 1);
260 * civicrm_tag_entities_get methods.
262 public function testCommonContactEntityTagAdd() {
264 'contact_id' => $this->_individualID
,
265 'tag_id' => $this->_tagID
,
268 $individualEntity = $this->callAPISuccess('entity_tag', 'create', $params);
269 $this->assertEquals($individualEntity['added'], 1);
273 public function testEntityTagCommonDeleteINDHH() {
274 $entityTagParams = array(
275 'contact_id_i' => $this->_individualID
,
276 'contact_id_h' => $this->_householdID
,
277 'tag_id' => $this->_tagID
,
279 $this->entityTagAdd($entityTagParams);
282 'contact_id_i' => $this->_individualID
,
283 'contact_id_h' => $this->_householdID
,
284 'tag_id' => $this->_tagID
,
287 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
288 $this->assertEquals($result['removed'], 2);
291 public function testEntityTagCommonDeleteHH() {
292 $entityTagParams = array(
293 'contact_id_i' => $this->_individualID
,
294 'contact_id_h' => $this->_householdID
,
295 'tag_id' => $this->_tagID
,
297 $this->entityTagAdd($entityTagParams);
300 'contact_id_h' => $this->_householdID
,
301 'tag_id' => $this->_tagID
,
304 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
305 $this->assertEquals($result['removed'], 1);
308 public function testEntityTagCommonDeleteHHORG() {
309 $entityTagParams = array(
310 'contact_id_i' => $this->_individualID
,
311 'contact_id_h' => $this->_householdID
,
312 'tag_id' => $this->_tagID
,
314 $this->entityTagAdd($entityTagParams);
317 'contact_id_h' => $this->_householdID
,
318 'contact_id_o' => $this->_organizationID
,
319 'tag_id' => $this->_tagID
,
322 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
323 $this->assertEquals($result['removed'], 1);
324 $this->assertEquals($result['not_removed'], 1);