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