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;
42 'description' => 'Test all Mailer methods.',
43 'group' => 'CiviCRM API Tests',
49 $this->_apiversion
= 3;
50 $this->_groupID
= $this->groupCreate(NULL);
51 $this->_email
= 'test@test.test';
55 $this->groupDelete($this->_groupID
);
59 * Test civicrm_mailing_create
61 public function testMailerCreateSuccess() {
64 'body_text' => 'bdkfhdskfhduew',
66 'name' => 'mailing name',
69 $result = civicrm_api('mailing', 'create', $params);
70 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
71 $jobs = civicrm_api('mailing_job', 'get', array('version' =>3, 'mailing_id' => $result['id']));
72 $this->assertAPISuccess($jobs);
73 $this->assertEquals(1, $jobs['count']);
74 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
75 unset($params['created_id']);// return isn't working on this in getAndCheck so lets not check it for now
76 $this->getAndCheck($params, $result['id'], 'mailing');
80 //@ todo tests below here are all failure tests which are not hugely useful - need success tests
82 //------------ civicrm_mailing_event_bounce methods------------
85 * Test civicrm_mailing_event_bounce with wrong params.
87 public function testMailerBounceWrongParams() {
89 'job_id' => 'Wrong ID',
90 'event_queue_id' => 'Wrong ID',
91 'hash' => 'Wrong Hash',
94 'time_stamp' => '20111109212100',
96 $result = civicrm_api('mailing_event', 'bounce', $params);
97 $this->assertEquals($result['is_error'], 1, 'In line ' . __LINE__
);
98 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__
);
101 //----------- civicrm_mailing_event_confirm methods -----------
104 * Test civicrm_mailing_event_confirm with wrong params.
106 public function testMailerConfirmWrongParams() {
108 'contact_id' => 'Wrong ID',
109 'subscribe_id' => 'Wrong ID',
110 'hash' => 'Wrong Hash',
111 'event_subscribe_id' => '123',
112 'time_stamp' => '20111111010101',
115 $result = civicrm_api('mailing_event', 'confirm', $params);
116 $this->assertEquals($result['is_error'], 1, 'In line ' . __LINE__
);
117 $this->assertEquals($result['error_message'], 'Confirmation failed', 'In line ' . __LINE__
);
120 //---------- civicrm_mailing_event_reply methods -----------
123 * Test civicrm_mailing_event_reply with wrong params.
125 public function testMailerReplyWrongParams() {
127 'job_id' => 'Wrong ID',
128 'event_queue_id' => 'Wrong ID',
129 'hash' => 'Wrong Hash',
130 'bodyTxt' => 'Body...',
131 'replyTo' => $this->_email
,
132 'time_stamp' => '20111111010101',
135 $result = civicrm_api('mailing_event', 'reply', $params);
136 $this->assertEquals($result['is_error'], 1, 'In line ' . __LINE__
);
137 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__
);
141 //----------- civicrm_mailing_event_forward methods ----------
144 * Test civicrm_mailing_event_forward with wrong params.
146 public function testMailerForwardWrongParams() {
148 'job_id' => 'Wrong ID',
149 'event_queue_id' => 'Wrong ID',
150 'hash' => 'Wrong Hash',
151 'email' => $this->_email
,
152 'time_stamp' => '20111111010101',
155 $result = civicrm_api('mailing_event', 'forward', $params);
156 $this->assertEquals($result['is_error'], 1, 'In line ' . __LINE__
);
157 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__
);
161 //----------- civicrm_mailing_create ----------