3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
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 +--------------------------------------------------------------------+
29 * Test APIv3 civicrm_entity_tag_* functions
31 * @package CiviCRM_APIv3
32 * @subpackage API_Core
35 require_once 'CiviTest/CiviUnitTestCase.php';
38 * Class api_v3_EntityTagTest.
40 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 * Basic parameters for create.
58 protected $_params = array();
63 public function setUp() {
65 $this->useTransaction(TRUE);
67 $this->_individualID
= $this->individualCreate();
68 $this->_tag
= $this->tagCreate();
69 $this->_tagID
= $this->_tag
['id'];
70 $this->_householdID
= $this->houseHoldCreate();
71 $this->_organizationID
= $this->organizationCreate();
72 $this->_params
= array(
73 'contact_id' => $this->_individualID
,
74 'tag_id' => $this->_tagID
,
79 * Test required parameters.
81 * These failure tests are low value and may not be worth putting in v4.
83 public function testFailureTests() {
84 $this->callAPIFailure('entity_tag', 'create', array('contact_id' => $this->_individualID
),
85 'tag_id is a required field'
87 $this->callAPIFailure('entity_tag', 'create', array('tag_id' => $this->_tagID
),
88 'contact_id is a required field'
95 public function testContactEntityTagCreate() {
96 $result = $this->callAPISuccess('entity_tag', 'create', $this->_params
);
97 $this->assertEquals($result['added'], 1);
101 * Test multiple add functionality.
103 * This needs review for api v4 as it makes for a very non standard api.
105 public function testAddDouble() {
107 $result = $this->callAPISuccess('entity_tag', 'create', $this->_params
);
108 $this->assertEquals($result['added'], 1);
111 'contact_id_i' => $this->_individualID
,
112 'contact_id_o' => $this->_organizationID
,
113 'tag_id' => $this->_tagID
,
116 $result = $this->callAPISuccess('entity_tag', 'create', $params);
117 $this->assertEquals($result['added'], 1);
118 $this->assertEquals($result['not_added'], 1);
122 * Test that get works without an entity.
124 public function testGetNoEntityID() {
125 $this->callAPISuccess('entity_tag', 'create', $this->_params
);
126 $result = $this->callAPISuccess($this->_entity
, 'get', array('sequential' => 1, 'tag_id' => $this->_tagID
));
127 $this->assertEquals($this->_individualID
, $result['values'][0]['entity_id']);
131 * Basic get functionality test.
133 public function testIndividualEntityTagGet() {
134 $individualEntity = $this->callAPISuccess('entity_tag', 'create', $this->_params
);
135 $this->assertEquals($individualEntity['added'], 1);
137 $paramsEntity = array(
138 'contact_id' => $this->_individualID
,
140 $this->callAPIAndDocument('entity_tag', 'get', $paramsEntity, __FUNCTION__
, __FILE__
);
144 * Test tag can be added to a household.
146 public function testHouseholdEntityCreate() {
148 'contact_id' => $this->_householdID
,
149 'tag_id' => $this->_tagID
,
152 $householdEntity = $this->callAPISuccess('entity_tag', 'create', $params);
153 $this->assertEquals($householdEntity['added'], 1);
157 * Test tag can be added to an organization.
159 public function testOrganizationEntityGet() {
162 'contact_id' => $this->_organizationID
,
163 'tag_id' => $this->_tagID
,
166 $organizationEntity = $this->callAPISuccess('entity_tag', 'create', $params);
167 $this->assertEquals($organizationEntity['added'], 1);
169 $this->callAPISuccess('entity_tag', 'getsingle', array('contact_id' => $this->_organizationID
));
173 * Civicrm_entity_tag_Delete methods.
175 public function testEntityTagDeleteNoTagId() {
176 $entityTagParams = array(
177 'contact_id_i' => $this->_individualID
,
178 'contact_id_h' => $this->_householdID
,
179 'tag_id' => $this->_tagID
,
181 $this->entityTagAdd($entityTagParams);
184 'contact_id_i' => $this->_individualID
,
185 'contact_id_h' => $this->_householdID
,
188 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
190 $this->assertEquals($result['not_removed'], 0);
191 $this->assertEquals($result['removed'], 2);
192 $this->assertEquals($result['total_count'], 2);
195 public function testEntityTagDeleteINDHH() {
196 $entityTagParams = array(
197 'contact_id_i' => $this->_individualID
,
198 'contact_id_h' => $this->_householdID
,
199 'tag_id' => $this->_tagID
,
201 $this->entityTagAdd($entityTagParams);
204 'contact_id_i' => $this->_individualID
,
205 'contact_id_h' => $this->_householdID
,
206 'tag_id' => $this->_tagID
,
209 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
211 $this->assertEquals($result['removed'], 2);
214 public function testEntityTagDeleteHH() {
215 $entityTagParams = array(
216 'contact_id_i' => $this->_individualID
,
217 'contact_id_h' => $this->_householdID
,
218 'tag_id' => $this->_tagID
,
220 $this->entityTagAdd($entityTagParams);
223 'contact_id_h' => $this->_householdID
,
224 'tag_id' => $this->_tagID
,
227 $result = $this->callAPIAndDocument('entity_tag', 'delete', $params, __FUNCTION__
, __FILE__
);
228 $this->assertEquals($result['removed'], 1);
231 public function testEntityTagDeleteHHORG() {
232 $entityTagParams = array(
233 'contact_id_i' => $this->_individualID
,
234 'contact_id_h' => $this->_householdID
,
235 'tag_id' => $this->_tagID
,
237 $this->entityTagAdd($entityTagParams);
240 'contact_id_h' => $this->_householdID
,
241 'contact_id_o' => $this->_organizationID
,
242 'tag_id' => $this->_tagID
,
245 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
246 $this->assertEquals($result['removed'], 1);
247 $this->assertEquals($result['not_removed'], 1);
250 public function testEntityTagCommonDeleteINDHH() {
251 $entityTagParams = array(
252 'contact_id_i' => $this->_individualID
,
253 'contact_id_h' => $this->_householdID
,
254 'tag_id' => $this->_tagID
,
256 $this->entityTagAdd($entityTagParams);
259 'contact_id_i' => $this->_individualID
,
260 'contact_id_h' => $this->_householdID
,
261 'tag_id' => $this->_tagID
,
264 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
265 $this->assertEquals($result['removed'], 2);
268 public function testEntityTagCommonDeleteHH() {
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_h' => $this->_householdID
,
278 'tag_id' => $this->_tagID
,
281 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
282 $this->assertEquals($result['removed'], 1);
285 public function testEntityTagCommonDeleteHHORG() {
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 'contact_id_o' => $this->_organizationID
,
296 'tag_id' => $this->_tagID
,
299 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
300 $this->assertEquals($result['removed'], 1);
301 $this->assertEquals($result['not_removed'], 1);