Merge pull request #2842 from totten/master-api-rollback-soft-errors
[civicrm-core.git] / tests / phpunit / api / v3 / MailingTest.php
1 <?php
2 /*
3 * File for the TestMailing class
4 *
5 * (PHP 5)
6 *
7 * @package CiviCRM
8 *
9 * This file is part of CiviCRM
10 *
11 * CiviCRM is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Affero General Public License
13 * as published by the Free Software Foundation; either version 3 of
14 * the License, or (at your option) any later version.
15 *
16 * CiviCRM is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Affero General Public License for more details.
20 *
21 * You should have received a copy of the GNU Affero General Public
22 * License along with this program. If not, see
23 * <http://www.gnu.org/licenses/>.
24 */
25
26 require_once 'CiviTest/CiviUnitTestCase.php';
27
28
29 /**
30 * Test APIv3 civicrm_mailing_* functions
31 *
32 * @package CiviCRM
33 */
34 class api_v3_MailingTest extends CiviUnitTestCase {
35 protected $_groupID;
36 protected $_email;
37 protected $_apiversion = 3;
38 protected $_params = array();
39 protected $_entity = 'Mailing';
40
41
42 /**
43 * @return array
44 */
45 function get_info() {
46 return array(
47 'name' => 'Mailer',
48 'description' => 'Test all Mailer methods.',
49 'group' => 'CiviCRM API Tests',
50 );
51 }
52
53 function setUp() {
54 parent::setUp();
55 $this->_groupID = $this->groupCreate();
56 $this->_email = 'test@test.test';
57 $this->_params = array(
58 'subject' => 'maild',
59 'body_text' => 'bdkfhdskfhduew',
60 'name' => 'mailing name',
61 'created_id' => 1,
62 );
63 }
64
65 function tearDown() {
66 $this->groupDelete($this->_groupID);
67 }
68
69 /**
70 * Test civicrm_mailing_create
71 */
72 public function testMailerCreateSuccess() {
73 $result = $this->callAPIAndDocument('mailing', 'create', $this->_params, __FUNCTION__, __FILE__);
74 $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $result['id']));
75 $this->assertEquals(1, $jobs['count']);
76 unset($this->_params['created_id']); // return isn't working on this in getAndCheck so lets not check it for now
77 $this->getAndCheck($this->_params, $result['id'], 'mailing');
78 }
79
80 /**
81 * Test civicrm_mailing_delete
82 */
83 public function testMailerDeleteSuccess() {
84 $result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
85 $jobs = $this->callAPIAndDocument($this->_entity, 'delete', array('id' => $result['id']), __FUNCTION__, __FILE__);
86 $this->assertAPIDeleted($this->_entity, $result['id']);
87 }
88
89 //@ todo tests below here are all failure tests which are not hugely useful - need success tests
90
91 //------------ civicrm_mailing_event_bounce methods------------
92
93 /**
94 * Test civicrm_mailing_event_bounce with wrong params.
95 * Note that tests like this are slightly better than no test but an
96 * api function cannot be considered supported / 'part of the api' without a
97 * success test
98 */
99 public function testMailerBounceWrongParams() {
100 $params = array(
101 'job_id' => 'Wrong ID',
102 'event_queue_id' => 'Wrong ID',
103 'hash' => 'Wrong Hash',
104 'body' => 'Body...',
105 'time_stamp' => '20111109212100',
106 );
107 $result = $this->callAPIFailure('mailing_event', 'bounce', $params,
108 'Queue event could not be found'
109 );
110 }
111
112 //----------- civicrm_mailing_event_confirm methods -----------
113
114 /**
115 * Test civicrm_mailing_event_confirm with wrong params.
116 * Note that tests like this are slightly better than no test but an
117 * api function cannot be considered supported / 'part of the api' without a
118 * success test
119 */
120 public function testMailerConfirmWrongParams() {
121 $params = array(
122 'contact_id' => 'Wrong ID',
123 'subscribe_id' => 'Wrong ID',
124 'hash' => 'Wrong Hash',
125 'event_subscribe_id' => '123',
126 'time_stamp' => '20111111010101',
127 );
128 $result = $this->callAPIFailure('mailing_event', 'confirm', $params,
129 'Confirmation failed'
130 );
131 }
132
133 //---------- civicrm_mailing_event_reply methods -----------
134
135 /**
136 * Test civicrm_mailing_event_reply with wrong params.
137 *
138 * Note that tests like this are slightly better than no test but an
139 * api function cannot be considered supported / 'part of the api' without a
140 * success test
141 */
142 public function testMailerReplyWrongParams() {
143 $params = array(
144 'job_id' => 'Wrong ID',
145 'event_queue_id' => 'Wrong ID',
146 'hash' => 'Wrong Hash',
147 'bodyTxt' => 'Body...',
148 'replyTo' => $this->_email,
149 'time_stamp' => '20111111010101',
150 );
151 $result = $this->callAPIFailure('mailing_event', 'reply', $params,
152 'Queue event could not be found'
153 );
154 }
155
156
157 //----------- civicrm_mailing_event_forward methods ----------
158
159 /**
160 * Test civicrm_mailing_event_forward with wrong params.
161 * Note that tests like this are slightly better than no test but an
162 * api function cannot be considered supported / 'part of the api' without a
163 * success test
164 */
165 public function testMailerForwardWrongParams() {
166 $params = array(
167 'job_id' => 'Wrong ID',
168 'event_queue_id' => 'Wrong ID',
169 'hash' => 'Wrong Hash',
170 'email' => $this->_email,
171 'time_stamp' => '20111111010101',
172 );
173 $result = $this->callAPIFailure('mailing_event', 'forward', $params,
174 'Queue event could not be found'
175 );
176 }
177
178 //----------- civicrm_mailing_create ----------
179
180 }