Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
29 | ||
30 | ||
31 | /** | |
32 | * Test APIv3 civicrm_entity_tag_* functions | |
33 | * | |
92915c55 TO |
34 | * @package CiviCRM_APIv3 |
35 | * @subpackage API_Core | |
6a488035 TO |
36 | */ |
37 | ||
38 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
4cbe18b8 EM |
39 | |
40 | /** | |
41 | * Class api_v3_EntityTagTest | |
42 | */ | |
6a488035 TO |
43 | class api_v3_EntityTagTest extends CiviUnitTestCase { |
44 | ||
45 | protected $_individualID; | |
46 | protected $_householdID; | |
47 | protected $_organizationID; | |
48 | protected $_tagID; | |
fc928539 | 49 | protected $_apiversion = 3; |
6a488035 | 50 | protected $_tag; |
283c85e9 | 51 | protected $_entity = 'entity_tag'; |
b7c9bc4c | 52 | |
6a488035 | 53 | |
00be9182 | 54 | public function setUp() { |
6a488035 | 55 | parent::setUp(); |
56b010a3 | 56 | $this->useTransaction(TRUE); |
6a488035 | 57 | |
e4d5f1e2 | 58 | $this->_individualID = $this->individualCreate(); |
fb32de45 | 59 | $this->_tag = $this->tagCreate(); |
6a488035 | 60 | $this->_tagID = $this->_tag['id']; |
678fbf79 | 61 | $this->_householdID = $this->houseHoldCreate(); |
62 | $this->_organizationID = $this->organizationCreate(); | |
6a488035 TO |
63 | } |
64 | ||
00be9182 | 65 | public function testAddEmptyParams() { |
fc928539 | 66 | $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params = array(), |
67 | 'contact_id is a required field' | |
68 | ); | |
6a488035 TO |
69 | } |
70 | ||
00be9182 | 71 | public function testAddWithoutTagID() { |
6a488035 TO |
72 | $params = array( |
73 | 'contact_id' => $this->_individualID, | |
6a488035 | 74 | ); |
fc928539 | 75 | $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params, |
76 | 'tag_id is a required field' | |
77 | ); | |
6a488035 TO |
78 | } |
79 | ||
00be9182 | 80 | public function testAddWithoutContactID() { |
6a488035 TO |
81 | $params = array( |
82 | 'tag_id' => $this->_tagID, | |
6a488035 | 83 | ); |
fc928539 | 84 | $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params, |
85 | 'contact_id is a required field'); | |
6a488035 TO |
86 | } |
87 | ||
00be9182 | 88 | public function testContactEntityTagCreate() { |
6a488035 TO |
89 | $params = array( |
90 | 'contact_id' => $this->_individualID, | |
91 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
92 | ); |
93 | ||
a828d7b8 | 94 | $result = $this->callAPISuccess('entity_tag', 'create', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
95 | $this->assertEquals($result['added'], 1); |
96 | } | |
97 | ||
00be9182 | 98 | public function testAddDouble() { |
92915c55 | 99 | $individualId = $this->_individualID; |
6a488035 | 100 | $organizationId = $this->_organizationID; |
92915c55 TO |
101 | $tagID = $this->_tagID; |
102 | $params = array( | |
6a488035 TO |
103 | 'contact_id' => $individualId, |
104 | 'tag_id' => $tagID, | |
6a488035 TO |
105 | ); |
106 | ||
fc928539 | 107 | $result = $this->callAPISuccess('entity_tag', 'create', $params); |
6a488035 | 108 | |
6a488035 TO |
109 | $this->assertEquals($result['added'], 1); |
110 | ||
111 | $params = array( | |
112 | 'contact_id_i' => $individualId, | |
113 | 'contact_id_o' => $organizationId, | |
114 | 'tag_id' => $tagID, | |
6a488035 TO |
115 | ); |
116 | ||
fc928539 | 117 | $result = $this->callAPISuccess('entity_tag', 'create', $params); |
6a488035 TO |
118 | $this->assertEquals($result['added'], 1); |
119 | $this->assertEquals($result['not_added'], 1); | |
120 | } | |
121 | ||
28a04ea9 | 122 | /** |
fe482240 | 123 | * civicrm_entity_tag_get methods. |
28a04ea9 | 124 | */ |
00be9182 | 125 | public function testGetNoEntityID() { |
6a488035 | 126 | $ContactId = $this->_individualID; |
92915c55 TO |
127 | $tagID = $this->_tagID; |
128 | $params = array( | |
6a488035 TO |
129 | 'contact_id' => $ContactId, |
130 | 'tag_id' => $tagID, | |
6a488035 TO |
131 | ); |
132 | ||
fc928539 | 133 | $individualEntity = $this->callAPISuccess('entity_tag', 'create', $params); |
6a488035 | 134 | $this->assertEquals($individualEntity['added'], 1); |
283c85e9 | 135 | $result = $this->callAPISuccess($this->_entity, 'get', array('sequential' => 1, 'tag_id' => $tagID)); |
136 | $this->assertEquals($ContactId, $result['values'][0]['entity_id']); | |
6a488035 TO |
137 | } |
138 | ||
00be9182 | 139 | public function testIndividualEntityTagGet() { |
6a488035 | 140 | $contactId = $this->_individualID; |
92915c55 TO |
141 | $tagID = $this->_tagID; |
142 | $params = array( | |
6a488035 TO |
143 | 'contact_id' => $contactId, |
144 | 'tag_id' => $tagID, | |
6a488035 TO |
145 | ); |
146 | ||
fb32de45 | 147 | $individualEntity = $this->callAPIAndDocument('entity_tag', 'create', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
148 | $this->assertEquals($individualEntity['added'], 1); |
149 | ||
150 | $paramsEntity = array( | |
151 | 'contact_id' => $contactId, | |
6a488035 | 152 | ); |
a828d7b8 | 153 | $entity = $this->callAPIAndDocument('entity_tag', 'get', $paramsEntity, __FUNCTION__, __FILE__); |
6a488035 TO |
154 | } |
155 | ||
00be9182 | 156 | public function testHouseholdEntityGet() { |
6a488035 | 157 | $ContactId = $this->_householdID; |
92915c55 TO |
158 | $tagID = $this->_tagID; |
159 | $params = array( | |
6a488035 TO |
160 | 'contact_id' => $ContactId, |
161 | 'tag_id' => $tagID, | |
6a488035 TO |
162 | ); |
163 | ||
fc928539 | 164 | $householdEntity = $this->callAPISuccess('entity_tag', 'create', $params); |
6a488035 | 165 | $this->assertEquals($householdEntity['added'], 1); |
6a488035 TO |
166 | } |
167 | ||
00be9182 | 168 | public function testOrganizationEntityGet() { |
6a488035 | 169 | $ContactId = $this->_organizationID; |
92915c55 TO |
170 | $tagID = $this->_tagID; |
171 | $params = array( | |
6a488035 TO |
172 | 'contact_id' => $ContactId, |
173 | 'tag_id' => $tagID, | |
6a488035 TO |
174 | ); |
175 | ||
fc928539 | 176 | $organizationEntity = $this->callAPISuccess('entity_tag', 'create', $params); |
6a488035 TO |
177 | $this->assertEquals($organizationEntity['added'], 1); |
178 | ||
179 | $paramsEntity = array('contact_id' => $ContactId); | |
fc928539 | 180 | $entity = $this->callAPISuccess('entity_tag', 'get', $paramsEntity); |
6a488035 TO |
181 | } |
182 | ||
28a04ea9 | 183 | /** |
fe482240 | 184 | * civicrm_entity_tag_Delete methods. |
28a04ea9 | 185 | */ |
00be9182 | 186 | public function testEntityTagDeleteNoTagId() { |
6a488035 TO |
187 | $entityTagParams = array( |
188 | 'contact_id_i' => $this->_individualID, | |
189 | 'contact_id_h' => $this->_householdID, | |
190 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
191 | ); |
192 | $this->entityTagAdd($entityTagParams); | |
193 | ||
194 | $params = array( | |
195 | 'contact_id_i' => $this->_individualID, | |
196 | 'contact_id_h' => $this->_householdID, | |
6a488035 TO |
197 | ); |
198 | ||
c3a18b64 WDC |
199 | $result = $this->callAPISuccess('entity_tag', 'delete', $params); |
200 | ||
201 | $this->assertEquals($result['not_removed'], 0); | |
202 | $this->assertEquals($result['removed'], 2); | |
203 | $this->assertEquals($result['total_count'], 2); | |
6a488035 TO |
204 | } |
205 | ||
00be9182 | 206 | public function testEntityTagDeleteINDHH() { |
6a488035 TO |
207 | $entityTagParams = array( |
208 | 'contact_id_i' => $this->_individualID, | |
209 | 'contact_id_h' => $this->_householdID, | |
210 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
211 | ); |
212 | $this->entityTagAdd($entityTagParams); | |
213 | ||
214 | $params = array( | |
215 | 'contact_id_i' => $this->_individualID, | |
216 | 'contact_id_h' => $this->_householdID, | |
217 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
218 | ); |
219 | ||
fc928539 | 220 | $result = $this->callAPISuccess('entity_tag', 'delete', $params); |
6a488035 | 221 | |
6a488035 TO |
222 | $this->assertEquals($result['removed'], 2); |
223 | } | |
224 | ||
00be9182 | 225 | public function testEntityTagDeleteHH() { |
6a488035 TO |
226 | $entityTagParams = array( |
227 | 'contact_id_i' => $this->_individualID, | |
228 | 'contact_id_h' => $this->_householdID, | |
229 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
230 | ); |
231 | $this->entityTagAdd($entityTagParams); | |
232 | ||
233 | $params = array( | |
234 | 'contact_id_h' => $this->_householdID, | |
235 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
236 | ); |
237 | ||
fc928539 | 238 | $result = $this->callAPIAndDocument('entity_tag', 'delete', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
239 | $this->assertEquals($result['removed'], 1); |
240 | } | |
241 | ||
00be9182 | 242 | public function testEntityTagDeleteHHORG() { |
6a488035 TO |
243 | $entityTagParams = array( |
244 | 'contact_id_i' => $this->_individualID, | |
245 | 'contact_id_h' => $this->_householdID, | |
246 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
247 | ); |
248 | $this->entityTagAdd($entityTagParams); | |
249 | ||
250 | $params = array( | |
251 | 'contact_id_h' => $this->_householdID, | |
252 | 'contact_id_o' => $this->_organizationID, | |
253 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
254 | ); |
255 | ||
fc928539 | 256 | $result = $this->callAPISuccess('entity_tag', 'delete', $params); |
6a488035 TO |
257 | $this->assertEquals($result['removed'], 1); |
258 | $this->assertEquals($result['not_removed'], 1); | |
259 | } | |
260 | ||
28a04ea9 | 261 | /** |
fe482240 | 262 | * civicrm_tag_entities_get methods. |
28a04ea9 | 263 | */ |
00be9182 | 264 | public function testCommonContactEntityTagAdd() { |
6a488035 TO |
265 | $params = array( |
266 | 'contact_id' => $this->_individualID, | |
267 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
268 | ); |
269 | ||
fc928539 | 270 | $individualEntity = $this->callAPISuccess('entity_tag', 'create', $params); |
6a488035 TO |
271 | $this->assertEquals($individualEntity['added'], 1); |
272 | } | |
273 | ||
6a488035 | 274 | |
00be9182 | 275 | public function testEntityTagCommonDeleteINDHH() { |
6a488035 TO |
276 | $entityTagParams = array( |
277 | 'contact_id_i' => $this->_individualID, | |
278 | 'contact_id_h' => $this->_householdID, | |
279 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
280 | ); |
281 | $this->entityTagAdd($entityTagParams); | |
282 | ||
283 | $params = array( | |
284 | 'contact_id_i' => $this->_individualID, | |
285 | 'contact_id_h' => $this->_householdID, | |
286 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
287 | ); |
288 | ||
fc928539 | 289 | $result = $this->callAPISuccess('entity_tag', 'delete', $params); |
6a488035 TO |
290 | $this->assertEquals($result['removed'], 2); |
291 | } | |
292 | ||
00be9182 | 293 | public function testEntityTagCommonDeleteHH() { |
6a488035 TO |
294 | $entityTagParams = array( |
295 | 'contact_id_i' => $this->_individualID, | |
296 | 'contact_id_h' => $this->_householdID, | |
297 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
298 | ); |
299 | $this->entityTagAdd($entityTagParams); | |
300 | ||
301 | $params = array( | |
302 | 'contact_id_h' => $this->_householdID, | |
303 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
304 | ); |
305 | ||
fc928539 | 306 | $result = $this->callAPISuccess('entity_tag', 'delete', $params); |
6a488035 TO |
307 | $this->assertEquals($result['removed'], 1); |
308 | } | |
309 | ||
00be9182 | 310 | public function testEntityTagCommonDeleteHHORG() { |
6a488035 TO |
311 | $entityTagParams = array( |
312 | 'contact_id_i' => $this->_individualID, | |
313 | 'contact_id_h' => $this->_householdID, | |
314 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
315 | ); |
316 | $this->entityTagAdd($entityTagParams); | |
317 | ||
318 | $params = array( | |
319 | 'contact_id_h' => $this->_householdID, | |
320 | 'contact_id_o' => $this->_organizationID, | |
321 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
322 | ); |
323 | ||
fc928539 | 324 | $result = $this->callAPISuccess('entity_tag', 'delete', $params); |
6a488035 TO |
325 | $this->assertEquals($result['removed'], 1); |
326 | $this->assertEquals($result['not_removed'], 1); | |
327 | } | |
96025800 | 328 | |
6a488035 | 329 | } |