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', 'time_stamp' => '20111111010101',
71 $result = $this->callAPIFailure('mailing_event_subscribe', 'create', $params);
72 if ($result['error_message'] != 'Subscription failed') {
73 $this->assertEquals($result['error_message'], 'Invalid Group id', 'In line ' . __LINE__
);
76 $this->assertEquals($result['error_message'], 'Subscription failed', 'In line ' . __LINE__
);
81 * Test civicrm_mailing_group_event_subscribe with given contact ID.
83 public function testMailerGroupSubscribeGivenContactId() {
85 'first_name' => 'Test',
86 'last_name' => 'Test',
87 'email' => $this->_email
,
88 'contact_type' => 'Individual', );
89 $contactID = $this->individualCreate($params);
92 'email' => $this->_email
,
93 'group_id' => $this->_groupID
,
94 'contact_id' => $contactID,
95 'hash' => 'b15de8b64e2cec34',
96 'time_stamp' => '20101212121212',
98 $result = $this->callAPIAndDocument('mailing_event_subscribe', 'create', $params, __FUNCTION__
, __FILE__
);
99 $this->assertEquals($result['values']['contact_id'], $contactID);
101 $this->contactDelete($contactID);
104 //-------- civicrm_mailing_group_event_unsubscribe methods-----------
107 * Test civicrm_mailing_group_event_unsubscribe with wrong params.
109 public function testMailerGroupUnsubscribeWrongParams() {
111 'job_id' => 'Wrong ID',
112 'event_queue_id' => 'Wrong ID',
113 'hash' => 'Wrong Hash', 'time_stamp' => '20101212121212',
116 $result = $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
117 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__
);
120 //--------- civicrm_mailing_group_event_domain_unsubscribe methods -------
123 * Test civicrm_mailing_group_event_domain_unsubscribe with wrong params.
125 public function testMailerGroupDomainUnsubscribeWrongParams() {
127 'job_id' => 'Wrong ID',
128 'event_queue_id' => 'Wrong ID',
129 'hash' => 'Wrong Hash',
130 'org_unsubscribe' => 1, 'time_stamp' => '20101212121212',
133 $result = $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
134 $this->assertEquals($result['error_message'], 'Domain Queue event could not be found', 'In line ' . __LINE__
);
138 //----------- civicrm_mailing_group_event_resubscribe methods--------
141 * Test civicrm_mailing_group_event_resubscribe with wrong params type.
145 * Test civicrm_mailing_group_event_resubscribe with wrong params.
147 public function testMailerGroupResubscribeWrongParams() {
149 'job_id' => 'Wrong ID',
150 'event_queue_id' => 'Wrong ID',
151 'hash' => 'Wrong Hash',
152 'org_unsubscribe' => 'test', 'time_stamp' => '20101212121212',
154 $result = $this->callAPIFailure('mailing_event_resubscribe', 'create', $params);
155 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__
);
158 //------------------------ success case ---------------------
161 * Test civicrm_mailing_group_event_subscribe and civicrm_mailing_event_confirm functions - success expected.
163 public function testMailerProcess() {
165 'first_name' => 'Test',
166 'last_name' => 'Test',
167 'email' => $this->_email
,
168 'contact_type' => 'Individual', );
169 $contactID = $this->individualCreate($params);
172 'email' => $this->_email
,
173 'group_id' => $this->_groupID
,
174 'contact_id' => $contactID, 'hash' => 'b15de8b64e2cec34',
175 'time_stamp' => '20101212121212',
177 $result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params);
179 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
180 $this->assertEquals($result['values']['contact_id'], $contactID);
183 'contact_id' => $result['values']['contact_id'],
184 'subscribe_id' => $result['values']['subscribe_id'],
185 'hash' => $result['values']['hash'], 'time_stamp' => '20101212121212',
186 'event_subscribe_id' => $result['values']['subscribe_id'],
190 $result = $this->callAPISuccess('mailing_event_confirm', 'create', $params);
192 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
193 $this->contactDelete($contactID);