Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the Survey.create API. |
50fb255d | 4 | * |
50fb255d | 5 | * @return array |
6 | * API result array | |
7 | */ | |
8 | function survey_create_example() { | |
9 | $params = array( | |
10 | 'title' => 'survey title', | |
11 | 'activity_type_id' => '30', | |
12 | 'max_number_of_contacts' => 12, | |
13 | 'instructions' => 'Call people, ask for money', | |
14 | ); | |
6a488035 | 15 | |
50fb255d | 16 | try{ |
a828d7b8 | 17 | $result = civicrm_api3('Survey', 'create', $params); |
50fb255d | 18 | } |
19 | catch (CiviCRM_API3_Exception $e) { | |
20 | // Handle error here. | |
21 | $errorMessage = $e->getMessage(); | |
22 | $errorCode = $e->getErrorCode(); | |
23 | $errorData = $e->getExtraParams(); | |
24 | return array( | |
1d8ee3d6 | 25 | 'is_error' => 1, |
26 | 'error_message' => $errorMessage, | |
50fb255d | 27 | 'error_code' => $errorCode, |
28 | 'error_data' => $errorData, | |
29 | ); | |
30 | } | |
31 | ||
32 | return $result; | |
6a488035 TO |
33 | } |
34 | ||
fb32de45 | 35 | /** |
50fb255d | 36 | * Function returns array of result expected from previous function. |
37 | * | |
38 | * @return array | |
39 | * API result array | |
6a488035 | 40 | */ |
50fb255d | 41 | function survey_create_expectedresult() { |
6a488035 | 42 | |
fbda92d3 | 43 | $expectedResult = array( |
50fb255d | 44 | 'is_error' => 0, |
45 | 'version' => 3, | |
46 | 'count' => 1, | |
47 | 'id' => 1, | |
48 | 'values' => array( | |
fbda92d3 | 49 | '1' => array( |
50fb255d | 50 | 'id' => '1', |
51 | 'title' => 'survey title', | |
52 | 'campaign_id' => '', | |
53 | 'activity_type_id' => '30', | |
54 | 'recontact_interval' => '', | |
55 | 'instructions' => 'Call people, ask for money', | |
56 | 'release_frequency' => '', | |
57 | 'max_number_of_contacts' => '12', | |
58 | 'default_number_of_contacts' => '', | |
59 | 'is_active' => '', | |
60 | 'is_default' => '', | |
61 | 'created_id' => '', | |
62 | 'created_date' => '2013-07-28 08:49:19', | |
63 | 'last_modified_id' => '', | |
64 | 'last_modified_date' => '', | |
65 | 'result_id' => '', | |
66 | 'bypass_confirm' => '', | |
67 | 'thankyou_title' => '', | |
68 | 'thankyou_text' => '', | |
69 | 'is_share' => '', | |
70 | ), | |
6a488035 | 71 | ), |
50fb255d | 72 | ); |
6a488035 | 73 | |
fb32de45 | 74 | return $expectedResult; |
6a488035 TO |
75 | } |
76 | ||
a828d7b8 | 77 | /* |
50fb255d | 78 | * This example has been generated from the API test suite. |
a828d7b8 CW |
79 | * The test that created it is called "testCreateSurvey" |
80 | * and can be found at: | |
69d79249 | 81 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/SurveyTest.php |
6a488035 TO |
82 | * |
83 | * You can see the outcome of the API tests at | |
69d79249 | 84 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
85 | * |
86 | * To Learn about the API read | |
69d79249 | 87 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 88 | * |
69d79249 | 89 | * Browse the api on your own site with the api explorer |
41d4d31f | 90 | * http://MYSITE.ORG/path/to/civicrm/api |
6a488035 TO |
91 | * |
92 | * Read more about testing here | |
93 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
94 | * | |
95 | * API Standards documentation: | |
96 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 97 | */ |