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