Merge pull request #196 from dlobo/CRM-12151
[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() {
36 $this->open($this->sboxPath);
37 $this->webtestLogin();
38
39 // make sure period is correct for the membership type we testing for,
40 // since it might have been modified by other tests
41 // add membership type
42 $membershipTypes = $this->webtestAddMembershipType('rolling', 2);
43
44 // quick create a contact
45 $firstName = substr(sha1(rand()), 0, 7);
46 $this->webtestAddContact($firstName, "Memberson", "{$firstName}@memberson.com");
47 $contactName = "$firstName Memberson";
48
49 // click through to the membership tab
50 $this->click('css=li#tab_member a');
51
52 $this->waitForElementPresent('link=Add Membership');
53 $this->click('link=Add Membership');
54
55 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
56
57 // fill in Membership Organization and Type
58 $this->select('membership_type_id[0]', "label={$membershipTypes['member_of_contact']}");
59 $this->select('membership_type_id[1]', "label={$membershipTypes['membership_type']}");
60
61 // fill in Source
62 $sourceText = 'Offline Membership Renewal Webtest';
63 $this->type('source', $sourceText);
64
65 // Fill Member Since
66 $this->webtestFillDate('join_date', '-2 year');
67
68 // Let Start Date and End Date be auto computed
69 // added sleep to make sure jscript onchange for total_amount has a chance to fire
70 sleep(2);
71
72 // Clicking save.
73 $this->click('_qf_Membership_upload-bottom');
74 $this->waitForPageToLoad($this->getTimeoutMsec());
75
76 // page was loaded
77 $this->waitForTextPresent($sourceText);
78
79 // Is status message correct?
f2ff7d84
PJ
80 $this->assertElementContainsText('crm-notification-container', "{$membershipTypes['membership_type']} membership for $firstName Memberson has been added.",
81 "Status message didn't show up after saving!"
82 );
6a488035
TO
83
84 $this->waitForElementPresent("xpath=//div[@id='Memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
85
86 // click through to the Membership Renewal Link
87 $this->click("xpath=//div[@id='Memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
88
89 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
90
91 // save the renewed membership
92 $this->click('_qf_MembershipRenewal_upload-bottom');
93
94 $this->waitForPageToLoad($this->getTimeoutMsec());
95
96 // page was loaded
97 $this->waitForTextPresent($sourceText);
98
99 $this->waitForElementPresent("xpath=//div[@id='Memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
100
101 // click through to the membership view screen
102 $this->click("xpath=//div[@id='Memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
103
104 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
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
PJ
119 $this->webtestVerifyTabularData($verifyMembershipRenewData);
120 }
6a488035
TO
121
122 function testOfflineMemberRenewOverride() {
123 $this->open($this->sboxPath);
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');
f2ff7d84 167
6a488035
TO
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?
f2ff7d84
PJ
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 );
6a488035
TO
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 );
f2ff7d84 228 $this->webtestVerifyTabularData($verifyMembershipRenewOverrideData);
6a488035
TO
229 }
230
231 function testOfflineMembershipRenewChangeType() {
232 $this->open($this->sboxPath);
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
265 // added sleep to make sure jscript onchange for total_amount has a chance to fire
266 sleep(2);
267
268 // Clicking save.
269 $this->click('_qf_Membership_upload-bottom');
270 $this->waitForPageToLoad($this->getTimeoutMsec());
271
272 // page was loaded
273 $this->waitForTextPresent($sourceText);
274
275 // Is status message correct?
f2ff7d84
PJ
276 $this->assertElementContainsText('crm-notification-container', "{$membershipTypes['membership_type']} membership for $firstName Memberson has been added.",
277 "Status message didn't show up after saving!"
278 );
6a488035
TO
279
280 $this->waitForElementPresent("xpath=//div[@id='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='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 sleep(2);
295
296 // save the renewed membership
297 $this->click('_qf_MembershipRenewal_upload-bottom');
298
299 $this->waitForPageToLoad($this->getTimeoutMsec());
300
301 // page was loaded
302 $this->waitForTextPresent($sourceText);
303
304 $this->waitForElementPresent("xpath=//div[@id='Memberships']//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
305
306 // click through to the membership view screen
307 $this->click("xpath=//div[@id='Memberships']//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
308
309 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
310
311 $joinDate = date('F jS, Y', strtotime("-2 year"));
312 $startDate = date('F jS, Y');
313 $endDate = date('F jS, Y', strtotime("+1 year -1 day"));
314
315 // verify membership renewed and the membership type is changed
316 $verifyMembershipData = array(
317 'Member' => $contactName,
318 'Membership Type' => $newMembershipType['membership_type'],
319 'Status' => 'Current',
320 'Source' => $sourceText,
321 'Member Since' => $joinDate,
322 'Start date' => $startDate,
323 'End date' => $endDate,
324 );
f2ff7d84 325 $this->webtestVerifyTabularData($verifyMembershipData);
6a488035
TO
326 }
327
328 function testOfflineMembershipRenewMultipleTerms() {
329 $this->open($this->sboxPath);
330 $this->webtestLogin();
331
332 // make sure period is correct for the membership type we testing for,
333 // since it might have been modified by other tests
334 // add membership type
335 $membershipTypes = $this->webtestAddMembershipType('rolling', 2);
336
337 // quick create a contact
338 $firstName = substr(sha1(rand()), 0, 7);
339 $this->webtestAddContact($firstName, "Memberson", "{$firstName}@memberson.com");
340 $contactName = "$firstName Memberson";
341
342 // click through to the membership tab
343 $this->click('css=li#tab_member a');
344
345 $this->waitForElementPresent('link=Add Membership');
346 $this->click('link=Add Membership');
347
348 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
349
350 // fill in Membership Organization and Type
351 $this->select('membership_type_id[0]', "label={$membershipTypes['member_of_contact']}");
352 $this->select('membership_type_id[1]', "label={$membershipTypes['membership_type']}");
353
354 // fill in Source
355 $sourceText = 'Offline Membership Renewal Webtest';
356 $this->type('source', $sourceText);
357
358 // Fill Member Since
359 $this->webtestFillDate('join_date', '-2 year');
360
361 // Let Start Date and End Date be auto computed
362
363 // Record contribution
364 $this->click('record_contribution');
365 $this->waitForElementPresent( 'financial_type_id' );
366 $this->select( 'financial_type_id', "label=Member Dues" );
367 $this->select('payment_instrument_id', "label=Check");
368 $this->waitForElementPresent('check_number');
369 $this->type('check_number', '1023');
370 $this->select('contribution_status_id', "label=Completed");
371 $this->click('send_receipt');
372 // added sleep to make sure jscript onchange for total_amount has a chance to fire
373 sleep(2);
374
375 // Clicking save.
376 $this->click('_qf_Membership_upload-bottom');
377 $this->waitForPageToLoad($this->getTimeoutMsec());
378
379 // page was loaded
380 $this->waitForTextPresent($sourceText);
381
382 // Is status message correct?
f2ff7d84
PJ
383 $this->assertElementContainsText('crm-notification-container', "{$membershipTypes['membership_type']} membership for $firstName Memberson has been added.",
384 "Status message didn't show up after saving!"
385 );
386 $this->assertElementContainsText('crm-notification-container', "A membership confirmation and receipt has been sent to {$firstName}@memberson.com.",
387 "Email sent to member message didn't show up after saving membership!"
388 );
6a488035
TO
389
390 $this->waitForElementPresent("xpath=//div[@id='Memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
391
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');
f2ff7d84 398 $this->waitForElementPresent('financial_type_id');
6a488035
TO
399 $this->click('changeTermsLink');
400 $this->waitForElementPresent('num_terms');
401 $this->type('num_terms', '');
402 $this->type('num_terms', '2');
403 // added sleep to make sure jscript onchange for total_amount has a chance to fire
404 sleep(2);
405 $this->click('total_amount');
406 $this->verifyValue('total_amount', "200.00");
f2ff7d84 407 $this->select('financial_type_id', "label=Member Dues");
6a488035
TO
408 $this->select('payment_instrument_id', "label=Check");
409 $this->waitForElementPresent('check_number');
410 $this->type('check_number', '1024');
411 $this->select('contribution_status_id', "label=Completed");
412 $this->click('send_receipt');
413
414 // save the renewed membership
415 $this->click('_qf_MembershipRenewal_upload-bottom');
416
417 $this->waitForPageToLoad($this->getTimeoutMsec());
418
419 // page was loaded
420 $this->waitForTextPresent($sourceText);
421
422 $this->waitForElementPresent("xpath=//div[@id='Memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
423
424 // click through to the membership view screen
425 $this->click("xpath=//div[@id='Memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
426
427 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
428
429 $joinDate = $startDate = date('F jS, Y', strtotime("-2 year"));
430 // Adding 2 x 2 years renewal to initial membership.
431 $endDate = date('F jS, Y', strtotime("+4 year -1 day"));
432
433 // verify membership renewed
434 $verifyMembershipRenewData = array(
435 'Member' => $contactName,
436 'Membership Type' => $membershipTypes['membership_type'],
437 'Status' => 'Current',
438 'Source' => $sourceText,
439 'Member Since' => $joinDate,
440 'Start date' => $startDate,
441 'End date' => $endDate,
442 );
f2ff7d84 443 $this->webtestVerifyTabularData($verifyMembershipRenewData);
6a488035 444 }
f2ff7d84 445}