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;
40 public function setUp() {
42 $this->useTransaction(TRUE);
43 $this->_apiversion
= 3;
44 $this->_groupID
= $this->groupCreate();
45 $this->_email
= 'test@test.test';
48 //---------- civicrm_mailing_event_subscribe methods ---------
51 * Test civicrm_mailing_group_event_subscribe with wrong params.
53 public function testMailerGroupSubscribeWrongParams() {
55 'email' => $this->_email
,
56 'group_id' => 'Wrong Group ID',
57 'contact_id' => '2121',
58 'time_stamp' => '20111111010101',
61 $result = $this->callAPIFailure('mailing_event_subscribe', 'create', $params);
62 if ($result['error_message'] != 'Subscription failed') {
63 $this->assertEquals($result['error_message'], 'Invalid Group id', 'In line ' . __LINE__
);
66 $this->assertEquals($result['error_message'], 'Subscription failed', 'In line ' . __LINE__
);
71 * Test civicrm_mailing_group_event_subscribe with given contact ID.
73 public function testMailerGroupSubscribeGivenContactId() {
75 'first_name' => 'Test',
76 'last_name' => 'Test',
77 'email' => $this->_email
,
78 'contact_type' => 'Individual',
80 $contactID = $this->individualCreate($params);
83 'email' => $this->_email
,
84 'group_id' => $this->_groupID
,
85 'contact_id' => $contactID,
86 'hash' => 'b15de8b64e2cec34',
87 'time_stamp' => '20101212121212',
89 $result = $this->callAPIAndDocument('mailing_event_subscribe', 'create', $params, __FUNCTION__
, __FILE__
);
90 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
92 $this->contactDelete($contactID);
95 //-------- civicrm_mailing_group_event_unsubscribe methods-----------
98 * Test civicrm_mailing_group_event_unsubscribe with wrong params.
100 public function testMailerGroupUnsubscribeWrongParams() {
102 'job_id' => 'Wrong ID',
103 'event_queue_id' => 'Wrong ID',
104 'hash' => 'Wrong Hash',
105 'time_stamp' => '20101212121212',
108 $result = $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
109 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__
);
112 //--------- civicrm_mailing_group_event_domain_unsubscribe methods -------
115 * Test civicrm_mailing_group_event_domain_unsubscribe with wrong params.
117 public function testMailerGroupDomainUnsubscribeWrongParams() {
119 'job_id' => 'Wrong ID',
120 'event_queue_id' => 'Wrong ID',
121 'hash' => 'Wrong Hash',
122 'org_unsubscribe' => 1,
123 'time_stamp' => '20101212121212',
126 $result = $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
127 $this->assertEquals($result['error_message'], 'Domain Queue event could not be found', 'In line ' . __LINE__
);
130 //----------- civicrm_mailing_group_event_resubscribe methods--------
133 * Test civicrm_mailing_group_event_resubscribe with wrong params type.
137 * Test civicrm_mailing_group_event_resubscribe with wrong params.
139 public function testMailerGroupResubscribeWrongParams() {
141 'job_id' => 'Wrong ID',
142 'event_queue_id' => 'Wrong ID',
143 'hash' => 'Wrong Hash',
144 'org_unsubscribe' => 'test',
145 'time_stamp' => '20101212121212',
147 $result = $this->callAPIFailure('mailing_event_resubscribe', 'create', $params);
148 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__
);
151 //------------------------ success case ---------------------
154 * Test civicrm_mailing_group_event_subscribe and civicrm_mailing_event_confirm functions - success expected.
156 public function testMailerProcess() {
158 'first_name' => 'Test',
159 'last_name' => 'Test',
160 'email' => $this->_email
,
161 'contact_type' => 'Individual',
163 $contactID = $this->individualCreate($params);
166 'email' => $this->_email
,
167 'group_id' => $this->_groupID
,
168 'contact_id' => $contactID,
169 'hash' => 'b15de8b64e2cec34',
170 'time_stamp' => '20101212121212',
172 $result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params);
174 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
177 'contact_id' => $result['values'][$result['id']]['contact_id'],
178 'subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
179 'hash' => $result['values'][$result['id']]['hash'],
180 'time_stamp' => '20101212121212',
181 'event_subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
184 $result = $this->callAPISuccess('mailing_event_confirm', 'create', $params);
185 $this->contactDelete($contactID);