| 1 | <?php |
| 2 | /** |
| 3 | * Test Generated example of using mailing create API |
| 4 | * * |
| 5 | */ |
| 6 | function mailing_create_example(){ |
| 7 | $params = array( |
| 8 | 'subject' => 'maild', |
| 9 | 'body_text' => 'bdkfhdskfhduew', |
| 10 | 'name' => 'mailing name', |
| 11 | 'created_id' => 1, |
| 12 | ); |
| 13 | |
| 14 | try{ |
| 15 | $result = civicrm_api3('mailing', 'create', $params); |
| 16 | } |
| 17 | catch (CiviCRM_API3_Exception $e) { |
| 18 | // handle error here |
| 19 | $errorMessage = $e->getMessage(); |
| 20 | $errorCode = $e->getErrorCode(); |
| 21 | $errorData = $e->getExtraParams(); |
| 22 | return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData); |
| 23 | } |
| 24 | |
| 25 | return $result; |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Function returns array of result expected from previous function |
| 30 | */ |
| 31 | function mailing_create_expectedresult(){ |
| 32 | |
| 33 | $expectedResult = array( |
| 34 | 'is_error' => 0, |
| 35 | 'version' => 3, |
| 36 | 'count' => 1, |
| 37 | 'id' => 1, |
| 38 | 'values' => array( |
| 39 | '1' => array( |
| 40 | 'id' => '1', |
| 41 | 'domain_id' => '1', |
| 42 | 'header_id' => 'null', |
| 43 | 'footer_id' => 'null', |
| 44 | 'reply_id' => '', |
| 45 | 'unsubscribe_id' => '', |
| 46 | 'resubscribe_id' => '', |
| 47 | 'optout_id' => '', |
| 48 | 'name' => 'mailing name', |
| 49 | 'from_name' => 'FIXME', |
| 50 | 'from_email' => 'info@EXAMPLE.ORG', |
| 51 | 'replyto_email' => 'info@EXAMPLE.ORG', |
| 52 | 'subject' => 'maild', |
| 53 | 'body_text' => 'bdkfhdskfhduew', |
| 54 | 'body_html' => '', |
| 55 | 'url_tracking' => '1', |
| 56 | 'forward_replies' => '', |
| 57 | 'auto_responder' => 0, |
| 58 | 'open_tracking' => '1', |
| 59 | 'is_completed' => '', |
| 60 | 'msg_template_id' => '', |
| 61 | 'override_verp' => '1', |
| 62 | 'created_id' => '1', |
| 63 | 'created_date' => '2013-07-28 08:49:19', |
| 64 | 'scheduled_id' => '', |
| 65 | 'scheduled_date' => '20130728085413', |
| 66 | 'approver_id' => '1', |
| 67 | 'approval_date' => '20130728085413', |
| 68 | 'approval_status_id' => '', |
| 69 | 'approval_note' => '', |
| 70 | 'is_archived' => '', |
| 71 | 'visibility' => 'User and User Admin Only', |
| 72 | 'campaign_id' => '', |
| 73 | 'dedupe_email' => '', |
| 74 | 'sms_provider_id' => '', |
| 75 | 'api.mailing_job.create' => array( |
| 76 | 'is_error' => 0, |
| 77 | 'version' => 3, |
| 78 | 'count' => 1, |
| 79 | 'id' => 1, |
| 80 | 'values' => array( |
| 81 | '0' => array( |
| 82 | 'id' => '1', |
| 83 | 'mailing_id' => '1', |
| 84 | 'scheduled_date' => '20130728085413', |
| 85 | 'start_date' => '', |
| 86 | 'end_date' => '', |
| 87 | 'status' => 'Scheduled', |
| 88 | 'is_test' => 0, |
| 89 | 'job_type' => '', |
| 90 | 'parent_id' => '', |
| 91 | 'job_offset' => '', |
| 92 | 'job_limit' => '', |
| 93 | ), |
| 94 | ), |
| 95 | ), |
| 96 | ), |
| 97 | ), |
| 98 | ); |
| 99 | |
| 100 | return $expectedResult; |
| 101 | } |
| 102 | |
| 103 | |
| 104 | /* |
| 105 | * This example has been generated from the API test suite. The test that created it is called |
| 106 | * |
| 107 | * testMailerCreateSuccess and can be found in |
| 108 | * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/MailingTest.php |
| 109 | * |
| 110 | * You can see the outcome of the API tests at |
| 111 | * http://tests.dev.civicrm.org/trunk/results-api_v3 |
| 112 | * |
| 113 | * To Learn about the API read |
| 114 | * http://book.civicrm.org/developer/current/techniques/api/ |
| 115 | * |
| 116 | * and review the wiki at |
| 117 | * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs |
| 118 | * |
| 119 | * Read more about testing here |
| 120 | * http://wiki.civicrm.org/confluence/display/CRM/Testing |
| 121 | * |
| 122 | * API Standards documentation: |
| 123 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards |
| 124 | */ |