Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the LocBlock.create API. |
50fb255d | 4 | * |
5c49fee0 | 5 | * Create entities and locBlock in 1 api call. |
50fb255d | 6 | * |
7 | * @return array | |
8 | * API result array | |
9 | */ | |
10 | function loc_block_create_example() { | |
11 | $params = array( | |
12 | 'email' => array( | |
6a488035 TO |
13 | 'location_type_id' => 1, |
14 | 'email' => 'test2@loc.block', | |
15 | ), | |
50fb255d | 16 | 'phone' => array( |
6a488035 TO |
17 | 'location_type_id' => 1, |
18 | 'phone' => '987654321', | |
19 | ), | |
50fb255d | 20 | 'phone_2' => array( |
6a488035 TO |
21 | 'location_type_id' => 1, |
22 | 'phone' => '456-7890', | |
23 | ), | |
50fb255d | 24 | 'address' => array( |
6a488035 TO |
25 | 'location_type_id' => 1, |
26 | 'street_address' => '987654321', | |
27 | ), | |
50fb255d | 28 | ); |
6a488035 | 29 | |
50fb255d | 30 | try{ |
a828d7b8 | 31 | $result = civicrm_api3('LocBlock', 'create', $params); |
50fb255d | 32 | } |
33 | catch (CiviCRM_API3_Exception $e) { | |
34 | // Handle error here. | |
35 | $errorMessage = $e->getMessage(); | |
36 | $errorCode = $e->getErrorCode(); | |
37 | $errorData = $e->getExtraParams(); | |
38 | return array( | |
39 | 'error' => $errorMessage, | |
40 | 'error_code' => $errorCode, | |
41 | 'error_data' => $errorData, | |
42 | ); | |
43 | } | |
6a488035 | 44 | |
50fb255d | 45 | return $result; |
6a488035 TO |
46 | } |
47 | ||
fb32de45 | 48 | /** |
50fb255d | 49 | * Function returns array of result expected from previous function. |
50 | * | |
51 | * @return array | |
52 | * API result array | |
6a488035 | 53 | */ |
50fb255d | 54 | function loc_block_create_expectedresult() { |
6a488035 | 55 | |
82adafa2 | 56 | $expectedResult = array( |
50fb255d | 57 | 'is_error' => 0, |
58 | 'version' => 3, | |
59 | 'count' => 1, | |
60 | 'id' => 3, | |
61 | 'values' => array( | |
82adafa2 | 62 | '3' => array( |
50fb255d | 63 | 'address' => array( |
64 | 'id' => '3', | |
65 | 'location_type_id' => '1', | |
66 | 'is_primary' => 0, | |
67 | 'is_billing' => 0, | |
68 | 'street_address' => '987654321', | |
69 | 'manual_geo_code' => 0, | |
70 | ), | |
71 | 'email' => array( | |
72 | 'id' => '4', | |
73 | 'contact_id' => '', | |
74 | 'location_type_id' => '1', | |
75 | 'email' => 'test2@loc.block', | |
76 | 'is_primary' => 0, | |
77 | 'is_billing' => '', | |
78 | 'on_hold' => '', | |
79 | 'is_bulkmail' => '', | |
80 | 'hold_date' => '', | |
81 | 'reset_date' => '', | |
82 | 'signature_text' => '', | |
83 | 'signature_html' => '', | |
84 | ), | |
85 | 'phone' => array( | |
6a488035 | 86 | 'id' => '3', |
50fb255d | 87 | 'contact_id' => '', |
88 | 'location_type_id' => '1', | |
89 | 'is_primary' => 0, | |
90 | 'is_billing' => '', | |
91 | 'mobile_provider_id' => '', | |
92 | 'phone' => '987654321', | |
93 | 'phone_ext' => '', | |
94 | 'phone_numeric' => '', | |
95 | 'phone_type_id' => '', | |
96 | ), | |
97 | 'phone_2' => array( | |
98 | 'id' => '4', | |
99 | 'contact_id' => '', | |
100 | 'location_type_id' => '1', | |
101 | 'is_primary' => 0, | |
102 | 'is_billing' => '', | |
103 | 'mobile_provider_id' => '', | |
104 | 'phone' => '456-7890', | |
105 | 'phone_ext' => '', | |
106 | 'phone_numeric' => '', | |
107 | 'phone_type_id' => '', | |
6a488035 | 108 | ), |
50fb255d | 109 | 'id' => '3', |
110 | 'address_id' => '3', | |
111 | 'email_id' => '4', | |
112 | 'phone_id' => '3', | |
113 | 'im_id' => '', | |
114 | 'address_2_id' => '', | |
115 | 'email_2_id' => '', | |
116 | 'phone_2_id' => '4', | |
117 | 'im_2_id' => '', | |
118 | ), | |
6a488035 | 119 | ), |
50fb255d | 120 | ); |
6a488035 | 121 | |
fb32de45 | 122 | return $expectedResult; |
6a488035 TO |
123 | } |
124 | ||
a828d7b8 | 125 | /* |
50fb255d | 126 | * This example has been generated from the API test suite. |
a828d7b8 CW |
127 | * The test that created it is called "testCreateLocBlockEntities" |
128 | * and can be found at: | |
69d79249 | 129 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/LocBlockTest.php |
6a488035 TO |
130 | * |
131 | * You can see the outcome of the API tests at | |
69d79249 | 132 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
133 | * |
134 | * To Learn about the API read | |
69d79249 | 135 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 136 | * |
69d79249 | 137 | * Browse the api on your own site with the api explorer |
41d4d31f | 138 | * http://MYSITE.ORG/path/to/civicrm/api |
6a488035 TO |
139 | * |
140 | * Read more about testing here | |
141 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
142 | * | |
143 | * API Standards documentation: | |
144 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 145 | */ |