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