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