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;
43 'name' => 'Mailer Group',
44 'description' => 'Test all Mailer Group methods.',
45 'group' => 'CiviCRM API Tests',
51 $this->_apiversion
= 3;
52 $this->_groupID
= $this->groupCreate();
53 $this->_email
= 'test@test.test';
57 $this->groupDelete($this->_groupID
);
60 //---------- civicrm_mailing_event_subscribe methods ---------
63 * Test civicrm_mailing_group_event_subscribe with wrong params.
65 public function testMailerGroupSubscribeWrongParams() {
67 'email' => $this->_email
,
68 'group_id' => 'Wrong Group ID',
69 'contact_id' => '2121',
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',
92 $contactID = $this->individualCreate($params);
95 'email' => $this->_email
,
96 'group_id' => $this->_groupID
,
97 'contact_id' => $contactID,
98 'hash' => 'b15de8b64e2cec34',
99 'time_stamp' => '20101212121212',
101 $result = $this->callAPIAndDocument('mailing_event_subscribe', 'create', $params, __FUNCTION__
, __FILE__
);
102 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
104 $this->contactDelete($contactID);
107 //-------- civicrm_mailing_group_event_unsubscribe methods-----------
110 * Test civicrm_mailing_group_event_unsubscribe with wrong params.
112 public function testMailerGroupUnsubscribeWrongParams() {
114 'job_id' => 'Wrong ID',
115 'event_queue_id' => 'Wrong ID',
116 'hash' => 'Wrong Hash',
117 'time_stamp' => '20101212121212',
120 $result = $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
121 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__
);
124 //--------- civicrm_mailing_group_event_domain_unsubscribe methods -------
127 * Test civicrm_mailing_group_event_domain_unsubscribe with wrong params.
129 public function testMailerGroupDomainUnsubscribeWrongParams() {
131 'job_id' => 'Wrong ID',
132 'event_queue_id' => 'Wrong ID',
133 'hash' => 'Wrong Hash',
134 'org_unsubscribe' => 1,
135 'time_stamp' => '20101212121212',
138 $result = $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
139 $this->assertEquals($result['error_message'], 'Domain Queue event could not be found', 'In line ' . __LINE__
);
142 //----------- civicrm_mailing_group_event_resubscribe methods--------
145 * Test civicrm_mailing_group_event_resubscribe with wrong params type.
149 * Test civicrm_mailing_group_event_resubscribe with wrong params.
151 public function testMailerGroupResubscribeWrongParams() {
153 'job_id' => 'Wrong ID',
154 'event_queue_id' => 'Wrong ID',
155 'hash' => 'Wrong Hash',
156 'org_unsubscribe' => 'test',
157 'time_stamp' => '20101212121212',
159 $result = $this->callAPIFailure('mailing_event_resubscribe', 'create', $params);
160 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__
);
163 //------------------------ success case ---------------------
166 * Test civicrm_mailing_group_event_subscribe and civicrm_mailing_event_confirm functions - success expected.
168 public function testMailerProcess() {
170 'first_name' => 'Test',
171 'last_name' => 'Test',
172 'email' => $this->_email
,
173 'contact_type' => 'Individual',
175 $contactID = $this->individualCreate($params);
178 'email' => $this->_email
,
179 'group_id' => $this->_groupID
,
180 'contact_id' => $contactID,
181 'hash' => 'b15de8b64e2cec34',
182 'time_stamp' => '20101212121212',
184 $result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params);
186 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
189 'contact_id' => $result['values'][$result['id']]['contact_id'],
190 'subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
191 'hash' => $result['values'][$result['id']]['hash'],
192 'time_stamp' => '20101212121212',
193 'event_subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
196 $result = $this->callAPISuccess('mailing_event_confirm', 'create', $params);
197 $this->contactDelete($contactID);