Action schedule API modifications
[civicrm-core.git] / tests / phpunit / api / v3 / MailingGroupTest.php
CommitLineData
6a488035 1<?php
b6708aeb 2/*
3 +--------------------------------------------------------------------+
232624b1 4| CiviCRM version 4.4 |
b6708aeb 5+--------------------------------------------------------------------+
6| Copyright CiviCRM LLC (c) 2004-2013 |
7+--------------------------------------------------------------------+
8| This file is a part of CiviCRM. |
9| |
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. |
13| |
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. |
18| |
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+--------------------------------------------------------------------+
26*/
6a488035
TO
27
28require_once 'CiviTest/CiviUnitTestCase.php';
29
30/**
31 * Test APIv3 civicrm_mailing_group_* functions
32 *
33 * @package CiviCRM
34 */
35class api_v3_MailingGroupTest extends CiviUnitTestCase {
36 protected $_groupID;
37 protected $_email;
430ae6dd 38 protected $_apiversion;
ef170fe0 39 public $_eNoticeCompliant = TRUE;
40
430ae6dd 41 function get_info() {
6a488035
TO
42 return array(
43 'name' => 'Mailer Group',
44 'description' => 'Test all Mailer Group methods.',
45 'group' => 'CiviCRM API Tests',
46 );
47 }
48
49 function setUp() {
50 parent::setUp();
51 $this->_apiversion = 3;
ef170fe0 52 $this->_groupID = $this->groupCreate(NULL);
53 $this->_email = 'test@test.test';
6a488035
TO
54 }
55
56 function tearDown() {
57 $this->groupDelete($this->_groupID);
58 }
59
60 //---------- civicrm_mailing_event_subscribe methods ---------
61
62 /**
63 * Test civicrm_mailing_group_event_subscribe with wrong params.
64 */
65 public function testMailerGroupSubscribeWrongParams() {
66 $params = array(
67 'email' => $this->_email,
68 'group_id' => 'Wrong Group ID',
ef170fe0 69 'contact_id' => '2121',
70 'time_stamp' => '20111111010101',
6a488035
TO
71 'hash' => 'sasa',
72 );
d0e1eff2 73 $result = $this->callAPIFailure('mailing_event_subscribe', 'create', $params);
6a488035
TO
74 if ($result['error_message'] != 'Subscription failed') {
75 $this->assertEquals($result['error_message'], 'Invalid Group id', 'In line ' . __LINE__);
76 }
77 else {
78 $this->assertEquals($result['error_message'], 'Subscription failed', 'In line ' . __LINE__);
79 }
80 }
81
82 /**
83 * Test civicrm_mailing_group_event_subscribe with given contact ID.
84 */
85 public function testMailerGroupSubscribeGivenContactId() {
86 $params = array(
87 'first_name' => 'Test',
88 'last_name' => 'Test',
89 'email' => $this->_email,
ef170fe0 90 'contact_type' => 'Individual',
91 );
6a488035
TO
92 $contactID = $this->individualCreate($params);
93
94 $params = array(
95 'email' => $this->_email,
96 'group_id' => $this->_groupID,
9f1b81e0 97 'contact_id' => $contactID,
98 'hash' => 'b15de8b64e2cec34',
6a488035
TO
99 'time_stamp' => '20101212121212',
100 );
7f0eb6cb 101 $result = $this->callAPIAndDocument('mailing_event_subscribe', 'create', $params, __FUNCTION__, __FILE__);
9e23eadb 102 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
6a488035
TO
103
104 $this->contactDelete($contactID);
105 }
106
107 //-------- civicrm_mailing_group_event_unsubscribe methods-----------
108
109 /**
110 * Test civicrm_mailing_group_event_unsubscribe with wrong params.
111 */
112 public function testMailerGroupUnsubscribeWrongParams() {
113 $params = array(
114 'job_id' => 'Wrong ID',
115 'event_queue_id' => 'Wrong ID',
ef170fe0 116 'hash' => 'Wrong Hash',
117 'time_stamp' => '20101212121212',
6a488035
TO
118 );
119
d0e1eff2 120 $result = $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
6a488035
TO
121 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__);
122 }
123
124 //--------- civicrm_mailing_group_event_domain_unsubscribe methods -------
125
126 /**
127 * Test civicrm_mailing_group_event_domain_unsubscribe with wrong params.
128 */
129 public function testMailerGroupDomainUnsubscribeWrongParams() {
130 $params = array(
131 'job_id' => 'Wrong ID',
132 'event_queue_id' => 'Wrong ID',
133 'hash' => 'Wrong Hash',
ef170fe0 134 'org_unsubscribe' => 1,
135 'time_stamp' => '20101212121212',
6a488035
TO
136 );
137
d0e1eff2 138 $result = $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
6a488035
TO
139 $this->assertEquals($result['error_message'], 'Domain Queue event could not be found', 'In line ' . __LINE__);
140 }
141
6a488035
TO
142 //----------- civicrm_mailing_group_event_resubscribe methods--------
143
144 /**
145 * Test civicrm_mailing_group_event_resubscribe with wrong params type.
146 */
147
148 /**
149 * Test civicrm_mailing_group_event_resubscribe with wrong params.
150 */
151 public function testMailerGroupResubscribeWrongParams() {
152 $params = array(
153 'job_id' => 'Wrong ID',
154 'event_queue_id' => 'Wrong ID',
155 'hash' => 'Wrong Hash',
ef170fe0 156 'org_unsubscribe' => 'test',
157 'time_stamp' => '20101212121212',
6a488035 158 );
d0e1eff2 159 $result = $this->callAPIFailure('mailing_event_resubscribe', 'create', $params);
6a488035
TO
160 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__);
161 }
162
163 //------------------------ success case ---------------------
164
165 /**
166 * Test civicrm_mailing_group_event_subscribe and civicrm_mailing_event_confirm functions - success expected.
167 */
168 public function testMailerProcess() {
169 $params = array(
170 'first_name' => 'Test',
171 'last_name' => 'Test',
172 'email' => $this->_email,
ef170fe0 173 'contact_type' => 'Individual',
174 );
6a488035
TO
175 $contactID = $this->individualCreate($params);
176
177 $params = array(
178 'email' => $this->_email,
179 'group_id' => $this->_groupID,
ef170fe0 180 'contact_id' => $contactID,
181 'hash' => 'b15de8b64e2cec34',
6a488035
TO
182 'time_stamp' => '20101212121212',
183 );
7f0eb6cb 184 $result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params);
6a488035 185
9e23eadb 186 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
6a488035
TO
187
188 $params = array(
9e23eadb 189 'contact_id' => $result['values'][$result['id']]['contact_id'],
190 'subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
ef170fe0 191 'hash' => $result['values'][$result['id']]['hash'],
192 'time_stamp' => '20101212121212',
9e23eadb 193 'event_subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
6a488035
TO
194 );
195
7f0eb6cb 196 $result = $this->callAPISuccess('mailing_event_confirm', 'create', $params);
6a488035
TO
197 $this->contactDelete($contactID);
198 }
199}
200