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;
39 public $_eNoticeCompliant = FALSE;
42 'name' => 'Mailer Group',
43 'description' => 'Test all Mailer Group methods.',
44 'group' => 'CiviCRM API Tests',
50 $this->_apiversion
= 3;
51 $this->_groupID
= $this->groupCreate(NULL);
52 $this->_email
= 'test@test.test';
56 $this->groupDelete($this->_groupID
);
59 //---------- civicrm_mailing_event_subscribe methods ---------
62 * Test civicrm_mailing_group_event_subscribe with wrong params.
64 public function testMailerGroupSubscribeWrongParams() {
66 'email' => $this->_email
,
67 'group_id' => 'Wrong Group ID',
68 'contact_id' => '2121',
69 'version' => $this->_apiversion
,
70 'time_stamp' => '20111111010101',
73 $result = $this->callAPIFailure('mailing_event_subscribe', 'create', $params);
74 if ($result['error_message'] != 'Subscription failed') {
75 $this->assertEquals($result['error_message'], 'Invalid Group id', 'In line ' . __LINE__
);
78 $this->assertEquals($result['error_message'], 'Subscription failed', 'In line ' . __LINE__
);
83 * Test civicrm_mailing_group_event_subscribe with given contact ID.
85 public function testMailerGroupSubscribeGivenContactId() {
87 'first_name' => 'Test',
88 'last_name' => 'Test',
89 'email' => $this->_email
,
90 'contact_type' => 'Individual',
91 'version' => $this->_apiversion
,
93 $contactID = $this->individualCreate($params);
96 'email' => $this->_email
,
97 'group_id' => $this->_groupID
,
98 'contact_id' => $contactID,
99 'version' => $this->_apiversion
,
100 'hash' => 'b15de8b64e2cec34',
101 'time_stamp' => '20101212121212',
103 $result = civicrm_api('mailing_event_subscribe', 'create', $params);
104 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
105 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
106 $this->assertEquals($result['values']['contact_id'], $contactID);
108 $this->contactDelete($contactID);
111 //-------- civicrm_mailing_group_event_unsubscribe methods-----------
114 * Test civicrm_mailing_group_event_unsubscribe with wrong params.
116 public function testMailerGroupUnsubscribeWrongParams() {
118 'job_id' => 'Wrong ID',
119 'event_queue_id' => 'Wrong ID',
120 'hash' => 'Wrong Hash',
121 'version' => $this->_apiversion
,
122 'time_stamp' => '20101212121212',
125 $result = $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
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 = $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
145 $this->assertEquals($result['error_message'], 'Domain Queue event could not be found', 'In line ' . __LINE__
);
149 //----------- civicrm_mailing_group_event_resubscribe methods--------
152 * Test civicrm_mailing_group_event_resubscribe with wrong params type.
156 * Test civicrm_mailing_group_event_resubscribe with wrong params.
158 public function testMailerGroupResubscribeWrongParams() {
160 'job_id' => 'Wrong ID',
161 'event_queue_id' => 'Wrong ID',
162 'hash' => 'Wrong Hash',
163 'org_unsubscribe' => 'test',
164 'version' => $this->_apiversion
,
165 'time_stamp' => '20101212121212',
167 $result = $this->callAPIFailure('mailing_event_resubscribe', 'create', $params);
168 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__
);
171 //------------------------ success case ---------------------
174 * Test civicrm_mailing_group_event_subscribe and civicrm_mailing_event_confirm functions - success expected.
176 public function testMailerProcess() {
178 'first_name' => 'Test',
179 'last_name' => 'Test',
180 'email' => $this->_email
,
181 'contact_type' => 'Individual',
182 'version' => $this->_apiversion
,
184 $contactID = $this->individualCreate($params);
187 'email' => $this->_email
,
188 'group_id' => $this->_groupID
,
189 'contact_id' => $contactID,
190 'version' => $this->_apiversion
,
191 'hash' => 'b15de8b64e2cec34',
192 'time_stamp' => '20101212121212',
194 $result = civicrm_api('mailing_event_subscribe', 'create', $params);
196 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
197 $this->assertEquals($result['values']['contact_id'], $contactID);
200 'contact_id' => $result['values']['contact_id'],
201 'subscribe_id' => $result['values']['subscribe_id'],
202 'hash' => $result['values']['hash'],
203 'version' => $this->_apiversion
,
204 'time_stamp' => '20101212121212',
205 'event_subscribe_id' => $result['values']['subscribe_id'],
209 $result = civicrm_api('mailing_event_confirm', 'create', $params);
211 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
212 $this->contactDelete($contactID);