Merge pull request #5592 from JKingsnorth/CRM-16256
[civicrm-core.git] / tests / phpunit / WebTest / Member / OfflineMembershipRenewTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
d25dd0ee 25 */
6a488035 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
00be9182 38 public 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 // page was loaded
97 $this->waitForTextPresent($sourceText);
e7066c8e 98 $this->waitForElementPresent("xpath=//div[@id='memberships']/div//table//tbody/tr/td[9]/span[1]/a[1][contains(text(),'View')]");
6a488035
TO
99
100 // click through to the membership view screen
e7066c8e 101 $this->click("xpath=//div[@id='memberships']/div//table//tbody/tr/td[9]/span[1]/a[1][contains(text(),'View')]");
6a488035 102
e7066c8e 103 $this->waitForElementPresent("xpath=//button//span[contains(text(),'Done')]");
6a488035
TO
104
105 $joinDate = $startDate = date('F jS, Y', strtotime("-2 year"));
106 $endDate = date('F jS, Y', strtotime("+2 year -1 day"));
107
108 // verify membership renewed
109 $verifyMembershipRenewData = array(
110 'Member' => $contactName,
111 'Membership Type' => $membershipTypes['membership_type'],
112 'Status' => 'Current',
113 'Source' => $sourceText,
114 'Member Since' => $joinDate,
115 'Start date' => $startDate,
116 'End date' => $endDate,
117 );
f2ff7d84 118 $this->webtestVerifyTabularData($verifyMembershipRenewData);
6c6e6187 119 }
6a488035 120
00be9182 121 public function testOfflineMemberRenewOverride() {
6a488035
TO
122 $this->webtestLogin();
123
124 // add membership type
125 $membershipTypes = $this->webtestAddMembershipType('rolling', 2);
126
127 $firstName = substr(sha1(rand()), 0, 7);
128 $this->webtestAddContact($firstName, "Memberson", "{$firstName}@memberson.com");
129 $contactName = "$firstName Memberson";
130
131 // click through to the membership tab
132 $this->click('css=li#tab_member a');
133
134 $this->waitForElementPresent('link=Add Membership');
135 $this->click('link=Add Membership');
136
137 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
138
139 // fill in Membership Organization and Type
140 $this->select('membership_type_id[0]', "label={$membershipTypes['member_of_contact']}");
141 $this->select('membership_type_id[1]', "label={$membershipTypes['membership_type']}");
142
143 // fill in Source
144 $sourceText = 'Offline Membership Renewal Webtest';
145 $this->type('source', $sourceText);
146
147 // Let Join Date stay default
148
149 // fill in Start Date
150 $this->webtestFillDate('start_date');
151
152 // Let End Date be auto computed
153
154 // fill in Status Override?
155 $this->click('is_override', 'value=1');
156 $this->waitForElementPresent('status_id');
157 $this->select('status_id', 'value=3');
158
159 // fill in Record Membership Payment?
160 $this->click('record_contribution', 'value=1');
161 $this->waitForElementPresent('contribution_status_id');
162
163 // select the financial type for the selected membership type
164 $this->select('financial_type_id', 'value=2');
f2ff7d84 165
6a488035
TO
166 // the amount for the selected membership type
167 $this->type('total_amount', '100.00');
168
169 // select payment instrument type = Check and enter chk number
170 $this->select("payment_instrument_id", "value=4");
171 $this->waitForElementPresent("check_number");
172 $this->type("check_number", "check #12345");
173 $this->type("trxn_id", "P5476785" . rand(100, 10000));
174
175 // fill the payment status be default
176 $this->select("contribution_status_id", "value=2");
177
178 // Clicking save.
179 $this->click('_qf_Membership_upload-bottom');
6a488035
TO
180
181 // page was loaded
182 $this->waitForTextPresent($sourceText);
183
184 // Is status message correct?
6c5f7368 185 $this->waitForText('crm-notification-container', "{$membershipTypes['membership_type']} membership for $firstName Memberson has been added.");
6a488035 186
1361cc61 187 $this->waitForElementPresent("xpath=//div[@id='memberships']/div/table/tbody/tr/td[9]/span[2][text()='more']/ul/li[1]/a[text()='Renew']");
6a488035
TO
188
189 // click through to the Membership Renewal Link
1361cc61 190 $this->click("xpath=//div[@id='memberships']/div/table/tbody/tr/td[9]/span[2][text()='more']/ul/li[1]/a[text()='Renew']");
6a488035
TO
191
192 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
193
194 // save the renewed membership
195 $this->click('_qf_MembershipRenewal_upload-bottom');
196
6a488035
TO
197 // page was loaded
198 $this->waitForTextPresent($sourceText);
199
5c80555f 200 $this->waitForElementPresent("xpath=//div[@id='memberships']/div/table/tbody/tr/td[9]/span[1]/a[1][text()='View']");
6a488035
TO
201
202 // click through to the membership view screen
4cbbec00 203 $this->click("xpath=//div[@id='memberships']/div/table/tbody/tr/td[9]/span/a[1][text()='View']");
6a488035
TO
204
205 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
206
92915c55 207 $joinDate = date('F jS, Y');
6a488035 208 $startDate = date('F jS, Y', strtotime("+1 month"));
92915c55 209 $endDate = date('F jS, Y', strtotime("+4 year 1 month -1 day"));
6a488035
TO
210
211 // verify membership renew override
212 $verifyMembershipRenewOverrideData = array(
213 'Member' => $contactName,
214 'Membership Type' => $membershipTypes['membership_type'],
215 'Status' => 'New',
216 'Source' => $sourceText,
217 'Member Since' => $joinDate,
218 'Start date' => $startDate,
219 'End date' => $endDate,
220 );
f2ff7d84 221 $this->webtestVerifyTabularData($verifyMembershipRenewOverrideData);
6a488035
TO
222 }
223
00be9182 224 public function testOfflineMembershipRenewChangeType() {
6a488035
TO
225 $this->webtestLogin();
226
227 // make sure period is correct for the membership type we testing for,
228 // since it might have been modified by other tests
229 // add membership type
230 $membershipTypes = $this->webtestAddMembershipType('rolling', 1);
231 $newMembershipType = $this->webtestAddMembershipType('rolling', 1);
232
233 $firstName = substr(sha1(rand()), 0, 7);
234 $this->webtestAddContact($firstName, "Memberson", "{$firstName}@memberson.com");
235 $contactName = "$firstName Memberson";
236
237 // click through to the membership tab
238 $this->click('css=li#tab_member a');
239
240 $this->waitForElementPresent('link=Add Membership');
241 $this->click('link=Add Membership');
242
243 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
244
245 // fill in Membership Organization and Type
246 $this->select('membership_type_id[0]', "label={$membershipTypes['member_of_contact']}");
247 $this->select('membership_type_id[1]', "label={$membershipTypes['membership_type']}");
248
249 // fill in Source
250 $sourceText = 'Offline Membership Renewal Webtest';
251 $this->type('source', $sourceText);
252
253 // Fill Member Since
254 $this->webtestFillDate('join_date', '-2 year');
255
256 // Let Start Date and End Date be auto computed
efb29358
CW
257
258 // Because it tends to cause problems, all uses of sleep() must be justified in comments
259 // Sleep should never be used for wait for anything to load from the server
260 // Justification for this instance: make sure onchange for total_amount has a chance to fire
6a488035
TO
261 sleep(2);
262
263 // Clicking save.
264 $this->click('_qf_Membership_upload-bottom');
6a488035
TO
265
266 // page was loaded
267 $this->waitForTextPresent($sourceText);
268
269 // Is status message correct?
6c5f7368 270 $this->waitForText('crm-notification-container', "{$membershipTypes['membership_type']} membership for $firstName Memberson has been added.");
6a488035 271
5ddf4885 272 $this->waitForElementPresent("xpath=//div[@id='inactive-memberships']//table/tbody/tr/td[7]/span[2][text()='more']/ul/li/a[text()='Renew']");
6a488035
TO
273
274 // click through to the Membership Renewal Link
5ddf4885 275 $this->click("xpath=//div[@id='inactive-memberships']//table/tbody/tr/td[7]/span[2][text()='more']/ul/li/a[text()='Renew']");
6a488035
TO
276
277 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
278
279 //change membership type
280 $this->click("changeMembershipOrgType");
281 $this->waitForElementPresent('membership_type_id[1]');
282 $this->select('membership_type_id[0]', "label={$newMembershipType['member_of_contact']}");
283 $this->select('membership_type_id[1]', "label={$newMembershipType['membership_type']}");
284
285 $this->click('membership_type_id[0]');
efb29358
CW
286 // Because it tends to cause problems, all uses of sleep() must be justified in comments
287 // Sleep should never be used for wait for anything to load from the server
288 // Justification for this instance: wait for onchange handler
6a488035
TO
289 sleep(2);
290
291 // save the renewed membership
292 $this->click('_qf_MembershipRenewal_upload-bottom');
293
6a488035
TO
294 // page was loaded
295 $this->waitForTextPresent($sourceText);
296
5ddf4885 297 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
6a488035
TO
298
299 // click through to the membership view screen
5ddf4885 300 $this->click("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
6a488035
TO
301
302 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
303
92915c55 304 $joinDate = date('F jS, Y', strtotime("-2 year"));
6a488035 305 $startDate = date('F jS, Y');
92915c55 306 $endDate = date('F jS, Y', strtotime("+1 year -1 day"));
6a488035
TO
307
308 // verify membership renewed and the membership type is changed
309 $verifyMembershipData = array(
310 'Member' => $contactName,
311 'Membership Type' => $newMembershipType['membership_type'],
312 'Status' => 'Current',
313 'Source' => $sourceText,
314 'Member Since' => $joinDate,
315 'Start date' => $startDate,
316 'End date' => $endDate,
317 );
f2ff7d84 318 $this->webtestVerifyTabularData($verifyMembershipData);
6a488035
TO
319 }
320
00be9182 321 public function testOfflineMembershipRenewMultipleTerms() {
6a488035
TO
322 $this->webtestLogin();
323
324 // make sure period is correct for the membership type we testing for,
325 // since it might have been modified by other tests
326 // add membership type
327 $membershipTypes = $this->webtestAddMembershipType('rolling', 2);
328
329 // quick create a contact
330 $firstName = substr(sha1(rand()), 0, 7);
331 $this->webtestAddContact($firstName, "Memberson", "{$firstName}@memberson.com");
332 $contactName = "$firstName Memberson";
333
334 // click through to the membership tab
335 $this->click('css=li#tab_member a');
336
337 $this->waitForElementPresent('link=Add Membership');
338 $this->click('link=Add Membership');
339
340 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
341
342 // fill in Membership Organization and Type
343 $this->select('membership_type_id[0]', "label={$membershipTypes['member_of_contact']}");
344 $this->select('membership_type_id[1]', "label={$membershipTypes['membership_type']}");
345
346 // fill in Source
347 $sourceText = 'Offline Membership Renewal Webtest';
348 $this->type('source', $sourceText);
349
350 // Fill Member Since
351 $this->webtestFillDate('join_date', '-2 year');
352
353 // Let Start Date and End Date be auto computed
354
355 // Record contribution
356 $this->click('record_contribution');
481a74f4
TO
357 $this->waitForElementPresent('financial_type_id');
358 $this->select('financial_type_id', "label=Member Dues");
6a488035
TO
359 $this->select('payment_instrument_id', "label=Check");
360 $this->waitForElementPresent('check_number');
361 $this->type('check_number', '1023');
362 $this->select('contribution_status_id', "label=Completed");
363 $this->click('send_receipt');
efb29358
CW
364
365 // Because it tends to cause problems, all uses of sleep() must be justified in comments
366 // Sleep should never be used for wait for anything to load from the server
367 // Justification for this instance: make sure onchange for total_amount has a chance to fire
6a488035
TO
368 sleep(2);
369
370 // Clicking save.
371 $this->click('_qf_Membership_upload-bottom');
6a488035
TO
372
373 // page was loaded
374 $this->waitForTextPresent($sourceText);
375
376 // Is status message correct?
6c5f7368
CW
377 $this->waitForText('crm-notification-container', "{$membershipTypes['membership_type']} membership for $firstName Memberson has been added.");
378 $this->waitForText('crm-notification-container', "A membership confirmation and receipt has been sent to {$firstName}@memberson.com.");
6a488035 379
5ddf4885 380 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
6a488035 381 // click through to the Membership Renewal Link
5ddf4885 382 $this->click("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
6a488035
TO
383
384 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
385 // Record contribution and set number of terms to 2
386 $this->click('record_contribution');
f2ff7d84 387 $this->waitForElementPresent('financial_type_id');
6a488035
TO
388 $this->click('changeTermsLink');
389 $this->waitForElementPresent('num_terms');
390 $this->type('num_terms', '');
391 $this->type('num_terms', '2');
efb29358
CW
392
393 // Because it tends to cause problems, all uses of sleep() must be justified in comments
394 // Sleep should never be used for wait for anything to load from the server
395 // Justification for this instance: make sure onchange for total_amount has a chance to fire
6a488035
TO
396 sleep(2);
397 $this->click('total_amount');
398 $this->verifyValue('total_amount', "200.00");
f2ff7d84 399 $this->select('financial_type_id', "label=Member Dues");
6a488035
TO
400 $this->select('payment_instrument_id', "label=Check");
401 $this->waitForElementPresent('check_number');
402 $this->type('check_number', '1024');
403 $this->select('contribution_status_id', "label=Completed");
404 $this->click('send_receipt');
405
406 // save the renewed membership
407 $this->click('_qf_MembershipRenewal_upload-bottom');
408
6a488035
TO
409 // page was loaded
410 $this->waitForTextPresent($sourceText);
411
5ddf4885 412 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
6a488035
TO
413
414 // click through to the membership view screen
5ddf4885 415 $this->click("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
6a488035
TO
416
417 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
418
419 $joinDate = $startDate = date('F jS, Y', strtotime("-2 year"));
420 // Adding 2 x 2 years renewal to initial membership.
421 $endDate = date('F jS, Y', strtotime("+4 year -1 day"));
422
423 // verify membership renewed
424 $verifyMembershipRenewData = array(
425 'Member' => $contactName,
426 'Membership Type' => $membershipTypes['membership_type'],
427 'Status' => 'Current',
428 'Source' => $sourceText,
429 'Member Since' => $joinDate,
430 'Start date' => $startDate,
431 'End date' => $endDate,
432 );
f2ff7d84 433 $this->webtestVerifyTabularData($verifyMembershipRenewData);
6a488035 434 }
96025800 435
42daf119 436}