6954b9a626526e51b288a9d25ed5fd02adbdb27a
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 +--------------------------------------------------------------------+
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 $this->callAPIFailure('mailing_event_subscribe', 'create', $params);
65 * Test civicrm_mailing_group_event_subscribe with given contact ID.
67 public function testMailerGroupSubscribeGivenContactId() {
69 'first_name' => 'Test',
70 'last_name' => 'Test',
71 'email' => $this->_email
,
72 'contact_type' => 'Individual',
74 $contactID = $this->individualCreate($params);
77 'email' => $this->_email
,
78 'group_id' => $this->_groupID
,
79 'contact_id' => $contactID,
80 'hash' => 'b15de8b64e2cec34',
81 'time_stamp' => '20101212121212',
83 $result = $this->callAPIAndDocument('mailing_event_subscribe', 'create', $params, __FUNCTION__
, __FILE__
);
84 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
86 $this->contactDelete($contactID);
89 //-------- civicrm_mailing_group_event_unsubscribe methods-----------
92 * Test civicrm_mailing_group_event_unsubscribe with wrong params.
94 public function testMailerGroupUnsubscribeWrongParams() {
96 'job_id' => 'Wrong ID',
97 'event_queue_id' => 'Wrong ID',
98 'hash' => 'Wrong Hash',
99 'time_stamp' => '20101212121212',
102 $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
105 //--------- civicrm_mailing_group_event_domain_unsubscribe methods -------
108 * Test civicrm_mailing_group_event_domain_unsubscribe with wrong params.
110 public function testMailerGroupDomainUnsubscribeWrongParams() {
112 'job_id' => 'Wrong ID',
113 'event_queue_id' => 'Wrong ID',
114 'hash' => 'Wrong Hash',
115 'org_unsubscribe' => 1,
116 'time_stamp' => '20101212121212',
119 $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
122 //----------- civicrm_mailing_group_event_resubscribe methods--------
125 * Test civicrm_mailing_group_event_resubscribe with wrong params type.
129 * Test civicrm_mailing_group_event_resubscribe with wrong params.
131 public function testMailerGroupResubscribeWrongParams() {
133 'job_id' => 'Wrong ID',
134 'event_queue_id' => 'Wrong ID',
135 'hash' => 'Wrong Hash',
136 'org_unsubscribe' => 'test',
137 'time_stamp' => '20101212121212',
139 $this->callAPIFailure('mailing_event_resubscribe', 'create', $params);
142 //------------------------ success case ---------------------
145 * Test civicrm_mailing_group_event_subscribe and civicrm_mailing_event_confirm functions - success expected.
147 public function testMailerProcess() {
149 'first_name' => 'Test',
150 'last_name' => 'Test',
151 'email' => $this->_email
,
152 'contact_type' => 'Individual',
154 $contactID = $this->individualCreate($params);
157 'email' => $this->_email
,
158 'group_id' => $this->_groupID
,
159 'contact_id' => $contactID,
160 'hash' => 'b15de8b64e2cec34',
161 'time_stamp' => '20101212121212',
163 $result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params);
165 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
168 'contact_id' => $result['values'][$result['id']]['contact_id'],
169 'subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
170 'hash' => $result['values'][$result['id']]['hash'],
171 'time_stamp' => '20101212121212',
172 'event_subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
175 $result = $this->callAPISuccess('mailing_event_confirm', 'create', $params);
176 $this->contactDelete($contactID);