Merge pull request #15309 from totten/master-api4
[civicrm-core.git] / api / v3 / examples / Profile / Apply.ex.php
1 <?php
2 /**
3 * Test Generated example demonstrating the Profile.apply API.
4 *
5 * @return array
6 * API result array
7 */
8 function profile_apply_example() {
9 $params = [
10 'profile_id' => 30,
11 'contact_id' => 5,
12 'first_name' => 'abc2',
13 'last_name' => 'xyz2',
14 'email-Primary' => 'abc2.xyz2@gmail.com',
15 'phone-1-1' => '022 321 826',
16 'country-1' => '1013',
17 'state_province-1' => '1000',
18 ];
19
20 try{
21 $result = civicrm_api3('Profile', 'apply', $params);
22 }
23 catch (CiviCRM_API3_Exception $e) {
24 // Handle error here.
25 $errorMessage = $e->getMessage();
26 $errorCode = $e->getErrorCode();
27 $errorData = $e->getExtraParams();
28 return [
29 'is_error' => 1,
30 'error_message' => $errorMessage,
31 'error_code' => $errorCode,
32 'error_data' => $errorData,
33 ];
34 }
35
36 return $result;
37 }
38
39 /**
40 * Function returns array of result expected from previous function.
41 *
42 * @return array
43 * API result array
44 */
45 function profile_apply_expectedresult() {
46
47 $expectedResult = [
48 'is_error' => 0,
49 'version' => 3,
50 'count' => 11,
51 'values' => [
52 'contact_type' => 'Individual',
53 'contact_sub_type' => '',
54 'contact_id' => 5,
55 'version' => 3,
56 'debug' => 1,
57 'profile_id' => 30,
58 'first_name' => 'abc2',
59 'last_name' => 'xyz2',
60 'email' => [
61 '1' => [
62 'location_type_id' => '1',
63 'is_primary' => 1,
64 'email' => 'abc2.xyz2@gmail.com',
65 ],
66 ],
67 'phone' => [
68 '2' => [
69 'location_type_id' => '1',
70 'is_primary' => 1,
71 'phone_type_id' => '1',
72 'phone' => '022 321 826',
73 ],
74 ],
75 'address' => [
76 '1' => [
77 'location_type_id' => '1',
78 'is_primary' => 1,
79 'country_id' => '1013',
80 'state_province_id' => '1000',
81 ],
82 ],
83 ],
84 ];
85
86 return $expectedResult;
87 }
88
89 /*
90 * This example has been generated from the API test suite.
91 * The test that created it is called "testProfileApply"
92 * and can be found at:
93 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ProfileTest.php
94 *
95 * You can see the outcome of the API tests at
96 * https://test.civicrm.org/job/CiviCRM-Core-Matrix/
97 *
98 * To Learn about the API read
99 * https://docs.civicrm.org/dev/en/latest/api/
100 *
101 * Browse the API on your own site with the API Explorer. It is in the main
102 * CiviCRM menu, under: Support > Development > API Explorer.
103 *
104 * Read more about testing here
105 * https://docs.civicrm.org/dev/en/latest/testing/
106 *
107 * API Standards documentation:
108 * https://docs.civicrm.org/dev/en/latest/framework/api-architecture/
109 */