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