Move pingback code to separate repo
[civicrm-core.git] / tests / phpunit / WebTest / Member / OfflineMembershipRenewTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06a1bc01 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
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 along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25*/
26
6a488035 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Member_OfflineMembershipRenewTest
31 */
6a488035
TO
32class WebTest_Member_OfflineMembershipRenewTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testOfflineMembershipRenew() {
6a488035
TO
39 $this->webtestLogin();
40
41 // make sure period is correct for the membership type we testing for,
42 // since it might have been modified by other tests
43 // add membership type
44 $membershipTypes = $this->webtestAddMembershipType('rolling', 2);
45
46 // quick create a contact
47 $firstName = substr(sha1(rand()), 0, 7);
48 $this->webtestAddContact($firstName, "Memberson", "{$firstName}@memberson.com");
49 $contactName = "$firstName Memberson";
50
51 // click through to the membership tab
52 $this->click('css=li#tab_member a');
53
54 $this->waitForElementPresent('link=Add Membership');
55 $this->click('link=Add Membership');
56
57 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
58
59 // fill in Membership Organization and Type
60 $this->select('membership_type_id[0]', "label={$membershipTypes['member_of_contact']}");
61 $this->select('membership_type_id[1]', "label={$membershipTypes['membership_type']}");
62
63 // fill in Source
64 $sourceText = 'Offline Membership Renewal Webtest';
65 $this->type('source', $sourceText);
66
67 // Fill Member Since
68 $this->webtestFillDate('join_date', '-2 year');
69
70 // Let Start Date and End Date be auto computed
efb29358
CW
71
72 // Because it tends to cause problems, all uses of sleep() must be justified in comments
73 // Sleep should never be used for wait for anything to load from the server
74 // Justification for this instance: make sure onchange for total_amount has a chance to fire
6a488035
TO
75 sleep(2);
76
77 // Clicking save.
78 $this->click('_qf_Membership_upload-bottom');
6a488035
TO
79
80 // page was loaded
81 $this->waitForTextPresent($sourceText);
82
83 // Is status message correct?
6c5f7368 84 $this->waitForText('crm-notification-container', "{$membershipTypes['membership_type']} membership for $firstName Memberson has been added.");
6a488035 85
5ddf4885 86 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
6a488035
TO
87
88 // click through to the Membership Renewal Link
5ddf4885 89 $this->click("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
6a488035
TO
90
91 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
92
93 // save the renewed membership
94 $this->click('_qf_MembershipRenewal_upload-bottom');
95
6a488035
TO
96
97 // page was loaded
98 $this->waitForTextPresent($sourceText);
99
5ddf4885 100 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
6a488035
TO
101
102 // click through to the membership view screen
5ddf4885 103 $this->click("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
6a488035
TO
104
105 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
106
107 $joinDate = $startDate = date('F jS, Y', strtotime("-2 year"));
108 $endDate = date('F jS, Y', strtotime("+2 year -1 day"));
109
110 // verify membership renewed
111 $verifyMembershipRenewData = array(
112 'Member' => $contactName,
113 'Membership Type' => $membershipTypes['membership_type'],
114 'Status' => 'Current',
115 'Source' => $sourceText,
116 'Member Since' => $joinDate,
117 'Start date' => $startDate,
118 'End date' => $endDate,
119 );
f2ff7d84
PJ
120 $this->webtestVerifyTabularData($verifyMembershipRenewData);
121 }
6a488035
TO
122
123 function testOfflineMemberRenewOverride() {
6a488035
TO
124 $this->webtestLogin();
125
126 // add membership type
127 $membershipTypes = $this->webtestAddMembershipType('rolling', 2);
128
129 $firstName = substr(sha1(rand()), 0, 7);
130 $this->webtestAddContact($firstName, "Memberson", "{$firstName}@memberson.com");
131 $contactName = "$firstName Memberson";
132
133 // click through to the membership tab
134 $this->click('css=li#tab_member a');
135
136 $this->waitForElementPresent('link=Add Membership');
137 $this->click('link=Add Membership');
138
139 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
140
141 // fill in Membership Organization and Type
142 $this->select('membership_type_id[0]', "label={$membershipTypes['member_of_contact']}");
143 $this->select('membership_type_id[1]', "label={$membershipTypes['membership_type']}");
144
145 // fill in Source
146 $sourceText = 'Offline Membership Renewal Webtest';
147 $this->type('source', $sourceText);
148
149 // Let Join Date stay default
150
151 // fill in Start Date
152 $this->webtestFillDate('start_date');
153
154 // Let End Date be auto computed
155
156 // fill in Status Override?
157 $this->click('is_override', 'value=1');
158 $this->waitForElementPresent('status_id');
159 $this->select('status_id', 'value=3');
160
161 // fill in Record Membership Payment?
162 $this->click('record_contribution', 'value=1');
163 $this->waitForElementPresent('contribution_status_id');
164
165 // select the financial type for the selected membership type
166 $this->select('financial_type_id', 'value=2');
f2ff7d84 167
6a488035
TO
168 // the amount for the selected membership type
169 $this->type('total_amount', '100.00');
170
171 // select payment instrument type = Check and enter chk number
172 $this->select("payment_instrument_id", "value=4");
173 $this->waitForElementPresent("check_number");
174 $this->type("check_number", "check #12345");
175 $this->type("trxn_id", "P5476785" . rand(100, 10000));
176
177 // fill the payment status be default
178 $this->select("contribution_status_id", "value=2");
179
180 // Clicking save.
181 $this->click('_qf_Membership_upload-bottom');
6a488035
TO
182
183 // page was loaded
184 $this->waitForTextPresent($sourceText);
185
186 // Is status message correct?
6c5f7368 187 $this->waitForText('crm-notification-container', "{$membershipTypes['membership_type']} membership for $firstName Memberson has been added.");
6a488035 188
5ddf4885 189 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
6a488035
TO
190
191 // click through to the Membership Renewal Link
5ddf4885 192 $this->click("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
6a488035
TO
193
194 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
195
196 // save the renewed membership
197 $this->click('_qf_MembershipRenewal_upload-bottom');
198
6a488035
TO
199
200 // page was loaded
201 $this->waitForTextPresent($sourceText);
202
f78f9745 203 $this->waitForElementPresent("xpath=//div[@id='memberships']/div/table/tbody/tr/td[9]/span[1]/a[1][text()='View']");
6a488035
TO
204
205 // click through to the membership view screen
57c2bdf0 206 $this->click("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[9]/span[1]/a[1][text()='View']");
6a488035
TO
207
208 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
209
210 $joinDate = date('F jS, Y');
211 $startDate = date('F jS, Y', strtotime("+1 month"));
212 $endDate = date('F jS, Y', strtotime("+4 year 1 month -1 day"));
213
214 // verify membership renew override
215 $verifyMembershipRenewOverrideData = array(
216 'Member' => $contactName,
217 'Membership Type' => $membershipTypes['membership_type'],
218 'Status' => 'New',
219 'Source' => $sourceText,
220 'Member Since' => $joinDate,
221 'Start date' => $startDate,
222 'End date' => $endDate,
223 );
f2ff7d84 224 $this->webtestVerifyTabularData($verifyMembershipRenewOverrideData);
6a488035
TO
225 }
226
227 function testOfflineMembershipRenewChangeType() {
6a488035
TO
228 $this->webtestLogin();
229
230 // make sure period is correct for the membership type we testing for,
231 // since it might have been modified by other tests
232 // add membership type
233 $membershipTypes = $this->webtestAddMembershipType('rolling', 1);
234 $newMembershipType = $this->webtestAddMembershipType('rolling', 1);
235
236 $firstName = substr(sha1(rand()), 0, 7);
237 $this->webtestAddContact($firstName, "Memberson", "{$firstName}@memberson.com");
238 $contactName = "$firstName Memberson";
239
240 // click through to the membership tab
241 $this->click('css=li#tab_member a');
242
243 $this->waitForElementPresent('link=Add Membership');
244 $this->click('link=Add Membership');
245
246 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
247
248 // fill in Membership Organization and Type
249 $this->select('membership_type_id[0]', "label={$membershipTypes['member_of_contact']}");
250 $this->select('membership_type_id[1]', "label={$membershipTypes['membership_type']}");
251
252 // fill in Source
253 $sourceText = 'Offline Membership Renewal Webtest';
254 $this->type('source', $sourceText);
255
256 // Fill Member Since
257 $this->webtestFillDate('join_date', '-2 year');
258
259 // Let Start Date and End Date be auto computed
efb29358
CW
260
261 // Because it tends to cause problems, all uses of sleep() must be justified in comments
262 // Sleep should never be used for wait for anything to load from the server
263 // Justification for this instance: make sure onchange for total_amount has a chance to fire
6a488035
TO
264 sleep(2);
265
266 // Clicking save.
267 $this->click('_qf_Membership_upload-bottom');
6a488035
TO
268
269 // page was loaded
270 $this->waitForTextPresent($sourceText);
271
272 // Is status message correct?
6c5f7368 273 $this->waitForText('crm-notification-container', "{$membershipTypes['membership_type']} membership for $firstName Memberson has been added.");
6a488035 274
5ddf4885 275 $this->waitForElementPresent("xpath=//div[@id='inactive-memberships']//table/tbody/tr/td[7]/span[2][text()='more']/ul/li/a[text()='Renew']");
6a488035
TO
276
277 // click through to the Membership Renewal Link
5ddf4885 278 $this->click("xpath=//div[@id='inactive-memberships']//table/tbody/tr/td[7]/span[2][text()='more']/ul/li/a[text()='Renew']");
6a488035
TO
279
280 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
281
282 //change membership type
283 $this->click("changeMembershipOrgType");
284 $this->waitForElementPresent('membership_type_id[1]');
285 $this->select('membership_type_id[0]', "label={$newMembershipType['member_of_contact']}");
286 $this->select('membership_type_id[1]', "label={$newMembershipType['membership_type']}");
287
288 $this->click('membership_type_id[0]');
efb29358
CW
289 // Because it tends to cause problems, all uses of sleep() must be justified in comments
290 // Sleep should never be used for wait for anything to load from the server
291 // Justification for this instance: wait for onchange handler
6a488035
TO
292 sleep(2);
293
294 // save the renewed membership
295 $this->click('_qf_MembershipRenewal_upload-bottom');
296
6a488035
TO
297
298 // page was loaded
299 $this->waitForTextPresent($sourceText);
300
5ddf4885 301 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
6a488035
TO
302
303 // click through to the membership view screen
5ddf4885 304 $this->click("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
6a488035
TO
305
306 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
307
308 $joinDate = date('F jS, Y', strtotime("-2 year"));
309 $startDate = date('F jS, Y');
310 $endDate = date('F jS, Y', strtotime("+1 year -1 day"));
311
312 // verify membership renewed and the membership type is changed
313 $verifyMembershipData = array(
314 'Member' => $contactName,
315 'Membership Type' => $newMembershipType['membership_type'],
316 'Status' => 'Current',
317 'Source' => $sourceText,
318 'Member Since' => $joinDate,
319 'Start date' => $startDate,
320 'End date' => $endDate,
321 );
f2ff7d84 322 $this->webtestVerifyTabularData($verifyMembershipData);
6a488035
TO
323 }
324
325 function testOfflineMembershipRenewMultipleTerms() {
6a488035
TO
326 $this->webtestLogin();
327
328 // make sure period is correct for the membership type we testing for,
329 // since it might have been modified by other tests
330 // add membership type
331 $membershipTypes = $this->webtestAddMembershipType('rolling', 2);
332
333 // quick create a contact
334 $firstName = substr(sha1(rand()), 0, 7);
335 $this->webtestAddContact($firstName, "Memberson", "{$firstName}@memberson.com");
336 $contactName = "$firstName Memberson";
337
338 // click through to the membership tab
339 $this->click('css=li#tab_member a');
340
341 $this->waitForElementPresent('link=Add Membership');
342 $this->click('link=Add Membership');
343
344 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
345
346 // fill in Membership Organization and Type
347 $this->select('membership_type_id[0]', "label={$membershipTypes['member_of_contact']}");
348 $this->select('membership_type_id[1]', "label={$membershipTypes['membership_type']}");
349
350 // fill in Source
351 $sourceText = 'Offline Membership Renewal Webtest';
352 $this->type('source', $sourceText);
353
354 // Fill Member Since
355 $this->webtestFillDate('join_date', '-2 year');
356
357 // Let Start Date and End Date be auto computed
358
359 // Record contribution
360 $this->click('record_contribution');
361 $this->waitForElementPresent( 'financial_type_id' );
362 $this->select( 'financial_type_id', "label=Member Dues" );
363 $this->select('payment_instrument_id', "label=Check");
364 $this->waitForElementPresent('check_number');
365 $this->type('check_number', '1023');
366 $this->select('contribution_status_id', "label=Completed");
367 $this->click('send_receipt');
efb29358
CW
368
369 // Because it tends to cause problems, all uses of sleep() must be justified in comments
370 // Sleep should never be used for wait for anything to load from the server
371 // Justification for this instance: make sure onchange for total_amount has a chance to fire
6a488035
TO
372 sleep(2);
373
374 // Clicking save.
375 $this->click('_qf_Membership_upload-bottom');
6a488035
TO
376
377 // page was loaded
378 $this->waitForTextPresent($sourceText);
379
380 // Is status message correct?
6c5f7368
CW
381 $this->waitForText('crm-notification-container', "{$membershipTypes['membership_type']} membership for $firstName Memberson has been added.");
382 $this->waitForText('crm-notification-container', "A membership confirmation and receipt has been sent to {$firstName}@memberson.com.");
6a488035 383
6a488035 384
5ddf4885 385 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
6a488035 386 // click through to the Membership Renewal Link
5ddf4885 387 $this->click("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
6a488035
TO
388
389 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
390 // Record contribution and set number of terms to 2
391 $this->click('record_contribution');
f2ff7d84 392 $this->waitForElementPresent('financial_type_id');
6a488035
TO
393 $this->click('changeTermsLink');
394 $this->waitForElementPresent('num_terms');
395 $this->type('num_terms', '');
396 $this->type('num_terms', '2');
efb29358
CW
397
398 // Because it tends to cause problems, all uses of sleep() must be justified in comments
399 // Sleep should never be used for wait for anything to load from the server
400 // Justification for this instance: make sure onchange for total_amount has a chance to fire
6a488035
TO
401 sleep(2);
402 $this->click('total_amount');
403 $this->verifyValue('total_amount', "200.00");
f2ff7d84 404 $this->select('financial_type_id', "label=Member Dues");
6a488035
TO
405 $this->select('payment_instrument_id', "label=Check");
406 $this->waitForElementPresent('check_number');
407 $this->type('check_number', '1024');
408 $this->select('contribution_status_id', "label=Completed");
409 $this->click('send_receipt');
410
411 // save the renewed membership
412 $this->click('_qf_MembershipRenewal_upload-bottom');
413
6a488035
TO
414
415 // page was loaded
416 $this->waitForTextPresent($sourceText);
417
5ddf4885 418 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
6a488035
TO
419
420 // click through to the membership view screen
5ddf4885 421 $this->click("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
6a488035
TO
422
423 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
424
425 $joinDate = $startDate = date('F jS, Y', strtotime("-2 year"));
426 // Adding 2 x 2 years renewal to initial membership.
427 $endDate = date('F jS, Y', strtotime("+4 year -1 day"));
428
429 // verify membership renewed
430 $verifyMembershipRenewData = array(
431 'Member' => $contactName,
432 'Membership Type' => $membershipTypes['membership_type'],
433 'Status' => 'Current',
434 'Source' => $sourceText,
435 'Member Since' => $joinDate,
436 'Start date' => $startDate,
437 'End date' => $endDate,
438 );
f2ff7d84 439 $this->webtestVerifyTabularData($verifyMembershipRenewData);
6a488035 440 }
42daf119 441}