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