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