Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the Address.get API. |
50fb255d | 4 | * |
5c49fee0 | 5 | * Demonstrates Use of sort filter. |
50fb255d | 6 | * |
7 | * @return array | |
8 | * API result array | |
9 | */ | |
10 | function address_get_example() { | |
11 | $params = array( | |
12 | 'options' => array( | |
6a488035 TO |
13 | 'sort' => 'street_address DESC', |
14 | 'limit' => 2, | |
15 | ), | |
50fb255d | 16 | 'sequential' => 1, |
17 | ); | |
6a488035 | 18 | |
50fb255d | 19 | try{ |
a828d7b8 | 20 | $result = civicrm_api3('Address', 'get', $params); |
50fb255d | 21 | } |
22 | catch (CiviCRM_API3_Exception $e) { | |
23 | // Handle error here. | |
24 | $errorMessage = $e->getMessage(); | |
25 | $errorCode = $e->getErrorCode(); | |
26 | $errorData = $e->getExtraParams(); | |
27 | return array( | |
28 | 'error' => $errorMessage, | |
29 | 'error_code' => $errorCode, | |
30 | 'error_data' => $errorData, | |
31 | ); | |
32 | } | |
6a488035 | 33 | |
50fb255d | 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_get_expectedresult() { |
6a488035 | 44 | |
edb0d67a | 45 | $expectedResult = array( |
50fb255d | 46 | 'is_error' => 0, |
47 | 'version' => 3, | |
48 | 'count' => 2, | |
49 | 'values' => array( | |
edb0d67a | 50 | '0' => array( |
50fb255d | 51 | 'id' => '2', |
52 | 'contact_id' => '19', | |
53 | 'location_type_id' => '17', | |
54 | 'is_primary' => '1', | |
55 | 'is_billing' => 0, | |
56 | 'street_address' => 'yzy', | |
57 | 'street_number' => '23', | |
58 | 'street_name' => 'Ambachtstraat', | |
59 | 'city' => 'Brummen', | |
60 | 'postal_code' => '6971 BN', | |
61 | 'country_id' => '1152', | |
62 | 'manual_geo_code' => 0, | |
63 | ), | |
edb0d67a | 64 | '1' => array( |
50fb255d | 65 | 'id' => '1', |
66 | 'contact_id' => '19', | |
67 | 'location_type_id' => '17', | |
68 | 'is_primary' => 0, | |
69 | 'is_billing' => 0, | |
70 | 'street_address' => 'Ambachtstraat 23', | |
71 | 'street_number' => '23', | |
72 | 'street_name' => 'Ambachtstraat', | |
73 | 'city' => 'Brummen', | |
74 | 'postal_code' => '6971 BN', | |
75 | 'country_id' => '1152', | |
76 | 'manual_geo_code' => 0, | |
77 | ), | |
6a488035 | 78 | ), |
50fb255d | 79 | ); |
6a488035 | 80 | |
fb32de45 | 81 | return $expectedResult; |
6a488035 TO |
82 | } |
83 | ||
a828d7b8 | 84 | /* |
50fb255d | 85 | * This example has been generated from the API test suite. |
a828d7b8 CW |
86 | * The test that created it is called "testGetAddressSort" |
87 | * and can be found at: | |
69d79249 | 88 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/AddressTest.php |
6a488035 TO |
89 | * |
90 | * You can see the outcome of the API tests at | |
69d79249 | 91 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
92 | * |
93 | * To Learn about the API read | |
69d79249 | 94 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 95 | * |
69d79249 | 96 | * Browse the api on your own site with the api explorer |
41d4d31f | 97 | * http://MYSITE.ORG/path/to/civicrm/api |
6a488035 TO |
98 | * |
99 | * Read more about testing here | |
100 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
101 | * | |
102 | * API Standards documentation: | |
103 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 104 | */ |