3 * File for the TestMailing class
9 * This file is part of CiviCRM
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.
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.
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/>.
26 require_once 'CiviTest/CiviUnitTestCase.php';
30 * Test APIv3 civicrm_mailing_* functions
34 class api_v3_MailingTest
extends CiviUnitTestCase
{
37 protected $_apiversion = 3;
38 protected $_params = array();
39 protected $_entity = 'Mailing';
48 'description' => 'Test all Mailer methods.',
49 'group' => 'CiviCRM API Tests',
55 $this->_groupID
= $this->groupCreate();
56 $this->_email
= 'test@test.test';
57 $this->_params
= array(
59 'body_text' => 'bdkfhdskfhduew',
60 'name' => 'mailing name',
66 $this->groupDelete($this->_groupID
);
70 * Test civicrm_mailing_create
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');
81 * Test civicrm_mailing_delete
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']);
89 //@ todo tests below here are all failure tests which are not hugely useful - need success tests
91 //------------ civicrm_mailing_event_bounce methods------------
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
99 public function testMailerBounceWrongParams() {
101 'job_id' => 'Wrong ID',
102 'event_queue_id' => 'Wrong ID',
103 'hash' => 'Wrong Hash',
105 'time_stamp' => '20111109212100',
107 $result = $this->callAPIFailure('mailing_event', 'bounce', $params,
108 'Queue event could not be found'
112 //----------- civicrm_mailing_event_confirm methods -----------
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
120 public function testMailerConfirmWrongParams() {
122 'contact_id' => 'Wrong ID',
123 'subscribe_id' => 'Wrong ID',
124 'hash' => 'Wrong Hash',
125 'event_subscribe_id' => '123',
126 'time_stamp' => '20111111010101',
128 $result = $this->callAPIFailure('mailing_event', 'confirm', $params,
129 'Confirmation failed'
133 //---------- civicrm_mailing_event_reply methods -----------
136 * Test civicrm_mailing_event_reply with wrong params.
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
142 public function testMailerReplyWrongParams() {
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',
151 $result = $this->callAPIFailure('mailing_event', 'reply', $params,
152 'Queue event could not be found'
157 //----------- civicrm_mailing_event_forward methods ----------
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
165 public function testMailerForwardWrongParams() {
167 'job_id' => 'Wrong ID',
168 'event_queue_id' => 'Wrong ID',
169 'hash' => 'Wrong Hash',
170 'email' => $this->_email
,
171 'time_stamp' => '20111111010101',
173 $result = $this->callAPIFailure('mailing_event', 'forward', $params,
174 'Queue event could not be found'
178 //----------- civicrm_mailing_create ----------