Merge pull request #15168 from MegaphoneJon/class-fixes
[civicrm-core.git] / api / v3 / examples / Email / Create.ex.php
1 <?php
2 /**
3 * Test Generated example demonstrating the Email.create API.
4 *
5 * @return array
6 * API result array
7 */
8 function email_create_example() {
9 $params = [
10 'contact_id' => 23,
11 'email' => 'api@a-team.com',
12 'on_hold' => '2',
13 ];
14
15 try{
16 $result = civicrm_api3('Email', 'create', $params);
17 }
18 catch (CiviCRM_API3_Exception $e) {
19 // Handle error here.
20 $errorMessage = $e->getMessage();
21 $errorCode = $e->getErrorCode();
22 $errorData = $e->getExtraParams();
23 return [
24 'is_error' => 1,
25 'error_message' => $errorMessage,
26 'error_code' => $errorCode,
27 'error_data' => $errorData,
28 ];
29 }
30
31 return $result;
32 }
33
34 /**
35 * Function returns array of result expected from previous function.
36 *
37 * @return array
38 * API result array
39 */
40 function email_create_expectedresult() {
41
42 $expectedResult = [
43 'is_error' => 0,
44 'version' => 3,
45 'count' => 1,
46 'id' => 26,
47 'values' => [
48 '26' => [
49 'id' => '26',
50 'contact_id' => '23',
51 'location_type_id' => '1',
52 'email' => 'api@a-team.com',
53 'is_primary' => '1',
54 'is_billing' => '',
55 'on_hold' => '2',
56 'is_bulkmail' => '',
57 'hold_date' => '20190820191652',
58 'reset_date' => '',
59 'signature_text' => '',
60 'signature_html' => '',
61 ],
62 ],
63 ];
64
65 return $expectedResult;
66 }
67
68 /*
69 * This example has been generated from the API test suite.
70 * The test that created it is called "testEmailOnHold"
71 * and can be found at:
72 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/EmailTest.php
73 *
74 * You can see the outcome of the API tests at
75 * https://test.civicrm.org/job/CiviCRM-Core-Matrix/
76 *
77 * To Learn about the API read
78 * https://docs.civicrm.org/dev/en/latest/api/
79 *
80 * Browse the API on your own site with the API Explorer. It is in the main
81 * CiviCRM menu, under: Support > Development > API Explorer.
82 *
83 * Read more about testing here
84 * https://docs.civicrm.org/dev/en/latest/testing/
85 *
86 * API Standards documentation:
87 * https://docs.civicrm.org/dev/en/latest/framework/api-architecture/
88 */