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