Merge branch '4.5' into 4.6
[civicrm-core.git] / api / v3 / examples / Profile / Apply.php
CommitLineData
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 */
8function profile_apply_example() {
9 $params = array(
10 'profile_id' => 31,
11 'contact_id' => 3,
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 );
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();
28 return array(
29 'error' => $errorMessage,
30 'error_code' => $errorCode,
31 'error_data' => $errorData,
32 );
33 }
34
35 return $result;
6a488035
TO
36}
37
fb32de45 38/**
50fb255d 39 * Function returns array of result expected from previous function.
40 *
41 * @return array
42 * API result array
6a488035 43 */
50fb255d 44function profile_apply_expectedresult() {
6a488035 45
53ca8fd7 46 $expectedResult = array(
50fb255d 47 'is_error' => 0,
48 'version' => 3,
49 'count' => 11,
50 'values' => array(
6a488035
TO
51 'contact_type' => 'Individual',
52 'contact_sub_type' => '',
89bf81b4 53 'contact_id' => 3,
6a488035 54 'version' => 3,
f27f2724 55 'debug' => 1,
c3d3e837 56 'profile_id' => 31,
6a488035
TO
57 'first_name' => 'abc2',
58 'last_name' => 'xyz2',
53ca8fd7 59 'email' => array(
50fb255d 60 '1' => array(
61 'location_type_id' => '1',
62 'is_primary' => 1,
63 'email' => 'abc2.xyz2@gmail.com',
6a488035 64 ),
50fb255d 65 ),
53ca8fd7 66 'phone' => array(
50fb255d 67 '2' => array(
68 'location_type_id' => '1',
69 'is_primary' => 1,
70 'phone_type_id' => '1',
71 'phone' => '022 321 826',
6a488035 72 ),
50fb255d 73 ),
53ca8fd7 74 'address' => array(
50fb255d 75 '1' => array(
76 'location_type_id' => '1',
77 'is_primary' => 1,
78 'country_id' => '1013',
79 'state_province_id' => '1000',
6a488035 80 ),
50fb255d 81 ),
6a488035 82 ),
50fb255d 83 );
6a488035 84
fb32de45 85 return $expectedResult;
6a488035
TO
86}
87
a828d7b8 88/*
50fb255d 89* This example has been generated from the API test suite.
a828d7b8
CW
90* The test that created it is called "testProfileApply"
91* and can be found at:
69d79249 92* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ProfileTest.php
6a488035
TO
93*
94* You can see the outcome of the API tests at
69d79249 95* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
96*
97* To Learn about the API read
69d79249 98* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 99*
69d79249 100* Browse the api on your own site with the api explorer
41d4d31f 101* http://MYSITE.ORG/path/to/civicrm/api
6a488035
TO
102*
103* Read more about testing here
104* http://wiki.civicrm.org/confluence/display/CRM/Testing
105*
106* API Standards documentation:
107* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 108*/