3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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;
46 'name' => 'Mailer Group',
47 'description' => 'Test all Mailer Group methods.',
48 'group' => 'CiviCRM API Tests',
54 $this->_apiversion
= 3;
55 $this->_groupID
= $this->groupCreate();
56 $this->_email
= 'test@test.test';
60 $this->groupDelete($this->_groupID
);
63 //---------- civicrm_mailing_event_subscribe methods ---------
66 * Test civicrm_mailing_group_event_subscribe with wrong params.
68 public function testMailerGroupSubscribeWrongParams() {
70 'email' => $this->_email
,
71 'group_id' => 'Wrong Group ID',
72 'contact_id' => '2121',
73 'time_stamp' => '20111111010101',
76 $result = $this->callAPIFailure('mailing_event_subscribe', 'create', $params);
77 if ($result['error_message'] != 'Subscription failed') {
78 $this->assertEquals($result['error_message'], 'Invalid Group id', 'In line ' . __LINE__
);
81 $this->assertEquals($result['error_message'], 'Subscription failed', 'In line ' . __LINE__
);
86 * Test civicrm_mailing_group_event_subscribe with given contact ID.
88 public function testMailerGroupSubscribeGivenContactId() {
90 'first_name' => 'Test',
91 'last_name' => 'Test',
92 'email' => $this->_email
,
93 'contact_type' => 'Individual',
95 $contactID = $this->individualCreate($params);
98 'email' => $this->_email
,
99 'group_id' => $this->_groupID
,
100 'contact_id' => $contactID,
101 'hash' => 'b15de8b64e2cec34',
102 'time_stamp' => '20101212121212',
104 $result = $this->callAPIAndDocument('mailing_event_subscribe', 'create', $params, __FUNCTION__
, __FILE__
);
105 $this->assertEquals($result['values'][$result['id']]['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 'time_stamp' => '20101212121212',
123 $result = $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
124 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__
);
127 //--------- civicrm_mailing_group_event_domain_unsubscribe methods -------
130 * Test civicrm_mailing_group_event_domain_unsubscribe with wrong params.
132 public function testMailerGroupDomainUnsubscribeWrongParams() {
134 'job_id' => 'Wrong ID',
135 'event_queue_id' => 'Wrong ID',
136 'hash' => 'Wrong Hash',
137 'org_unsubscribe' => 1,
138 'time_stamp' => '20101212121212',
141 $result = $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
142 $this->assertEquals($result['error_message'], 'Domain Queue event could not be found', 'In line ' . __LINE__
);
145 //----------- civicrm_mailing_group_event_resubscribe methods--------
148 * Test civicrm_mailing_group_event_resubscribe with wrong params type.
152 * Test civicrm_mailing_group_event_resubscribe with wrong params.
154 public function testMailerGroupResubscribeWrongParams() {
156 'job_id' => 'Wrong ID',
157 'event_queue_id' => 'Wrong ID',
158 'hash' => 'Wrong Hash',
159 'org_unsubscribe' => 'test',
160 'time_stamp' => '20101212121212',
162 $result = $this->callAPIFailure('mailing_event_resubscribe', 'create', $params);
163 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__
);
166 //------------------------ success case ---------------------
169 * Test civicrm_mailing_group_event_subscribe and civicrm_mailing_event_confirm functions - success expected.
171 public function testMailerProcess() {
173 'first_name' => 'Test',
174 'last_name' => 'Test',
175 'email' => $this->_email
,
176 'contact_type' => 'Individual',
178 $contactID = $this->individualCreate($params);
181 'email' => $this->_email
,
182 'group_id' => $this->_groupID
,
183 'contact_id' => $contactID,
184 'hash' => 'b15de8b64e2cec34',
185 'time_stamp' => '20101212121212',
187 $result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params);
189 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
192 'contact_id' => $result['values'][$result['id']]['contact_id'],
193 'subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
194 'hash' => $result['values'][$result['id']]['hash'],
195 'time_stamp' => '20101212121212',
196 'event_subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
199 $result = $this->callAPISuccess('mailing_event_confirm', 'create', $params);
200 $this->contactDelete($contactID);