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 | 27 | |
6a488035 TO |
28 | /** |
29 | * Test APIv3 civicrm_entity_tag_* functions | |
30 | * | |
92915c55 TO |
31 | * @package CiviCRM_APIv3 |
32 | * @subpackage API_Core | |
6a488035 TO |
33 | */ |
34 | ||
35 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
4cbe18b8 EM |
36 | |
37 | /** | |
24602943 | 38 | * Class api_v3_EntityTagTest. |
4cbe18b8 | 39 | */ |
6a488035 TO |
40 | class api_v3_EntityTagTest extends CiviUnitTestCase { |
41 | ||
24602943 | 42 | /** |
43 | * @var int | |
44 | */ | |
6a488035 TO |
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 | |
24602943 | 53 | /** |
54 | * Basic parameters for create. | |
55 | * | |
56 | * @var array | |
57 | */ | |
58 | protected $_params = array(); | |
6a488035 | 59 | |
24602943 | 60 | /** |
61 | * Set up for test. | |
62 | */ | |
00be9182 | 63 | public function setUp() { |
6a488035 | 64 | parent::setUp(); |
56b010a3 | 65 | $this->useTransaction(TRUE); |
6a488035 | 66 | |
e4d5f1e2 | 67 | $this->_individualID = $this->individualCreate(); |
fb32de45 | 68 | $this->_tag = $this->tagCreate(); |
6a488035 | 69 | $this->_tagID = $this->_tag['id']; |
678fbf79 | 70 | $this->_householdID = $this->houseHoldCreate(); |
71 | $this->_organizationID = $this->organizationCreate(); | |
24602943 | 72 | $this->_params = array( |
73 | 'contact_id' => $this->_individualID, | |
74 | 'tag_id' => $this->_tagID, | |
fc928539 | 75 | ); |
6a488035 TO |
76 | } |
77 | ||
24602943 | 78 | /** |
79 | * Test required parameters. | |
80 | * | |
81 | * These failure tests are low value and may not be worth putting in v4. | |
82 | */ | |
83 | public function testFailureTests() { | |
84 | $this->callAPIFailure('entity_tag', 'create', array('contact_id' => $this->_individualID), | |
fc928539 | 85 | 'tag_id is a required field' |
86 | ); | |
24602943 | 87 | $this->callAPIFailure('entity_tag', 'create', array('tag_id' => $this->_tagID), |
88 | 'contact_id is a required field' | |
6a488035 | 89 | ); |
6a488035 TO |
90 | } |
91 | ||
24602943 | 92 | /** |
93 | * Test basic create. | |
94 | */ | |
00be9182 | 95 | public function testContactEntityTagCreate() { |
24602943 | 96 | $result = $this->callAPISuccess('entity_tag', 'create', $this->_params); |
6a488035 TO |
97 | $this->assertEquals($result['added'], 1); |
98 | } | |
99 | ||
24602943 | 100 | /** |
101 | * Test multiple add functionality. | |
102 | * | |
103 | * This needs review for api v4 as it makes for a very non standard api. | |
104 | */ | |
00be9182 | 105 | public function testAddDouble() { |
6a488035 | 106 | |
24602943 | 107 | $result = $this->callAPISuccess('entity_tag', 'create', $this->_params); |
6a488035 TO |
108 | $this->assertEquals($result['added'], 1); |
109 | ||
110 | $params = array( | |
24602943 | 111 | 'contact_id_i' => $this->_individualID, |
112 | 'contact_id_o' => $this->_organizationID, | |
113 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
114 | ); |
115 | ||
fc928539 | 116 | $result = $this->callAPISuccess('entity_tag', 'create', $params); |
6a488035 TO |
117 | $this->assertEquals($result['added'], 1); |
118 | $this->assertEquals($result['not_added'], 1); | |
119 | } | |
120 | ||
28a04ea9 | 121 | /** |
24602943 | 122 | * Test that get works without an entity. |
28a04ea9 | 123 | */ |
00be9182 | 124 | public function testGetNoEntityID() { |
24602943 | 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']); | |
6a488035 TO |
128 | } |
129 | ||
24602943 | 130 | /** |
131 | * Basic get functionality test. | |
132 | */ | |
00be9182 | 133 | public function testIndividualEntityTagGet() { |
24602943 | 134 | $individualEntity = $this->callAPISuccess('entity_tag', 'create', $this->_params); |
6a488035 TO |
135 | $this->assertEquals($individualEntity['added'], 1); |
136 | ||
137 | $paramsEntity = array( | |
24602943 | 138 | 'contact_id' => $this->_individualID, |
6a488035 | 139 | ); |
24602943 | 140 | $this->callAPIAndDocument('entity_tag', 'get', $paramsEntity, __FUNCTION__, __FILE__); |
6a488035 TO |
141 | } |
142 | ||
24602943 | 143 | /** |
144 | * Test tag can be added to a household. | |
145 | */ | |
146 | public function testHouseholdEntityCreate() { | |
92915c55 | 147 | $params = array( |
24602943 | 148 | 'contact_id' => $this->_householdID, |
149 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
150 | ); |
151 | ||
fc928539 | 152 | $householdEntity = $this->callAPISuccess('entity_tag', 'create', $params); |
6a488035 | 153 | $this->assertEquals($householdEntity['added'], 1); |
6a488035 TO |
154 | } |
155 | ||
24602943 | 156 | /** |
157 | * Test tag can be added to an organization. | |
158 | */ | |
00be9182 | 159 | public function testOrganizationEntityGet() { |
24602943 | 160 | |
92915c55 | 161 | $params = array( |
24602943 | 162 | 'contact_id' => $this->_organizationID, |
163 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
164 | ); |
165 | ||
fc928539 | 166 | $organizationEntity = $this->callAPISuccess('entity_tag', 'create', $params); |
6a488035 TO |
167 | $this->assertEquals($organizationEntity['added'], 1); |
168 | ||
24602943 | 169 | $this->callAPISuccess('entity_tag', 'getsingle', array('contact_id' => $this->_organizationID)); |
6a488035 TO |
170 | } |
171 | ||
28a04ea9 | 172 | /** |
24602943 | 173 | * Civicrm_entity_tag_Delete methods. |
28a04ea9 | 174 | */ |
00be9182 | 175 | public function testEntityTagDeleteNoTagId() { |
6a488035 TO |
176 | $entityTagParams = array( |
177 | 'contact_id_i' => $this->_individualID, | |
178 | 'contact_id_h' => $this->_householdID, | |
179 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
180 | ); |
181 | $this->entityTagAdd($entityTagParams); | |
182 | ||
183 | $params = array( | |
184 | 'contact_id_i' => $this->_individualID, | |
185 | 'contact_id_h' => $this->_householdID, | |
6a488035 TO |
186 | ); |
187 | ||
c3a18b64 WDC |
188 | $result = $this->callAPISuccess('entity_tag', 'delete', $params); |
189 | ||
190 | $this->assertEquals($result['not_removed'], 0); | |
191 | $this->assertEquals($result['removed'], 2); | |
192 | $this->assertEquals($result['total_count'], 2); | |
6a488035 TO |
193 | } |
194 | ||
00be9182 | 195 | public function testEntityTagDeleteINDHH() { |
6a488035 TO |
196 | $entityTagParams = array( |
197 | 'contact_id_i' => $this->_individualID, | |
198 | 'contact_id_h' => $this->_householdID, | |
199 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
200 | ); |
201 | $this->entityTagAdd($entityTagParams); | |
202 | ||
203 | $params = array( | |
204 | 'contact_id_i' => $this->_individualID, | |
205 | 'contact_id_h' => $this->_householdID, | |
206 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
207 | ); |
208 | ||
fc928539 | 209 | $result = $this->callAPISuccess('entity_tag', 'delete', $params); |
6a488035 | 210 | |
6a488035 TO |
211 | $this->assertEquals($result['removed'], 2); |
212 | } | |
213 | ||
00be9182 | 214 | public function testEntityTagDeleteHH() { |
6a488035 TO |
215 | $entityTagParams = array( |
216 | 'contact_id_i' => $this->_individualID, | |
217 | 'contact_id_h' => $this->_householdID, | |
218 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
219 | ); |
220 | $this->entityTagAdd($entityTagParams); | |
221 | ||
222 | $params = array( | |
223 | 'contact_id_h' => $this->_householdID, | |
224 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
225 | ); |
226 | ||
fc928539 | 227 | $result = $this->callAPIAndDocument('entity_tag', 'delete', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
228 | $this->assertEquals($result['removed'], 1); |
229 | } | |
230 | ||
00be9182 | 231 | public function testEntityTagDeleteHHORG() { |
6a488035 TO |
232 | $entityTagParams = array( |
233 | 'contact_id_i' => $this->_individualID, | |
234 | 'contact_id_h' => $this->_householdID, | |
235 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
236 | ); |
237 | $this->entityTagAdd($entityTagParams); | |
238 | ||
239 | $params = array( | |
240 | 'contact_id_h' => $this->_householdID, | |
241 | 'contact_id_o' => $this->_organizationID, | |
242 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
243 | ); |
244 | ||
fc928539 | 245 | $result = $this->callAPISuccess('entity_tag', 'delete', $params); |
6a488035 TO |
246 | $this->assertEquals($result['removed'], 1); |
247 | $this->assertEquals($result['not_removed'], 1); | |
248 | } | |
249 | ||
00be9182 | 250 | public function testEntityTagCommonDeleteINDHH() { |
6a488035 TO |
251 | $entityTagParams = array( |
252 | 'contact_id_i' => $this->_individualID, | |
253 | 'contact_id_h' => $this->_householdID, | |
254 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
255 | ); |
256 | $this->entityTagAdd($entityTagParams); | |
257 | ||
258 | $params = array( | |
259 | 'contact_id_i' => $this->_individualID, | |
260 | 'contact_id_h' => $this->_householdID, | |
261 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
262 | ); |
263 | ||
fc928539 | 264 | $result = $this->callAPISuccess('entity_tag', 'delete', $params); |
6a488035 TO |
265 | $this->assertEquals($result['removed'], 2); |
266 | } | |
267 | ||
00be9182 | 268 | public function testEntityTagCommonDeleteHH() { |
6a488035 TO |
269 | $entityTagParams = array( |
270 | 'contact_id_i' => $this->_individualID, | |
271 | 'contact_id_h' => $this->_householdID, | |
272 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
273 | ); |
274 | $this->entityTagAdd($entityTagParams); | |
275 | ||
276 | $params = array( | |
277 | 'contact_id_h' => $this->_householdID, | |
278 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
279 | ); |
280 | ||
fc928539 | 281 | $result = $this->callAPISuccess('entity_tag', 'delete', $params); |
6a488035 TO |
282 | $this->assertEquals($result['removed'], 1); |
283 | } | |
284 | ||
00be9182 | 285 | public function testEntityTagCommonDeleteHHORG() { |
6a488035 TO |
286 | $entityTagParams = array( |
287 | 'contact_id_i' => $this->_individualID, | |
288 | 'contact_id_h' => $this->_householdID, | |
289 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
290 | ); |
291 | $this->entityTagAdd($entityTagParams); | |
292 | ||
293 | $params = array( | |
294 | 'contact_id_h' => $this->_householdID, | |
295 | 'contact_id_o' => $this->_organizationID, | |
296 | 'tag_id' => $this->_tagID, | |
6a488035 TO |
297 | ); |
298 | ||
fc928539 | 299 | $result = $this->callAPISuccess('entity_tag', 'delete', $params); |
6a488035 TO |
300 | $this->assertEquals($result['removed'], 1); |
301 | $this->assertEquals($result['not_removed'], 1); | |
302 | } | |
96025800 | 303 | |
6a488035 | 304 | } |