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