3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
31 * Test APIv3 civicrm_mailing_group_* functions
35 class api_v3_MailingGroupTest
extends CiviUnitTestCase
{
38 protected $_apiversion; function get_info() {
40 'name' => 'Mailer Group',
41 'description' => 'Test all Mailer Group methods.',
42 'group' => 'CiviCRM API Tests',
48 $this->_apiversion
= 3;
49 $this->_groupID
= $this->groupCreate(NULL);
50 $this->_email
= 'test@test.test';
54 $this->groupDelete($this->_groupID
);
57 //---------- civicrm_mailing_event_subscribe methods ---------
60 * Test civicrm_mailing_group_event_subscribe with wrong params.
62 public function testMailerGroupSubscribeWrongParams() {
64 'email' => $this->_email
,
65 'group_id' => 'Wrong Group ID',
66 'contact_id' => '2121',
67 'version' => $this->_apiversion
,
68 'time_stamp' => '20111111010101',
71 $result = civicrm_api('mailing_event_subscribe', 'create', $params);
72 $this->assertEquals($result['is_error'], 1, 'In line ' . __LINE__
);
73 if ($result['error_message'] != 'Subscription failed') {
74 $this->assertEquals($result['error_message'], 'Invalid Group id', 'In line ' . __LINE__
);
77 $this->assertEquals($result['error_message'], 'Subscription failed', 'In line ' . __LINE__
);
82 * Test civicrm_mailing_group_event_subscribe with given contact ID.
84 public function testMailerGroupSubscribeGivenContactId() {
86 'first_name' => 'Test',
87 'last_name' => 'Test',
88 'email' => $this->_email
,
89 'contact_type' => 'Individual',
90 'version' => $this->_apiversion
,
92 $contactID = $this->individualCreate($params);
95 'email' => $this->_email
,
96 'group_id' => $this->_groupID
,
97 'contact_id' => $contactID,
98 'version' => $this->_apiversion
,
99 'hash' => 'b15de8b64e2cec34',
100 'time_stamp' => '20101212121212',
102 $result = civicrm_api('mailing_event_subscribe', 'create', $params);
103 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
104 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
105 $this->assertEquals($result['values']['contact_id'], $contactID);
107 $this->contactDelete($contactID);
110 //-------- civicrm_mailing_group_event_unsubscribe methods-----------
113 * Test civicrm_mailing_group_event_unsubscribe with wrong params.
115 public function testMailerGroupUnsubscribeWrongParams() {
117 'job_id' => 'Wrong ID',
118 'event_queue_id' => 'Wrong ID',
119 'hash' => 'Wrong Hash',
120 'version' => $this->_apiversion
,
121 'time_stamp' => '20101212121212',
124 $result = civicrm_api('mailing_event_unsubscribe', 'create', $params);
125 $this->assertEquals($result['is_error'], 1, 'In line ' . __LINE__
);
126 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__
);
129 //--------- civicrm_mailing_group_event_domain_unsubscribe methods -------
132 * Test civicrm_mailing_group_event_domain_unsubscribe with wrong params.
134 public function testMailerGroupDomainUnsubscribeWrongParams() {
136 'job_id' => 'Wrong ID',
137 'event_queue_id' => 'Wrong ID',
138 'hash' => 'Wrong Hash',
139 'org_unsubscribe' => 1,
140 'version' => $this->_apiversion
,
141 'time_stamp' => '20101212121212',
144 $result = civicrm_api('mailing_event_unsubscribe', 'create', $params);
145 $this->assertEquals($result['is_error'], 1, 'In line ' . __LINE__
);
146 $this->assertEquals($result['error_message'], 'Domain Queue event could not be found', 'In line ' . __LINE__
);
150 //----------- civicrm_mailing_group_event_resubscribe methods--------
153 * Test civicrm_mailing_group_event_resubscribe with wrong params type.
157 * Test civicrm_mailing_group_event_resubscribe with wrong params.
159 public function testMailerGroupResubscribeWrongParams() {
161 'job_id' => 'Wrong ID',
162 'event_queue_id' => 'Wrong ID',
163 'hash' => 'Wrong Hash',
164 'org_unsubscribe' => 'test',
165 'version' => $this->_apiversion
,
166 'time_stamp' => '20101212121212',
168 $result = civicrm_api('mailing_event_resubscribe', 'create', $params);
169 $this->assertEquals($result['is_error'], 1, 'In line ' . __LINE__
);
170 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__
);
173 //------------------------ success case ---------------------
176 * Test civicrm_mailing_group_event_subscribe and civicrm_mailing_event_confirm functions - success expected.
178 public function testMailerProcess() {
180 'first_name' => 'Test',
181 'last_name' => 'Test',
182 'email' => $this->_email
,
183 'contact_type' => 'Individual',
184 'version' => $this->_apiversion
,
186 $contactID = $this->individualCreate($params);
189 'email' => $this->_email
,
190 'group_id' => $this->_groupID
,
191 'contact_id' => $contactID,
192 'version' => $this->_apiversion
,
193 'hash' => 'b15de8b64e2cec34',
194 'time_stamp' => '20101212121212',
196 $result = civicrm_api('mailing_event_subscribe', 'create', $params);
198 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
199 $this->assertEquals($result['values']['contact_id'], $contactID);
202 'contact_id' => $result['values']['contact_id'],
203 'subscribe_id' => $result['values']['subscribe_id'],
204 'hash' => $result['values']['hash'],
205 'version' => $this->_apiversion
,
206 'time_stamp' => '20101212121212',
207 'event_subscribe_id' => $result['values']['subscribe_id'],
211 $result = civicrm_api('mailing_event_confirm', 'create', $params);
213 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
214 $this->contactDelete($contactID);