| 1 | <?php |
| 2 | /** |
| 3 | * Test Generated example of using email replace API |
| 4 | * * |
| 5 | */ |
| 6 | function email_replace_example(){ |
| 7 | $params = array( |
| 8 | 'contact_id' => 9, |
| 9 | 'values' => array( |
| 10 | '0' => array( |
| 11 | 'location_type_id' => 18, |
| 12 | 'email' => '1-1@example.com', |
| 13 | 'is_primary' => 1, |
| 14 | ), |
| 15 | '1' => array( |
| 16 | 'location_type_id' => 18, |
| 17 | 'email' => '1-2@example.com', |
| 18 | 'is_primary' => 0, |
| 19 | ), |
| 20 | '2' => array( |
| 21 | 'location_type_id' => 18, |
| 22 | 'email' => '1-3@example.com', |
| 23 | 'is_primary' => 0, |
| 24 | ), |
| 25 | '3' => array( |
| 26 | 'location_type_id' => 19, |
| 27 | 'email' => '2-1@example.com', |
| 28 | 'is_primary' => 0, |
| 29 | ), |
| 30 | '4' => array( |
| 31 | 'location_type_id' => 19, |
| 32 | 'email' => '2-2@example.com', |
| 33 | 'is_primary' => 0, |
| 34 | ), |
| 35 | ), |
| 36 | ); |
| 37 | |
| 38 | try{ |
| 39 | $result = civicrm_api3('email', 'replace', $params); |
| 40 | } |
| 41 | catch (CiviCRM_API3_Exception $e) { |
| 42 | // handle error here |
| 43 | $errorMessage = $e->getMessage(); |
| 44 | $errorCode = $e->getErrorCode(); |
| 45 | $errorData = $e->getExtraParams(); |
| 46 | return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData); |
| 47 | } |
| 48 | |
| 49 | return $result; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Function returns array of result expected from previous function |
| 54 | */ |
| 55 | function email_replace_expectedresult(){ |
| 56 | |
| 57 | $expectedResult = array( |
| 58 | 'is_error' => 0, |
| 59 | 'version' => 3, |
| 60 | 'count' => 5, |
| 61 | 'values' => array( |
| 62 | '12' => array( |
| 63 | 'id' => '12', |
| 64 | 'contact_id' => '9', |
| 65 | 'location_type_id' => '18', |
| 66 | 'email' => '1-1@example.com', |
| 67 | 'is_primary' => '1', |
| 68 | 'is_billing' => '', |
| 69 | 'on_hold' => '', |
| 70 | 'is_bulkmail' => '', |
| 71 | 'hold_date' => '', |
| 72 | 'reset_date' => '', |
| 73 | 'signature_text' => '', |
| 74 | 'signature_html' => '', |
| 75 | ), |
| 76 | '13' => array( |
| 77 | 'id' => '13', |
| 78 | 'contact_id' => '9', |
| 79 | 'location_type_id' => '18', |
| 80 | 'email' => '1-2@example.com', |
| 81 | 'is_primary' => 0, |
| 82 | 'is_billing' => '', |
| 83 | 'on_hold' => '', |
| 84 | 'is_bulkmail' => '', |
| 85 | 'hold_date' => '', |
| 86 | 'reset_date' => '', |
| 87 | 'signature_text' => '', |
| 88 | 'signature_html' => '', |
| 89 | ), |
| 90 | '14' => array( |
| 91 | 'id' => '14', |
| 92 | 'contact_id' => '9', |
| 93 | 'location_type_id' => '18', |
| 94 | 'email' => '1-3@example.com', |
| 95 | 'is_primary' => 0, |
| 96 | 'is_billing' => '', |
| 97 | 'on_hold' => '', |
| 98 | 'is_bulkmail' => '', |
| 99 | 'hold_date' => '', |
| 100 | 'reset_date' => '', |
| 101 | 'signature_text' => '', |
| 102 | 'signature_html' => '', |
| 103 | ), |
| 104 | '15' => array( |
| 105 | 'id' => '15', |
| 106 | 'contact_id' => '9', |
| 107 | 'location_type_id' => '19', |
| 108 | 'email' => '2-1@example.com', |
| 109 | 'is_primary' => 0, |
| 110 | 'is_billing' => '', |
| 111 | 'on_hold' => '', |
| 112 | 'is_bulkmail' => '', |
| 113 | 'hold_date' => '', |
| 114 | 'reset_date' => '', |
| 115 | 'signature_text' => '', |
| 116 | 'signature_html' => '', |
| 117 | ), |
| 118 | '16' => array( |
| 119 | 'id' => '16', |
| 120 | 'contact_id' => '9', |
| 121 | 'location_type_id' => '19', |
| 122 | 'email' => '2-2@example.com', |
| 123 | 'is_primary' => 0, |
| 124 | 'is_billing' => '', |
| 125 | 'on_hold' => '', |
| 126 | 'is_bulkmail' => '', |
| 127 | 'hold_date' => '', |
| 128 | 'reset_date' => '', |
| 129 | 'signature_text' => '', |
| 130 | 'signature_html' => '', |
| 131 | ), |
| 132 | ), |
| 133 | ); |
| 134 | |
| 135 | return $expectedResult; |
| 136 | } |
| 137 | |
| 138 | |
| 139 | /* |
| 140 | * This example has been generated from the API test suite. The test that created it is called |
| 141 | * |
| 142 | * testReplaceEmail and can be found in |
| 143 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/EmailTest.php |
| 144 | * |
| 145 | * You can see the outcome of the API tests at |
| 146 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
| 147 | * |
| 148 | * To Learn about the API read |
| 149 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
| 150 | * |
| 151 | * Browse the api on your own site with the api explorer |
| 152 | * http://MYSITE.ORG/path/to/civicrm/api/explorer |
| 153 | * |
| 154 | * Read more about testing here |
| 155 | * http://wiki.civicrm.org/confluence/display/CRM/Testing |
| 156 | * |
| 157 | * API Standards documentation: |
| 158 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards |
| 159 | */ |