Merge pull request #8166 from otetard/CRM-18432
[civicrm-core.git] / tests / phpunit / WebTest / Member / OnlineMembershipRenewTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
81621fee 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
fa938177 6 | Copyright CiviCRM LLC (c) 2004-2016 |
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 +--------------------------------------------------------------------+
25 */
26
6a488035 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Member_OnlineMembershipRenewTest
31 */
6a488035
TO
32class WebTest_Member_OnlineMembershipRenewTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
b45c587e
CW
38 /**
39 * FIXME: This test tries to update a contribution page (id=2) that may not exist :(
40 */
00be9182 41 public function testOnlineMembershipRenew() {
6a488035
TO
42 // a random 7-char string and an even number to make this pass unique
43 $hash = substr(sha1(rand()), 0, 7);
44 $rand = 2 * rand(2, 50);
45
6a488035
TO
46 // Log in using webtestLogin() method
47 $this->webtestLogin();
48
c3ad8633
CW
49 // Use default payment processor
50 $processorName = 'Test Processor';
6a488035
TO
51 $this->webtestAddPaymentProcessor($processorName);
52
42daf119 53 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=2", "_qf_Amount_next");
6a488035
TO
54 // this contribution page for membership signup
55 // select newly created processor
56 $xpath = "xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]";
2ac4a694 57 $this->waitForText('css=.crm-contribution-contributionpage-amount-form-block-payment_processor', $processorName);
6a488035
TO
58 $this->check($xpath);
59
60 // save
61 $this->waitForElementPresent("_qf_Amount_next");
b45c587e 62 $this->clickLink('_qf_Amount_next');
6a488035
TO
63
64 // go to Membership block
65 $this->click('css=#tab_membership a');
66 $this->waitForElementPresent("member_is_active");
67 $this->check("member_is_active");
76e86fd8
CW
68
69 $this->waitForElementPresent("new_title");
70
6a488035 71 if ($this->isElementPresent("member_price_set_id")) {
6c6e6187 72 $this->waitForElementPresent("member_price_set_id");
76e86fd8 73
6c6e6187 74 $this->select("member_price_set_id", "label=- none -");
6a488035 75 }
76e86fd8 76
6a488035
TO
77 $this->waitForElementPresent("membership_type-block");
78 $this->check("xpath=//tr[@id='membership_type-block']/td[2]/table/tbody/tr/td/label[text()='General']/../input[2]");
79 $this->check("xpath=//tr[@id='membership_type-block']/td[2]/table/tbody/tr/td/label[text()='Student']/../input[2]");
80 $this->click("_qf_MembershipBlock_next-bottom");
81 $this->waitForTextPresent("'MembershipBlock' information has been saved");
76e86fd8 82
6a488035
TO
83 // go to Profiles
84 $this->click('css=#tab_custom a');
85
86 // fill in Profiles
87 $this->waitForElementPresent('custom_pre_id');
73072f84 88 $this->select('css=tr.crm-contribution-contributionpage-custom-form-block-custom_pre_id span.crm-profile-selector-select select', 'value=1');
6a488035
TO
89
90 // save
91 $this->click('_qf_Custom_upload_done');
92 $this->waitForPageToLoad();
93
94 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
42daf119
CW
95 $lastName = 'An' . substr(sha1(rand()), 0, 7);
96 $email = $firstName . "@example.com";
6a488035
TO
97
98 //logout
42daf119 99 $this->webtestLogout();
6a488035
TO
100
101 //Go to online membership signup page
f1224701 102 $this->openCiviPage("contribute/transact", "reset=1&id=2&action=preview", "_qf_Main_upload-bottom");
76e86fd8 103
b21dd815 104 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div[2]/span/label/span[1][contains(text(),'Student')]");
6a488035
TO
105
106 //Type first name and last name and email
107 $this->type("first_name", $firstName);
108 $this->type("last_name", $lastName);
109 $this->type("email-5", $email);
73072f84 110 $this->select("state_province-1", "value=1001");
6a488035
TO
111
112 //Credit Card Info
113 $this->select("credit_card_type", "value=Visa");
114 $this->select("credit_card_type", "label=Visa");
115 $this->type("credit_card_number", "4111111111111111");
116 $this->type("cvv2", "000");
117 $this->select("credit_card_exp_date[M]", "value=1");
118 $this->select("credit_card_exp_date[Y]", "value=2020");
119
120 //Billing Info
121 $this->type("billing_first_name", $firstName . "billing");
122 $this->type("billing_last_name", $lastName . "billing");
123 $this->type("billing_street_address-5", "15 Main St.");
124 $this->type(" billing_city-5", "San Jose");
125 $this->select("billing_country_id-5", "value=1228");
126 $this->select("billing_state_province_id-5", "value=1004");
127 $this->type("billing_postal_code-5", "94129");
128
225a8648 129 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
6a488035
TO
130
131 $this->click("_qf_Confirm_next-bottom");
6a488035
TO
132
133 // Log in using webtestLogin() method
6a488035
TO
134 $this->webtestLogin();
135 //Find Member
42daf119 136 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
6a488035 137
8fb46c61 138 $this->type("sort_name", "$lastName $firstName");
f1224701 139 $this->click("xpath=//tr/td[1]/p/label[contains(text(),'Membership is a Test?')]/../label[contains(text(),'Yes')]/preceding-sibling::input[1]");
a1c7d42f
CW
140 $this->clickLink("_qf_Search_refresh", 'css=#memberSearch table tbody tr td span a.action-item:first-child');
141 $this->click('css=#memberSearch table tbody tr td span a.action-item:first-child');
6a488035
TO
142 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
143
144 //View Membership Record
145 $verifyMembershipData = array(
146 'Member' => $firstName . ' ' . $lastName,
147 'Membership Type' => 'Student',
148 'Status' => 'New',
149 'Source' => 'Online Contribution: Member Signup and Renewal',
150 );
151 foreach ($verifyMembershipData as $label => $value) {
152 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
153 preg_quote($value)
154 );
155 }
156
157 //logout
42daf119 158 $this->webtestLogout();
6a488035 159
f1224701 160 $this->openCiviPage("contribute/transact", "reset=1&id=2&action=preview", "_qf_Main_upload-bottom");
6a488035 161
b21dd815 162 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div[2]/span/label/span[1][contains(text(),'Student')]");
6a488035
TO
163
164 //Type first name and last name and email
165 $this->type("first_name", $firstName);
166 $this->type("last_name", $lastName);
167 $this->type("email-5", $email);
73072f84 168 $this->select("state_province-1", "value=1001");
6a488035
TO
169
170 //Credit Card Info
171 $this->select("credit_card_type", "value=Visa");
172 $this->select("credit_card_type", "label=Visa");
173 $this->type("credit_card_number", "4111111111111111");
174 $this->type("cvv2", "000");
175 $this->select("credit_card_exp_date[M]", "value=1");
176 $this->select("credit_card_exp_date[Y]", "value=2020");
177
178 //Billing Info
179 $this->type("billing_first_name", $firstName . "billing");
180 $this->type("billing_last_name", $lastName . "billing");
181 $this->type("billing_street_address-5", "15 Main St.");
182 $this->type(" billing_city-5", "San Jose");
183 $this->select("billing_country_id-5", "value=1228");
184 $this->select("billing_state_province_id-5", "value=1004");
185 $this->type("billing_postal_code-5", "94129");
186
225a8648 187 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
6a488035 188 $this->click("_qf_Confirm_next-bottom");
6a488035 189
6a488035
TO
190 $this->webtestLogin();
191 //Find Member
42daf119 192 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
6a488035 193
8fb46c61 194 $this->type("sort_name", "$lastName $firstName");
f1224701 195 $this->click("xpath=//tr/td[1]/p/label[contains(text(),'Membership is a Test?')]/../label[contains(text(),'Yes')]/preceding-sibling::input[1]");
a1c7d42f
CW
196 $this->clickLink("_qf_Search_refresh", 'css=#memberSearch table tbody tr td span a.action-item:first-child');
197 $this->click('css=#memberSearch table tbody tr td span a.action-item:first-child');
6a488035
TO
198 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
199
200 //View Membership Record
201 $verifyMembershipData = array(
202 'Member' => $firstName . ' ' . $lastName,
203 'Membership Type' => 'Student',
204 'Status' => 'New',
205 'Source' => 'Online Contribution: Member Signup and Renewal',
206 );
207 foreach ($verifyMembershipData as $label => $value) {
208 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
209 preg_quote($value)
210 );
211 }
212 }
213
b45c587e
CW
214 /**
215 * FIXME: This test tries to update a contribution page (id=2) that may not exist :(
216 */
00be9182 217 public function testOnlineMembershipRenewChangeType() {
6a488035
TO
218 // a random 7-char string and an even number to make this pass unique
219 $hash = substr(sha1(rand()), 0, 7);
220 $rand = 2 * rand(2, 50);
221
6a488035
TO
222 // Log in using webtestLogin() method
223 $this->webtestLogin();
224
c3ad8633
CW
225 // Use default payment processor
226 $processorName = 'Test Processor';
6a488035
TO
227 $this->webtestAddPaymentProcessor($processorName);
228
42daf119 229 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=2", '_qf_Amount_next');
6a488035
TO
230
231 //this contribution page for membership signup
232 $xpath = "xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]";
2ac4a694 233 $this->waitForText('css=.crm-contribution-contributionpage-amount-form-block-payment_processor', $processorName);
6a488035
TO
234 $this->check($xpath);
235
236 // save
237 $this->waitForElementPresent('_qf_Amount_next');
238 $this->click('_qf_Amount_next');
239 $this->waitForPageToLoad();
240
241 // go to Membership block
242 $this->click('css=#tab_membership a');
243 $this->waitForElementPresent("member_is_active");
244 $this->check("member_is_active");
76e86fd8 245
6a488035
TO
246 $this->waitForElementPresent("new_title");
247 if ($this->isElementPresent("member_price_set_id")) {
6c6e6187 248 $this->waitForElementPresent("member_price_set_id");
76e86fd8 249
6c6e6187 250 $this->select("member_price_set_id", "label=- none -");
6a488035 251 }
76e86fd8 252
6a488035
TO
253 $this->waitForElementPresent("membership_type-block");
254 $this->check("xpath=//tr[@id='membership_type-block']/td[2]/table/tbody/tr/td/label[text()='General']/../input[2]");
255 $this->check("xpath=//tr[@id='membership_type-block']/td[2]/table/tbody/tr/td/label[text()='Student']/../input[2]");
256 $this->click("_qf_MembershipBlock_next-bottom");
257 $this->waitForTextPresent("'MembershipBlock' information has been saved");
76e86fd8 258
6a488035
TO
259 // go to Profiles
260 $this->click('css=#tab_custom a');
261
262 // fill in Profiles
263 $this->waitForElementPresent('custom_pre_id');
73072f84 264 $this->select('css=tr.crm-contribution-contributionpage-custom-form-block-custom_pre_id span.crm-profile-selector-select select', 'value=1');
6a488035
TO
265
266 // save
267 $this->click('_qf_Custom_upload_done');
268 $this->waitForPageToLoad();
269
270 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
271 $lastName = 'An' . substr(sha1(rand()), 0, 7);
272
273 //Go to online membership signup page
f1224701 274 $this->openCiviPage("contribute/transact", "reset=1&id=2&action=preview", "_qf_Main_upload-bottom");
b21dd815 275 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div[1]/span/label/span[1][contains(text(),'General')]");
6a488035
TO
276 //Type first name and last name
277 $this->type("first_name", $firstName);
278 $this->type("last_name", $lastName);
279
73072f84 280 $this->select("state_province-1", "value=1001");
6a488035
TO
281 //Credit Card Info
282 $this->select("credit_card_type", "value=Visa");
283 $this->select("credit_card_type", "label=Visa");
284 $this->type("credit_card_number", "4111111111111111");
285 $this->type("cvv2", "000");
286 $this->select("credit_card_exp_date[M]", "value=1");
287 $this->select("credit_card_exp_date[Y]", "value=2020");
288
289 //Billing Info
290 $this->type("billing_first_name", $firstName . "billing");
291 $this->type("billing_last_name", $lastName . "billing");
292 $this->type("billing_street_address-5", "15 Main St.");
293 $this->type(" billing_city-5", "San Jose");
294 $this->select("billing_country_id-5", "value=1228");
295 $this->select("billing_state_province_id-5", "value=1004");
296 $this->type("billing_postal_code-5", "94129");
297
225a8648 298 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
6a488035
TO
299
300 $this->click("_qf_Confirm_next-bottom");
6a488035
TO
301
302 //Find Member
42daf119 303 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
6a488035 304
8fb46c61 305 $this->type("sort_name", "$lastName $firstName");
f1224701 306 $this->click("xpath=//tr/td[1]/p/label[contains(text(),'Membership is a Test?')]/../label[contains(text(),'Yes')]/preceding-sibling::input[1]");
a1c7d42f
CW
307 $this->clickLink("_qf_Search_refresh", 'css=#memberSearch table tbody tr td span a.action-item:first-child');
308 $this->click('css=#memberSearch table tbody tr td span a.action-item:first-child');
6a488035
TO
309 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
310
a471a3b6 311 $membershipCreatedId = $this->urlArg('id');
6a488035
TO
312
313 $memberSince = date('F jS, Y');
314
315 //View Membership Record
316 $verifyMembershipData = array(
317 'Member' => $firstName . ' ' . $lastName,
318 'Membership Type' => 'General',
319 'Status' => 'New',
320 'Source' => 'Online Contribution: Member Signup and Renewal',
321 );
322 foreach ($verifyMembershipData as $label => $value) {
323 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
324 preg_quote($value)
325 );
326 }
f1224701 327 $this->openCiviPage("contribute/transact", "reset=1&id=2&action=preview", "_qf_Main_upload-bottom");
b21dd815 328 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div[2]/span/label/span[1][contains(text(),'Student')]");
6a488035
TO
329
330 //Credit Card Info
331 $this->select("credit_card_type", "value=Visa");
332 $this->select("credit_card_type", "label=Visa");
333 $this->type("credit_card_number", "4111111111111111");
334 $this->type("cvv2", "000");
335 $this->select("credit_card_exp_date[M]", "value=1");
336 $this->select("credit_card_exp_date[Y]", "value=2020");
225a8648 337 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
6a488035 338 $this->click("_qf_Confirm_next-bottom");
6a488035
TO
339
340 //Find Member
42daf119 341 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
6a488035 342
8fb46c61 343 $this->type("sort_name", "$lastName $firstName");
f1224701 344 $this->click("xpath=//tr/td[1]/p/label[contains(text(),'Membership is a Test?')]/../label[contains(text(),'Yes')]/preceding-sibling::input[1]");
a1c7d42f
CW
345 $this->clickLink("_qf_Search_refresh", 'css=#memberSearch table tbody tr td span a.action-item:first-child');
346 $this->click('css=#memberSearch table tbody tr td span a.action-item:first-child');
6a488035
TO
347 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
348
a471a3b6 349 $membershipRenewedId = $this->urlArg('id');
6a488035
TO
350
351 //View Membership Record
352 $verifyMembershipData = array(
353 'Member' => $firstName . ' ' . $lastName,
354 'Membership Type' => 'Student',
355 'Status' => 'New',
356 'Source' => 'Online Contribution: Member Signup and Renewal',
357 'Member Since' => $memberSince,
358 );
359 foreach ($verifyMembershipData as $label => $value) {
360 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
361 preg_quote($value)
362 );
363 }
364 $this->assertEquals($membershipCreatedId, $membershipRenewedId);
365 }
366
00be9182 367 public function testUpdateInheritedMembershipOnBehalfOfRenewal() {
42daf119
CW
368 // Log in as admin
369 $this->webtestLogin('admin');
76e86fd8 370
42daf119 371 $this->enableComponents('CiviMember');
6a488035 372
42daf119
CW
373 //check for online contribution and profile listings permissions
374 $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms");
375 $this->changePermissions($permissions);
376
377 // Log in as normal user
6a488035
TO
378 $this->webtestLogin();
379
42daf119 380 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
6a488035
TO
381
382 $title = substr(sha1(rand()), 0, 7);
383 $this->type('organization_name', "Organization $title");
384 $this->type('email_1_email', "$title@org.com");
385 $this->click('_qf_Contact_upload_view');
386 $this->waitForPageToLoad($this->getTimeoutMsec());
387
2ac4a694 388 $this->waitForText('crm-notification-container', "Organization $title has been created.");
6a488035 389
071a6d2e 390 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
6a488035
TO
391
392 $this->click('link=Add Membership Type');
393 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
394
395 $membershipTypeTitle = "Membership Type $title";
396 $this->type('name', "Membership Type $title");
76e86fd8 397
73072f84 398 $this->select2('member_of_contact_id', $title);
6a488035
TO
399
400 $this->type('minimum_fee', '100');
481a74f4 401 $this->select('financial_type_id', 'value=2');
6a488035
TO
402 $this->type('duration_interval', 1);
403 $this->select('duration_unit', 'label=year');
73072f84 404 $this->select('period_type', 'value=rolling');
f64f0f3c 405 $this->select2('relationship_type_id', 'Employer of', TRUE);
6a488035
TO
406
407 $this->click('_qf_MembershipType_upload-bottom');
408 $this->waitForElementPresent('link=Add Membership Type');
2ac4a694 409 $this->waitForText('crm-notification-container', "The membership type 'Membership Type $title' has been saved.");
6a488035 410
5c80555f
WA
411 $this->waitForElementPresent("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$membershipTypeTitle}']/../../td[12]/span/a[3][text()='Delete']/@href");
412 $url = $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$membershipTypeTitle}']/../../td[12]/span/a[3][text()='Delete']/@href");
6a488035
TO
413 $matches = array();
414 preg_match('/id=([0-9]+)/', $url, $matches);
415 $membershipTypeId = $matches[1];
416
c3ad8633
CW
417 // Use default payment processor
418 $processorName = 'Test Processor';
6a488035 419
6a488035 420 // create contribution page with randomized title and default params
42daf119
CW
421 $hash = substr(sha1(rand()), 0, 7);
422 $rand = 2 * rand(2, 50);
6a488035 423 $amountSection = FALSE;
42daf119
CW
424 $payLater = FALSE;
425 $onBehalf = FALSE;
426 $pledges = FALSE;
427 $recurring = FALSE;
428 $memberships = FALSE;
6a488035 429 $memPriceSetId = NULL;
42daf119
CW
430 $friend = FALSE;
431 $profilePreId = 1;
6a488035 432 $profilePostId = NULL;
42daf119
CW
433 $premiums = FALSE;
434 $widget = FALSE;
435 $pcp = FALSE;
6a488035
TO
436
437 $contributionTitle = "Title $hash";
438 $pageId = $this->webtestAddContributionPage($hash,
439 $rand,
440 $contributionTitle,
441 array($processorName => 'Dummy'),
442 $amountSection,
443 $payLater,
444 $onBehalf,
445 $pledges,
446 $recurring,
447 $memberships,
448 $memPriceSetId,
449 $friend,
450 $profilePreId,
451 $profilePostId,
452 $premiums,
453 $widget,
454 $pcp,
455 TRUE
456 );
457
458 $hash = substr(sha1(rand()), 0, 7);
071a6d2e 459 $this->openCiviPage("admin/contribute/settings", "reset=1&action=update&id=$pageId");
6a488035
TO
460
461 $this->click('link=Title');
462 $this->waitForElementPresent('_qf_Settings_cancel-bottom');
463 $this->click('is_organization');
c900afb1 464 $this->select("xpath=//input[@id='onbehalf_profile_id']/parent::td/div/div/span/select", "value=9");
6a488035
TO
465 $this->type('for_organization', "On behalf $hash");
466 $this->click('_qf_Settings_next-bottom');
467 $this->waitForPageToLoad($this->getTimeoutMsec());
468
469 $this->click('link=Memberships');
470 $this->waitForElementPresent('_qf_MembershipBlock_cancel-bottom');
471 $this->click('member_is_active');
472 $this->type('new_title', "Title - New Membership $hash");
473 $this->type('renewal_title', "Title - Renewals $hash");
474 $this->click("membership_type_{$membershipTypeId}");
475 $this->click('is_required');
476 $this->click('_qf_MembershipBlock_next-bottom');
477 $this->waitForPageToLoad($this->getTimeoutMsec());
478
479 //logout
42daf119 480 $this->webtestLogout();
6a488035
TO
481
482 //get Url for Live Contribution Page
f1224701 483 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", '_qf_Main_upload-bottom');
b21dd815 484 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div/span/label/span[1][contains(text(),'$membershipTypeTitle')]");
42daf119
CW
485 $firstName = 'Eia' . substr(sha1(rand()), 0, 4);
486 $lastName = 'Ande' . substr(sha1(rand()), 0, 4);
487 $name = $firstName . ' ' . $lastName;
6a488035
TO
488 $organisationName = 'TestOrg' . substr(sha1(rand()), 0, 7);
489
490 $email = $firstName . '@example.com';
491 $this->type('email-5', $email);
492 $this->click('is_for_organization');
493 $this->type('onbehalf_organization_name', $organisationName);
494 $this->type('onbehalf_phone-3-1', '2222-222222');
495 $this->type('onbehalf_email-3', $organisationName . '@example.com');
496 $this->type('onbehalf_street_address-3', '54A Excelsior Ave. Apt 1C');
497 $this->type('onbehalf_city-3', 'Driftwood');
498 $this->type('onbehalf_postal_code-3', '75653');
499 $this->select('onbehalf_country-3', "value=1228");
500 $this->select('onbehalf_state_province-3', "value=1061");
501
502 $this->type('first_name', $firstName);
503 $this->type('last_name', $lastName);
73072f84 504 $this->select("state_province-1", "value=1001");
6a488035
TO
505
506 //Credit Card Info
507 $this->select("credit_card_type", "value=Visa");
508 $this->select("credit_card_type", "label=Visa");
509 $this->type("credit_card_number", "4111111111111111");
510 $this->type("cvv2", "000");
511 $this->select("credit_card_exp_date[M]", "value=1");
512 $this->select("credit_card_exp_date[Y]", "value=2020");
513
514 //Billing Info
515 $this->type("billing_first_name", $firstName . "billing");
516 $this->type("billing_last_name", $lastName . "billing");
517 $this->type("billing_street_address-5", "15 Main St.");
518 $this->type(" billing_city-5", "San Jose");
519 $this->select("billing_country_id-5", "value=1228");
520 $this->select("billing_state_province_id-5", "value=1004");
521 $this->type("billing_postal_code-5", "94129");
225a8648 522 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
6a488035
TO
523
524 $this->click("_qf_Confirm_next-bottom");
525 $this->waitForPageToLoad($this->getTimeoutMsec());
526
6a488035 527 // Log in using webtestLogin() method
6a488035
TO
528 $this->webtestLogin();
529
530 //Find member
531 $endDate = date('F jS, Y', strtotime(" +1 year -1 day"));
42daf119 532 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
6a488035
TO
533
534 $this->type("sort_name", "$organisationName");
f1224701 535 $this->click("xpath=//tr/td[1]/p/label[contains(text(),'Membership is a Test?')]/../label[contains(text(),'Yes')]/preceding-sibling::input[1]");
a1c7d42f
CW
536 $this->clickLink("_qf_Search_refresh", 'css=#memberSearch table tbody tr td span a.action-item:first-child');
537 $this->click('css=#memberSearch table tbody tr td span a.action-item:first-child');
6a488035
TO
538 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
539
540 //View Membership Record
541 $verifyMembershipData = array(
542 'Member' => $organisationName,
543 'Membership Type' => $membershipTypeTitle,
544 'Status' => 'New',
545 'End date' => $endDate,
546 );
547
548 foreach ($verifyMembershipData as $label => $value) {
549 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
550 preg_quote($value)
551 );
552 }
553
42daf119 554 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
6a488035
TO
555
556 $this->type("sort_name", "$lastName, $firstName");
f1224701 557 $this->click("xpath=//tr/td[1]/p/label[contains(text(),'Membership is a Test?')]/../label[contains(text(),'Yes')]/preceding-sibling::input[1]");
4dc8abb7
WA
558 $this->clickLink("_qf_Search_refresh", "css=#memberSearch table tbody tr td a.action-item:first-child");
559 $this->click("css=#memberSearch table tbody tr td a.action-item:first-child");
6a488035
TO
560 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
561
562 //View Membership Record
563 $verifyMembershipData = array(
564 'Member' => $name,
565 'Membership Type' => $membershipTypeTitle,
566 'Status' => 'New',
567 'End date' => $endDate,
568 );
569
570 foreach ($verifyMembershipData as $label => $value) {
571 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
572 preg_quote($value)
573 );
574 }
575
576 //logout
42daf119 577 $this->webtestLogout();
6a488035 578
f1224701 579 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom");
6a488035 580
b21dd815 581 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div/span/label/span[1][contains(text(),'$membershipTypeTitle')]");
6a488035
TO
582 $this->type("email-5", $email);
583 $this->click('is_for_organization');
584 $this->type('onbehalf_organization_name', $organisationName);
585 $this->type('onbehalf_phone-3-1', '2222-222222');
586 $this->type('onbehalf_email-3', $organisationName . '@example.com');
587 $this->type('onbehalf_street_address-3', '22A Excelsior Ave. Unit 1h');
588 $this->type('onbehalf_city-3', 'Driftwood');
589 $this->type('onbehalf_postal_code-3', '75653');
590 $this->select('onbehalf_country-3', "value=1228");
591 $this->select('onbehalf_state_province-3', "value=1061");
592
593 $this->type('first_name', $firstName);
594 $this->type('last_name', $lastName);
73072f84 595 $this->select("state_province-1", "value=1001");
6a488035
TO
596
597 //Credit Card Info
598 $this->select("credit_card_type", "value=Visa");
599 $this->select("credit_card_type", "label=Visa");
600 $this->type("credit_card_number", "4111111111111111");
601 $this->type("cvv2", "000");
602 $this->select("credit_card_exp_date[M]", "value=1");
603 $this->select("credit_card_exp_date[Y]", "value=2020");
604
605 //Billing Info
606 $this->type("billing_first_name", $firstName . "billing");
607 $this->type("billing_last_name", $lastName . "billing");
608 $this->type("billing_street_address-5", "15 Main St.");
609 $this->type(" billing_city-5", "San Jose");
610 $this->select("billing_country_id-5", "value=1228");
611 $this->select("billing_state_province_id-5", "value=1004");
612 $this->type("billing_postal_code-5", "94129");
613
225a8648 614 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
6a488035
TO
615
616 $this->click("_qf_Confirm_next-bottom");
617 $this->waitForPageToLoad($this->getTimeoutMsec());
618
619 // Log in using webtestLogin() method
6a488035
TO
620 $this->webtestLogin();
621
622 //Find member
623 $endDate = date('F jS, Y', strtotime(" +2 year -1 day"));
42daf119 624 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
6a488035
TO
625
626 $this->type("sort_name", "$organisationName");
f1224701 627 $this->click("xpath=//tr/td[1]/p/label[contains(text(),'Membership is a Test?')]/../label[contains(text(),'Yes')]/preceding-sibling::input[1]");
4dc8abb7
WA
628 $this->clickLink("_qf_Search_refresh", 'css=#memberSearch table tbody tr td a.action-item:first-child');
629 $this->click('css=#memberSearch table tbody tr td a.action-item:first-child');
6a488035
TO
630 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
631
632 //View Membership Record
633 $verifyMembershipData = array(
634 'Member' => $organisationName,
635 'Membership Type' => $membershipTypeTitle,
636 'End date' => $endDate,
637 );
638
639 foreach ($verifyMembershipData as $label => $value) {
640 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
641 preg_quote($value)
642 );
643 }
644
42daf119 645 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
6a488035
TO
646
647 $this->type("sort_name", "$lastName, $firstName");
f1224701 648 $this->click("xpath=//tr/td[1]/p/label[contains(text(),'Membership is a Test?')]/../label[contains(text(),'Yes')]/preceding-sibling::input[1]");
4dc8abb7
WA
649 $this->clickLink("_qf_Search_refresh", 'css=#memberSearch table tbody tr td a.action-item:first-child');
650 $this->click('css=#memberSearch table tbody tr td a.action-item:first-child');
6a488035
TO
651 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
652
653 //View Membership Record
654 $verifyMembershipData = array(
655 'Member' => $name,
656 'Membership Type' => $membershipTypeTitle,
657 'End date' => $endDate,
658 );
659
660 foreach ($verifyMembershipData as $label => $value) {
661 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
662 preg_quote($value)
663 );
664 }
665 }
96025800 666
aeebbf4b 667 /**
668 * CRM-16165
669 */
0b181bcb 670 public function testOnRecurringContributionAndMembershipRenewal() {
671 // Log in as admin
672 $this->webtestLogin('admin');
673
674 $this->enableComponents('CiviMember');
675
676 // Log in as normal user
677 $this->webtestLogin();
678
679 // Add membership Type
680 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
681
682 $this->click('link=Add Membership Type');
683 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
684
685 $title = substr(sha1(rand()), 0, 7);
686 $membershipTypeTitle = "Membership Type $title";
687 $this->type('name', "Membership Type $title");
c543dff8 688 $this->waitForAjaxContent();
0b181bcb 689 $this->select2('member_of_contact_id', 'Default Organization');
690
691 $this->type('minimum_fee', '100');
692 $this->select('financial_type_id', 'value=2');
693 $this->type('duration_interval', 1);
694 $this->select('duration_unit', 'label=year');
695 $this->select('period_type', 'value=rolling');
696 $this->click('CIVICRM_QFID_1_auto_renew');
697
698 $this->click('_qf_MembershipType_upload-bottom');
699 $this->waitForElementPresent('link=Add Membership Type');
700 $this->waitForText('crm-notification-container', "The membership type 'Membership Type $title' has been saved.");
701
702 $this->waitForElementPresent("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$membershipTypeTitle}']/../../td[12]/span/a[3][text()='Delete']/@href");
703 $url = $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$membershipTypeTitle}']/../../td[12]/span/a[3][text()='Delete']/@href");
704 $matches = array();
705 preg_match('/id=([0-9]+)/', $url, $matches);
706 $membershipTypeId = $matches[1];
707
708 // Use default payment processor
709 $processorName = 'Test Processor';
710
711 // create contribution page with randomized title and default params
712 $hash = substr(sha1(rand()), 0, 7);
713 $rand = 2 * rand(2, 50);
714 $amountSection = FALSE;
715 $payLater = FALSE;
716 $onBehalf = FALSE;
717 $pledges = FALSE;
718 $recurring = FALSE;
719 $memberships = FALSE;
720 $memPriceSetId = NULL;
721 $friend = FALSE;
722 $profilePreId = NULL;
723 $profilePostId = NULL;
724 $premiums = FALSE;
725 $widget = FALSE;
726 $pcp = FALSE;
727
728 $contributionTitle = "Title $hash";
729 $pageId = $this->webtestAddContributionPage($hash,
730 $rand,
731 $contributionTitle,
732 array($processorName => 'Dummy'),
733 $amountSection,
734 $payLater,
735 $onBehalf,
736 $pledges,
737 $recurring,
738 $memberships,
739 $memPriceSetId,
740 $friend,
741 $profilePreId,
742 $profilePostId,
743 $premiums,
744 $widget,
745 $pcp,
746 TRUE
747 );
748
749 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_next');
750
751 //this contribution page for membership signup
752 $xpath = "xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]";
753 $this->waitForText('css=.crm-contribution-contributionpage-amount-form-block-payment_processor', $processorName);
754 $this->check($xpath);
755
756 //enable contribution amaount
757 $this->click('amount_block_is_active');
758 $this->waitForElementPresent('amount_label');
759 $this->type('amount_label', 'Additional Contribution');
760 $this->click('is_allow_other_amount');
761 $this->type('min_amount', '10');
762 $this->type('max_amount', '1000');
763
764 // save
765 $this->waitForElementPresent('_qf_Amount_submit_savenext');
766 $this->click('_qf_Amount_submit_savenext');
767 $this->waitForPageToLoad();
768
769 //enable membership block
770 $this->waitForElementPresent("member_is_active");
771 $this->check("member_is_active");
772 $this->waitForElementPresent("new_title");
773 $this->type('new_title', 'Membership Levels');
774 $this->type('membership_type_label', 'Membership Levels');
775 $this->check("membership_type_$membershipTypeId");
776 $this->check("is_required");
777 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
778
779 //Scenario 1(a) - (is_separate_payment=FALSE + recurring contribution + non-renewal membership) on Amount page
780 $this->click('link=Amounts');
781 $this->waitForElementPresent("is_recur");
782 $this->click('is_recur');
783 $this->clickLink('_qf_Amount_next', '_qf_Amount_next-bottom');
784 $this->waitForElementPresent("is_recur");
785 $this->assertTrue($this->isTextPresent("You need to enable Separate Membership Payment when online contribution page is configured for both Membership and Recurring Contribution."));
786
787 //Scenario 1(b) - (is_separate_payment=FALSE + recurring contribution + non-renewal membership) on MembershipBlock page
788 $this->click('link=Memberships');
789 $this->waitForElementPresent("is_separate_payment");
790 $this->click('is_separate_payment');//enable is_separate_payment
791 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
792 $this->click('link=Amounts');//switch back to amount page
793 $this->waitForElementPresent("is_recur");
794 $this->click('is_recur');//enable recurring contribution
795 $this->clickLink('_qf_Amount_next', '_qf_Amount_next-bottom');
796 $this->click('link=Memberships');//switch back to MembershipBlock page
797 $this->waitForElementPresent("is_separate_payment");
798 $this->uncheck('is_separate_payment');//disable is_separate_payment
799 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
800 $this->waitForElementPresent("is_separate_payment");
801 $this->assertTrue($this->isTextPresent("You need to enable Separate Membership Payment when online contribution page is configured for both Membership and Recurring Contribution"));
802
803 //Scenario 2(a) - (is_separate_payment=TRUE + recurring contribution + auto-renewal membership) on MembershipBlock page
804 $this->click('is_separate_payment');//enable is_separate_payment
805 $this->select("auto_renew_$membershipTypeId", 'value=1');//choose auto-renew as optional
806 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
807 $this->assertTrue($this->isTextPresent("You cannot enable both Recurring Contributions and Auto-renew memberships on the same online contribution page"));
808
809 //Scenario 2(b) - (is_separate_payment=TRUE + recurring contribution + auto-renewal membership) on Amount page
810 $this->click('link=Amounts');//switch back to amount page
811 $this->waitForElementPresent("is_recur");
812 $this->uncheck('is_recur');//disable recurring contribution
813 $this->clickLink('_qf_Amount_next', '_qf_Amount_next-bottom');
814 $this->click('link=Memberships');//switch back to MembershipBlock page
815 $this->waitForElementPresent("auto_renew_$membershipTypeId");
816 $this->select("auto_renew_$membershipTypeId", 'value=1');//choose auto-renew as optional
817 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
818 $this->click('link=Amounts');//switch back to amount page
819 $this->waitForElementPresent("is_recur");
820 $this->click('is_recur');//enable recurring contribution
821 $this->clickLink('_qf_Amount_next', '_qf_Amount_next-bottom');
822 $this->waitForElementPresent("is_recur");
823 $this->assertTrue($this->isTextPresent("You cannot enable both Recurring Contributions and Auto-renew memberships on the same online contribution page"));
824
825 //Scenario 3 - Online Registration on
826 // (is_separate_payment=TRUE + non-recurring Additional contribution + auto-renewal membership) setting
827 $firstName = 'Eia' . substr(sha1(rand()), 0, 4);
828 $lastName = 'Ande' . substr(sha1(rand()), 0, 4);
829 $email = $firstName . '@test.com';
830
f1224701 831 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom");
0b181bcb 832
833 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div/span/label/span[1][contains(text(),'$membershipTypeTitle')]");
834 $this->waitForElementPresent("auto_renew");
835 $this->type("xpath=//div[@class='content other_amount-content']/input[@type='text']", '20');
836 $this->click("auto_renew");
837
838 //fill email
839 $this->type('email-5', $email);
840
841 //Credit Card Info
842 $this->select("credit_card_type", "value=Visa");
843 $this->select("credit_card_type", "label=Visa");
844 $this->type("credit_card_number", "4111111111111111");
845 $this->type("cvv2", "000");
846 $this->select("credit_card_exp_date[M]", "value=1");
847 $this->select("credit_card_exp_date[Y]", "value=2020");
848
849 //Billing Info
850 $this->type("billing_first_name", $firstName . "billing");
851 $this->type("billing_last_name", $lastName . "billing");
852 $this->type("billing_street_address-5", "15 Main St.");
853 $this->type(" billing_city-5", "San Jose");
854 $this->select("billing_country_id-5", "value=1228");
855 $this->select("billing_state_province_id-5", "value=1004");
856 $this->type("billing_postal_code-5", "94129");
857
858 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
859 $this->assertTrue($this->isTextPresent("I want this membership to be renewed automatically every 1 year(s)."));
860 $this->click("_qf_Confirm_next-bottom");
861 $this->waitForPageToLoad($this->getTimeoutMsec());
862
863 $expectedParams = array(
864 'Pending' => array(
865 'total_amount' => 100.00),
866 'Completed' => array(
867 'total_amount' => 20.00,
868 ),
869 );
870
871 //Assert that additional contribution and auto-renewal membrship
872 $membership = $this->webtest_civicrm_api("Membership", "get", array('membership_type_id' => $membershipTypeId));
873 $this->assertEquals($membership['count'], 1);
874 $membershipId = $membership['id'];
875 $this->assertEquals($membership['values'][$membershipId]['membership_name'], $membershipTypeTitle);
d0426425
SB
876 //CRM-16165: if membership contribution status is pending then membership status should be pending
877 $pendingStatus = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', 'Pending', 'id', 'name');
878 $this->assertEquals($membership['values'][$membershipId]['status_id'], $pendingStatus);
0b181bcb 879
880 //check if the membership created is set to reccuring
881 $recurringContributionId = $membership['values'][$membershipId]['contribution_recur_id'];
882 $recurringContribution = $this->webtest_civicrm_api("ContributionRecur", "get", array('id' => $recurringContributionId));
883 $this->assertEquals($recurringContribution['count'], 1);
884 $this->assertEquals($recurringContribution['values'][$recurringContributionId]['auto_renew'], 1);
885 $this->assertEquals($recurringContribution['values'][$recurringContributionId]['frequency_unit'], 'year');
886 $this->assertEquals($recurringContribution['values'][$recurringContributionId]['frequency_interval'], 1);
887
888 $results = $this->webtest_civicrm_api("Contribution", "get", array('source' => array('LIKE' => "%$contributionTitle%")));
889 foreach ($results['values'] as $value) {
890 $status = $value['contribution_status'];
891 $this->assertEquals($value['total_amount'], $expectedParams[$status]['total_amount']);
892 $this->webtest_civicrm_api("Contribution", "delete", array('id' => $value['contribution_id']));
893 }
894
895 //Cleanup data before trying next combination
896 $this->webtest_civicrm_api("Membership", "delete", array('id' => $membershipId));
897 $this->webtest_civicrm_api("ContributionRecur", "delete", array('id' => $recurringContributionId));
898
899 //Scenario 4 - Online Registration on
900 // (is_separate_payment=TRUE + recurring Additional contribution + non auto-renewal membership) setting
901 $this->openCiviPage("admin/contribute/membership", "reset=1&action=update&id=$pageId");
902 $this->waitForElementPresent("auto_renew_$membershipTypeId");
903 $this->select("auto_renew_$membershipTypeId", 'value=0');
904 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
905 $this->click('link=Amounts');//switch back to amount page
906 $this->waitForElementPresent("is_recur");
907 $this->click('is_recur');//disable recurring contribution
908 $this->clickLink('_qf_Amount_next', '_qf_Amount_next-bottom');
909
f1224701 910 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom");
0b181bcb 911 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div/span/label/span[1][contains(text(),'$membershipTypeTitle')]");
912 $this->type("xpath=//div[@class='content other_amount-content']/input[@type='text']", '30');
913 $this->click("is_recur");
914
915 //Credit Card Info
916 $this->select("credit_card_type", "value=Visa");
917 $this->select("credit_card_type", "label=Visa");
918 $this->type("credit_card_number", "4111111111111111");
919 $this->type("cvv2", "000");
920 $this->select("credit_card_exp_date[M]", "value=1");
921 $this->select("credit_card_exp_date[Y]", "value=2020");
922
923 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
924 $this->assertTrue($this->isTextPresent("I want to contribute this amount every month."));
925 $this->click("_qf_Confirm_next-bottom");
0b181bcb 926 $this->waitForPageToLoad($this->getTimeoutMsec());
927
928 $expectedParams = array(
929 'Pending' => array(
930 'total_amount' => 30.00),
931 'Completed' => array(
932 'total_amount' => 100.00,
933 ),
934 );
935
936 //Assert that additional contribution and auto-renewal membrship
937 $membership = $this->webtest_civicrm_api("Membership", "get", array('membership_type_id' => $membershipTypeId));
938 $this->assertEquals($membership['count'], 1);
939 $membershipId = $membership['id'];
940 $this->assertEquals($membership['values'][$membershipId]['membership_name'], $membershipTypeTitle);
941 $this->assertEquals($membership['values'][$membershipId]['status_id'], 1);
942 $this->assertEquals($membership['values'][$membershipId]['source'], "Online Contribution: $contributionTitle");
943
944 $results = $this->webtest_civicrm_api("Contribution", "get", array('source' => array('LIKE' => "%$contributionTitle%")));
945 foreach ($results['values'] as $value) {
946 $status = $value['contribution_status'];
947 $this->assertEquals($value['total_amount'], $expectedParams[$status]['total_amount']);
948 if ($status == 'Pending') {
949 $recurringContributionId = $value['contribution_recur_id'];
950 $recurringContribution = $this->webtest_civicrm_api("ContributionRecur", "get", array('id' => $recurringContributionId));
951 $this->assertEquals($recurringContribution['count'], 1);
952 $this->assertEquals($recurringContribution['values'][$recurringContributionId]['frequency_unit'], 'month');
953 $this->assertEquals($recurringContribution['values'][$recurringContributionId]['frequency_interval'], 1);
954 }
955 $this->webtest_civicrm_api("Contribution", "delete", array('id' => $value['contribution_id']));
956 }
957 }
958
6a488035 959}