3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
29 * Test APIv3 civicrm_mailing_group_* functions
33 class api_v3_MailingGroupTest
extends CiviUnitTestCase
{
36 protected $_apiversion;
38 public function setUp() {
40 $this->useTransaction(TRUE);
41 $this->_apiversion
= 3;
42 $this->_groupID
= $this->groupCreate();
43 $this->_email
= 'test@test.test';
46 //---------- civicrm_mailing_event_subscribe methods ---------
49 * Test civicrm_mailing_group_event_subscribe with wrong params.
51 public function testMailerGroupSubscribeWrongParams() {
53 'email' => $this->_email
,
54 'group_id' => 'Wrong Group ID',
55 'contact_id' => '2121',
56 'time_stamp' => '20111111010101',
59 $this->callAPIFailure('mailing_event_subscribe', 'create', $params);
63 * Test civicrm_mailing_group_event_subscribe with given contact ID.
65 public function testMailerGroupSubscribeGivenContactId() {
67 'first_name' => 'Test',
68 'last_name' => 'Test',
69 'email' => $this->_email
,
70 'contact_type' => 'Individual',
72 $contactID = $this->individualCreate($params);
75 'email' => $this->_email
,
76 'group_id' => $this->_groupID
,
77 'contact_id' => $contactID,
78 'hash' => 'b15de8b64e2cec34',
79 'time_stamp' => '20101212121212',
81 $result = $this->callAPIAndDocument('mailing_event_subscribe', 'create', $params, __FUNCTION__
, __FILE__
);
82 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
84 $this->contactDelete($contactID);
87 //-------- civicrm_mailing_group_event_unsubscribe methods-----------
90 * Test civicrm_mailing_group_event_unsubscribe with wrong params.
92 public function testMailerGroupUnsubscribeWrongParams() {
94 'job_id' => 'Wrong ID',
95 'event_queue_id' => 'Wrong ID',
96 'hash' => 'Wrong Hash',
97 'time_stamp' => '20101212121212',
100 $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
103 //--------- civicrm_mailing_group_event_domain_unsubscribe methods -------
106 * Test civicrm_mailing_group_event_domain_unsubscribe with wrong params.
108 public function testMailerGroupDomainUnsubscribeWrongParams() {
110 'job_id' => 'Wrong ID',
111 'event_queue_id' => 'Wrong ID',
112 'hash' => 'Wrong Hash',
113 'org_unsubscribe' => 1,
114 'time_stamp' => '20101212121212',
117 $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
120 //----------- civicrm_mailing_group_event_resubscribe methods--------
123 * Test civicrm_mailing_group_event_resubscribe with wrong params type.
127 * Test civicrm_mailing_group_event_resubscribe with wrong params.
129 public function testMailerGroupResubscribeWrongParams() {
131 'job_id' => 'Wrong ID',
132 'event_queue_id' => 'Wrong ID',
133 'hash' => 'Wrong Hash',
134 'org_unsubscribe' => 'test',
135 'time_stamp' => '20101212121212',
137 $this->callAPIFailure('mailing_event_resubscribe', 'create', $params);
140 //------------------------ success case ---------------------
143 * Test civicrm_mailing_group_event_subscribe and civicrm_mailing_event_confirm functions - success expected.
145 public function testMailerProcess() {
147 'first_name' => 'Test',
148 'last_name' => 'Test',
149 'email' => $this->_email
,
150 'contact_type' => 'Individual',
152 $contactID = $this->individualCreate($params);
155 'email' => $this->_email
,
156 'group_id' => $this->_groupID
,
157 'contact_id' => $contactID,
158 'hash' => 'b15de8b64e2cec34',
159 'time_stamp' => '20101212121212',
161 $result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params);
163 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
166 'contact_id' => $result['values'][$result['id']]['contact_id'],
167 'subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
168 'hash' => $result['values'][$result['id']]['hash'],
169 'time_stamp' => '20101212121212',
170 'event_subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
173 $result = $this->callAPISuccess('mailing_event_confirm', 'create', $params);
174 $this->contactDelete($contactID);