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