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