846dfcc5ed981db42879512194829af76a4291c7
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';
40 public $_eNoticeCompliant = TRUE;
45 'description' => 'Test all Mailer methods.',
46 'group' => 'CiviCRM API Tests',
52 $this->_groupID
= $this->groupCreate(NULL);
53 $this->_email
= 'test@test.test';
54 $this->_params
= array(
56 'body_text' => 'bdkfhdskfhduew',
57 'name' => 'mailing name',
63 $this->groupDelete($this->_groupID
);
67 * Test civicrm_mailing_create
69 public function testMailerCreateSuccess() {
70 $result = $this->callAPIAndDocument('mailing', 'create', $this->_params
, __FUNCTION__
, __FILE__
);
71 $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $result['id']));
72 $this->assertEquals(1, $jobs['count']);
73 unset($this->_params
['created_id']); // return isn't working on this in getAndCheck so lets not check it for now
74 $this->getAndCheck($this->_params
, $result['id'], 'mailing');
78 * Test civicrm_mailing_delete
80 public function testMailerDeleteSuccess() {
81 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
82 $jobs = $this->callAPIAndDocument($this->_entity
, 'delete', array('id' => $result['id']), __FUNCTION__
, __FILE__
);
83 $this->assertAPIDeleted($this->_entity
, $result['id']);
86 //@ todo tests below here are all failure tests which are not hugely useful - need success tests
88 //------------ civicrm_mailing_event_bounce methods------------
91 * Test civicrm_mailing_event_bounce with wrong params.
92 * Note that tests like this are slightly better than no test but an
93 * api function cannot be considered supported / 'part of the api' without a
96 public function testMailerBounceWrongParams() {
98 'job_id' => 'Wrong ID',
99 'event_queue_id' => 'Wrong ID',
100 'hash' => 'Wrong Hash',
102 'time_stamp' => '20111109212100',
104 $result = $this->callAPIFailure('mailing_event', 'bounce', $params,
105 'Queue event could not be found'
109 //----------- civicrm_mailing_event_confirm methods -----------
112 * Test civicrm_mailing_event_confirm with wrong params.
113 * Note that tests like this are slightly better than no test but an
114 * api function cannot be considered supported / 'part of the api' without a
117 public function testMailerConfirmWrongParams() {
119 'contact_id' => 'Wrong ID',
120 'subscribe_id' => 'Wrong ID',
121 'hash' => 'Wrong Hash',
122 'event_subscribe_id' => '123',
123 'time_stamp' => '20111111010101',
125 $result = $this->callAPIFailure('mailing_event', 'confirm', $params,
126 'Confirmation failed'
130 //---------- civicrm_mailing_event_reply methods -----------
133 * Test civicrm_mailing_event_reply with wrong params.
135 * Note that tests like this are slightly better than no test but an
136 * api function cannot be considered supported / 'part of the api' without a
139 public function testMailerReplyWrongParams() {
141 'job_id' => 'Wrong ID',
142 'event_queue_id' => 'Wrong ID',
143 'hash' => 'Wrong Hash',
144 'bodyTxt' => 'Body...',
145 'replyTo' => $this->_email
,
146 'time_stamp' => '20111111010101',
148 $result = $this->callAPIFailure('mailing_event', 'reply', $params,
149 'Queue event could not be found'
154 //----------- civicrm_mailing_event_forward methods ----------
157 * Test civicrm_mailing_event_forward with wrong params.
158 * Note that tests like this are slightly better than no test but an
159 * api function cannot be considered supported / 'part of the api' without a
162 public function testMailerForwardWrongParams() {
164 'job_id' => 'Wrong ID',
165 'event_queue_id' => 'Wrong ID',
166 'hash' => 'Wrong Hash',
167 'email' => $this->_email
,
168 'time_stamp' => '20111111010101',
170 $result = $this->callAPIFailure('mailing_event', 'forward', $params,
171 'Queue event could not be found'
175 //----------- civicrm_mailing_create ----------