| 1 | <?php |
| 2 | /** |
| 3 | * Test Generated example of using profile submit API |
| 4 | * * |
| 5 | */ |
| 6 | function profile_submit_example(){ |
| 7 | $params = array( |
| 8 | 'profile_id' => 29, |
| 9 | 'contact_id' => 2, |
| 10 | 'first_name' => 'abc2', |
| 11 | 'last_name' => 'xyz2', |
| 12 | 'email-primary' => 'abc2.xyz2@gmail.com', |
| 13 | 'phone-1-1' => '022 321 826', |
| 14 | 'country-1' => '1013', |
| 15 | 'state_province-1' => '1000', |
| 16 | ); |
| 17 | |
| 18 | try{ |
| 19 | $result = civicrm_api3('profile', 'submit', $params); |
| 20 | } |
| 21 | catch (CiviCRM_API3_Exception $e) { |
| 22 | // handle error here |
| 23 | $errorMessage = $e->getMessage(); |
| 24 | $errorCode = $e->getErrorCode(); |
| 25 | $errorData = $e->getExtraParams(); |
| 26 | return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData); |
| 27 | } |
| 28 | |
| 29 | return $result; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Function returns array of result expected from previous function |
| 34 | */ |
| 35 | function profile_submit_expectedresult(){ |
| 36 | |
| 37 | $expectedResult = array( |
| 38 | 'is_error' => 0, |
| 39 | 'version' => 3, |
| 40 | 'count' => 1, |
| 41 | 'id' => 2, |
| 42 | 'values' => array( |
| 43 | '2' => array( |
| 44 | 'id' => '2', |
| 45 | 'contact_type' => 'Individual', |
| 46 | 'contact_sub_type' => '', |
| 47 | 'do_not_email' => 0, |
| 48 | 'do_not_phone' => 0, |
| 49 | 'do_not_mail' => 0, |
| 50 | 'do_not_sms' => 0, |
| 51 | 'do_not_trade' => 0, |
| 52 | 'is_opt_out' => 0, |
| 53 | 'legal_identifier' => '', |
| 54 | 'external_identifier' => '', |
| 55 | 'sort_name' => 'xyz2, abc2', |
| 56 | 'display_name' => 'abc2 xyz2', |
| 57 | 'nick_name' => '', |
| 58 | 'legal_name' => '', |
| 59 | 'image_URL' => '', |
| 60 | 'preferred_communication_method' => '', |
| 61 | 'preferred_language' => 'en_US', |
| 62 | 'preferred_mail_format' => 'Both', |
| 63 | 'hash' => '67eac7789eaee00', |
| 64 | 'api_key' => '', |
| 65 | 'first_name' => 'abc2', |
| 66 | 'middle_name' => 'J.', |
| 67 | 'last_name' => 'xyz2', |
| 68 | 'prefix_id' => '3', |
| 69 | 'suffix_id' => '3', |
| 70 | 'email_greeting_id' => '1', |
| 71 | 'email_greeting_custom' => '', |
| 72 | 'email_greeting_display' => 'Dear abc1', |
| 73 | 'postal_greeting_id' => '1', |
| 74 | 'postal_greeting_custom' => '', |
| 75 | 'postal_greeting_display' => 'Dear abc1', |
| 76 | 'addressee_id' => '1', |
| 77 | 'addressee_custom' => '', |
| 78 | 'addressee_display' => 'Mr. abc1 J. xyz1 II', |
| 79 | 'job_title' => '', |
| 80 | 'gender_id' => '', |
| 81 | 'birth_date' => '', |
| 82 | 'is_deceased' => 0, |
| 83 | 'deceased_date' => '', |
| 84 | 'household_name' => '', |
| 85 | 'primary_contact_id' => '', |
| 86 | 'organization_name' => '', |
| 87 | 'sic_code' => '', |
| 88 | 'user_unique_id' => '', |
| 89 | 'created_date' => '2013-07-28 08:49:19', |
| 90 | 'modified_date' => '2012-11-14 16:02:35', |
| 91 | ), |
| 92 | ), |
| 93 | ); |
| 94 | |
| 95 | return $expectedResult; |
| 96 | } |
| 97 | |
| 98 | |
| 99 | /* |
| 100 | * This example has been generated from the API test suite. The test that created it is called |
| 101 | * |
| 102 | * testProfileSubmit and can be found in |
| 103 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ProfileTest.php |
| 104 | * |
| 105 | * You can see the outcome of the API tests at |
| 106 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
| 107 | * |
| 108 | * To Learn about the API read |
| 109 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
| 110 | * |
| 111 | * Browse the api on your own site with the api explorer |
| 112 | * http://MYSITE.ORG/path/to/civicrm/api/explorer |
| 113 | * |
| 114 | * Read more about testing here |
| 115 | * http://wiki.civicrm.org/confluence/display/CRM/Testing |
| 116 | * |
| 117 | * API Standards documentation: |
| 118 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards |
| 119 | */ |