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