Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /** | |
d177a2a6 | 3 | * @file |
6a488035 TO |
4 | * File for the TestActivity class |
5 | * | |
6 | * (PHP 5) | |
7 | * | |
6c6e6187 TO |
8 | * @author Walt Haas <walt@dharmatech.org> (801) 534-1262 |
9 | * @copyright Copyright CiviCRM LLC (C) 2009 | |
10 | * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html | |
6a488035 | 11 | * GNU Affero General Public License version 3 |
6c6e6187 TO |
12 | * @version $Id: ActivityTest.php 31254 2010-12-15 10:09:29Z eileen $ |
13 | * @package CiviCRM | |
6a488035 TO |
14 | * |
15 | * This file is part of CiviCRM | |
16 | * | |
17 | * CiviCRM is free software; you can redistribute it and/or | |
18 | * modify it under the terms of the GNU Affero General Public License | |
19 | * as published by the Free Software Foundation; either version 3 of | |
20 | * the License, or (at your option) any later version. | |
21 | * | |
22 | * CiviCRM is distributed in the hope that it will be useful, | |
23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25 | * GNU Affero General Public License for more details. | |
26 | * | |
27 | * You should have received a copy of the GNU Affero General Public | |
28 | * License along with this program. If not, see | |
29 | * <http://www.gnu.org/licenses/>. | |
30 | */ | |
31 | ||
32 | /** | |
33 | * Include class definitions | |
34 | */ | |
6a488035 TO |
35 | |
36 | /** | |
d177a2a6 | 37 | * Test APIv3 civicrm_activity_* functions |
6a488035 | 38 | * |
6c6e6187 TO |
39 | * @package CiviCRM_APIv3 |
40 | * @subpackage API_Activity | |
acb109b7 | 41 | * @group headless |
6a488035 | 42 | */ |
6a488035 TO |
43 | class api_v3_ActivityTest extends CiviUnitTestCase { |
44 | protected $_params; | |
45 | protected $_params2; | |
46 | protected $_entity = 'activity'; | |
47 | protected $_apiversion = 3; | |
48 | protected $test_activity_type_value; | |
b8a3da18 | 49 | protected $_contactID; |
9f1b81e0 | 50 | |
6a488035 | 51 | /** |
d177a2a6 | 52 | * Test setup for every test. |
6a488035 | 53 | * |
d177a2a6 EM |
54 | * Connect to the database, truncate the tables that will be used |
55 | * and redirect stdin to a temporary file | |
6a488035 TO |
56 | */ |
57 | public function setUp() { | |
e3aa0dd1 | 58 | // Connect to the database |
6a488035 | 59 | parent::setUp(); |
6a488035 | 60 | |
b8a3da18 | 61 | $this->_contactID = $this->individualCreate(); |
6a488035 | 62 | //create activity types |
7b1dc1f6 | 63 | $this->test_activity_type_value = 9999; |
b8a3da18 | 64 | $activityTypes = $this->callAPISuccess('option_value', 'create', array( |
65 | 'option_group_id' => 2, | |
66 | 'name' => 'Test activity type', | |
67 | 'label' => 'Test activity type', | |
7b1dc1f6 | 68 | 'value' => $this->test_activity_type_value, |
21dfd5f5 | 69 | 'sequential' => 1, |
b8a3da18 | 70 | )); |
6a488035 TO |
71 | $this->test_activity_type_id = $activityTypes['id']; |
72 | $this->_params = array( | |
b8a3da18 | 73 | 'source_contact_id' => $this->_contactID, |
7b1dc1f6 | 74 | 'activity_type_id' => 'Test activity type', |
6a488035 TO |
75 | 'subject' => 'test activity type id', |
76 | 'activity_date_time' => '2011-06-02 14:36:13', | |
77 | 'status_id' => 2, | |
78 | 'priority_id' => 1, | |
79 | 'duration' => 120, | |
e3aa0dd1 | 80 | 'location' => 'Pennsylvania', |
6a488035 | 81 | 'details' => 'a test activity', |
6a488035 TO |
82 | ); |
83 | $this->_params2 = array( | |
b8a3da18 | 84 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
85 | 'subject' => 'Eat & drink', |
86 | 'activity_date_time' => date('Ymd'), | |
87 | 'duration' => 120, | |
88 | 'location' => 'Napier', | |
89 | 'details' => 'discuss & eat', | |
90 | 'status_id' => 1, | |
91 | 'activity_type_id' => $this->test_activity_type_value, | |
6a488035 TO |
92 | ); |
93 | // create a logged in USER since the code references it for source_contact_id | |
94 | $this->createLoggedInUser(); | |
95 | } | |
96 | ||
97 | /** | |
98 | * Tears down the fixture, for example, closes a network connection. | |
e3aa0dd1 | 99 | * |
6a488035 | 100 | * This method is called after a test is executed. |
6a488035 | 101 | */ |
00be9182 | 102 | public function tearDown() { |
6a488035 TO |
103 | $tablesToTruncate = array( |
104 | 'civicrm_contact', | |
105 | 'civicrm_activity', | |
b319d00a | 106 | 'civicrm_activity_contact', |
225d474b | 107 | 'civicrm_uf_match', |
6a488035 TO |
108 | ); |
109 | $this->quickCleanup($tablesToTruncate, TRUE); | |
a60c0bc8 SL |
110 | $type = $this->callAPISuccess('optionValue', 'get', array('id' => $this->test_activity_type_id)); |
111 | if (!empty($type['count'])) { | |
112 | $this->callAPISuccess('option_value', 'delete', array('id' => $this->test_activity_type_id)); | |
113 | } | |
6a488035 TO |
114 | } |
115 | ||
116 | /** | |
e3aa0dd1 | 117 | * Check fails with empty array. |
6a488035 | 118 | */ |
00be9182 | 119 | public function testActivityCreateEmpty() { |
e3aa0dd1 | 120 | $this->callAPIFailure('activity', 'create', array()); |
6a488035 TO |
121 | } |
122 | ||
123 | /** | |
eceb18cc | 124 | * Check if required fields are not passed. |
6a488035 | 125 | */ |
00be9182 | 126 | public function testActivityCreateWithoutRequired() { |
6a488035 TO |
127 | $params = array( |
128 | 'subject' => 'this case should fail', | |
129 | 'scheduled_date_time' => date('Ymd'), | |
6a488035 | 130 | ); |
d0e1eff2 | 131 | $result = $this->callAPIFailure('activity', 'create', $params); |
6a488035 TO |
132 | } |
133 | ||
134 | /** | |
d177a2a6 EM |
135 | * Test civicrm_activity_create() with mismatched activity_type_id |
136 | * and activity_name. | |
6a488035 | 137 | */ |
00be9182 | 138 | public function testActivityCreateMismatchNameType() { |
6a488035 | 139 | $params = array( |
b8a3da18 | 140 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
141 | 'subject' => 'Test activity', |
142 | 'activity_date_time' => date('Ymd'), | |
143 | 'duration' => 120, | |
e3aa0dd1 | 144 | 'location' => 'Pennsylvania', |
6a488035 TO |
145 | 'details' => 'a test activity', |
146 | 'status_id' => 1, | |
147 | 'activity_name' => 'Fubar activity type', | |
148 | 'activity_type_id' => 5, | |
149 | 'scheduled_date_time' => date('Ymd'), | |
6a488035 TO |
150 | ); |
151 | ||
d0e1eff2 | 152 | $result = $this->callAPIFailure('activity', 'create', $params); |
6a488035 TO |
153 | } |
154 | ||
155 | /** | |
d177a2a6 | 156 | * Test civicrm_activity_id() with missing source_contact_id is put with the current user. |
6a488035 | 157 | */ |
00be9182 | 158 | public function testActivityCreateWithMissingContactId() { |
6a488035 TO |
159 | $params = array( |
160 | 'subject' => 'Make-it-Happen Meeting', | |
161 | 'activity_date_time' => date('Ymd'), | |
162 | 'duration' => 120, | |
e3aa0dd1 | 163 | 'location' => 'Pennsylvania', |
6a488035 TO |
164 | 'details' => 'a test activity', |
165 | 'status_id' => 1, | |
166 | 'activity_name' => 'Test activity type', | |
6a488035 TO |
167 | ); |
168 | ||
d177a2a6 | 169 | $this->callAPISuccess('activity', 'create', $params); |
6a488035 TO |
170 | } |
171 | ||
c442f1b6 | 172 | /** |
173 | * CRM-20316 this should fail based on validation with no logged in user. | |
174 | * | |
175 | * Since the field is required the validation should reject the default. | |
176 | */ | |
177 | public function testActivityCreateWithMissingContactIdNoLoggedInUser() { | |
178 | CRM_Core_Session::singleton()->set('userID', NULL); | |
179 | $params = array( | |
180 | 'subject' => 'Make-it-Happen Meeting', | |
181 | 'activity_date_time' => date('Ymd'), | |
182 | 'duration' => 120, | |
183 | 'location' => 'Pennsylvania', | |
184 | 'details' => 'a test activity', | |
185 | 'status_id' => 1, | |
186 | 'activity_name' => 'Test activity type', | |
187 | ); | |
188 | ||
189 | $this->callAPIFailure('activity', 'create', $params, 'source_contact_id is not a valid integer'); | |
190 | } | |
191 | ||
6a488035 | 192 | /** |
d177a2a6 | 193 | * Test civicrm_activity_id() with non-numeric source_contact_id. |
6a488035 | 194 | */ |
00be9182 | 195 | public function testActivityCreateWithNonNumericContactId() { |
6a488035 TO |
196 | $params = array( |
197 | 'source_contact_id' => 'fubar', | |
198 | 'subject' => 'Make-it-Happen Meeting', | |
199 | 'activity_date_time' => date('Ymd'), | |
200 | 'duration' => 120, | |
e3aa0dd1 | 201 | 'location' => 'Pennsylvania', |
6a488035 TO |
202 | 'details' => 'a test activity', |
203 | 'status_id' => 1, | |
204 | 'activity_name' => 'Test activity type', | |
6a488035 TO |
205 | ); |
206 | ||
e3aa0dd1 | 207 | $this->callAPIFailure('activity', 'create', $params); |
6a488035 TO |
208 | } |
209 | ||
6a488035 | 210 | /** |
fe482240 EM |
211 | * Ensure that an invalid activity type causes failure. |
212 | * | |
213 | * Oddly enough this test was failing because the creation of the invalid type | |
feb2a730 | 214 | * got added to the set up routine. Probably a mis-fix on a test |
6a488035 | 215 | */ |
00be9182 | 216 | public function testActivityCreateWithNonNumericActivityTypeId() { |
6a488035 | 217 | $params = array( |
b8a3da18 | 218 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
219 | 'subject' => 'Make-it-Happen Meeting', |
220 | 'activity_date_time' => date('Ymd'), | |
221 | 'duration' => 120, | |
e3aa0dd1 | 222 | 'location' => 'Pennsylvania', |
6a488035 TO |
223 | 'details' => 'a test activity', |
224 | 'status_id' => 1, | |
feb2a730 | 225 | 'activity_type_id' => 'Invalid Test activity type', |
6a488035 TO |
226 | ); |
227 | ||
d0e1eff2 | 228 | $result = $this->callAPIFailure('activity', 'create', $params); |
6a488035 TO |
229 | } |
230 | ||
231 | /** | |
e3aa0dd1 | 232 | * Check with incorrect required fields. |
6a488035 | 233 | */ |
00be9182 | 234 | public function testActivityCreateWithUnknownActivityTypeId() { |
6a488035 | 235 | $params = array( |
b8a3da18 | 236 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
237 | 'subject' => 'Make-it-Happen Meeting', |
238 | 'activity_date_time' => date('Ymd'), | |
239 | 'duration' => 120, | |
e3aa0dd1 | 240 | 'location' => 'Pennsylvania', |
6a488035 TO |
241 | 'details' => 'a test activity', |
242 | 'status_id' => 1, | |
243 | 'activity_type_id' => 699, | |
6a488035 TO |
244 | ); |
245 | ||
d0e1eff2 | 246 | $result = $this->callAPIFailure('activity', 'create', $params); |
6a488035 TO |
247 | } |
248 | ||
00be9182 | 249 | public function testActivityCreateWithInvalidPriority() { |
6a488035 | 250 | $params = array( |
b8a3da18 | 251 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
252 | 'subject' => 'Make-it-Happen Meeting', |
253 | 'activity_date_time' => date('Ymd'), | |
254 | 'duration' => 120, | |
e3aa0dd1 | 255 | 'location' => 'Pennsylvania', |
6a488035 TO |
256 | 'details' => 'a test activity', |
257 | 'status_id' => 1, | |
258 | 'priority_id' => 44, | |
259 | 'activity_type_id' => 1, | |
6a488035 TO |
260 | ); |
261 | ||
b8a3da18 | 262 | $result = $this->callAPIFailure('activity', 'create', $params, |
263 | "'44' is not a valid option for field priority_id"); | |
283f988c | 264 | $this->assertEquals('priority_id', $result['error_field']); |
6a488035 TO |
265 | } |
266 | ||
feb2a730 | 267 | |
e3aa0dd1 | 268 | /** |
269 | * Test create succeeds with valid string for priority. | |
270 | */ | |
00be9182 | 271 | public function testActivityCreateWithValidStringPriority() { |
6a488035 | 272 | $params = array( |
b8a3da18 | 273 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
274 | 'subject' => 'Make-it-Happen Meeting', |
275 | 'activity_date_time' => date('Ymd'), | |
276 | 'duration' => 120, | |
e3aa0dd1 | 277 | 'location' => 'Pennsylvania', |
6a488035 TO |
278 | 'details' => 'a test activity', |
279 | 'status_id' => 1, | |
280 | 'priority_id' => 'Urgent', | |
281 | 'activity_type_id' => 1, | |
6a488035 TO |
282 | ); |
283 | ||
b8a3da18 | 284 | $result = $this->callAPISuccess('activity', 'create', $params); |
6a488035 TO |
285 | $this->assertEquals(1, $result['values'][$result['id']]['priority_id']); |
286 | } | |
287 | ||
e3aa0dd1 | 288 | /** |
289 | * Test create fails with invalid priority string. | |
290 | */ | |
00be9182 | 291 | public function testActivityCreateWithInValidStringPriority() { |
6a488035 | 292 | $params = array( |
b8a3da18 | 293 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
294 | 'subject' => 'Make-it-Happen Meeting', |
295 | 'activity_date_time' => date('Ymd'), | |
296 | 'duration' => 120, | |
e3aa0dd1 | 297 | 'location' => 'Pennsylvania', |
6a488035 TO |
298 | 'details' => 'a test activity', |
299 | 'status_id' => 1, | |
300 | 'priority_id' => 'ergUrgent', | |
301 | 'activity_type_id' => 1, | |
6a488035 TO |
302 | ); |
303 | ||
e3aa0dd1 | 304 | $this->callAPIFailure('activity', 'create', $params, |
b8a3da18 | 305 | "'ergUrgent' is not a valid option for field priority_id"); |
6a488035 TO |
306 | } |
307 | ||
308 | /** | |
e3aa0dd1 | 309 | * Test civicrm_activity_create() with valid parameters. |
6a488035 | 310 | */ |
00be9182 | 311 | public function testActivityCreate() { |
6a488035 | 312 | |
e3aa0dd1 | 313 | $this->callAPISuccess('activity', 'create', $this->_params); |
b8a3da18 | 314 | $result = $this->callAPISuccess('activity', 'get', $this->_params); |
e3aa0dd1 | 315 | $this->assertEquals($result['values'][$result['id']]['duration'], 120); |
316 | $this->assertEquals($result['values'][$result['id']]['subject'], 'test activity type id'); | |
317 | $this->assertEquals($result['values'][$result['id']]['activity_date_time'], '2011-06-02 14:36:13'); | |
318 | $this->assertEquals($result['values'][$result['id']]['location'], 'Pennsylvania'); | |
319 | $this->assertEquals($result['values'][$result['id']]['details'], 'a test activity'); | |
320 | $this->assertEquals($result['values'][$result['id']]['status_id'], 2); | |
321 | $this->assertEquals($result['values'][$result['id']]['id'], $result['id']); | |
6a488035 TO |
322 | } |
323 | ||
324 | /** | |
d177a2a6 | 325 | * Test civicrm_activity_create() with valid parameters - use type_id. |
6a488035 | 326 | */ |
00be9182 | 327 | public function testActivityCreateCampaignTypeID() { |
07fd63f5 | 328 | $this->enableCiviCampaign(); |
6a488035 | 329 | |
6a488035 | 330 | $params = array( |
b8a3da18 | 331 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
332 | 'subject' => 'Make-it-Happen Meeting', |
333 | 'activity_date_time' => '20110316', | |
334 | 'duration' => 120, | |
e3aa0dd1 | 335 | 'location' => 'Pennsylvania', |
6a488035 TO |
336 | 'details' => 'a test activity', |
337 | 'status_id' => 1, | |
338 | 'activity_type_id' => 29, | |
6a488035 TO |
339 | ); |
340 | ||
b8a3da18 | 341 | $result = $this->callAPISuccess('activity', 'create', $params); |
6a488035 | 342 | |
f20dc314 | 343 | $result = $this->callAPISuccess('activity', 'getsingle', array('id' => $result['id'])); |
344 | $this->assertEquals($result['duration'], 120); | |
345 | $this->assertEquals($result['subject'], 'Make-it-Happen Meeting'); | |
346 | $this->assertEquals($result['activity_date_time'], '2011-03-16 00:00:00'); | |
347 | $this->assertEquals($result['location'], 'Pennsylvania'); | |
348 | $this->assertEquals($result['details'], 'a test activity'); | |
349 | $this->assertEquals($result['status_id'], 1); | |
350 | ||
351 | $priorities = $this->callAPISuccess('activity', 'getoptions', array('field' => 'priority_id')); | |
352 | $this->assertEquals($result['priority_id'], array_search('Normal', $priorities['values'])); | |
6a488035 TO |
353 | } |
354 | ||
e3aa0dd1 | 355 | /** |
356 | * Test get returns target and assignee contacts. | |
357 | */ | |
00be9182 | 358 | public function testActivityReturnTargetAssignee() { |
6a488035 | 359 | |
5c49fee0 | 360 | $description = "Demonstrates setting & retrieving activity target & source."; |
92915c55 TO |
361 | $subfile = "GetTargetandAssignee"; |
362 | $params = array( | |
b8a3da18 | 363 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
364 | 'subject' => 'Make-it-Happen Meeting', |
365 | 'activity_date_time' => '20110316', | |
366 | 'duration' => 120, | |
e3aa0dd1 | 367 | 'location' => 'Pennsylvania', |
6a488035 TO |
368 | 'details' => 'a test activity', |
369 | 'status_id' => 1, | |
370 | 'activity_type_id' => 1, | |
6a488035 | 371 | 'priority_id' => 1, |
b8a3da18 | 372 | 'target_contact_id' => $this->_contactID, |
373 | 'assignee_contact_id' => $this->_contactID, | |
6a488035 TO |
374 | ); |
375 | ||
9f1b81e0 | 376 | $result = $this->callAPIAndDocument('activity', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); |
92915c55 | 377 | $result = $this->callAPISuccess('activity', 'get', array( |
c301f76e | 378 | 'id' => $result['id'], |
379 | 'version' => $this->_apiversion, | |
380 | 'return.assignee_contact_id' => 1, | |
381 | 'return.target_contact_id' => 1, | |
382 | )); | |
6a488035 | 383 | |
e3aa0dd1 | 384 | $this->assertEquals($this->_contactID, $result['values'][$result['id']]['assignee_contact_id'][0]); |
385 | $this->assertEquals($this->_contactID, $result['values'][$result['id']]['target_contact_id'][0]); | |
6a488035 TO |
386 | } |
387 | ||
db6e8cb4 CW |
388 | /** |
389 | * Test get returns target and assignee contact names. | |
390 | */ | |
391 | public function testActivityReturnTargetAssigneeName() { | |
392 | ||
393 | $description = "Demonstrates retrieving activity target & source contact names."; | |
394 | $subfile = "GetTargetandAssigneeName"; | |
395 | $target1 = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'first_name' => 'A', 'last_name' => 'Cat')); | |
396 | $target2 = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'first_name' => 'B', 'last_name' => 'Good')); | |
397 | $assignee = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'first_name' => 'C', 'last_name' => 'Shore')); | |
398 | $source = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'first_name' => 'D', 'last_name' => 'Bug')); | |
399 | ||
400 | $params = array( | |
401 | 'source_contact_id' => $source['id'], | |
402 | 'subject' => 'Make-it-Happen Meeting', | |
403 | 'activity_date_time' => '20170316', | |
404 | 'status_id' => 1, | |
405 | 'activity_type_id' => 1, | |
406 | 'target_contact_id' => array($target1['id'], $target2['id']), | |
407 | 'assignee_contact_id' => $assignee['id'], | |
408 | ); | |
409 | ||
410 | $result = $this->callAPISuccess('activity', 'create', $params); | |
411 | $result = $this->callAPIAndDocument('activity', 'getsingle', array( | |
412 | 'id' => $result['id'], | |
413 | 'return' => array('source_contact_name', 'target_contact_name', 'assignee_contact_name', 'subject'), | |
414 | ), __FUNCTION__, __FILE__, $description, $subfile); | |
415 | ||
416 | $this->assertEquals($params['subject'], $result['subject']); | |
417 | $this->assertEquals($source['id'], $result['source_contact_id']); | |
418 | $this->assertEquals('D Bug', $result['source_contact_name']); | |
419 | $this->assertEquals('A Cat', $result['target_contact_name'][$target1['id']]); | |
420 | $this->assertEquals('B Good', $result['target_contact_name'][$target2['id']]); | |
421 | $this->assertEquals('C Shore', $result['assignee_contact_name'][$assignee['id']]); | |
422 | $this->assertEquals($assignee['id'], $result['assignee_contact_id'][0]); | |
423 | } | |
424 | ||
6a488035 | 425 | /** |
d177a2a6 | 426 | * Test civicrm_activity_create() with valid parameters and custom data. |
6a488035 | 427 | */ |
00be9182 | 428 | public function testActivityCreateCustom() { |
6a488035 TO |
429 | $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); |
430 | $params = $this->_params; | |
431 | $params['custom_' . $ids['custom_field_id']] = "custom string"; | |
9f1b81e0 | 432 | $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__); |
92915c55 | 433 | $result = $this->callAPISuccess($this->_entity, 'get', array( |
c301f76e | 434 | 'return.custom_' . $ids['custom_field_id'] => 1, |
c301f76e | 435 | 'id' => $result['id'], |
436 | )); | |
6a488035 TO |
437 | $this->assertEquals("custom string", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); |
438 | ||
439 | $this->customFieldDelete($ids['custom_field_id']); | |
440 | $this->customGroupDelete($ids['custom_group_id']); | |
441 | } | |
442 | ||
7b1dc1f6 PN |
443 | /** |
444 | * Test civicrm_activity_create() using example code. | |
445 | */ | |
446 | public function testActivityCreateExample() { | |
447 | require_once 'api/v3/examples/Activity/Create.php'; | |
448 | $result = activity_create_example(); | |
449 | $expectedResult = activity_create_expectedresult(); | |
450 | $this->assertEquals($result, $expectedResult); | |
451 | } | |
452 | ||
b62bc939 EM |
453 | /** |
454 | * Test civicrm_activity_create() with valid parameters and custom data. | |
455 | */ | |
456 | public function testActivityCreateCustomSubType() { | |
457 | $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); | |
458 | $this->callAPISuccess('CustomGroup', 'create', array( | |
459 | 'extends_entity_column_value' => $this->test_activity_type_value, | |
460 | 'id' => $ids['custom_group_id'], | |
461 | 'extends' => 'Activity', | |
462 | 'is_active' => TRUE, | |
463 | )); | |
464 | $params = $this->_params; | |
465 | $params['custom_' . $ids['custom_field_id']] = "custom string"; | |
466 | $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__); | |
467 | $result = $this->callAPISuccess($this->_entity, 'get', array( | |
468 | 'return.custom_' . $ids['custom_field_id'] => 1, | |
469 | 'id' => $result['id'], | |
470 | )); | |
471 | $this->assertEquals("custom string", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']]); | |
472 | ||
473 | $this->customFieldDelete($ids['custom_field_id']); | |
474 | $this->customGroupDelete($ids['custom_group_id']); | |
475 | } | |
476 | ||
6a488035 | 477 | /** |
d177a2a6 | 478 | * Test civicrm_activity_create() with valid parameters and custom data. |
6a488035 | 479 | */ |
00be9182 | 480 | public function testActivityCreateCustomContactRefField() { |
6a488035 | 481 | |
b8a3da18 | 482 | $this->callAPISuccess('contact', 'create', array('id' => $this->_contactID, 'sort_name' => 'Contact, Test')); |
92915c55 | 483 | $subfile = 'ContactRefCustomField'; |
5c49fee0 | 484 | $description = "Demonstrates create with Contact Reference Custom Field."; |
92915c55 TO |
485 | $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); |
486 | $params = array( | |
6a488035 TO |
487 | 'custom_group_id' => $ids['custom_group_id'], |
488 | 'name' => 'Worker_Lookup', | |
489 | 'label' => 'Worker Lookup', | |
490 | 'html_type' => 'Autocomplete-Select', | |
491 | 'data_type' => 'ContactReference', | |
492 | 'weight' => 4, | |
493 | 'is_searchable' => 1, | |
494 | 'is_active' => 1, | |
6a488035 TO |
495 | ); |
496 | ||
b8a3da18 | 497 | $customField = $this->callAPISuccess('custom_field', 'create', $params); |
6a488035 | 498 | $params = $this->_params; |
b8a3da18 | 499 | $params['custom_' . $customField['id']] = "$this->_contactID"; |
6a488035 | 500 | |
a828d7b8 | 501 | $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); |
92915c55 | 502 | $result = $this->callAPIAndDocument($this->_entity, 'get', array( |
c301f76e | 503 | 'return.custom_' . $customField['id'] => 1, |
504 | 'id' => $result['id'], | |
a828d7b8 | 505 | ), __FUNCTION__, __FILE__, 'Get with Contact Ref Custom Field', 'ContactRefCustomFieldGet'); |
6a488035 | 506 | |
e3aa0dd1 | 507 | $this->assertEquals('Anderson, Anthony', $result['values'][$result['id']]['custom_' . $customField['id']]); |
b8a3da18 | 508 | $this->assertEquals($this->_contactID, $result['values'][$result['id']]['custom_' . $customField['id'] . "_id"], ' in line ' . __LINE__); |
509 | $this->assertEquals('Anderson, Anthony', $result['values'][$result['id']]['custom_' . $customField['id'] . '_1'], ' in line ' . __LINE__); | |
510 | $this->assertEquals($this->_contactID, $result['values'][$result['id']]['custom_' . $customField['id'] . "_1_id"], ' in line ' . __LINE__); | |
6a488035 TO |
511 | $this->customFieldDelete($ids['custom_field_id']); |
512 | $this->customGroupDelete($ids['custom_group_id']); | |
513 | } | |
514 | ||
515 | /** | |
e3aa0dd1 | 516 | * Test civicrm_activity_create() with an invalid text status_id. |
6a488035 | 517 | */ |
00be9182 | 518 | public function testActivityCreateBadTextStatus() { |
6a488035 TO |
519 | |
520 | $params = array( | |
b8a3da18 | 521 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
522 | 'subject' => 'Discussion on Apis for v3', |
523 | 'activity_date_time' => date('Ymd'), | |
524 | 'duration' => 120, | |
e3aa0dd1 | 525 | 'location' => 'Pennsylvania', |
6a488035 TO |
526 | 'details' => 'a test activity', |
527 | 'status_id' => 'Invalid', | |
528 | 'activity_name' => 'Test activity type', | |
6a488035 TO |
529 | ); |
530 | ||
e3aa0dd1 | 531 | $this->callAPIFailure('activity', 'create', $params); |
feb2a730 | 532 | } |
533 | ||
534 | /** | |
e3aa0dd1 | 535 | * Test civicrm_activity_create() with an invalid text status_id. |
feb2a730 | 536 | */ |
00be9182 | 537 | public function testActivityCreateSupportActivityStatus() { |
feb2a730 | 538 | |
539 | $params = array( | |
b8a3da18 | 540 | 'source_contact_id' => $this->_contactID, |
feb2a730 | 541 | 'subject' => 'Discussion on Apis for v3', |
542 | 'activity_date_time' => date('Ymd'), | |
543 | 'duration' => 120, | |
e3aa0dd1 | 544 | 'location' => 'Pennsylvania', |
feb2a730 | 545 | 'details' => 'a test activity', |
546 | 'activity_status_id' => 'Invalid', | |
547 | 'activity_name' => 'Test activity type', | |
6a488035 | 548 | ); |
feb2a730 | 549 | |
b8a3da18 | 550 | $result = $this->callAPIFailure('activity', 'create', $params, |
551 | "'Invalid' is not a valid option for field status_id"); | |
6a488035 TO |
552 | } |
553 | ||
feb2a730 | 554 | |
6a488035 | 555 | /** |
e3aa0dd1 | 556 | * Test civicrm_activity_create() with using a text status_id. |
6a488035 | 557 | */ |
00be9182 | 558 | public function testActivityCreateTextStatus() { |
6a488035 | 559 | |
6a488035 | 560 | $params = array( |
b8a3da18 | 561 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
562 | 'subject' => 'Make-it-Happen Meeting', |
563 | 'activity_date_time' => date('Ymd'), | |
564 | 'duration' => 120, | |
e3aa0dd1 | 565 | 'location' => 'Pennsylvania', |
6a488035 TO |
566 | 'details' => 'a test activity', |
567 | 'status_id' => 'Scheduled', | |
568 | 'activity_name' => 'Test activity type', | |
6a488035 TO |
569 | ); |
570 | ||
b8a3da18 | 571 | $result = $this->callAPISuccess('activity', 'create', $params); |
e3aa0dd1 | 572 | $this->assertEquals($result['values'][$result['id']]['duration'], 120); |
573 | $this->assertEquals($result['values'][$result['id']]['subject'], 'Make-it-Happen Meeting'); | |
574 | $this->assertEquals($result['values'][$result['id']]['activity_date_time'], date('Ymd') . '000000'); | |
575 | $this->assertEquals($result['values'][$result['id']]['location'], 'Pennsylvania'); | |
576 | $this->assertEquals($result['values'][$result['id']]['details'], 'a test activity'); | |
6a488035 TO |
577 | } |
578 | ||
579 | /** | |
d177a2a6 | 580 | * Test civicrm_activity_get() with no params |
6a488035 | 581 | */ |
00be9182 | 582 | public function testActivityGetEmpty() { |
b8a3da18 | 583 | $result = $this->callAPISuccess('activity', 'get', array()); |
6a488035 TO |
584 | } |
585 | ||
586 | /** | |
d177a2a6 | 587 | * Test civicrm_activity_get() with a good activity ID |
6a488035 | 588 | */ |
00be9182 | 589 | public function testActivityGetGoodID1() { |
5c49fee0 | 590 | // Insert rows in civicrm_activity creating activities 4 and 13 |
a828d7b8 | 591 | $description = "Demonstrates getting assignee_contact_id & using it to get the contact."; |
92915c55 TO |
592 | $subfile = 'ReturnAssigneeContact'; |
593 | $activity = $this->callAPISuccess('activity', 'create', $this->_params); | |
6a488035 | 594 | |
b8a3da18 | 595 | $contact = $this->callAPISuccess('Contact', 'Create', array( |
92915c55 TO |
596 | 'first_name' => "The Rock", |
597 | 'last_name' => 'roccky', | |
598 | 'contact_type' => 'Individual', | |
599 | 'version' => 3, | |
600 | 'api.activity.create' => array( | |
601 | 'id' => $activity['id'], | |
602 | 'assignee_contact_id' => '$value.id', | |
603 | ), | |
604 | )); | |
6a488035 TO |
605 | |
606 | $params = array( | |
607 | 'activity_id' => $activity['id'], | |
608 | 'version' => $this->_apiversion, | |
609 | 'sequential' => 1, | |
610 | 'return.assignee_contact_id' => 1, | |
611 | 'api.contact.get' => array( | |
612 | 'id' => '$value.source_contact_id', | |
613 | ), | |
614 | ); | |
615 | ||
9f1b81e0 | 616 | $result = $this->callAPIAndDocument('Activity', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile); |
6a488035 | 617 | |
ba4a1892 | 618 | $this->assertEquals($activity['id'], $result['id']); |
6a488035 | 619 | |
ba4a1892 | 620 | $this->assertEquals($contact['id'], $result['values'][0]['assignee_contact_id'][0]); |
6a488035 | 621 | |
ba4a1892 TM |
622 | $this->assertEquals($this->_contactID, $result['values'][0]['api.contact.get']['values'][0]['contact_id']); |
623 | $this->assertEquals($this->test_activity_type_value, $result['values'][0]['activity_type_id']); | |
624 | $this->assertEquals("test activity type id", $result['values'][0]['subject']); | |
6a488035 TO |
625 | } |
626 | ||
d424ffde | 627 | /** |
eceb18cc | 628 | * test that get functioning does filtering. |
42d30b83 | 629 | */ |
00be9182 | 630 | public function testGetFilter() { |
6a488035 | 631 | $params = array( |
b8a3da18 | 632 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
633 | 'subject' => 'Make-it-Happen Meeting', |
634 | 'activity_date_time' => '20110316', | |
635 | 'duration' => 120, | |
e3aa0dd1 | 636 | 'location' => 'Pennsylvania', |
6a488035 TO |
637 | 'details' => 'a test activity', |
638 | 'status_id' => 1, | |
639 | 'activity_name' => 'Test activity type', | |
6a488035 TO |
640 | 'priority_id' => 1, |
641 | ); | |
9f1b81e0 | 642 | $result = $this->callAPISuccess('Activity', 'Create', $params); |
643 | $this->callAPISuccess('Activity', 'Get', array('subject' => 'Make-it-Happen Meeting')); | |
6a488035 TO |
644 | $this->assertEquals(1, $result['count']); |
645 | $this->assertEquals('Make-it-Happen Meeting', $result['values'][$result['id']]['subject']); | |
9f1b81e0 | 646 | $this->callAPISuccess('Activity', 'Delete', array('id' => $result['id'])); |
6a488035 | 647 | } |
6e1bb60c N |
648 | |
649 | ||
650 | /** | |
d177a2a6 | 651 | * Test civicrm_activity_get() with filter target_contact_id |
6e1bb60c | 652 | */ |
00be9182 | 653 | public function testActivityGetTargetFilter() { |
6e1bb60c N |
654 | $params = $this->_params; |
655 | $contact1Params = array( | |
656 | 'first_name' => 'John', | |
657 | 'middle_name' => 'J.', | |
658 | 'last_name' => 'Anderson', | |
659 | 'prefix_id' => 3, | |
660 | 'suffix_id' => 3, | |
661 | 'email' => 'john_anderson@civicrm.org', | |
662 | 'contact_type' => 'Individual', | |
663 | ); | |
664 | ||
665 | $contact1 = $this->individualCreate($contact1Params); | |
666 | $contact2Params = array( | |
667 | 'first_name' => 'Michal', | |
668 | 'middle_name' => 'J.', | |
669 | 'last_name' => 'Anderson', | |
670 | 'prefix_id' => 3, | |
671 | 'suffix_id' => 3, | |
672 | 'email' => 'michal_anderson@civicrm.org', | |
673 | 'contact_type' => 'Individual', | |
674 | ); | |
675 | ||
676 | $contact2 = $this->individualCreate($contact2Params); | |
677 | ||
678 | $params['assignee_contact_id'] = array($contact1, $contact2); | |
679 | $params['target_contact_id'] = array($contact2 => $contact2); | |
680 | $activity = $this->callAPISuccess('Activity', 'Create', $params); | |
681 | ||
92915c55 | 682 | $activityget = $this->callAPISuccess('Activity', 'get', array( |
c301f76e | 683 | 'id' => $activity['id'], |
684 | 'target_contact_id' => $contact2, | |
685 | 'return.target_contact_id' => 1, | |
686 | )); | |
ba4a1892 TM |
687 | $this->assertEquals($activity['id'], $activityget['id']); |
688 | $this->assertEquals($contact2, $activityget['values'][$activityget['id']]['target_contact_id'][0]); | |
6e1bb60c | 689 | |
92915c55 | 690 | $activityget = $this->callAPISuccess('activity', 'get', array( |
c301f76e | 691 | 'target_contact_id' => $this->_contactID, |
692 | 'return.target_contact_id' => 1, | |
693 | 'id' => $activity['id'], | |
694 | )); | |
6e1bb60c | 695 | if ($activityget['count'] > 0) { |
ba4a1892 | 696 | $this->assertNotEquals($contact2, $activityget['values'][$activityget['id']]['target_contact_id'][0]); |
6e1bb60c N |
697 | } |
698 | } | |
699 | ||
28fc35eb AS |
700 | /** |
701 | * Test that activity.get api works when filtering on subject. | |
702 | */ | |
f21fb92b | 703 | public function testActivityGetSubjectFilter() { |
1196e086 | 704 | $subject = 'test activity ' . __FUNCTION__ . mt_rand(); |
f21fb92b AS |
705 | $params = $this->_params; |
706 | $params['subject'] = $subject; | |
707 | $activity = $this->callAPISuccess('Activity', 'Create', $params); | |
708 | $activityget = $this->callAPISuccess('activity', 'getsingle', array( | |
709 | 'subject' => $subject, | |
f21fb92b AS |
710 | )); |
711 | $this->assertEquals($activityget['subject'], $subject); | |
712 | } | |
713 | ||
28fc35eb AS |
714 | /** |
715 | * Test that activity.get api works when filtering on details. | |
716 | */ | |
f21fb92b | 717 | public function testActivityGetDetailsFilter() { |
1196e086 | 718 | $details = 'test activity ' . __FUNCTION__ . mt_rand(); |
f21fb92b AS |
719 | $params = $this->_params; |
720 | $params['details'] = $details; | |
721 | $activity = $this->callAPISuccess('Activity', 'Create', $params); | |
722 | $activityget = $this->callAPISuccess('activity', 'getsingle', array( | |
723 | 'details' => $details, | |
f21fb92b AS |
724 | )); |
725 | $this->assertEquals($activityget['details'], $details); | |
726 | } | |
727 | ||
1196e086 CW |
728 | /** |
729 | * Test that activity.get api works when filtering on tag. | |
730 | */ | |
731 | public function testActivityGetTagFilter() { | |
732 | $tag = $this->callAPISuccess('Tag', 'create', array('name' => mt_rand(), 'used_for' => 'Activities')); | |
733 | $activity = $this->callAPISuccess('Activity', 'Create', $this->_params); | |
734 | $this->callAPISuccess('EntityTag', 'create', array('entity_table' => 'civicrm_activity', 'tag_id' => $tag['id'], 'entity_id' => $activity['id'])); | |
735 | $activityget = $this->callAPISuccess('activity', 'getsingle', array( | |
736 | 'tag_id' => $tag['id'], | |
737 | )); | |
738 | $this->assertEquals($activityget['id'], $activity['id']); | |
739 | } | |
740 | ||
40875a91 CW |
741 | /** |
742 | * Return tag info | |
743 | */ | |
744 | public function testJoinOnTags() { | |
745 | $tagName = 'act_tag_nm_' . mt_rand(); | |
746 | $tagDescription = 'act_tag_ds_' . mt_rand(); | |
747 | $tagColor = '#' . substr(md5(mt_rand()), 0, 6); | |
748 | $tag = $this->callAPISuccess('Tag', 'create', array('name' => $tagName, 'color' => $tagColor, 'description' => $tagDescription, 'used_for' => 'Activities')); | |
749 | $activity = $this->callAPISuccess('Activity', 'Create', $this->_params); | |
750 | $this->callAPISuccess('EntityTag', 'create', array('entity_table' => 'civicrm_activity', 'tag_id' => $tag['id'], 'entity_id' => $activity['id'])); | |
751 | $activityget = $this->callAPISuccess('activity', 'getsingle', array( | |
752 | 'id' => $activity['id'], | |
753 | 'return' => array('tag_id.name', 'tag_id.description', 'tag_id.color'), | |
754 | )); | |
755 | $this->assertEquals($tagName, $activityget['tag_id'][$tag['id']]['tag_id.name']); | |
756 | $this->assertEquals($tagColor, $activityget['tag_id'][$tag['id']]['tag_id.color']); | |
757 | $this->assertEquals($tagDescription, $activityget['tag_id'][$tag['id']]['tag_id.description']); | |
758 | } | |
759 | ||
760 | ||
761 | /** | |
762 | * Test that activity.get api works to filter on and return files. | |
763 | */ | |
764 | public function testActivityGetFile() { | |
765 | $activity = $this->callAPISuccess('Activity', 'create', $this->_params); | |
766 | $activity2 = $this->callAPISuccess('Activity', 'create', $this->_params2); | |
767 | $file = $this->callAPISuccess('Attachment', 'create', array( | |
768 | 'name' => 'actAttachment.txt', | |
769 | 'mime_type' => 'text/plain', | |
770 | 'description' => 'My test description', | |
771 | 'content' => 'My test content', | |
772 | 'entity_table' => 'civicrm_activity', | |
773 | 'entity_id' => $activity2['id'], | |
774 | )); | |
775 | $activityget = $this->callAPISuccess('activity', 'getsingle', array( | |
776 | 'file_id' => $file['id'], | |
777 | 'return' => 'file_id', | |
778 | )); | |
779 | $this->assertEquals($activityget['id'], $activity2['id']); | |
780 | $this->assertEquals($file['id'], $activityget['file_id'][0]); | |
781 | } | |
782 | ||
d424ffde | 783 | /** |
eceb18cc | 784 | * test that get functioning does filtering. |
42d30b83 | 785 | */ |
00be9182 | 786 | public function testGetStatusID() { |
6a488035 | 787 | $params = array( |
b8a3da18 | 788 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
789 | 'subject' => 'Make-it-Happen Meeting', |
790 | 'activity_date_time' => '20110316', | |
791 | 'duration' => 120, | |
e3aa0dd1 | 792 | 'location' => 'Pennsylvania', |
6a488035 TO |
793 | 'details' => 'a test activity', |
794 | 'status_id' => 1, | |
795 | 'activity_name' => 'Test activity type', | |
6a488035 TO |
796 | 'priority_id' => 1, |
797 | ); | |
b8a3da18 | 798 | $this->callAPISuccess('Activity', 'Create', $params); |
2b46f1da | 799 | $result = $this->callAPISuccess('Activity', 'Get', array('activity_status_id' => '1')); |
6a488035 TO |
800 | $this->assertEquals(1, $result['count'], 'one activity of status 1 should exist'); |
801 | ||
2b46f1da | 802 | $result = $this->callAPISuccess('Activity', 'Get', array('status_id' => '1')); |
6a488035 TO |
803 | $this->assertEquals(1, $result['count'], 'status_id should also work'); |
804 | ||
2b46f1da | 805 | $result = $this->callAPISuccess('Activity', 'Get', array('activity_status_id' => '2')); |
6a488035 | 806 | $this->assertEquals(0, $result['count'], 'No activities of status 1 should exist'); |
b8a3da18 | 807 | $result = $this->callAPISuccess('Activity', 'Get', array( |
92915c55 | 808 | 'version' => $this->_apiversion, |
c301f76e | 809 | 'status_id' => '2', |
92915c55 | 810 | )); |
6a488035 TO |
811 | $this->assertEquals(0, $result['count'], 'No activities of status 1 should exist'); |
812 | ||
42d30b83 | 813 | } |
6a488035 | 814 | |
d424ffde | 815 | /** |
eceb18cc | 816 | * test that get functioning does filtering. |
42d30b83 | 817 | */ |
00be9182 | 818 | public function testGetFilterMaxDate() { |
6a488035 | 819 | $params = array( |
b8a3da18 | 820 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
821 | 'subject' => 'Make-it-Happen Meeting', |
822 | 'activity_date_time' => '20110101', | |
823 | 'duration' => 120, | |
e3aa0dd1 | 824 | 'location' => 'Pennsylvania', |
6a488035 TO |
825 | 'details' => 'a test activity', |
826 | 'status_id' => 1, | |
827 | 'activity_name' => 'Test activity type', | |
828 | 'version' => $this->_apiversion, | |
829 | 'priority_id' => 1, | |
830 | ); | |
b8a3da18 | 831 | $activityOne = $this->callAPISuccess('Activity', 'Create', $params); |
6a488035 | 832 | $params['activity_date_time'] = 20120216; |
b8a3da18 | 833 | $activityTwo = $this->callAPISuccess('Activity', 'Create', $params); |
834 | $result = $this->callAPISuccess('Activity', 'Get', array( | |
92915c55 TO |
835 | 'version' => 3, |
836 | )); | |
5c49fee0 | 837 | $description = "Demonstrates _low filter (at time of writing doesn't work if contact_id is set."; |
6a488035 TO |
838 | $subfile = "DateTimeLow"; |
839 | $this->assertEquals(2, $result['count']); | |
840 | $params = array( | |
841 | 'version' => 3, | |
842 | 'filter.activity_date_time_low' => '20120101000000', | |
843 | 'sequential' => 1, | |
844 | ); | |
9f1b81e0 | 845 | $result = $this->callAPIAndDocument('Activity', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile); |
e3aa0dd1 | 846 | $this->assertEquals(1, $result['count']); |
5c49fee0 | 847 | $description = "Demonstrates _high filter (at time of writing doesn't work if contact_id is set."; |
6a488035 | 848 | $subfile = "DateTimeHigh"; |
e3aa0dd1 | 849 | $this->assertEquals('2012-02-16 00:00:00', $result['values'][0]['activity_date_time']); |
6a488035 | 850 | $params = array( |
b8a3da18 | 851 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
852 | 'version' => 3, |
853 | 'filter.activity_date_time_high' => '20120101000000', | |
854 | 'sequential' => 1, | |
855 | ); | |
9f1b81e0 | 856 | $result = $this->callAPIAndDocument('Activity', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile); |
6a488035 TO |
857 | |
858 | $this->assertEquals(1, $result['count']); | |
e3aa0dd1 | 859 | $this->assertEquals('2011-01-01 00:00:00', $result['values'][0]['activity_date_time']); |
6a488035 | 860 | |
b8a3da18 | 861 | $this->callAPISuccess('Activity', 'Delete', array('version' => 3, 'id' => $activityOne['id'])); |
862 | $this->callAPISuccess('Activity', 'Delete', array('version' => 3, 'id' => $activityTwo['id'])); | |
6a488035 TO |
863 | } |
864 | ||
865 | /** | |
d177a2a6 EM |
866 | * Test civicrm_activity_get() with a good activity ID which |
867 | * has associated custom data | |
6a488035 | 868 | */ |
00be9182 | 869 | public function testActivityGetGoodIDCustom() { |
6a488035 TO |
870 | $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); |
871 | ||
872 | $params = $this->_params; | |
873 | $params['custom_' . $ids['custom_field_id']] = "custom string"; | |
874 | ||
e3aa0dd1 | 875 | $this->callAPISuccess($this->_entity, 'create', $params); |
9f1b81e0 | 876 | |
e3aa0dd1 | 877 | // Retrieve the test value. |
6a488035 TO |
878 | $params = array( |
879 | 'activity_type_id' => $this->test_activity_type_value, | |
6a488035 TO |
880 | 'sequential' => 1, |
881 | 'return.custom_' . $ids['custom_field_id'] => 1, | |
882 | ); | |
9f1b81e0 | 883 | $result = $this->callAPIAndDocument('activity', 'get', $params, __FUNCTION__, __FILE__); |
884 | $this->assertEquals("custom string", $result['values'][0]['custom_' . $ids['custom_field_id']]); | |
6a488035 | 885 | |
9f1b81e0 | 886 | $this->assertEquals($this->test_activity_type_value, $result['values'][0]['activity_type_id']); |
ba4a1892 | 887 | $this->assertEquals('test activity type id', $result['values'][0]['subject']); |
6a488035 TO |
888 | $this->customFieldDelete($ids['custom_field_id']); |
889 | $this->customGroupDelete($ids['custom_group_id']); | |
890 | } | |
891 | ||
892 | /** | |
d177a2a6 EM |
893 | * Test civicrm_activity_get() with a good activity ID which |
894 | * has associated custom data | |
6a488035 | 895 | */ |
00be9182 | 896 | public function testActivityGetContact_idCustom() { |
6a488035 TO |
897 | $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); |
898 | ||
899 | $params = $this->_params; | |
900 | $params['custom_' . $ids['custom_field_id']] = "custom string"; | |
901 | ||
b8a3da18 | 902 | $result = $this->callAPISuccess($this->_entity, 'create', $params); |
e3aa0dd1 | 903 | // Retrieve the test value |
6a488035 TO |
904 | $params = array( |
905 | 'contact_id' => $this->_params['source_contact_id'], | |
906 | 'activity_type_id' => $this->test_activity_type_value, | |
6a488035 TO |
907 | 'sequential' => 1, |
908 | 'return.custom_' . $ids['custom_field_id'] => 1, | |
909 | ); | |
9f1b81e0 | 910 | $result = $this->callAPIAndDocument('activity', 'get', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
911 | $this->assertEquals("custom string", $result['values'][0]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); |
912 | ||
ba4a1892 TM |
913 | $this->assertEquals($this->test_activity_type_value, $result['values'][0]['activity_type_id']); |
914 | $this->assertEquals('test activity type id', $result['values'][0]['subject']); | |
e3aa0dd1 | 915 | $this->assertEquals($result['values'][0]['id'], $result['id']); |
6a488035 TO |
916 | } |
917 | ||
918 | /** | |
e3aa0dd1 | 919 | * Check activity deletion with empty params. |
6a488035 | 920 | */ |
00be9182 | 921 | public function testDeleteActivityForEmptyParams() { |
6a488035 | 922 | $params = array('version' => $this->_apiversion); |
e3aa0dd1 | 923 | $this->callAPIFailure('activity', 'delete', $params); |
6a488035 TO |
924 | } |
925 | ||
926 | /** | |
e3aa0dd1 | 927 | * Check activity deletion without activity id. |
6a488035 | 928 | */ |
00be9182 | 929 | public function testDeleteActivityWithoutId() { |
6a488035 TO |
930 | $params = array( |
931 | 'activity_name' => 'Meeting', | |
932 | 'version' => $this->_apiversion, | |
933 | ); | |
d0e1eff2 | 934 | $result = $this->callAPIFailure('activity', 'delete', $params); |
6a488035 TO |
935 | } |
936 | ||
937 | /** | |
eceb18cc | 938 | * Check activity deletion without activity type. |
6a488035 | 939 | */ |
00be9182 | 940 | public function testDeleteActivityWithoutActivityType() { |
6a488035 | 941 | $params = array('id' => 1); |
d0e1eff2 | 942 | $result = $this->callAPIFailure('activity', 'delete', $params); |
6a488035 TO |
943 | } |
944 | ||
945 | /** | |
eceb18cc | 946 | * Check activity deletion with incorrect data. |
6a488035 | 947 | */ |
00be9182 | 948 | public function testDeleteActivityWithIncorrectActivityType() { |
6a488035 TO |
949 | $params = array( |
950 | 'id' => 1, | |
951 | 'activity_name' => 'Test Activity', | |
952 | ); | |
953 | ||
d0e1eff2 | 954 | $result = $this->callAPIFailure('activity', 'delete', $params); |
6a488035 TO |
955 | } |
956 | ||
957 | /** | |
eceb18cc | 958 | * Check activity deletion with correct data. |
6a488035 | 959 | */ |
00be9182 | 960 | public function testDeleteActivity() { |
b8a3da18 | 961 | $result = $this->callAPISuccess('activity', 'create', $this->_params); |
6a488035 TO |
962 | $params = array( |
963 | 'id' => $result['id'], | |
964 | 'version' => $this->_apiversion, | |
965 | ); | |
966 | ||
a828d7b8 | 967 | $this->callAPIAndDocument('activity', 'delete', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
968 | } |
969 | ||
6a488035 | 970 | /** |
eceb18cc | 971 | * Check if required fields are not passed. |
6a488035 | 972 | */ |
00be9182 | 973 | public function testActivityUpdateWithoutRequired() { |
6a488035 TO |
974 | $params = array( |
975 | 'subject' => 'this case should fail', | |
976 | 'scheduled_date_time' => date('Ymd'), | |
977 | ); | |
978 | ||
d0e1eff2 | 979 | $result = $this->callAPIFailure('activity', 'create', $params); |
6a488035 TO |
980 | } |
981 | ||
982 | /** | |
983 | * Test civicrm_activity_update() with non-numeric id | |
984 | */ | |
00be9182 | 985 | public function testActivityUpdateWithNonNumericId() { |
6a488035 TO |
986 | $params = array( |
987 | 'id' => 'lets break it', | |
988 | 'activity_name' => 'Meeting', | |
989 | 'subject' => 'this case should fail', | |
990 | 'scheduled_date_time' => date('Ymd'), | |
991 | ); | |
992 | ||
d0e1eff2 | 993 | $result = $this->callAPIFailure('activity', 'create', $params); |
6a488035 TO |
994 | } |
995 | ||
996 | /** | |
eceb18cc | 997 | * Check with incorrect required fields. |
6a488035 | 998 | */ |
00be9182 | 999 | public function testActivityUpdateWithIncorrectContactActivityType() { |
6a488035 TO |
1000 | $params = array( |
1001 | 'id' => 1, | |
1002 | 'activity_name' => 'Test Activity', | |
1003 | 'subject' => 'this case should fail', | |
1004 | 'scheduled_date_time' => date('Ymd'), | |
b8a3da18 | 1005 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
1006 | ); |
1007 | ||
b8a3da18 | 1008 | $result = $this->callAPIFailure('activity', 'create', $params, |
1009 | 'Invalid Activity Id'); | |
6a488035 TO |
1010 | } |
1011 | ||
1012 | /** | |
d177a2a6 | 1013 | * Test civicrm_activity_update() to update an existing activity |
6a488035 | 1014 | */ |
00be9182 | 1015 | public function testActivityUpdate() { |
b8a3da18 | 1016 | $result = $this->callAPISuccess('activity', 'create', $this->_params); |
6a488035 TO |
1017 | |
1018 | $params = array( | |
1019 | 'id' => $result['id'], | |
1020 | 'subject' => 'Make-it-Happen Meeting', | |
1021 | 'activity_date_time' => '20091011123456', | |
1022 | 'duration' => 120, | |
1023 | 'location' => '21, Park Avenue', | |
1024 | 'details' => 'Lets update Meeting', | |
1025 | 'status_id' => 1, | |
b8a3da18 | 1026 | 'source_contact_id' => $this->_contactID, |
6a488035 | 1027 | 'priority_id' => 1, |
6a488035 TO |
1028 | ); |
1029 | ||
b8a3da18 | 1030 | $result = $this->callAPISuccess('activity', 'create', $params); |
6a488035 TO |
1031 | //hack on date comparison - really we should make getAndCheck smarter to handle dates |
1032 | $params['activity_date_time'] = '2009-10-11 12:34:56'; | |
42d30b83 DL |
1033 | // we also unset source_contact_id since it is stored in an aux table |
1034 | unset($params['source_contact_id']); | |
6a488035 TO |
1035 | $this->getAndCheck($params, $result['id'], 'activity'); |
1036 | } | |
1037 | ||
1038 | /** | |
d177a2a6 EM |
1039 | * Test civicrm_activity_update() with valid parameters |
1040 | * and some custom data | |
6a488035 | 1041 | */ |
00be9182 | 1042 | public function testActivityUpdateCustom() { |
6a488035 TO |
1043 | $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); |
1044 | ||
1045 | $params = $this->_params; | |
1046 | ||
e3aa0dd1 | 1047 | // Create an activity with custom data |
6a488035 TO |
1048 | //this has been updated from the previous 'old format' function - need to make it work |
1049 | $params = array( | |
b8a3da18 | 1050 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
1051 | 'subject' => 'Make-it-Happen Meeting', |
1052 | 'activity_date_time' => '2009-10-18', | |
1053 | 'duration' => 120, | |
e3aa0dd1 | 1054 | 'location' => 'Pennsylvania', |
6a488035 TO |
1055 | 'details' => 'a test activity to check the update api', |
1056 | 'status_id' => 1, | |
1057 | 'activity_name' => 'Test activity type', | |
1058 | 'version' => $this->_apiversion, | |
1059 | 'custom_' . $ids['custom_field_id'] => 'custom string', | |
1060 | ); | |
b8a3da18 | 1061 | $result = $this->callAPISuccess('activity', 'create', $params); |
6a488035 TO |
1062 | |
1063 | $activityId = $result['id']; | |
92915c55 | 1064 | $result = $this->callAPISuccess($this->_entity, 'get', array( |
c301f76e | 1065 | 'return.custom_' . $ids['custom_field_id'] => 1, |
1066 | 'version' => 3, | |
1067 | 'id' => $result['id'], | |
1068 | )); | |
e3aa0dd1 | 1069 | $this->assertEquals("custom string", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']]); |
1070 | $this->assertEquals("2009-10-18 00:00:00", $result['values'][$result['id']]['activity_date_time']); | |
b8a3da18 | 1071 | $fields = $this->callAPISuccess('activity', 'getfields', array('version' => $this->_apiversion)); |
6a488035 TO |
1072 | $this->assertTrue(is_array($fields['values']['custom_' . $ids['custom_field_id']])); |
1073 | ||
e3aa0dd1 | 1074 | // Update the activity with custom data. |
6a488035 TO |
1075 | $params = array( |
1076 | 'id' => $activityId, | |
b8a3da18 | 1077 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
1078 | 'subject' => 'Make-it-Happen Meeting', |
1079 | 'status_id' => 1, | |
1080 | 'activity_name' => 'Test activity type', | |
1081 | // add this since dates are messed up | |
1082 | 'activity_date_time' => date('Ymd'), | |
1083 | 'custom_' . $ids['custom_field_id'] => 'Updated my test data', | |
1084 | 'version' => $this->_apiversion, | |
1085 | ); | |
b8a3da18 | 1086 | $result = $this->callAPISuccess('Activity', 'Create', $params); |
6a488035 | 1087 | |
92915c55 | 1088 | $result = $this->callAPISuccess($this->_entity, 'get', array( |
c301f76e | 1089 | 'return.custom_' . $ids['custom_field_id'] => 1, |
1090 | 'version' => 3, | |
1091 | 'id' => $result['id'], | |
1092 | )); | |
e3aa0dd1 | 1093 | $this->assertEquals("Updated my test data", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']]); |
6a488035 TO |
1094 | } |
1095 | ||
1096 | /** | |
d177a2a6 EM |
1097 | * Test civicrm_activity_update() for core activity fields |
1098 | * and some custom data | |
6a488035 | 1099 | */ |
00be9182 | 1100 | public function testActivityUpdateCheckCoreFields() { |
6a488035 TO |
1101 | $params = $this->_params; |
1102 | $contact1Params = array( | |
1103 | 'first_name' => 'John', | |
1104 | 'middle_name' => 'J.', | |
1105 | 'last_name' => 'Anderson', | |
1106 | 'prefix_id' => 3, | |
1107 | 'suffix_id' => 3, | |
1108 | 'email' => 'john_anderson@civicrm.org', | |
1109 | 'contact_type' => 'Individual', | |
1110 | ); | |
1111 | ||
1112 | $contact1 = $this->individualCreate($contact1Params); | |
1113 | $contact2Params = array( | |
1114 | 'first_name' => 'Michal', | |
1115 | 'middle_name' => 'J.', | |
1116 | 'last_name' => 'Anderson', | |
1117 | 'prefix_id' => 3, | |
1118 | 'suffix_id' => 3, | |
1119 | 'email' => 'michal_anderson@civicrm.org', | |
1120 | 'contact_type' => 'Individual', | |
1121 | ); | |
1122 | ||
1123 | $contact2 = $this->individualCreate($contact2Params); | |
1124 | ||
1125 | $params['assignee_contact_id'] = array($contact1, $contact2); | |
1126 | $params['target_contact_id'] = array($contact2 => $contact2); | |
b8a3da18 | 1127 | $result = $this->callAPISuccess('Activity', 'Create', $params); |
6a488035 | 1128 | |
6a488035 | 1129 | $activityId = $result['id']; |
6a488035 TO |
1130 | $getParams = array( |
1131 | 'return.assignee_contact_id' => 1, | |
1132 | 'return.target_contact_id' => 1, | |
1133 | 'version' => $this->_apiversion, | |
1134 | 'id' => $activityId, | |
1135 | ); | |
481a74f4 | 1136 | $result = $this->callAPISuccess($this->_entity, 'get', $getParams); |
6a488035 TO |
1137 | $assignee = $result['values'][$result['id']]['assignee_contact_id']; |
1138 | $target = $result['values'][$result['id']]['target_contact_id']; | |
1139 | $this->assertEquals(2, count($assignee), ' in line ' . __LINE__); | |
1140 | $this->assertEquals(1, count($target), ' in line ' . __LINE__); | |
1141 | $this->assertEquals(TRUE, in_array($contact1, $assignee), ' in line ' . __LINE__); | |
1142 | $this->assertEquals(TRUE, in_array($contact2, $target), ' in line ' . __LINE__); | |
1143 | ||
1144 | $contact3Params = array( | |
1145 | 'first_name' => 'Jijo', | |
1146 | 'middle_name' => 'J.', | |
1147 | 'last_name' => 'Anderson', | |
1148 | 'prefix_id' => 3, | |
1149 | 'suffix_id' => 3, | |
1150 | 'email' => 'jijo_anderson@civicrm.org', | |
1151 | 'contact_type' => 'Individual', | |
1152 | ); | |
1153 | ||
1154 | $contact4Params = array( | |
1155 | 'first_name' => 'Grant', | |
1156 | 'middle_name' => 'J.', | |
1157 | 'last_name' => 'Anderson', | |
1158 | 'prefix_id' => 3, | |
1159 | 'suffix_id' => 3, | |
1160 | 'email' => 'grant_anderson@civicrm.org', | |
1161 | 'contact_type' => 'Individual', | |
1162 | ); | |
1163 | ||
1164 | $contact3 = $this->individualCreate($contact3Params); | |
1165 | $contact4 = $this->individualCreate($contact4Params); | |
1166 | ||
1167 | $params = array(); | |
1168 | $params['id'] = $activityId; | |
6a488035 TO |
1169 | $params['assignee_contact_id'] = array($contact3 => $contact3); |
1170 | $params['target_contact_id'] = array($contact4 => $contact4); | |
1171 | ||
b8a3da18 | 1172 | $result = $this->callAPISuccess('activity', 'create', $params); |
6a488035 TO |
1173 | |
1174 | $this->assertEquals($activityId, $result['id'], ' in line ' . __LINE__); | |
1175 | ||
b8a3da18 | 1176 | $result = $this->callAPISuccess( |
42d30b83 DL |
1177 | $this->_entity, |
1178 | 'get', | |
1179 | array( | |
1180 | 'return.assignee_contact_id' => 1, | |
1181 | 'return.target_contact_id' => 1, | |
1182 | 'return.source_contact_id' => 1, | |
21dfd5f5 | 1183 | 'id' => $result['id'], |
42d30b83 DL |
1184 | ) |
1185 | ); | |
6a488035 TO |
1186 | |
1187 | $assignee = $result['values'][$result['id']]['assignee_contact_id']; | |
1188 | $target = $result['values'][$result['id']]['target_contact_id']; | |
1189 | ||
1190 | $this->assertEquals(1, count($assignee), ' in line ' . __LINE__); | |
1191 | $this->assertEquals(1, count($target), ' in line ' . __LINE__); | |
1192 | $this->assertEquals(TRUE, in_array($contact3, $assignee), ' in line ' . __LINE__); | |
1193 | $this->assertEquals(TRUE, in_array($contact4, $target), ' in line ' . __LINE__); | |
7b1dc1f6 | 1194 | $this->_params['activity_type_id'] = $this->test_activity_type_value; |
6a488035 | 1195 | foreach ($this->_params as $fld => $val) { |
9f1b81e0 | 1196 | $this->assertEquals($val, $result['values'][$result['id']][$fld]); |
6a488035 TO |
1197 | } |
1198 | } | |
1199 | ||
1200 | /** | |
d177a2a6 EM |
1201 | * Test civicrm_activity_update() where the DB has a date_time |
1202 | * value and there is none in the update params. | |
6a488035 | 1203 | */ |
00be9182 | 1204 | public function testActivityUpdateNotDate() { |
b8a3da18 | 1205 | $result = $this->callAPISuccess('activity', 'create', $this->_params); |
6a488035 TO |
1206 | |
1207 | $params = array( | |
1208 | 'id' => $result['id'], | |
1209 | 'subject' => 'Make-it-Happen Meeting', | |
1210 | 'duration' => 120, | |
1211 | 'location' => '21, Park Avenue', | |
1212 | 'details' => 'Lets update Meeting', | |
1213 | 'status_id' => 1, | |
b8a3da18 | 1214 | 'source_contact_id' => $this->_contactID, |
6a488035 | 1215 | 'priority_id' => 1, |
6a488035 TO |
1216 | ); |
1217 | ||
b8a3da18 | 1218 | $result = $this->callAPISuccess('activity', 'create', $params); |
6a488035 TO |
1219 | //hack on date comparison - really we should make getAndCheck smarter to handle dates |
1220 | $params['activity_date_time'] = $this->_params['activity_date_time']; | |
42d30b83 DL |
1221 | // we also unset source_contact_id since it is stored in an aux table |
1222 | unset($params['source_contact_id']); | |
6a488035 TO |
1223 | $this->getAndCheck($params, $result['id'], 'activity'); |
1224 | } | |
1225 | ||
1226 | /** | |
eceb18cc | 1227 | * Check activity update with status. |
6a488035 | 1228 | */ |
00be9182 | 1229 | public function testActivityUpdateWithStatus() { |
b8a3da18 | 1230 | $activity = $this->callAPISuccess('activity', 'create', $this->_params); |
6a488035 TO |
1231 | $params = array( |
1232 | 'id' => $activity['id'], | |
b8a3da18 | 1233 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
1234 | 'subject' => 'Hurry update works', |
1235 | 'status_id' => 1, | |
1236 | 'activity_name' => 'Test activity type', | |
6a488035 TO |
1237 | ); |
1238 | ||
b8a3da18 | 1239 | $result = $this->callAPISuccess('activity', 'create', $params); |
9f1b81e0 | 1240 | $this->assertEquals($result['id'], $activity['id']); |
1241 | $this->assertEquals($result['values'][$activity['id']]['subject'], 'Hurry update works'); | |
1242 | $this->assertEquals($result['values'][$activity['id']]['status_id'], 1 | |
6a488035 TO |
1243 | ); |
1244 | } | |
1245 | ||
1246 | /** | |
d177a2a6 EM |
1247 | * Test civicrm_activity_update() where the source_contact_id |
1248 | * is not in the update params. | |
6a488035 | 1249 | */ |
00be9182 | 1250 | public function testActivityUpdateKeepSource() { |
b8a3da18 | 1251 | $activity = $this->callAPISuccess('activity', 'create', $this->_params); |
e3aa0dd1 | 1252 | // Updating the activity but not providing anything for the source contact |
1253 | // (It was set as $this->_contactID earlier.) | |
6a488035 TO |
1254 | $params = array( |
1255 | 'id' => $activity['id'], | |
1256 | 'subject' => 'Updated Make-it-Happen Meeting', | |
1257 | 'duration' => 120, | |
1258 | 'location' => '21, Park Avenue', | |
1259 | 'details' => 'Lets update Meeting', | |
1260 | 'status_id' => 1, | |
1261 | 'activity_name' => 'Test activity type', | |
1262 | 'priority_id' => 1, | |
6a488035 TO |
1263 | ); |
1264 | ||
b8a3da18 | 1265 | $result = $this->callAPISuccess('activity', 'create', $params); |
9f1b81e0 | 1266 | $findactivity = $this->callAPISuccess('Activity', 'Get', array('id' => $activity['id'])); |
6a488035 TO |
1267 | } |
1268 | ||
1269 | /** | |
d177a2a6 | 1270 | * Test civicrm_activities_contact_get() |
6a488035 | 1271 | */ |
00be9182 | 1272 | public function testActivitiesContactGet() { |
b8a3da18 | 1273 | $activity = $this->callAPISuccess('activity', 'create', $this->_params); |
1274 | $activity2 = $this->callAPISuccess('activity', 'create', $this->_params2); | |
e3aa0dd1 | 1275 | // Get activities associated with contact $this->_contactID. |
6a488035 | 1276 | $params = array( |
b8a3da18 | 1277 | 'contact_id' => $this->_contactID, |
6a488035 | 1278 | ); |
b8a3da18 | 1279 | $result = $this->callAPISuccess('activity', 'get', $params); |
6a488035 | 1280 | |
ba4a1892 | 1281 | $this->assertEquals(2, $result['count']); |
e3aa0dd1 | 1282 | $this->assertEquals($this->test_activity_type_value, $result['values'][$activity['id']]['activity_type_id']); |
1283 | $this->assertEquals('Test activity type', $result['values'][$activity['id']]['activity_name']); | |
1284 | $this->assertEquals('Test activity type', $result['values'][$activity2['id']]['activity_name']); | |
6a488035 | 1285 | } |
92915c55 | 1286 | |
d424ffde | 1287 | /** |
e3aa0dd1 | 1288 | * Test chained Activity format. |
42d30b83 | 1289 | */ |
e3aa0dd1 | 1290 | public function testChainedActivityGet() { |
6a488035 | 1291 | |
b8a3da18 | 1292 | $activity = $this->callAPISuccess('Contact', 'Create', array( |
92915c55 TO |
1293 | 'display_name' => "bob brown", |
1294 | 'contact_type' => 'Individual', | |
1295 | 'api.activity_type.create' => array( | |
1296 | 'weight' => '2', | |
1297 | 'label' => 'send out letters', | |
1298 | 'filter' => 0, | |
1299 | 'is_active' => 1, | |
1300 | 'is_optgroup' => 1, | |
1301 | 'is_default' => 0, | |
1302 | ), | |
1303 | 'api.activity.create' => array( | |
1304 | 'subject' => 'send letter', | |
c301f76e | 1305 | 'activity_type_id' => '$value.api.activity_type.create.values.0.value', |
92915c55 TO |
1306 | ), |
1307 | )); | |
6a488035 | 1308 | |
b8a3da18 | 1309 | $result = $this->callAPISuccess('Activity', 'Get', array( |
92915c55 TO |
1310 | 'id' => $activity['id'], |
1311 | 'return.assignee_contact_id' => 1, | |
1312 | 'api.contact.get' => array('api.pledge.get' => 1), | |
1313 | )); | |
6a488035 TO |
1314 | } |
1315 | ||
6a488035 | 1316 | /** |
e3aa0dd1 | 1317 | * Test civicrm_activity_contact_get() with invalid Contact ID. |
6a488035 | 1318 | */ |
00be9182 | 1319 | public function testActivitiesContactGetWithInvalidContactId() { |
6a488035 | 1320 | $params = array('contact_id' => 'contact'); |
e3aa0dd1 | 1321 | $this->callAPIFailure('activity', 'get', $params); |
6a488035 TO |
1322 | } |
1323 | ||
1324 | /** | |
e3aa0dd1 | 1325 | * Test civicrm_activity_contact_get() with contact having no Activity. |
6a488035 | 1326 | */ |
00be9182 | 1327 | public function testActivitiesContactGetHavingNoActivity() { |
6a488035 TO |
1328 | $params = array( |
1329 | 'first_name' => 'dan', | |
1330 | 'last_name' => 'conberg', | |
1331 | 'email' => 'dan.conberg@w.co.in', | |
1332 | 'contact_type' => 'Individual', | |
6a488035 TO |
1333 | ); |
1334 | ||
b8a3da18 | 1335 | $contact = $this->callAPISuccess('contact', 'create', $params); |
6a488035 TO |
1336 | $params = array( |
1337 | 'contact_id' => $contact['id'], | |
6a488035 | 1338 | ); |
b8a3da18 | 1339 | $result = $this->callAPISuccess('activity', 'get', $params); |
e3aa0dd1 | 1340 | $this->assertEquals($result['count'], 0); |
6a488035 TO |
1341 | } |
1342 | ||
e3aa0dd1 | 1343 | /** |
1344 | * Test getfields function. | |
1345 | */ | |
00be9182 | 1346 | public function testGetFields() { |
b8a3da18 | 1347 | $params = array('action' => 'create'); |
a828d7b8 | 1348 | $result = $this->callAPIAndDocument('activity', 'getfields', $params, __FUNCTION__, __FILE__, NULL, NULL); |
e3aa0dd1 | 1349 | $this->assertTrue(is_array($result['values']), 'get fields doesn\'t return values array'); |
6a488035 | 1350 | foreach ($result['values'] as $key => $value) { |
e3aa0dd1 | 1351 | $this->assertTrue(is_array($value), $key . " is not an array"); |
6a488035 TO |
1352 | } |
1353 | } | |
96025800 | 1354 | |
fe59b2a7 CW |
1355 | public function testGetWithOr() { |
1356 | $acts = array( | |
1357 | 'test or 1' => 'orOperator', | |
1358 | 'test or 2' => 'orOperator', | |
1359 | 'test or 3' => 'nothing', | |
1360 | ); | |
1361 | foreach ($acts as $subject => $details) { | |
1362 | $params = $this->_params; | |
1363 | $params['subject'] = $subject; | |
1364 | $params['details'] = $details; | |
1365 | $this->callAPISuccess('Activity', 'create', $params); | |
1366 | } | |
1367 | $result = $this->callAPISuccess('Activity', 'get', array( | |
1368 | 'details' => 'orOperator', | |
1369 | )); | |
1370 | $this->assertEquals(2, $result['count']); | |
1371 | $result = $this->callAPISuccess('Activity', 'get', array( | |
1372 | 'details' => 'orOperator', | |
1373 | 'subject' => 'test or 3', | |
1374 | )); | |
1375 | $this->assertEquals(0, $result['count']); | |
1376 | $result = $this->callAPISuccess('Activity', 'get', array( | |
1377 | 'details' => 'orOperator', | |
1378 | 'subject' => 'test or 3', | |
1379 | 'options' => array('or' => array(array('details', 'subject'))), | |
1380 | )); | |
1381 | $this->assertEquals(3, $result['count']); | |
1382 | } | |
1383 | ||
6a488035 | 1384 | } |