Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-07-14-13-42-39
[civicrm-core.git] / tests / phpunit / WebTest / Member / OfflineMembershipRenewTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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
29 /**
30 * Class WebTest_Member_OfflineMembershipRenewTest
31 */
32 class WebTest_Member_OfflineMembershipRenewTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testOfflineMembershipRenew() {
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
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
75 sleep(2);
76
77 // Clicking save.
78 $this->click('_qf_Membership_upload-bottom');
79 $this->waitForPageToLoad($this->getTimeoutMsec());
80
81 // page was loaded
82 $this->waitForTextPresent($sourceText);
83
84 // Is status message correct?
85 $this->waitForText('crm-notification-container', "{$membershipTypes['membership_type']} membership for $firstName Memberson has been added.");
86
87 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
88
89 // click through to the Membership Renewal Link
90 $this->click("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
91
92 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
93
94 // save the renewed membership
95 $this->click('_qf_MembershipRenewal_upload-bottom');
96
97 $this->waitForPageToLoad($this->getTimeoutMsec());
98
99 // page was loaded
100 $this->waitForTextPresent($sourceText);
101
102 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
103
104 // click through to the membership view screen
105 $this->click("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
106
107 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
108
109 $joinDate = $startDate = date('F jS, Y', strtotime("-2 year"));
110 $endDate = date('F jS, Y', strtotime("+2 year -1 day"));
111
112 // verify membership renewed
113 $verifyMembershipRenewData = array(
114 'Member' => $contactName,
115 'Membership Type' => $membershipTypes['membership_type'],
116 'Status' => 'Current',
117 'Source' => $sourceText,
118 'Member Since' => $joinDate,
119 'Start date' => $startDate,
120 'End date' => $endDate,
121 );
122 $this->webtestVerifyTabularData($verifyMembershipRenewData);
123 }
124
125 function testOfflineMemberRenewOverride() {
126 $this->webtestLogin();
127
128 // add membership type
129 $membershipTypes = $this->webtestAddMembershipType('rolling', 2);
130
131 $firstName = substr(sha1(rand()), 0, 7);
132 $this->webtestAddContact($firstName, "Memberson", "{$firstName}@memberson.com");
133 $contactName = "$firstName Memberson";
134
135 // click through to the membership tab
136 $this->click('css=li#tab_member a');
137
138 $this->waitForElementPresent('link=Add Membership');
139 $this->click('link=Add Membership');
140
141 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
142
143 // fill in Membership Organization and Type
144 $this->select('membership_type_id[0]', "label={$membershipTypes['member_of_contact']}");
145 $this->select('membership_type_id[1]', "label={$membershipTypes['membership_type']}");
146
147 // fill in Source
148 $sourceText = 'Offline Membership Renewal Webtest';
149 $this->type('source', $sourceText);
150
151 // Let Join Date stay default
152
153 // fill in Start Date
154 $this->webtestFillDate('start_date');
155
156 // Let End Date be auto computed
157
158 // fill in Status Override?
159 $this->click('is_override', 'value=1');
160 $this->waitForElementPresent('status_id');
161 $this->select('status_id', 'value=3');
162
163 // fill in Record Membership Payment?
164 $this->click('record_contribution', 'value=1');
165 $this->waitForElementPresent('contribution_status_id');
166
167 // select the financial type for the selected membership type
168 $this->select('financial_type_id', 'value=2');
169
170 // the amount for the selected membership type
171 $this->type('total_amount', '100.00');
172
173 // select payment instrument type = Check and enter chk number
174 $this->select("payment_instrument_id", "value=4");
175 $this->waitForElementPresent("check_number");
176 $this->type("check_number", "check #12345");
177 $this->type("trxn_id", "P5476785" . rand(100, 10000));
178
179 // fill the payment status be default
180 $this->select("contribution_status_id", "value=2");
181
182 // Clicking save.
183 $this->click('_qf_Membership_upload-bottom');
184 $this->waitForPageToLoad($this->getTimeoutMsec());
185
186 // page was loaded
187 $this->waitForTextPresent($sourceText);
188
189 // Is status message correct?
190 $this->waitForText('crm-notification-container', "{$membershipTypes['membership_type']} membership for $firstName Memberson has been added.");
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->waitForText('crm-notification-container', "{$membershipTypes['membership_type']} membership for $firstName Memberson has been added.");
279
280 $this->waitForElementPresent("xpath=//div[@id='inactive-memberships']//table/tbody/tr/td[7]/span[2][text()='more']/ul/li/a[text()='Renew']");
281
282 // click through to the Membership Renewal Link
283 $this->click("xpath=//div[@id='inactive-memberships']//table/tbody/tr/td[7]/span[2][text()='more']/ul/li/a[text()='Renew']");
284
285 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
286
287 //change membership type
288 $this->click("changeMembershipOrgType");
289 $this->waitForElementPresent('membership_type_id[1]');
290 $this->select('membership_type_id[0]', "label={$newMembershipType['member_of_contact']}");
291 $this->select('membership_type_id[1]', "label={$newMembershipType['membership_type']}");
292
293 $this->click('membership_type_id[0]');
294 // Because it tends to cause problems, all uses of sleep() must be justified in comments
295 // Sleep should never be used for wait for anything to load from the server
296 // Justification for this instance: wait for onchange handler
297 sleep(2);
298
299 // save the renewed membership
300 $this->click('_qf_MembershipRenewal_upload-bottom');
301
302
303 // page was loaded
304 $this->waitForTextPresent($sourceText);
305
306 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
307
308 // click through to the membership view screen
309 $this->click("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
310
311 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
312
313 $joinDate = date('F jS, Y', strtotime("-2 year"));
314 $startDate = date('F jS, Y');
315 $endDate = date('F jS, Y', strtotime("+1 year -1 day"));
316
317 // verify membership renewed and the membership type is changed
318 $verifyMembershipData = array(
319 'Member' => $contactName,
320 'Membership Type' => $newMembershipType['membership_type'],
321 'Status' => 'Current',
322 'Source' => $sourceText,
323 'Member Since' => $joinDate,
324 'Start date' => $startDate,
325 'End date' => $endDate,
326 );
327 $this->webtestVerifyTabularData($verifyMembershipData);
328 }
329
330 function testOfflineMembershipRenewMultipleTerms() {
331 $this->webtestLogin();
332
333 // make sure period is correct for the membership type we testing for,
334 // since it might have been modified by other tests
335 // add membership type
336 $membershipTypes = $this->webtestAddMembershipType('rolling', 2);
337
338 // quick create a contact
339 $firstName = substr(sha1(rand()), 0, 7);
340 $this->webtestAddContact($firstName, "Memberson", "{$firstName}@memberson.com");
341 $contactName = "$firstName Memberson";
342
343 // click through to the membership tab
344 $this->click('css=li#tab_member a');
345
346 $this->waitForElementPresent('link=Add Membership');
347 $this->click('link=Add Membership');
348
349 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
350
351 // fill in Membership Organization and Type
352 $this->select('membership_type_id[0]', "label={$membershipTypes['member_of_contact']}");
353 $this->select('membership_type_id[1]', "label={$membershipTypes['membership_type']}");
354
355 // fill in Source
356 $sourceText = 'Offline Membership Renewal Webtest';
357 $this->type('source', $sourceText);
358
359 // Fill Member Since
360 $this->webtestFillDate('join_date', '-2 year');
361
362 // Let Start Date and End Date be auto computed
363
364 // Record contribution
365 $this->click('record_contribution');
366 $this->waitForElementPresent( 'financial_type_id' );
367 $this->select( 'financial_type_id', "label=Member Dues" );
368 $this->select('payment_instrument_id', "label=Check");
369 $this->waitForElementPresent('check_number');
370 $this->type('check_number', '1023');
371 $this->select('contribution_status_id', "label=Completed");
372 $this->click('send_receipt');
373
374 // Because it tends to cause problems, all uses of sleep() must be justified in comments
375 // Sleep should never be used for wait for anything to load from the server
376 // Justification for this instance: make sure onchange for total_amount has a chance to fire
377 sleep(2);
378
379 // Clicking save.
380 $this->click('_qf_Membership_upload-bottom');
381 $this->waitForPageToLoad($this->getTimeoutMsec());
382
383 // page was loaded
384 $this->waitForTextPresent($sourceText);
385
386 // Is status message correct?
387 $this->waitForText('crm-notification-container', "{$membershipTypes['membership_type']} membership for $firstName Memberson has been added.");
388 $this->waitForText('crm-notification-container', "A membership confirmation and receipt has been sent to {$firstName}@memberson.com.");
389
390
391 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
392 // click through to the Membership Renewal Link
393 $this->click("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
394
395 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
396 // Record contribution and set number of terms to 2
397 $this->click('record_contribution');
398 $this->waitForElementPresent('financial_type_id');
399 $this->click('changeTermsLink');
400 $this->waitForElementPresent('num_terms');
401 $this->type('num_terms', '');
402 $this->type('num_terms', '2');
403
404 // Because it tends to cause problems, all uses of sleep() must be justified in comments
405 // Sleep should never be used for wait for anything to load from the server
406 // Justification for this instance: make sure onchange for total_amount has a chance to fire
407 sleep(2);
408 $this->click('total_amount');
409 $this->verifyValue('total_amount', "200.00");
410 $this->select('financial_type_id', "label=Member Dues");
411 $this->select('payment_instrument_id', "label=Check");
412 $this->waitForElementPresent('check_number');
413 $this->type('check_number', '1024');
414 $this->select('contribution_status_id', "label=Completed");
415 $this->click('send_receipt');
416
417 // save the renewed membership
418 $this->click('_qf_MembershipRenewal_upload-bottom');
419
420
421 // page was loaded
422 $this->waitForTextPresent($sourceText);
423
424 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
425
426 // click through to the membership view screen
427 $this->click("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
428
429 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
430
431 $joinDate = $startDate = date('F jS, Y', strtotime("-2 year"));
432 // Adding 2 x 2 years renewal to initial membership.
433 $endDate = date('F jS, Y', strtotime("+4 year -1 day"));
434
435 // verify membership renewed
436 $verifyMembershipRenewData = array(
437 'Member' => $contactName,
438 'Membership Type' => $membershipTypes['membership_type'],
439 'Status' => 'Current',
440 'Source' => $sourceText,
441 'Member Since' => $joinDate,
442 'Start date' => $startDate,
443 'End date' => $endDate,
444 );
445 $this->webtestVerifyTabularData($verifyMembershipRenewData);
446 }
447 }