3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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
34 class api_v3_MailingGroupTest
extends CiviUnitTestCase
{
37 protected $_apiversion;
39 public function setUp() {
41 $this->useTransaction(TRUE);
42 $this->_apiversion
= 3;
43 $this->_groupID
= $this->groupCreate();
44 $this->_email
= 'test@test.test';
47 //---------- civicrm_mailing_event_subscribe methods ---------
50 * Test civicrm_mailing_group_event_subscribe with wrong params.
52 public function testMailerGroupSubscribeWrongParams() {
54 'email' => $this->_email
,
55 'group_id' => 'Wrong Group ID',
56 'contact_id' => '2121',
57 'time_stamp' => '20111111010101',
60 $this->callAPIFailure('mailing_event_subscribe', 'create', $params);
64 * Test civicrm_mailing_group_event_subscribe with given contact ID.
66 public function testMailerGroupSubscribeGivenContactId() {
68 'first_name' => 'Test',
69 'last_name' => 'Test',
70 'email' => $this->_email
,
71 'contact_type' => 'Individual',
73 $contactID = $this->individualCreate($params);
76 'email' => $this->_email
,
77 'group_id' => $this->_groupID
,
78 'contact_id' => $contactID,
79 'hash' => 'b15de8b64e2cec34',
80 'time_stamp' => '20101212121212',
82 $result = $this->callAPIAndDocument('mailing_event_subscribe', 'create', $params, __FUNCTION__
, __FILE__
);
83 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
85 $this->contactDelete($contactID);
88 //-------- civicrm_mailing_group_event_unsubscribe methods-----------
91 * Test civicrm_mailing_group_event_unsubscribe with wrong params.
93 public function testMailerGroupUnsubscribeWrongParams() {
95 'job_id' => 'Wrong ID',
96 'event_queue_id' => 'Wrong ID',
97 'hash' => 'Wrong Hash',
98 'time_stamp' => '20101212121212',
101 $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
104 //--------- civicrm_mailing_group_event_domain_unsubscribe methods -------
107 * Test civicrm_mailing_group_event_domain_unsubscribe with wrong params.
109 public function testMailerGroupDomainUnsubscribeWrongParams() {
111 'job_id' => 'Wrong ID',
112 'event_queue_id' => 'Wrong ID',
113 'hash' => 'Wrong Hash',
114 'org_unsubscribe' => 1,
115 'time_stamp' => '20101212121212',
118 $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
121 //----------- civicrm_mailing_group_event_resubscribe methods--------
124 * Test civicrm_mailing_group_event_resubscribe with wrong params type.
128 * Test civicrm_mailing_group_event_resubscribe with wrong params.
130 public function testMailerGroupResubscribeWrongParams() {
132 'job_id' => 'Wrong ID',
133 'event_queue_id' => 'Wrong ID',
134 'hash' => 'Wrong Hash',
135 'org_unsubscribe' => 'test',
136 'time_stamp' => '20101212121212',
138 $this->callAPIFailure('mailing_event_resubscribe', 'create', $params);
141 //------------------------ success case ---------------------
144 * Test civicrm_mailing_group_event_subscribe and civicrm_mailing_event_confirm functions - success expected.
146 public function testMailerProcess() {
148 'first_name' => 'Test',
149 'last_name' => 'Test',
150 'email' => $this->_email
,
151 'contact_type' => 'Individual',
153 $contactID = $this->individualCreate($params);
156 'email' => $this->_email
,
157 'group_id' => $this->_groupID
,
158 'contact_id' => $contactID,
159 'hash' => 'b15de8b64e2cec34',
160 'time_stamp' => '20101212121212',
162 $result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params);
164 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
167 'contact_id' => $result['values'][$result['id']]['contact_id'],
168 'subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
169 'hash' => $result['values'][$result['id']]['hash'],
170 'time_stamp' => '20101212121212',
171 'event_subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
174 $result = $this->callAPISuccess('mailing_event_confirm', 'create', $params);
175 $this->contactDelete($contactID);