89bf81b4 |
1 | <?php |
2 | /** |
50fb255d |
3 | * @file |
4 | * Test Generated API Example. |
5 | * See bottom of this file for more detail. |
89bf81b4 |
6 | */ |
89bf81b4 |
7 | |
50fb255d |
8 | /** |
9 | * Test Generated example of using mailing create API. |
10 | * |
11 | * |
12 | * @return array |
13 | * API result array |
14 | */ |
15 | function mailing_create_example() { |
16 | $params = array( |
17 | 'subject' => 'Hello {contact.display_name}', |
18 | 'body_text' => 'This is {contact.display_name}', |
19 | 'body_html' => '<p>This is {contact.display_name}</p>', |
20 | 'name' => 'mailing name', |
21 | 'created_id' => 3, |
22 | ); |
89bf81b4 |
23 | |
50fb255d |
24 | try{ |
25 | $result = civicrm_api3('mailing', 'create', $params); |
26 | } |
27 | catch (CiviCRM_API3_Exception $e) { |
28 | // Handle error here. |
29 | $errorMessage = $e->getMessage(); |
30 | $errorCode = $e->getErrorCode(); |
31 | $errorData = $e->getExtraParams(); |
32 | return array( |
33 | 'error' => $errorMessage, |
34 | 'error_code' => $errorCode, |
35 | 'error_data' => $errorData, |
36 | ); |
37 | } |
38 | |
39 | return $result; |
89bf81b4 |
40 | } |
41 | |
42 | /** |
50fb255d |
43 | * Function returns array of result expected from previous function. |
44 | * |
45 | * @return array |
46 | * API result array |
89bf81b4 |
47 | */ |
50fb255d |
48 | function mailing_create_expectedresult() { |
89bf81b4 |
49 | |
50 | $expectedResult = array( |
50fb255d |
51 | 'is_error' => 0, |
52 | 'version' => 3, |
53 | 'count' => 1, |
54 | 'id' => 1, |
55 | 'values' => array( |
89bf81b4 |
56 | '1' => array( |
50fb255d |
57 | 'id' => '1', |
58 | 'domain_id' => '1', |
59 | 'header_id' => '', |
60 | 'footer_id' => '', |
61 | 'reply_id' => '', |
62 | 'unsubscribe_id' => '', |
63 | 'resubscribe_id' => '', |
64 | 'optout_id' => '', |
65 | 'name' => 'mailing name', |
66 | 'from_name' => 'FIXME', |
67 | 'from_email' => 'info@EXAMPLE.ORG', |
68 | 'replyto_email' => 'info@EXAMPLE.ORG', |
69 | 'subject' => 'Hello {contact.display_name}', |
70 | 'body_text' => 'This is {contact.display_name}', |
71 | 'body_html' => '<p>This is {contact.display_name}</p>', |
72 | 'url_tracking' => '1', |
73 | 'forward_replies' => '', |
74 | 'auto_responder' => 0, |
75 | 'open_tracking' => '1', |
76 | 'is_completed' => '', |
77 | 'msg_template_id' => '', |
78 | 'override_verp' => '1', |
79 | 'created_id' => '3', |
80 | 'created_date' => '2013-07-28 08:49:19', |
81 | 'scheduled_id' => '', |
82 | 'scheduled_date' => '', |
83 | 'approver_id' => '', |
84 | 'approval_date' => '', |
85 | 'approval_status_id' => '', |
86 | 'approval_note' => '', |
87 | 'is_archived' => '', |
88 | 'visibility' => 'Public Pages', |
89 | 'campaign_id' => '', |
90 | 'dedupe_email' => '', |
91 | 'sms_provider_id' => '', |
92 | 'hash' => '', |
93 | 'location_type_id' => '', |
94 | 'email_selection_method' => '', |
95 | 'api.mailing_job.create' => array( |
96 | 'is_error' => 0, |
97 | 'version' => 3, |
98 | 'count' => 1, |
99 | 'id' => 1, |
100 | 'values' => array( |
101 | '0' => array( |
102 | 'id' => '1', |
103 | 'mailing_id' => '1', |
104 | 'scheduled_date' => '20130728085413', |
105 | 'start_date' => '', |
106 | 'end_date' => '', |
107 | 'status' => 'Scheduled', |
108 | 'is_test' => 0, |
109 | 'job_type' => '', |
110 | 'parent_id' => '', |
111 | 'job_offset' => '', |
112 | 'job_limit' => '', |
89bf81b4 |
113 | ), |
50fb255d |
114 | ), |
89bf81b4 |
115 | ), |
50fb255d |
116 | ), |
89bf81b4 |
117 | ), |
50fb255d |
118 | ); |
89bf81b4 |
119 | |
120 | return $expectedResult; |
121 | } |
122 | |
50fb255d |
123 | /** |
124 | * This example has been generated from the API test suite. |
125 | * The test that created it is called |
126 | * testMailerCreateSuccess |
127 | * and can be found in |
89bf81b4 |
128 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/MailingTest.php |
129 | * |
130 | * You can see the outcome of the API tests at |
131 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
132 | * |
133 | * To Learn about the API read |
134 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
135 | * |
136 | * Browse the api on your own site with the api explorer |
137 | * http://MYSITE.ORG/path/to/civicrm/api/explorer |
138 | * |
139 | * Read more about testing here |
140 | * http://wiki.civicrm.org/confluence/display/CRM/Testing |
141 | * |
142 | * API Standards documentation: |
143 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards |
144 | */ |