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
36 * Class api_v3_EntityTagTest.
38 class api_v3_EntityTagTest
extends CiviUnitTestCase
{
43 protected $_individualID;
44 protected $_householdID;
45 protected $_organizationID;
47 protected $_apiversion = 3;
49 protected $_entity = 'entity_tag';
52 * Basic parameters for create.
56 protected $_params = array();
61 public function setUp() {
63 $this->useTransaction(TRUE);
65 $this->_individualID
= $this->individualCreate();
66 $this->_tag
= $this->tagCreate();
67 $this->_tagID
= $this->_tag
['id'];
68 $this->_householdID
= $this->houseHoldCreate();
69 $this->_organizationID
= $this->organizationCreate();
70 $this->_params
= array(
71 'contact_id' => $this->_individualID
,
72 'tag_id' => $this->_tagID
,
77 * Test required parameters.
79 * These failure tests are low value and may not be worth putting in v4.
81 public function testFailureTests() {
82 $this->callAPIFailure('entity_tag', 'create', array('contact_id' => $this->_individualID
),
83 'tag_id is a required field'
85 $this->callAPIFailure('entity_tag', 'create', array('tag_id' => $this->_tagID
),
86 'contact_id is a required field'
93 public function testContactEntityTagCreate() {
94 $result = $this->callAPISuccess('entity_tag', 'create', $this->_params
);
95 $this->assertEquals($result['added'], 1);
99 * Test multiple add functionality.
101 * This needs review for api v4 as it makes for a very non standard api.
103 public function testAddDouble() {
105 $result = $this->callAPISuccess('entity_tag', 'create', $this->_params
);
106 $this->assertEquals($result['added'], 1);
109 'contact_id_i' => $this->_individualID
,
110 'contact_id_o' => $this->_organizationID
,
111 'tag_id' => $this->_tagID
,
114 $result = $this->callAPISuccess('entity_tag', 'create', $params);
115 $this->assertEquals($result['added'], 1);
116 $this->assertEquals($result['not_added'], 1);
120 * Test that get works without an entity.
122 public function testGetNoEntityID() {
123 $this->callAPISuccess('entity_tag', 'create', $this->_params
);
124 $result = $this->callAPISuccess($this->_entity
, 'get', array('sequential' => 1, 'tag_id' => $this->_tagID
));
125 $this->assertEquals($this->_individualID
, $result['values'][0]['entity_id']);
129 * Basic get functionality test.
131 public function testIndividualEntityTagGet() {
132 $individualEntity = $this->callAPISuccess('entity_tag', 'create', $this->_params
);
133 $this->assertEquals($individualEntity['added'], 1);
135 $paramsEntity = array(
136 'contact_id' => $this->_individualID
,
138 $this->callAPIAndDocument('entity_tag', 'get', $paramsEntity, __FUNCTION__
, __FILE__
);
142 * Test tag can be added to a household.
144 public function testHouseholdEntityCreate() {
146 'contact_id' => $this->_householdID
,
147 'tag_id' => $this->_tagID
,
150 $householdEntity = $this->callAPISuccess('entity_tag', 'create', $params);
151 $this->assertEquals($householdEntity['added'], 1);
155 * Test tag can be added to an organization.
157 public function testOrganizationEntityGet() {
160 'contact_id' => $this->_organizationID
,
161 'tag_id' => $this->_tagID
,
164 $organizationEntity = $this->callAPISuccess('entity_tag', 'create', $params);
165 $this->assertEquals($organizationEntity['added'], 1);
167 $this->callAPISuccess('entity_tag', 'getsingle', array('contact_id' => $this->_organizationID
));
171 * Civicrm_entity_tag_Delete methods.
173 public function testEntityTagDeleteNoTagId() {
174 $entityTagParams = array(
175 'contact_id_i' => $this->_individualID
,
176 'contact_id_h' => $this->_householdID
,
177 'tag_id' => $this->_tagID
,
179 $this->entityTagAdd($entityTagParams);
182 'contact_id_i' => $this->_individualID
,
183 'contact_id_h' => $this->_householdID
,
186 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
188 $this->assertEquals($result['not_removed'], 0);
189 $this->assertEquals($result['removed'], 2);
190 $this->assertEquals($result['total_count'], 2);
193 public function testEntityTagDeleteINDHH() {
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
,
204 'tag_id' => $this->_tagID
,
207 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
209 $this->assertEquals($result['removed'], 2);
212 public function testEntityTagDeleteHH() {
213 $entityTagParams = array(
214 'contact_id_i' => $this->_individualID
,
215 'contact_id_h' => $this->_householdID
,
216 'tag_id' => $this->_tagID
,
218 $this->entityTagAdd($entityTagParams);
221 'contact_id_h' => $this->_householdID
,
222 'tag_id' => $this->_tagID
,
225 $result = $this->callAPIAndDocument('entity_tag', 'delete', $params, __FUNCTION__
, __FILE__
);
226 $this->assertEquals($result['removed'], 1);
229 public function testEntityTagDeleteHHORG() {
230 $entityTagParams = array(
231 'contact_id_i' => $this->_individualID
,
232 'contact_id_h' => $this->_householdID
,
233 'tag_id' => $this->_tagID
,
235 $this->entityTagAdd($entityTagParams);
238 'contact_id_h' => $this->_householdID
,
239 'contact_id_o' => $this->_organizationID
,
240 'tag_id' => $this->_tagID
,
243 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
244 $this->assertEquals($result['removed'], 1);
245 $this->assertEquals($result['not_removed'], 1);
248 public function testEntityTagCommonDeleteINDHH() {
249 $entityTagParams = array(
250 'contact_id_i' => $this->_individualID
,
251 'contact_id_h' => $this->_householdID
,
252 'tag_id' => $this->_tagID
,
254 $this->entityTagAdd($entityTagParams);
257 'contact_id_i' => $this->_individualID
,
258 'contact_id_h' => $this->_householdID
,
259 'tag_id' => $this->_tagID
,
262 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
263 $this->assertEquals($result['removed'], 2);
266 public function testEntityTagCommonDeleteHH() {
267 $entityTagParams = array(
268 'contact_id_i' => $this->_individualID
,
269 'contact_id_h' => $this->_householdID
,
270 'tag_id' => $this->_tagID
,
272 $this->entityTagAdd($entityTagParams);
275 'contact_id_h' => $this->_householdID
,
276 'tag_id' => $this->_tagID
,
279 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
280 $this->assertEquals($result['removed'], 1);
283 public function testEntityTagCommonDeleteHHORG() {
284 $entityTagParams = array(
285 'contact_id_i' => $this->_individualID
,
286 'contact_id_h' => $this->_householdID
,
287 'tag_id' => $this->_tagID
,
289 $this->entityTagAdd($entityTagParams);
292 'contact_id_h' => $this->_householdID
,
293 'contact_id_o' => $this->_organizationID
,
294 'tag_id' => $this->_tagID
,
297 $result = $this->callAPISuccess('entity_tag', 'delete', $params);
298 $this->assertEquals($result['removed'], 1);
299 $this->assertEquals($result['not_removed'], 1);