Commit | Line | Data |
---|---|---|
89bf81b4 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the Country.create API. |
50fb255d | 4 | * |
50fb255d | 5 | * @return array |
6 | * API result array | |
7 | */ | |
8 | function country_create_example() { | |
cf8f0fff | 9 | $params = [ |
50fb255d | 10 | 'name' => 'Made Up Land', |
11 | 'iso_code' => 'ZZ', | |
12 | 'region_id' => 1, | |
cf8f0fff | 13 | ]; |
89bf81b4 | 14 | |
50fb255d | 15 | try{ |
a828d7b8 | 16 | $result = civicrm_api3('Country', 'create', $params); |
50fb255d | 17 | } |
18 | catch (CiviCRM_API3_Exception $e) { | |
19 | // Handle error here. | |
20 | $errorMessage = $e->getMessage(); | |
21 | $errorCode = $e->getErrorCode(); | |
22 | $errorData = $e->getExtraParams(); | |
cf8f0fff | 23 | return [ |
5be22f39 | 24 | 'is_error' => 1, |
25 | 'error_message' => $errorMessage, | |
50fb255d | 26 | 'error_code' => $errorCode, |
27 | 'error_data' => $errorData, | |
cf8f0fff | 28 | ]; |
50fb255d | 29 | } |
30 | ||
31 | return $result; | |
89bf81b4 | 32 | } |
33 | ||
34 | /** | |
50fb255d | 35 | * Function returns array of result expected from previous function. |
36 | * | |
37 | * @return array | |
38 | * API result array | |
89bf81b4 | 39 | */ |
50fb255d | 40 | function country_create_expectedresult() { |
89bf81b4 | 41 | |
cf8f0fff | 42 | $expectedResult = [ |
50fb255d | 43 | 'is_error' => 0, |
44 | 'version' => 3, | |
45 | 'count' => 1, | |
1d8ee3d6 | 46 | 'id' => 1254, |
cf8f0fff CW |
47 | 'values' => [ |
48 | '1254' => [ | |
1d8ee3d6 | 49 | 'id' => '1254', |
50fb255d | 50 | 'name' => 'Made Up Land', |
51 | 'iso_code' => 'ZZ', | |
52 | 'country_code' => '', | |
53 | 'address_format_id' => '', | |
54 | 'idd_prefix' => '', | |
55 | 'ndd_prefix' => '', | |
56 | 'region_id' => '1', | |
57 | 'is_province_abbreviated' => '', | |
cf8f0fff CW |
58 | ], |
59 | ], | |
60 | ]; | |
89bf81b4 | 61 | |
62 | return $expectedResult; | |
63 | } | |
64 | ||
a828d7b8 | 65 | /* |
50fb255d | 66 | * This example has been generated from the API test suite. |
a828d7b8 CW |
67 | * The test that created it is called "testCreateCountry" |
68 | * and can be found at: | |
89bf81b4 | 69 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/CountryTest.php |
70 | * | |
71 | * You can see the outcome of the API tests at | |
72 | * https://test.civicrm.org/job/CiviCRM-master-git/ | |
73 | * | |
74 | * To Learn about the API read | |
75 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API | |
76 | * | |
77 | * Browse the api on your own site with the api explorer | |
41d4d31f | 78 | * http://MYSITE.ORG/path/to/civicrm/api |
89bf81b4 | 79 | * |
80 | * Read more about testing here | |
81 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
82 | * | |
83 | * API Standards documentation: | |
84 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
85 | */ |