Global webtest cleanup
[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
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Member_OfflineMembershipRenewTest extends CiviSeleniumTestCase {
30
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testOfflineMembershipRenew() {
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
68 // added sleep to make sure jscript onchange for total_amount has a chance to fire
69 sleep(2);
70
71 // Clicking save.
72 $this->click('_qf_Membership_upload-bottom');
73 $this->waitForPageToLoad($this->getTimeoutMsec());
74
75 // page was loaded
76 $this->waitForTextPresent($sourceText);
77
78 // Is status message correct?
79 $this->assertElementContainsText('crm-notification-container', "{$membershipTypes['membership_type']} membership for $firstName Memberson has been added.",
80 "Status message didn't show up after saving!"
81 );
82
83 $this->waitForElementPresent("xpath=//div[@id='Memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
84
85 // click through to the Membership Renewal Link
86 $this->click("xpath=//div[@id='Memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
87
88 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
89
90 // save the renewed membership
91 $this->click('_qf_MembershipRenewal_upload-bottom');
92
93 $this->waitForPageToLoad($this->getTimeoutMsec());
94
95 // page was loaded
96 $this->waitForTextPresent($sourceText);
97
98 $this->waitForElementPresent("xpath=//div[@id='Memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
99
100 // click through to the membership view screen
101 $this->click("xpath=//div[@id='Memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
102
103 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
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 );
118 $this->webtestVerifyTabularData($verifyMembershipRenewData);
119 }
120
121 function testOfflineMemberRenewOverride() {
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');
165
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');
180 $this->waitForPageToLoad($this->getTimeoutMsec());
181
182 // page was loaded
183 $this->waitForTextPresent($sourceText);
184
185 // Is status message correct?
186 $this->assertElementContainsText('crm-notification-container', "{$membershipTypes['membership_type']} membership for $firstName Memberson has been added.",
187 "Status message didn't show up after saving!"
188 );
189
190 $this->waitForElementPresent("xpath=//div[@id='Memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
191
192 // click through to the Membership Renewal Link
193 $this->click("xpath=//div[@id='Memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
194
195 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
196
197 // save the renewed membership
198 $this->click('_qf_MembershipRenewal_upload-bottom');
199
200 $this->waitForPageToLoad($this->getTimeoutMsec());
201
202 // page was loaded
203 $this->waitForTextPresent($sourceText);
204
205 $this->waitForElementPresent("xpath=//div[@id='Memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
206
207 // click through to the membership view screen
208 $this->click("xpath=//div[@id='Memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
209
210 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
211
212 $joinDate = date('F jS, Y');
213 $startDate = date('F jS, Y', strtotime("+1 month"));
214 $endDate = date('F jS, Y', strtotime("+4 year 1 month -1 day"));
215
216 // verify membership renew override
217 $verifyMembershipRenewOverrideData = array(
218 'Member' => $contactName,
219 'Membership Type' => $membershipTypes['membership_type'],
220 'Status' => 'New',
221 'Source' => $sourceText,
222 'Member Since' => $joinDate,
223 'Start date' => $startDate,
224 'End date' => $endDate,
225 );
226 $this->webtestVerifyTabularData($verifyMembershipRenewOverrideData);
227 }
228
229 function testOfflineMembershipRenewChangeType() {
230 $this->webtestLogin();
231
232 // make sure period is correct for the membership type we testing for,
233 // since it might have been modified by other tests
234 // add membership type
235 $membershipTypes = $this->webtestAddMembershipType('rolling', 1);
236 $newMembershipType = $this->webtestAddMembershipType('rolling', 1);
237
238 $firstName = substr(sha1(rand()), 0, 7);
239 $this->webtestAddContact($firstName, "Memberson", "{$firstName}@memberson.com");
240 $contactName = "$firstName Memberson";
241
242 // click through to the membership tab
243 $this->click('css=li#tab_member a');
244
245 $this->waitForElementPresent('link=Add Membership');
246 $this->click('link=Add Membership');
247
248 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
249
250 // fill in Membership Organization and Type
251 $this->select('membership_type_id[0]', "label={$membershipTypes['member_of_contact']}");
252 $this->select('membership_type_id[1]', "label={$membershipTypes['membership_type']}");
253
254 // fill in Source
255 $sourceText = 'Offline Membership Renewal Webtest';
256 $this->type('source', $sourceText);
257
258 // Fill Member Since
259 $this->webtestFillDate('join_date', '-2 year');
260
261 // Let Start Date and End Date be auto computed
262 // added sleep to make sure jscript onchange for total_amount has a chance to fire
263 sleep(2);
264
265 // Clicking save.
266 $this->click('_qf_Membership_upload-bottom');
267 $this->waitForPageToLoad($this->getTimeoutMsec());
268
269 // page was loaded
270 $this->waitForTextPresent($sourceText);
271
272 // Is status message correct?
273 $this->assertElementContainsText('crm-notification-container', "{$membershipTypes['membership_type']} membership for $firstName Memberson has been added.",
274 "Status message didn't show up after saving!"
275 );
276
277 $this->waitForElementPresent("xpath=//div[@id='Memberships']//table/tbody/tr/td[7]/span[2][text()='more']/ul/li/a[text()='Renew']");
278
279 // click through to the Membership Renewal Link
280 $this->click("xpath=//div[@id='Memberships']//table/tbody/tr/td[7]/span[2][text()='more']/ul/li/a[text()='Renew']");
281
282 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
283
284 //change membership type
285 $this->click("changeMembershipOrgType");
286 $this->waitForElementPresent('membership_type_id[1]');
287 $this->select('membership_type_id[0]', "label={$newMembershipType['member_of_contact']}");
288 $this->select('membership_type_id[1]', "label={$newMembershipType['membership_type']}");
289
290 $this->click('membership_type_id[0]');
291 sleep(2);
292
293 // save the renewed membership
294 $this->click('_qf_MembershipRenewal_upload-bottom');
295
296 $this->waitForPageToLoad($this->getTimeoutMsec());
297
298 // page was loaded
299 $this->waitForTextPresent($sourceText);
300
301 $this->waitForElementPresent("xpath=//div[@id='Memberships']//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
302
303 // click through to the membership view screen
304 $this->click("xpath=//div[@id='Memberships']//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
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 );
322 $this->webtestVerifyTabularData($verifyMembershipData);
323 }
324
325 function testOfflineMembershipRenewMultipleTerms() {
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');
368 // added sleep to make sure jscript onchange for total_amount has a chance to fire
369 sleep(2);
370
371 // Clicking save.
372 $this->click('_qf_Membership_upload-bottom');
373 $this->waitForPageToLoad($this->getTimeoutMsec());
374
375 // page was loaded
376 $this->waitForTextPresent($sourceText);
377
378 // Is status message correct?
379 $this->assertElementContainsText('crm-notification-container', "{$membershipTypes['membership_type']} membership for $firstName Memberson has been added.",
380 "Status message didn't show up after saving!"
381 );
382 $this->assertElementContainsText('crm-notification-container', "A membership confirmation and receipt has been sent to {$firstName}@memberson.com.",
383 "Email sent to member message didn't show up after saving membership!"
384 );
385
386 $this->waitForElementPresent("xpath=//div[@id='Memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
387
388 // click through to the Membership Renewal Link
389 $this->click("xpath=//div[@id='Memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
390
391 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
392 // Record contribution and set number of terms to 2
393 $this->click('record_contribution');
394 $this->waitForElementPresent('financial_type_id');
395 $this->click('changeTermsLink');
396 $this->waitForElementPresent('num_terms');
397 $this->type('num_terms', '');
398 $this->type('num_terms', '2');
399 // added sleep to make sure jscript onchange for total_amount has a chance to fire
400 sleep(2);
401 $this->click('total_amount');
402 $this->verifyValue('total_amount', "200.00");
403 $this->select('financial_type_id', "label=Member Dues");
404 $this->select('payment_instrument_id', "label=Check");
405 $this->waitForElementPresent('check_number');
406 $this->type('check_number', '1024');
407 $this->select('contribution_status_id', "label=Completed");
408 $this->click('send_receipt');
409
410 // save the renewed membership
411 $this->click('_qf_MembershipRenewal_upload-bottom');
412
413 $this->waitForPageToLoad($this->getTimeoutMsec());
414
415 // page was loaded
416 $this->waitForTextPresent($sourceText);
417
418 $this->waitForElementPresent("xpath=//div[@id='Memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
419
420 // click through to the membership view screen
421 $this->click("xpath=//div[@id='Memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
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 );
439 $this->webtestVerifyTabularData($verifyMembershipRenewData);
440 }
441 }