3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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;
42 $this->_apiversion
= 3;
43 $this->_groupID
= $this->groupCreate();
44 $this->_email
= 'test@test.test';
48 $this->groupDelete($this->_groupID
);
51 //---------- civicrm_mailing_event_subscribe methods ---------
54 * Test civicrm_mailing_group_event_subscribe with wrong params.
56 public function testMailerGroupSubscribeWrongParams() {
58 'email' => $this->_email
,
59 'group_id' => 'Wrong Group ID',
60 'contact_id' => '2121',
61 'time_stamp' => '20111111010101',
64 $result = $this->callAPIFailure('mailing_event_subscribe', 'create', $params);
65 if ($result['error_message'] != 'Subscription failed') {
66 $this->assertEquals($result['error_message'], 'Invalid Group id', 'In line ' . __LINE__
);
69 $this->assertEquals($result['error_message'], 'Subscription failed', 'In line ' . __LINE__
);
74 * Test civicrm_mailing_group_event_subscribe with given contact ID.
76 public function testMailerGroupSubscribeGivenContactId() {
78 'first_name' => 'Test',
79 'last_name' => 'Test',
80 'email' => $this->_email
,
81 'contact_type' => 'Individual',
83 $contactID = $this->individualCreate($params);
86 'email' => $this->_email
,
87 'group_id' => $this->_groupID
,
88 'contact_id' => $contactID,
89 'hash' => 'b15de8b64e2cec34',
90 'time_stamp' => '20101212121212',
92 $result = $this->callAPIAndDocument('mailing_event_subscribe', 'create', $params, __FUNCTION__
, __FILE__
);
93 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
95 $this->contactDelete($contactID);
98 //-------- civicrm_mailing_group_event_unsubscribe methods-----------
101 * Test civicrm_mailing_group_event_unsubscribe with wrong params.
103 public function testMailerGroupUnsubscribeWrongParams() {
105 'job_id' => 'Wrong ID',
106 'event_queue_id' => 'Wrong ID',
107 'hash' => 'Wrong Hash',
108 'time_stamp' => '20101212121212',
111 $result = $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
112 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__
);
115 //--------- civicrm_mailing_group_event_domain_unsubscribe methods -------
118 * Test civicrm_mailing_group_event_domain_unsubscribe with wrong params.
120 public function testMailerGroupDomainUnsubscribeWrongParams() {
122 'job_id' => 'Wrong ID',
123 'event_queue_id' => 'Wrong ID',
124 'hash' => 'Wrong Hash',
125 'org_unsubscribe' => 1,
126 'time_stamp' => '20101212121212',
129 $result = $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
130 $this->assertEquals($result['error_message'], 'Domain Queue event could not be found', 'In line ' . __LINE__
);
133 //----------- civicrm_mailing_group_event_resubscribe methods--------
136 * Test civicrm_mailing_group_event_resubscribe with wrong params type.
140 * Test civicrm_mailing_group_event_resubscribe with wrong params.
142 public function testMailerGroupResubscribeWrongParams() {
144 'job_id' => 'Wrong ID',
145 'event_queue_id' => 'Wrong ID',
146 'hash' => 'Wrong Hash',
147 'org_unsubscribe' => 'test',
148 'time_stamp' => '20101212121212',
150 $result = $this->callAPIFailure('mailing_event_resubscribe', 'create', $params);
151 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__
);
154 //------------------------ success case ---------------------
157 * Test civicrm_mailing_group_event_subscribe and civicrm_mailing_event_confirm functions - success expected.
159 public function testMailerProcess() {
161 'first_name' => 'Test',
162 'last_name' => 'Test',
163 'email' => $this->_email
,
164 'contact_type' => 'Individual',
166 $contactID = $this->individualCreate($params);
169 'email' => $this->_email
,
170 'group_id' => $this->_groupID
,
171 'contact_id' => $contactID,
172 'hash' => 'b15de8b64e2cec34',
173 'time_stamp' => '20101212121212',
175 $result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params);
177 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
180 'contact_id' => $result['values'][$result['id']]['contact_id'],
181 'subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
182 'hash' => $result['values'][$result['id']]['hash'],
183 'time_stamp' => '20101212121212',
184 'event_subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
187 $result = $this->callAPISuccess('mailing_event_confirm', 'create', $params);
188 $this->contactDelete($contactID);