Import from SVN (r45945, r596)
[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->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?
80 $this->assertTrue($this->isTextPresent("{$membershipTypes['membership_type']} membership for $firstName Memberson has been added."), "Status message didn't show up after saving!");
81
82 $this->waitForElementPresent("xpath=//div[@id='Memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
83
84 // click through to the Membership Renewal Link
85 $this->click("xpath=//div[@id='Memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
86
87 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
88
89 // save the renewed membership
90 $this->click('_qf_MembershipRenewal_upload-bottom');
91
92 $this->waitForPageToLoad($this->getTimeoutMsec());
93
94 // page was loaded
95 $this->waitForTextPresent($sourceText);
96
97 $this->waitForElementPresent("xpath=//div[@id='Memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
98
99 // click through to the membership view screen
100 $this->click("xpath=//div[@id='Memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
101
102 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
103
104 $joinDate = $startDate = date('F jS, Y', strtotime("-2 year"));
105 $endDate = date('F jS, Y', strtotime("+2 year -1 day"));
106
107 // verify membership renewed
108 $verifyMembershipRenewData = array(
109 'Member' => $contactName,
110 'Membership Type' => $membershipTypes['membership_type'],
111 'Status' => 'Current',
112 'Source' => $sourceText,
113 'Member Since' => $joinDate,
114 'Start date' => $startDate,
115 'End date' => $endDate,
116 );
117 foreach ($verifyMembershipRenewData as $label => $value) {
118 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td", preg_quote($value));
119 }
120 }
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');
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->assertTrue($this->isTextPresent("{$membershipTypes['membership_type']} membership for $firstName Memberson has been added."), "Status message didn't show up after saving!");
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 foreach ($verifyMembershipRenewOverrideData as $label => $value) {
227 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td", preg_quote($value));
228 }
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?
276 $this->assertTrue($this->isTextPresent("{$membershipTypes['membership_type']} membership for $firstName Memberson has been added."), "Status message didn't show up after saving!");
277
278 $this->waitForElementPresent("xpath=//div[@id='Memberships']//table/tbody/tr/td[7]/span[2][text()='more']/ul/li/a[text()='Renew']");
279
280 // click through to the Membership Renewal Link
281 $this->click("xpath=//div[@id='Memberships']//table/tbody/tr/td[7]/span[2][text()='more']/ul/li/a[text()='Renew']");
282
283 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
284
285 //change membership type
286 $this->click("changeMembershipOrgType");
287 $this->waitForElementPresent('membership_type_id[1]');
288 $this->select('membership_type_id[0]', "label={$newMembershipType['member_of_contact']}");
289 $this->select('membership_type_id[1]', "label={$newMembershipType['membership_type']}");
290
291 $this->click('membership_type_id[0]');
292 sleep(2);
293
294 // save the renewed membership
295 $this->click('_qf_MembershipRenewal_upload-bottom');
296
297 $this->waitForPageToLoad($this->getTimeoutMsec());
298
299 // page was loaded
300 $this->waitForTextPresent($sourceText);
301
302 $this->waitForElementPresent("xpath=//div[@id='Memberships']//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
303
304 // click through to the membership view screen
305 $this->click("xpath=//div[@id='Memberships']//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']");
306
307 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
308
309 $joinDate = date('F jS, Y', strtotime("-2 year"));
310 $startDate = date('F jS, Y');
311 $endDate = date('F jS, Y', strtotime("+1 year -1 day"));
312
313 // verify membership renewed and the membership type is changed
314 $verifyMembershipData = array(
315 'Member' => $contactName,
316 'Membership Type' => $newMembershipType['membership_type'],
317 'Status' => 'Current',
318 'Source' => $sourceText,
319 'Member Since' => $joinDate,
320 'Start date' => $startDate,
321 'End date' => $endDate,
322 );
323 foreach ($verifyMembershipData as $label => $value) {
324 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td", preg_quote($value));
325 }
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?
383 $this->assertTrue($this->isTextPresent("{$membershipTypes['membership_type']} membership for $firstName Memberson has been added."), "Status message didn't show up after saving!");
384 $this->assertTrue($this->isTextPresent("A membership confirmation and receipt has been sent to {$firstName}@memberson.com."), "Email sent to member message didn't show up after saving membership!");
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 foreach ($verifyMembershipRenewData as $label => $value) {
440 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td", preg_quote($value));
441 }
442 }
443 }
444