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