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, 'hash' => 'b15de8b64e2cec34',
95 'time_stamp' => '20101212121212',
97 $result = $this->callAPIAndDocument('mailing_event_subscribe', 'create', $params, __FUNCTION__
, __FILE__
);
98 $this->assertEquals($result['values']['contact_id'], $contactID);
100 $this->contactDelete($contactID);
103 //-------- civicrm_mailing_group_event_unsubscribe methods-----------
106 * Test civicrm_mailing_group_event_unsubscribe with wrong params.
108 public function testMailerGroupUnsubscribeWrongParams() {
110 'job_id' => 'Wrong ID',
111 'event_queue_id' => 'Wrong ID',
112 'hash' => 'Wrong Hash', 'time_stamp' => '20101212121212',
115 $result = $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
116 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__
);
119 //--------- civicrm_mailing_group_event_domain_unsubscribe methods -------
122 * Test civicrm_mailing_group_event_domain_unsubscribe with wrong params.
124 public function testMailerGroupDomainUnsubscribeWrongParams() {
126 'job_id' => 'Wrong ID',
127 'event_queue_id' => 'Wrong ID',
128 'hash' => 'Wrong Hash',
129 'org_unsubscribe' => 1, 'time_stamp' => '20101212121212',
132 $result = $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
133 $this->assertEquals($result['error_message'], 'Domain Queue event could not be found', 'In line ' . __LINE__
);
137 //----------- civicrm_mailing_group_event_resubscribe methods--------
140 * Test civicrm_mailing_group_event_resubscribe with wrong params type.
144 * Test civicrm_mailing_group_event_resubscribe with wrong params.
146 public function testMailerGroupResubscribeWrongParams() {
148 'job_id' => 'Wrong ID',
149 'event_queue_id' => 'Wrong ID',
150 'hash' => 'Wrong Hash',
151 'org_unsubscribe' => 'test', 'time_stamp' => '20101212121212',
153 $result = $this->callAPIFailure('mailing_event_resubscribe', 'create', $params);
154 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__
);
157 //------------------------ success case ---------------------
160 * Test civicrm_mailing_group_event_subscribe and civicrm_mailing_event_confirm functions - success expected.
162 public function testMailerProcess() {
164 'first_name' => 'Test',
165 'last_name' => 'Test',
166 'email' => $this->_email
,
167 'contact_type' => 'Individual', );
168 $contactID = $this->individualCreate($params);
171 'email' => $this->_email
,
172 'group_id' => $this->_groupID
,
173 'contact_id' => $contactID, 'hash' => 'b15de8b64e2cec34',
174 'time_stamp' => '20101212121212',
176 $result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params);
178 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
179 $this->assertEquals($result['values']['contact_id'], $contactID);
182 'contact_id' => $result['values']['contact_id'],
183 'subscribe_id' => $result['values']['subscribe_id'],
184 'hash' => $result['values']['hash'], 'time_stamp' => '20101212121212',
185 'event_subscribe_id' => $result['values']['subscribe_id'],
189 $result = $this->callAPISuccess('mailing_event_confirm', 'create', $params);
191 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
192 $this->contactDelete($contactID);