3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
30 * Class WebTest_Member_OnlineMembershipRenewTest
32 class WebTest_Member_OnlineMembershipRenewTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
39 * FIXME: This test tries to update a contribution page (id=2) that may not exist :(
41 public function testOnlineMembershipRenew() {
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);
46 // Log in using webtestLogin() method
47 $this->webtestLogin();
49 // Use default payment processor
50 $processorName = 'Test Processor';
51 $this->webtestAddPaymentProcessor($processorName);
53 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=2", "_qf_Amount_next");
54 // this contribution page for membership signup
55 // select newly created processor
56 $xpath = "xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]";
57 $this->waitForText('css=.crm-contribution-contributionpage-amount-form-block-payment_processor', $processorName);
61 $this->waitForElementPresent("_qf_Amount_next");
62 $this->clickLink('_qf_Amount_next');
64 // go to Membership block
65 $this->click('css=#tab_membership a');
66 $this->waitForElementPresent("member_is_active");
67 $this->check("member_is_active");
69 $this->waitForElementPresent("new_title");
71 if ($this->isElementPresent("member_price_set_id")) {
72 $this->waitForElementPresent("member_price_set_id");
74 $this->select("member_price_set_id", "label=- none -");
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");
84 $this->click('css=#tab_custom a');
87 $this->waitForElementPresent('custom_pre_id');
88 $this->select('css=tr.crm-contribution-contributionpage-custom-form-block-custom_pre_id span.crm-profile-selector-select select', 'value=1');
91 $this->click('_qf_Custom_upload_done');
92 $this->waitForPageToLoad();
94 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
95 $lastName = 'An' . substr(sha1(rand()), 0, 7);
96 $email = $firstName . "@example.com";
99 $this->webtestLogout();
101 //Go to online membership signup page
102 $this->openCiviPage("contribute/transact", "reset=1&id=2", "_qf_Main_upload-bottom");
104 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div[2]/span/label/span[1][contains(text(),'Student')]");
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);
110 $this->select("state_province-1", "value=1001");
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");
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");
129 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
131 $this->click("_qf_Confirm_next-bottom");
133 // Log in using webtestLogin() method
134 $this->webtestLogin();
136 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
138 $this->type("sort_name", "$lastName $firstName");
139 $this->clickLink("_qf_Search_refresh", 'css=#memberSearch table tbody tr td span a.action-item:first-child');
140 $this->click('css=#memberSearch table tbody tr td span a.action-item:first-child');
141 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
143 //View Membership Record
144 $verifyMembershipData = array(
145 'Member' => $firstName . ' ' . $lastName,
146 'Membership Type' => 'Student',
148 'Source' => 'Online Contribution: Member Signup and Renewal',
150 foreach ($verifyMembershipData as $label => $value) {
151 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
157 $this->webtestLogout();
159 $this->openCiviPage("contribute/transact", "reset=1&id=2", "_qf_Main_upload-bottom");
161 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div[2]/span/label/span[1][contains(text(),'Student')]");
163 //Type first name and last name and email
164 $this->type("first_name", $firstName);
165 $this->type("last_name", $lastName);
166 $this->type("email-5", $email);
167 $this->select("state_province-1", "value=1001");
170 $this->select("credit_card_type", "value=Visa");
171 $this->select("credit_card_type", "label=Visa");
172 $this->type("credit_card_number", "4111111111111111");
173 $this->type("cvv2", "000");
174 $this->select("credit_card_exp_date[M]", "value=1");
175 $this->select("credit_card_exp_date[Y]", "value=2020");
178 $this->type("billing_first_name", $firstName . "billing");
179 $this->type("billing_last_name", $lastName . "billing");
180 $this->type("billing_street_address-5", "15 Main St.");
181 $this->type(" billing_city-5", "San Jose");
182 $this->select("billing_country_id-5", "value=1228");
183 $this->select("billing_state_province_id-5", "value=1004");
184 $this->type("billing_postal_code-5", "94129");
186 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
187 $this->click("_qf_Confirm_next-bottom");
189 $this->webtestLogin();
191 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
193 $this->type("sort_name", "$lastName $firstName");
194 $this->clickLink("_qf_Search_refresh", 'css=#memberSearch table tbody tr td span a.action-item:first-child');
195 $this->click('css=#memberSearch table tbody tr td span a.action-item:first-child');
196 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
198 //View Membership Record
199 $verifyMembershipData = array(
200 'Member' => $firstName . ' ' . $lastName,
201 'Membership Type' => 'Student',
203 'Source' => 'Online Contribution: Member Signup and Renewal',
205 foreach ($verifyMembershipData as $label => $value) {
206 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
213 * FIXME: This test tries to update a contribution page (id=2) that may not exist :(
215 public function testOnlineMembershipRenewChangeType() {
216 // a random 7-char string and an even number to make this pass unique
217 $hash = substr(sha1(rand()), 0, 7);
218 $rand = 2 * rand(2, 50);
220 // Log in using webtestLogin() method
221 $this->webtestLogin();
223 // Use default payment processor
224 $processorName = 'Test Processor';
225 $this->webtestAddPaymentProcessor($processorName);
227 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=2", '_qf_Amount_next');
229 //this contribution page for membership signup
230 $xpath = "xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]";
231 $this->waitForText('css=.crm-contribution-contributionpage-amount-form-block-payment_processor', $processorName);
232 $this->check($xpath);
235 $this->waitForElementPresent('_qf_Amount_next');
236 $this->click('_qf_Amount_next');
237 $this->waitForPageToLoad();
239 // go to Membership block
240 $this->click('css=#tab_membership a');
241 $this->waitForElementPresent("member_is_active");
242 $this->check("member_is_active");
244 $this->waitForElementPresent("new_title");
245 if ($this->isElementPresent("member_price_set_id")) {
246 $this->waitForElementPresent("member_price_set_id");
248 $this->select("member_price_set_id", "label=- none -");
251 $this->waitForElementPresent("membership_type-block");
252 $this->check("xpath=//tr[@id='membership_type-block']/td[2]/table/tbody/tr/td/label[text()='General']/../input[2]");
253 $this->check("xpath=//tr[@id='membership_type-block']/td[2]/table/tbody/tr/td/label[text()='Student']/../input[2]");
254 $this->click("_qf_MembershipBlock_next-bottom");
255 $this->waitForTextPresent("'MembershipBlock' information has been saved");
258 $this->click('css=#tab_custom a');
261 $this->waitForElementPresent('custom_pre_id');
262 $this->select('css=tr.crm-contribution-contributionpage-custom-form-block-custom_pre_id span.crm-profile-selector-select select', 'value=1');
265 $this->click('_qf_Custom_upload_done');
266 $this->waitForPageToLoad();
268 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
269 $lastName = 'An' . substr(sha1(rand()), 0, 7);
271 //Go to online membership signup page
272 $this->openCiviPage("contribute/transact", "reset=1&id=2", "_qf_Main_upload-bottom");
273 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div[1]/span/label/span[1][contains(text(),'General')]");
274 //Type first name and last name
275 $this->type("first_name", $firstName);
276 $this->type("last_name", $lastName);
278 $this->select("state_province-1", "value=1001");
280 $this->select("credit_card_type", "value=Visa");
281 $this->select("credit_card_type", "label=Visa");
282 $this->type("credit_card_number", "4111111111111111");
283 $this->type("cvv2", "000");
284 $this->select("credit_card_exp_date[M]", "value=1");
285 $this->select("credit_card_exp_date[Y]", "value=2020");
288 $this->type("billing_first_name", $firstName . "billing");
289 $this->type("billing_last_name", $lastName . "billing");
290 $this->type("billing_street_address-5", "15 Main St.");
291 $this->type(" billing_city-5", "San Jose");
292 $this->select("billing_country_id-5", "value=1228");
293 $this->select("billing_state_province_id-5", "value=1004");
294 $this->type("billing_postal_code-5", "94129");
296 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
298 $this->click("_qf_Confirm_next-bottom");
301 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
303 $this->type("sort_name", "$lastName $firstName");
304 $this->clickLink("_qf_Search_refresh", 'css=#memberSearch table tbody tr td span a.action-item:first-child');
305 $this->click('css=#memberSearch table tbody tr td span a.action-item:first-child');
306 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
308 $membershipCreatedId = $this->urlArg('id');
310 $memberSince = date('F jS, Y');
312 //View Membership Record
313 $verifyMembershipData = array(
314 'Member' => $firstName . ' ' . $lastName,
315 'Membership Type' => 'General',
317 'Source' => 'Online Contribution: Member Signup and Renewal',
319 foreach ($verifyMembershipData as $label => $value) {
320 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
324 $this->openCiviPage("contribute/transact", "reset=1&id=2", "_qf_Main_upload-bottom");
325 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div[2]/span/label/span[1][contains(text(),'Student')]");
328 $this->select("credit_card_type", "value=Visa");
329 $this->select("credit_card_type", "label=Visa");
330 $this->type("credit_card_number", "4111111111111111");
331 $this->type("cvv2", "000");
332 $this->select("credit_card_exp_date[M]", "value=1");
333 $this->select("credit_card_exp_date[Y]", "value=2020");
334 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
335 $this->click("_qf_Confirm_next-bottom");
338 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
340 $this->type("sort_name", "$lastName $firstName");
341 $this->clickLink("_qf_Search_refresh", 'css=#memberSearch table tbody tr td span a.action-item:first-child');
342 $this->click('css=#memberSearch table tbody tr td span a.action-item:first-child');
343 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
345 $membershipRenewedId = $this->urlArg('id');
347 //View Membership Record
348 $verifyMembershipData = array(
349 'Member' => $firstName . ' ' . $lastName,
350 'Membership Type' => 'Student',
352 'Source' => 'Online Contribution: Member Signup and Renewal',
353 'Member Since' => $memberSince,
355 foreach ($verifyMembershipData as $label => $value) {
356 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
360 $this->assertEquals($membershipCreatedId, $membershipRenewedId);
363 public function testUpdateInheritedMembershipOnBehalfOfRenewal() {
365 $this->webtestLogin('admin');
367 $this->enableComponents('CiviMember');
369 //check for online contribution and profile listings permissions
370 $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms");
371 $this->changePermissions($permissions);
373 // Log in as normal user
374 $this->webtestLogin();
376 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
378 $title = substr(sha1(rand()), 0, 7);
379 $this->type('organization_name', "Organization $title");
380 $this->type('email_1_email', "$title@org.com");
381 $this->click('_qf_Contact_upload_view');
382 $this->waitForPageToLoad($this->getTimeoutMsec());
384 $this->waitForText('crm-notification-container', "Organization $title has been created.");
386 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
388 $this->click('link=Add Membership Type');
389 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
391 $membershipTypeTitle = "Membership Type $title";
392 $this->type('name', "Membership Type $title");
394 $this->select2('member_of_contact_id', $title);
396 $this->type('minimum_fee', '100');
397 $this->select('financial_type_id', 'value=2');
398 $this->type('duration_interval', 1);
399 $this->select('duration_unit', 'label=year');
400 $this->select('period_type', 'value=rolling');
402 $this->select2('relationship_type_id', 'Employer of', TRUE);
404 $this->click('_qf_MembershipType_upload-bottom');
405 $this->waitForElementPresent('link=Add Membership Type');
406 $this->waitForText('crm-notification-container', "The membership type 'Membership Type $title' has been saved.");
408 $this->waitForElementPresent("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$membershipTypeTitle}']/../../td[12]/span/a[3][text()='Delete']/@href");
409 $url = $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$membershipTypeTitle}']/../../td[12]/span/a[3][text()='Delete']/@href");
411 preg_match('/id=([0-9]+)/', $url, $matches);
412 $membershipTypeId = $matches[1];
414 // Use default payment processor
415 $processorName = 'Test Processor';
417 // create contribution page with randomized title and default params
418 $hash = substr(sha1(rand()), 0, 7);
419 $rand = 2 * rand(2, 50);
420 $amountSection = FALSE;
425 $memberships = FALSE;
426 $memPriceSetId = NULL;
429 $profilePostId = NULL;
434 $contributionTitle = "Title $hash";
435 $pageId = $this->webtestAddContributionPage($hash,
438 array($processorName => 'Dummy'),
455 $hash = substr(sha1(rand()), 0, 7);
456 $this->openCiviPage("admin/contribute/settings", "reset=1&action=update&id=$pageId");
458 $this->click('link=Title');
459 $this->waitForElementPresent('_qf_Settings_cancel-bottom');
460 $this->click('is_organization');
461 $this->select("xpath=//input[@id='onbehalf_profile_id']/parent::td/div/div/span/select", "value=9");
462 $this->type('for_organization', "On behalf $hash");
463 $this->click('_qf_Settings_next-bottom');
464 $this->waitForPageToLoad($this->getTimeoutMsec());
466 $this->click('link=Memberships');
467 $this->waitForElementPresent('_qf_MembershipBlock_cancel-bottom');
468 $this->click('member_is_active');
469 $this->type('new_title', "Title - New Membership $hash");
470 $this->type('renewal_title', "Title - Renewals $hash");
471 $this->click("membership_type_{$membershipTypeId}");
472 $this->click('is_required');
473 $this->click('_qf_MembershipBlock_next-bottom');
474 $this->waitForPageToLoad($this->getTimeoutMsec());
477 $this->webtestLogout();
479 //get Url for Live Contribution Page
480 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", '_qf_Main_upload-bottom');
481 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div/span/label/span[1][contains(text(),'$membershipTypeTitle')]");
482 $firstName = 'Eia' . substr(sha1(rand()), 0, 4);
483 $lastName = 'Ande' . substr(sha1(rand()), 0, 4);
484 $name = $firstName . ' ' . $lastName;
485 $organisationName = 'TestOrg' . substr(sha1(rand()), 0, 7);
487 $email = $firstName . '@example.com';
488 $this->type('email-5', $email);
489 $this->click('is_for_organization');
490 $this->type('onbehalf_organization_name', $organisationName);
491 $this->type('onbehalf_phone-3-1', '2222-222222');
492 $this->type('onbehalf_email-3', $organisationName . '@example.com');
493 $this->type('onbehalf_street_address-3', '54A Excelsior Ave. Apt 1C');
494 $this->type('onbehalf_city-3', 'Driftwood');
495 $this->type('onbehalf_postal_code-3', '75653');
496 $this->select('onbehalf_country-3', "value=1228");
497 $this->select('onbehalf_state_province-3', "value=1061");
499 $this->type('first_name', $firstName);
500 $this->type('last_name', $lastName);
501 $this->select("state_province-1", "value=1001");
504 $this->select("credit_card_type", "value=Visa");
505 $this->select("credit_card_type", "label=Visa");
506 $this->type("credit_card_number", "4111111111111111");
507 $this->type("cvv2", "000");
508 $this->select("credit_card_exp_date[M]", "value=1");
509 $this->select("credit_card_exp_date[Y]", "value=2020");
512 $this->type("billing_first_name", $firstName . "billing");
513 $this->type("billing_last_name", $lastName . "billing");
514 $this->type("billing_street_address-5", "15 Main St.");
515 $this->type(" billing_city-5", "San Jose");
516 $this->select("billing_country_id-5", "value=1228");
517 $this->select("billing_state_province_id-5", "value=1004");
518 $this->type("billing_postal_code-5", "94129");
519 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
521 $this->click("_qf_Confirm_next-bottom");
522 $this->waitForPageToLoad($this->getTimeoutMsec());
524 // Log in using webtestLogin() method
525 $this->webtestLogin();
528 $endDate = date('F jS, Y', strtotime(" +1 year -1 day"));
529 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
531 $this->type("sort_name", "$organisationName");
532 $this->clickLink("_qf_Search_refresh", 'css=#memberSearch table tbody tr td span a.action-item:first-child');
533 $this->click('css=#memberSearch table tbody tr td span a.action-item:first-child');
534 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
536 //View Membership Record
537 $verifyMembershipData = array(
538 'Member' => $organisationName,
539 'Membership Type' => $membershipTypeTitle,
541 'End date' => $endDate,
544 foreach ($verifyMembershipData as $label => $value) {
545 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
550 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
552 $this->type("sort_name", "$lastName, $firstName");
553 $this->clickLink("_qf_Search_refresh", 'css=#memberSearch table tbody tr td span a.action-item:first-child');
554 $this->click('css=#memberSearch table tbody tr td span a.action-item:first-child');
555 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
557 //View Membership Record
558 $verifyMembershipData = array(
560 'Membership Type' => $membershipTypeTitle,
562 'End date' => $endDate,
565 foreach ($verifyMembershipData as $label => $value) {
566 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
572 $this->webtestLogout();
574 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
576 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div/span/label/span[1][contains(text(),'$membershipTypeTitle')]");
577 $this->type("email-5", $email);
578 $this->click('is_for_organization');
579 $this->type('onbehalf_organization_name', $organisationName);
580 $this->type('onbehalf_phone-3-1', '2222-222222');
581 $this->type('onbehalf_email-3', $organisationName . '@example.com');
582 $this->type('onbehalf_street_address-3', '22A Excelsior Ave. Unit 1h');
583 $this->type('onbehalf_city-3', 'Driftwood');
584 $this->type('onbehalf_postal_code-3', '75653');
585 $this->select('onbehalf_country-3', "value=1228");
586 $this->select('onbehalf_state_province-3', "value=1061");
588 $this->type('first_name', $firstName);
589 $this->type('last_name', $lastName);
590 $this->select("state_province-1", "value=1001");
593 $this->select("credit_card_type", "value=Visa");
594 $this->select("credit_card_type", "label=Visa");
595 $this->type("credit_card_number", "4111111111111111");
596 $this->type("cvv2", "000");
597 $this->select("credit_card_exp_date[M]", "value=1");
598 $this->select("credit_card_exp_date[Y]", "value=2020");
601 $this->type("billing_first_name", $firstName . "billing");
602 $this->type("billing_last_name", $lastName . "billing");
603 $this->type("billing_street_address-5", "15 Main St.");
604 $this->type(" billing_city-5", "San Jose");
605 $this->select("billing_country_id-5", "value=1228");
606 $this->select("billing_state_province_id-5", "value=1004");
607 $this->type("billing_postal_code-5", "94129");
609 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
611 $this->click("_qf_Confirm_next-bottom");
612 $this->waitForPageToLoad($this->getTimeoutMsec());
614 // Log in using webtestLogin() method
615 $this->webtestLogin();
618 $endDate = date('F jS, Y', strtotime(" +2 year -1 day"));
619 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
621 $this->type("sort_name", "$organisationName");
622 $this->clickLink("_qf_Search_refresh", 'css=#memberSearch table tbody tr td span a.action-item:first-child');
623 $this->click('css=#memberSearch table tbody tr td span a.action-item:first-child');
624 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
626 //View Membership Record
627 $verifyMembershipData = array(
628 'Member' => $organisationName,
629 'Membership Type' => $membershipTypeTitle,
630 'End date' => $endDate,
633 foreach ($verifyMembershipData as $label => $value) {
634 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
639 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
641 $this->type("sort_name", "$lastName, $firstName");
642 $this->clickLink("_qf_Search_refresh", 'css=#memberSearch table tbody tr td span a.action-item:first-child');
643 $this->click('css=#memberSearch table tbody tr td span a.action-item:first-child');
644 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
646 //View Membership Record
647 $verifyMembershipData = array(
649 'Membership Type' => $membershipTypeTitle,
650 'End date' => $endDate,
653 foreach ($verifyMembershipData as $label => $value) {
654 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
663 public function testOnRecurringContributionAndMembershipRenewal() {
665 $this->webtestLogin('admin');
667 $this->enableComponents('CiviMember');
669 // Log in as normal user
670 $this->webtestLogin();
672 // Add membership Type
673 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
675 $this->click('link=Add Membership Type');
676 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
678 $title = substr(sha1(rand()), 0, 7);
679 $membershipTypeTitle = "Membership Type $title";
680 $this->type('name', "Membership Type $title");
682 $this->select2('member_of_contact_id', 'Default Organization');
684 $this->type('minimum_fee', '100');
685 $this->select('financial_type_id', 'value=2');
686 $this->type('duration_interval', 1);
687 $this->select('duration_unit', 'label=year');
688 $this->select('period_type', 'value=rolling');
689 $this->click('CIVICRM_QFID_1_auto_renew');
691 $this->click('_qf_MembershipType_upload-bottom');
692 $this->waitForElementPresent('link=Add Membership Type');
693 $this->waitForText('crm-notification-container', "The membership type 'Membership Type $title' has been saved.");
695 $this->waitForElementPresent("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$membershipTypeTitle}']/../../td[12]/span/a[3][text()='Delete']/@href");
696 $url = $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$membershipTypeTitle}']/../../td[12]/span/a[3][text()='Delete']/@href");
698 preg_match('/id=([0-9]+)/', $url, $matches);
699 $membershipTypeId = $matches[1];
701 // Use default payment processor
702 $processorName = 'Test Processor';
704 // create contribution page with randomized title and default params
705 $hash = substr(sha1(rand()), 0, 7);
706 $rand = 2 * rand(2, 50);
707 $amountSection = FALSE;
712 $memberships = FALSE;
713 $memPriceSetId = NULL;
715 $profilePreId = NULL;
716 $profilePostId = NULL;
721 $contributionTitle = "Title $hash";
722 $pageId = $this->webtestAddContributionPage($hash,
725 array($processorName => 'Dummy'),
742 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_next');
744 //this contribution page for membership signup
745 $xpath = "xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]";
746 $this->waitForText('css=.crm-contribution-contributionpage-amount-form-block-payment_processor', $processorName);
747 $this->check($xpath);
749 //enable contribution amaount
750 $this->click('amount_block_is_active');
751 $this->waitForElementPresent('amount_label');
752 $this->type('amount_label', 'Additional Contribution');
753 $this->click('is_allow_other_amount');
754 $this->type('min_amount', '10');
755 $this->type('max_amount', '1000');
758 $this->waitForElementPresent('_qf_Amount_submit_savenext');
759 $this->click('_qf_Amount_submit_savenext');
760 $this->waitForPageToLoad();
762 //enable membership block
763 $this->waitForElementPresent("member_is_active");
764 $this->check("member_is_active");
765 $this->waitForElementPresent("new_title");
766 $this->type('new_title', 'Membership Levels');
767 $this->type('membership_type_label', 'Membership Levels');
768 $this->check("membership_type_$membershipTypeId");
769 $this->check("is_required");
770 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
772 //Scenario 1(a) - (is_separate_payment=FALSE + recurring contribution + non-renewal membership) on Amount page
773 $this->click('link=Amounts');
774 $this->waitForElementPresent("is_recur");
775 $this->click('is_recur');
776 $this->clickLink('_qf_Amount_next', '_qf_Amount_next-bottom');
777 $this->waitForElementPresent("is_recur");
778 $this->assertTrue($this->isTextPresent("You need to enable Separate Membership Payment when online contribution page is configured for both Membership and Recurring Contribution."));
780 //Scenario 1(b) - (is_separate_payment=FALSE + recurring contribution + non-renewal membership) on MembershipBlock page
781 $this->click('link=Memberships');
782 $this->waitForElementPresent("is_separate_payment");
783 $this->click('is_separate_payment');//enable is_separate_payment
784 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
785 $this->click('link=Amounts');//switch back to amount page
786 $this->waitForElementPresent("is_recur");
787 $this->click('is_recur');//enable recurring contribution
788 $this->clickLink('_qf_Amount_next', '_qf_Amount_next-bottom');
789 $this->click('link=Memberships');//switch back to MembershipBlock page
790 $this->waitForElementPresent("is_separate_payment");
791 $this->uncheck('is_separate_payment');//disable is_separate_payment
792 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
793 $this->waitForElementPresent("is_separate_payment");
794 $this->assertTrue($this->isTextPresent("You need to enable Separate Membership Payment when online contribution page is configured for both Membership and Recurring Contribution"));
796 //Scenario 2(a) - (is_separate_payment=TRUE + recurring contribution + auto-renewal membership) on MembershipBlock page
797 $this->click('is_separate_payment');//enable is_separate_payment
798 $this->select("auto_renew_$membershipTypeId", 'value=1');//choose auto-renew as optional
799 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
800 $this->assertTrue($this->isTextPresent("You cannot enable both Recurring Contributions and Auto-renew memberships on the same online contribution page"));
802 //Scenario 2(b) - (is_separate_payment=TRUE + recurring contribution + auto-renewal membership) on Amount page
803 $this->click('link=Amounts');//switch back to amount page
804 $this->waitForElementPresent("is_recur");
805 $this->uncheck('is_recur');//disable recurring contribution
806 $this->clickLink('_qf_Amount_next', '_qf_Amount_next-bottom');
807 $this->click('link=Memberships');//switch back to MembershipBlock page
808 $this->waitForElementPresent("auto_renew_$membershipTypeId");
809 $this->select("auto_renew_$membershipTypeId", 'value=1');//choose auto-renew as optional
810 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
811 $this->click('link=Amounts');//switch back to amount page
812 $this->waitForElementPresent("is_recur");
813 $this->click('is_recur');//enable recurring contribution
814 $this->clickLink('_qf_Amount_next', '_qf_Amount_next-bottom');
815 $this->waitForElementPresent("is_recur");
816 $this->assertTrue($this->isTextPresent("You cannot enable both Recurring Contributions and Auto-renew memberships on the same online contribution page"));
818 //Scenario 3 - Online Registration on
819 // (is_separate_payment=TRUE + non-recurring Additional contribution + auto-renewal membership) setting
820 $firstName = 'Eia' . substr(sha1(rand()), 0, 4);
821 $lastName = 'Ande' . substr(sha1(rand()), 0, 4);
822 $email = $firstName . '@test.com';
824 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
826 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div/span/label/span[1][contains(text(),'$membershipTypeTitle')]");
827 $this->waitForElementPresent("auto_renew");
828 $this->type("xpath=//div[@class='content other_amount-content']/input[@type='text']", '20');
829 $this->click("auto_renew");
832 $this->type('email-5', $email);
835 $this->select("credit_card_type", "value=Visa");
836 $this->select("credit_card_type", "label=Visa");
837 $this->type("credit_card_number", "4111111111111111");
838 $this->type("cvv2", "000");
839 $this->select("credit_card_exp_date[M]", "value=1");
840 $this->select("credit_card_exp_date[Y]", "value=2020");
843 $this->type("billing_first_name", $firstName . "billing");
844 $this->type("billing_last_name", $lastName . "billing");
845 $this->type("billing_street_address-5", "15 Main St.");
846 $this->type(" billing_city-5", "San Jose");
847 $this->select("billing_country_id-5", "value=1228");
848 $this->select("billing_state_province_id-5", "value=1004");
849 $this->type("billing_postal_code-5", "94129");
851 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
852 $this->assertTrue($this->isTextPresent("I want this membership to be renewed automatically every 1 year(s)."));
853 $this->click("_qf_Confirm_next-bottom");
854 $this->waitForPageToLoad($this->getTimeoutMsec());
856 $expectedParams = array(
858 'total_amount' => 100.00),
859 'Completed' => array(
860 'total_amount' => 20.00,
864 //Assert that additional contribution and auto-renewal membrship
865 $membership = $this->webtest_civicrm_api("Membership", "get", array('membership_type_id' => $membershipTypeId));
866 $this->assertEquals($membership['count'], 1);
867 $membershipId = $membership['id'];
868 $this->assertEquals($membership['values'][$membershipId]['membership_name'], $membershipTypeTitle);
869 //CRM-16165: if membership contribution status is pending then membership status should be pending
870 $pendingStatus = CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_MembershipStatus', 'Pending', 'id', 'name');
871 $this->assertEquals($membership['values'][$membershipId]['status_id'], $pendingStatus);
873 //check if the membership created is set to reccuring
874 $recurringContributionId = $membership['values'][$membershipId]['contribution_recur_id'];
875 $recurringContribution = $this->webtest_civicrm_api("ContributionRecur", "get", array('id' => $recurringContributionId));
876 $this->assertEquals($recurringContribution['count'], 1);
877 $this->assertEquals($recurringContribution['values'][$recurringContributionId]['auto_renew'], 1);
878 $this->assertEquals($recurringContribution['values'][$recurringContributionId]['frequency_unit'], 'year');
879 $this->assertEquals($recurringContribution['values'][$recurringContributionId]['frequency_interval'], 1);
881 $results = $this->webtest_civicrm_api("Contribution", "get", array('source' => array('LIKE' => "%$contributionTitle%")));
882 foreach ($results['values'] as $value) {
883 $status = $value['contribution_status'];
884 $this->assertEquals($value['total_amount'], $expectedParams[$status]['total_amount']);
885 $this->webtest_civicrm_api("Contribution", "delete", array('id' => $value['contribution_id']));
888 //Cleanup data before trying next combination
889 $this->webtest_civicrm_api("Membership", "delete", array('id' => $membershipId));
890 $this->webtest_civicrm_api("ContributionRecur", "delete", array('id' => $recurringContributionId));
892 //Scenario 4 - Online Registration on
893 // (is_separate_payment=TRUE + recurring Additional contribution + non auto-renewal membership) setting
894 $this->openCiviPage("admin/contribute/membership", "reset=1&action=update&id=$pageId");
895 $this->waitForElementPresent("auto_renew_$membershipTypeId");
896 $this->select("auto_renew_$membershipTypeId", 'value=0');
897 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
898 $this->click('link=Amounts');//switch back to amount page
899 $this->waitForElementPresent("is_recur");
900 $this->click('is_recur');//disable recurring contribution
901 $this->clickLink('_qf_Amount_next', '_qf_Amount_next-bottom');
903 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
904 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div/span/label/span[1][contains(text(),'$membershipTypeTitle')]");
905 $this->type("xpath=//div[@class='content other_amount-content']/input[@type='text']", '30');
906 $this->click("is_recur");
909 $this->select("credit_card_type", "value=Visa");
910 $this->select("credit_card_type", "label=Visa");
911 $this->type("credit_card_number", "4111111111111111");
912 $this->type("cvv2", "000");
913 $this->select("credit_card_exp_date[M]", "value=1");
914 $this->select("credit_card_exp_date[Y]", "value=2020");
916 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
917 $this->assertTrue($this->isTextPresent("I want to contribute this amount every month."));
918 $this->click("_qf_Confirm_next-bottom");
920 $this->waitForPageToLoad($this->getTimeoutMsec());
922 $expectedParams = array(
924 'total_amount' => 30.00),
925 'Completed' => array(
926 'total_amount' => 100.00,
930 //Assert that additional contribution and auto-renewal membrship
931 $membership = $this->webtest_civicrm_api("Membership", "get", array('membership_type_id' => $membershipTypeId));
932 $this->assertEquals($membership['count'], 1);
933 $membershipId = $membership['id'];
934 $this->assertEquals($membership['values'][$membershipId]['membership_name'], $membershipTypeTitle);
935 $this->assertEquals($membership['values'][$membershipId]['status_id'], 1);
936 $this->assertEquals($membership['values'][$membershipId]['source'], "Online Contribution: $contributionTitle");
938 $results = $this->webtest_civicrm_api("Contribution", "get", array('source' => array('LIKE' => "%$contributionTitle%")));
939 foreach ($results['values'] as $value) {
940 $status = $value['contribution_status'];
941 $this->assertEquals($value['total_amount'], $expectedParams[$status]['total_amount']);
942 if ($status == 'Pending') {
943 $recurringContributionId = $value['contribution_recur_id'];
944 $recurringContribution = $this->webtest_civicrm_api("ContributionRecur", "get", array('id' => $recurringContributionId));
945 $this->assertEquals($recurringContribution['count'], 1);
946 $this->assertEquals($recurringContribution['values'][$recurringContributionId]['frequency_unit'], 'month');
947 $this->assertEquals($recurringContribution['values'][$recurringContributionId]['frequency_interval'], 1);
949 $this->webtest_civicrm_api("Contribution", "delete", array('id' => $value['contribution_id']));