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