Merge pull request #5058 from eileenmcnaughton/test-examples
[civicrm-core.git] / api / v3 / examples / Activity / GetTargetandAssignee.php
CommitLineData
6a488035 1<?php
fb32de45 2/**
50fb255d 3 * @file
4 * Test Generated API Example.
5 * See bottom of this file for more detail.
6a488035 6 */
6a488035 7
50fb255d 8/**
9 * Test Generated example of using activity API.
10 *
11 * Example demonstrates setting & retrieving the target & source
12 *
13 * @return array
14 * API result array
15 */
16function activity__example() {
17 $params = array(
18 'source_contact_id' => 1,
19 'subject' => 'Make-it-Happen Meeting',
20 'activity_date_time' => '20110316',
21 'duration' => 120,
e3aa0dd1 22 'location' => 'Pennsylvania',
50fb255d 23 'details' => 'a test activity',
24 'status_id' => 1,
25 'activity_type_id' => 1,
26 'priority_id' => 1,
27 'target_contact_id' => 1,
28 'assignee_contact_id' => 1,
29 );
6a488035 30
50fb255d 31 try{
32 $result = civicrm_api3('activity', '', $params);
33 }
34 catch (CiviCRM_API3_Exception $e) {
35 // Handle error here.
36 $errorMessage = $e->getMessage();
37 $errorCode = $e->getErrorCode();
38 $errorData = $e->getExtraParams();
39 return array(
40 'error' => $errorMessage,
41 'error_code' => $errorCode,
42 'error_data' => $errorData,
43 );
44 }
45
46 return $result;
6a488035
TO
47}
48
fb32de45 49/**
50fb255d 50 * Function returns array of result expected from previous function.
51 *
52 * @return array
53 * API result array
6a488035 54 */
50fb255d 55function activity__expectedresult() {
6a488035 56
feb2a730 57 $expectedResult = array(
50fb255d 58 'is_error' => 0,
59 'version' => 3,
60 'count' => 1,
61 'id' => 1,
62 'values' => array(
feb2a730 63 '1' => array(
50fb255d 64 'id' => '1',
65 'source_record_id' => '',
66 'activity_type_id' => '1',
67 'subject' => 'Make-it-Happen Meeting',
68 'activity_date_time' => '20110316000000',
69 'duration' => '120',
e3aa0dd1 70 'location' => 'Pennsylvania',
50fb255d 71 'phone_id' => '',
72 'phone_number' => '',
73 'details' => 'a test activity',
74 'status_id' => '1',
75 'priority_id' => '1',
76 'parent_id' => '',
77 'is_test' => '',
78 'medium_id' => '',
79 'is_auto' => '',
80 'relationship_id' => '',
81 'is_current_revision' => '',
82 'original_id' => '',
83 'result' => '',
84 'is_deleted' => '',
85 'campaign_id' => '',
86 'engagement_level' => '',
87 'weight' => '',
88 ),
6a488035 89 ),
50fb255d 90 );
6a488035 91
fb32de45 92 return $expectedResult;
6a488035
TO
93}
94
50fb255d 95/**
96* This example has been generated from the API test suite.
97* The test that created it is called
98* testActivityReturnTargetAssignee
99* and can be found in
69d79249 100* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ActivityTest.php
6a488035
TO
101*
102* You can see the outcome of the API tests at
69d79249 103* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
104*
105* To Learn about the API read
69d79249 106* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 107*
69d79249
E
108* Browse the api on your own site with the api explorer
109* http://MYSITE.ORG/path/to/civicrm/api/explorer
6a488035
TO
110*
111* Read more about testing here
112* http://wiki.civicrm.org/confluence/display/CRM/Testing
113*
114* API Standards documentation:
115* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 116*/