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