3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
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&action=preview", "_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->click("xpath=//tr/td[1]/p/label[contains(text(),'Membership is a Test?')]/../label[contains(text(),'Yes')]/preceding-sibling::input[1]");
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');
142 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
144 //View Membership Record
145 $verifyMembershipData = array(
146 'Member' => $firstName . ' ' . $lastName,
147 'Membership Type' => 'Student',
149 'Source' => 'Online Contribution: Member Signup and Renewal',
151 foreach ($verifyMembershipData as $label => $value) {
152 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
158 $this->webtestLogout();
160 $this->openCiviPage("contribute/transact", "reset=1&id=2&action=preview", "_qf_Main_upload-bottom");
162 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div[2]/span/label/span[1][contains(text(),'Student')]");
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);
168 $this->select("state_province-1", "value=1001");
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");
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");
187 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
188 $this->click("_qf_Confirm_next-bottom");
190 $this->webtestLogin();
192 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
194 $this->type("sort_name", "$lastName $firstName");
195 $this->click("xpath=//tr/td[1]/p/label[contains(text(),'Membership is a Test?')]/../label[contains(text(),'Yes')]/preceding-sibling::input[1]");
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');
198 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
200 //View Membership Record
201 $verifyMembershipData = array(
202 'Member' => $firstName . ' ' . $lastName,
203 'Membership Type' => 'Student',
205 'Source' => 'Online Contribution: Member Signup and Renewal',
207 foreach ($verifyMembershipData as $label => $value) {
208 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
215 * FIXME: This test tries to update a contribution page (id=2) that may not exist :(
217 public function testOnlineMembershipRenewChangeType() {
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);
222 // Log in using webtestLogin() method
223 $this->webtestLogin();
225 // Use default payment processor
226 $processorName = 'Test Processor';
227 $this->webtestAddPaymentProcessor($processorName);
229 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=2", '_qf_Amount_next');
231 //this contribution page for membership signup
232 $xpath = "xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]";
233 $this->waitForText('css=.crm-contribution-contributionpage-amount-form-block-payment_processor', $processorName);
234 $this->check($xpath);
237 $this->waitForElementPresent('_qf_Amount_next');
238 $this->click('_qf_Amount_next');
239 $this->waitForPageToLoad();
241 // go to Membership block
242 $this->click('css=#tab_membership a');
243 $this->waitForElementPresent("member_is_active");
244 $this->check("member_is_active");
246 $this->waitForElementPresent("new_title");
247 if ($this->isElementPresent("member_price_set_id")) {
248 $this->waitForElementPresent("member_price_set_id");
250 $this->select("member_price_set_id", "label=- none -");
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");
260 $this->click('css=#tab_custom a');
263 $this->waitForElementPresent('custom_pre_id');
264 $this->select('css=tr.crm-contribution-contributionpage-custom-form-block-custom_pre_id span.crm-profile-selector-select select', 'value=1');
267 $this->click('_qf_Custom_upload_done');
268 $this->waitForPageToLoad();
270 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
271 $lastName = 'An' . substr(sha1(rand()), 0, 7);
273 //Go to online membership signup page
274 $this->openCiviPage("contribute/transact", "reset=1&id=2&action=preview", "_qf_Main_upload-bottom");
275 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div[1]/span/label/span[1][contains(text(),'General')]");
276 //Type first name and last name
277 $this->type("first_name", $firstName);
278 $this->type("last_name", $lastName);
280 $this->select("state_province-1", "value=1001");
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");
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");
298 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
300 $this->click("_qf_Confirm_next-bottom");
303 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
305 $this->type("sort_name", "$lastName $firstName");
306 $this->click("xpath=//tr/td[1]/p/label[contains(text(),'Membership is a Test?')]/../label[contains(text(),'Yes')]/preceding-sibling::input[1]");
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');
309 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
311 $membershipCreatedId = $this->urlArg('id');
313 $memberSince = date('F jS, Y');
315 //View Membership Record
316 $verifyMembershipData = array(
317 'Member' => $firstName . ' ' . $lastName,
318 'Membership Type' => 'General',
320 'Source' => 'Online Contribution: Member Signup and Renewal',
322 foreach ($verifyMembershipData as $label => $value) {
323 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
327 $this->openCiviPage("contribute/transact", "reset=1&id=2&action=preview", "_qf_Main_upload-bottom");
328 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div[2]/span/label/span[1][contains(text(),'Student')]");
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");
337 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
338 $this->click("_qf_Confirm_next-bottom");
341 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
343 $this->type("sort_name", "$lastName $firstName");
344 $this->click("xpath=//tr/td[1]/p/label[contains(text(),'Membership is a Test?')]/../label[contains(text(),'Yes')]/preceding-sibling::input[1]");
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');
347 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
349 $membershipRenewedId = $this->urlArg('id');
351 //View Membership Record
352 $verifyMembershipData = array(
353 'Member' => $firstName . ' ' . $lastName,
354 'Membership Type' => 'Student',
356 'Source' => 'Online Contribution: Member Signup and Renewal',
357 'Member Since' => $memberSince,
359 foreach ($verifyMembershipData as $label => $value) {
360 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
364 $this->assertEquals($membershipCreatedId, $membershipRenewedId);
367 public function testUpdateInheritedMembershipOnBehalfOfRenewal() {
369 $this->webtestLogin('admin');
371 $this->enableComponents('CiviMember');
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);
377 // Log in as normal user
378 $this->webtestLogin();
380 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
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());
388 $this->waitForText('crm-notification-container', "Organization $title has been created.");
390 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
392 $this->click('link=Add Membership Type');
393 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
395 $membershipTypeTitle = "Membership Type $title";
396 $this->type('name', "Membership Type $title");
398 $this->select2('member_of_contact_id', $title);
400 $this->type('minimum_fee', '100');
401 $this->select('financial_type_id', 'value=2');
402 $this->type('duration_interval', 1);
403 $this->select('duration_unit', 'label=year');
404 $this->select('period_type', 'value=rolling');
406 $this->removeSelection('relationship_type_id', 'label=- select -');
407 $this->addSelection('relationship_type_id', 'label=Employer of');
409 $this->click('_qf_MembershipType_upload-bottom');
410 $this->waitForElementPresent('link=Add Membership Type');
411 $this->waitForText('crm-notification-container', "The membership type 'Membership Type $title' has been saved.");
413 $this->waitForElementPresent("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$membershipTypeTitle}']/../../td[12]/span/a[3][text()='Delete']/@href");
414 $url = $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$membershipTypeTitle}']/../../td[12]/span/a[3][text()='Delete']/@href");
416 preg_match('/id=([0-9]+)/', $url, $matches);
417 $membershipTypeId = $matches[1];
419 // Use default payment processor
420 $processorName = 'Test Processor';
422 // create contribution page with randomized title and default params
423 $hash = substr(sha1(rand()), 0, 7);
424 $rand = 2 * rand(2, 50);
425 $amountSection = FALSE;
430 $memberships = FALSE;
431 $memPriceSetId = NULL;
434 $profilePostId = NULL;
439 $contributionTitle = "Title $hash";
440 $pageId = $this->webtestAddContributionPage($hash,
443 array($processorName => 'Dummy'),
460 $hash = substr(sha1(rand()), 0, 7);
461 $this->openCiviPage("admin/contribute/settings", "reset=1&action=update&id=$pageId");
463 $this->click('link=Title');
464 $this->waitForElementPresent('_qf_Settings_cancel-bottom');
465 $this->click('is_organization');
466 $this->select("xpath=//input[@id='onbehalf_profile_id']/parent::td/div/div/span/select", "value=9");
467 $this->type('for_organization', "On behalf $hash");
468 $this->click('_qf_Settings_next-bottom');
469 $this->waitForPageToLoad($this->getTimeoutMsec());
471 $this->click('link=Memberships');
472 $this->waitForElementPresent('_qf_MembershipBlock_cancel-bottom');
473 $this->click('member_is_active');
474 $this->type('new_title', "Title - New Membership $hash");
475 $this->type('renewal_title', "Title - Renewals $hash");
476 $this->click("membership_type_{$membershipTypeId}");
477 $this->click('is_required');
478 $this->click('_qf_MembershipBlock_next-bottom');
479 $this->waitForPageToLoad($this->getTimeoutMsec());
482 $this->webtestLogout();
484 //get Url for Live Contribution Page
485 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", '_qf_Main_upload-bottom');
486 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div/span/label/span[1][contains(text(),'$membershipTypeTitle')]");
487 $firstName = 'Eia' . substr(sha1(rand()), 0, 4);
488 $lastName = 'Ande' . substr(sha1(rand()), 0, 4);
489 $name = $firstName . ' ' . $lastName;
490 $organisationName = 'TestOrg' . substr(sha1(rand()), 0, 7);
492 $email = $firstName . '@example.com';
493 $this->type('email-5', $email);
494 $this->click('is_for_organization');
495 $this->type('onbehalf_organization_name', $organisationName);
496 $this->type('onbehalf_phone-3-1', '2222-222222');
497 $this->type('onbehalf_email-3', $organisationName . '@example.com');
498 $this->type('onbehalf_street_address-3', '54A Excelsior Ave. Apt 1C');
499 $this->type('onbehalf_city-3', 'Driftwood');
500 $this->type('onbehalf_postal_code-3', '75653');
501 $this->select('onbehalf_country-3', "value=1228");
502 $this->select('onbehalf_state_province-3', "value=1061");
504 $this->type('first_name', $firstName);
505 $this->type('last_name', $lastName);
506 $this->select("state_province-1", "value=1001");
509 $this->select("credit_card_type", "value=Visa");
510 $this->select("credit_card_type", "label=Visa");
511 $this->type("credit_card_number", "4111111111111111");
512 $this->type("cvv2", "000");
513 $this->select("credit_card_exp_date[M]", "value=1");
514 $this->select("credit_card_exp_date[Y]", "value=2020");
517 $this->type("billing_first_name", $firstName . "billing");
518 $this->type("billing_last_name", $lastName . "billing");
519 $this->type("billing_street_address-5", "15 Main St.");
520 $this->type(" billing_city-5", "San Jose");
521 $this->select("billing_country_id-5", "value=1228");
522 $this->select("billing_state_province_id-5", "value=1004");
523 $this->type("billing_postal_code-5", "94129");
524 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
526 $this->click("_qf_Confirm_next-bottom");
527 $this->waitForPageToLoad($this->getTimeoutMsec());
529 // Log in using webtestLogin() method
530 $this->webtestLogin();
533 $endDate = date('F jS, Y', strtotime(" +1 year -1 day"));
534 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
536 $this->type("sort_name", "$organisationName");
537 $this->click("xpath=//tr/td[1]/p/label[contains(text(),'Membership is a Test?')]/../label[contains(text(),'Yes')]/preceding-sibling::input[1]");
538 $this->clickLink("_qf_Search_refresh", 'css=#memberSearch table tbody tr td span a.action-item:first-child');
539 $this->click('css=#memberSearch table tbody tr td span a.action-item:first-child');
540 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
542 //View Membership Record
543 $verifyMembershipData = array(
544 'Member' => $organisationName,
545 'Membership Type' => $membershipTypeTitle,
547 'End date' => $endDate,
550 foreach ($verifyMembershipData as $label => $value) {
551 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
556 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
558 $this->type("sort_name", "$lastName, $firstName");
559 $this->click("xpath=//tr/td[1]/p/label[contains(text(),'Membership is a Test?')]/../label[contains(text(),'Yes')]/preceding-sibling::input[1]");
560 $this->clickLink("_qf_Search_refresh", 'css=#memberSearch table tbody tr td span a.action-item:first-child');
561 $this->click('css=#memberSearch table tbody tr td span a.action-item:first-child');
562 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
564 //View Membership Record
565 $verifyMembershipData = array(
567 'Membership Type' => $membershipTypeTitle,
569 'End date' => $endDate,
572 foreach ($verifyMembershipData as $label => $value) {
573 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
579 $this->webtestLogout();
581 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom");
583 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div/span/label/span[1][contains(text(),'$membershipTypeTitle')]");
584 $this->type("email-5", $email);
585 $this->click('is_for_organization');
586 $this->type('onbehalf_organization_name', $organisationName);
587 $this->type('onbehalf_phone-3-1', '2222-222222');
588 $this->type('onbehalf_email-3', $organisationName . '@example.com');
589 $this->type('onbehalf_street_address-3', '22A Excelsior Ave. Unit 1h');
590 $this->type('onbehalf_city-3', 'Driftwood');
591 $this->type('onbehalf_postal_code-3', '75653');
592 $this->select('onbehalf_country-3', "value=1228");
593 $this->select('onbehalf_state_province-3', "value=1061");
595 $this->type('first_name', $firstName);
596 $this->type('last_name', $lastName);
597 $this->select("state_province-1", "value=1001");
600 $this->select("credit_card_type", "value=Visa");
601 $this->select("credit_card_type", "label=Visa");
602 $this->type("credit_card_number", "4111111111111111");
603 $this->type("cvv2", "000");
604 $this->select("credit_card_exp_date[M]", "value=1");
605 $this->select("credit_card_exp_date[Y]", "value=2020");
608 $this->type("billing_first_name", $firstName . "billing");
609 $this->type("billing_last_name", $lastName . "billing");
610 $this->type("billing_street_address-5", "15 Main St.");
611 $this->type(" billing_city-5", "San Jose");
612 $this->select("billing_country_id-5", "value=1228");
613 $this->select("billing_state_province_id-5", "value=1004");
614 $this->type("billing_postal_code-5", "94129");
616 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
618 $this->click("_qf_Confirm_next-bottom");
619 $this->waitForPageToLoad($this->getTimeoutMsec());
621 // Log in using webtestLogin() method
622 $this->webtestLogin();
625 $endDate = date('F jS, Y', strtotime(" +2 year -1 day"));
626 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
628 $this->type("sort_name", "$organisationName");
629 $this->click("xpath=//tr/td[1]/p/label[contains(text(),'Membership is a Test?')]/../label[contains(text(),'Yes')]/preceding-sibling::input[1]");
630 $this->clickLink("_qf_Search_refresh", 'css=#memberSearch table tbody tr td span a.action-item:first-child');
631 $this->click('css=#memberSearch table tbody tr td span a.action-item:first-child');
632 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
634 //View Membership Record
635 $verifyMembershipData = array(
636 'Member' => $organisationName,
637 'Membership Type' => $membershipTypeTitle,
638 'End date' => $endDate,
641 foreach ($verifyMembershipData as $label => $value) {
642 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
647 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
649 $this->type("sort_name", "$lastName, $firstName");
650 $this->click("xpath=//tr/td[1]/p/label[contains(text(),'Membership is a Test?')]/../label[contains(text(),'Yes')]/preceding-sibling::input[1]");
651 $this->clickLink("_qf_Search_refresh", 'css=#memberSearch table tbody tr td span a.action-item:first-child');
652 $this->click('css=#memberSearch table tbody tr td span a.action-item:first-child');
653 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
655 //View Membership Record
656 $verifyMembershipData = array(
658 'Membership Type' => $membershipTypeTitle,
659 'End date' => $endDate,
662 foreach ($verifyMembershipData as $label => $value) {
663 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
672 public function testOnRecurringContributionAndMembershipRenewal() {
674 $this->webtestLogin('admin');
676 $this->enableComponents('CiviMember');
678 // Log in as normal user
679 $this->webtestLogin();
681 // Add membership Type
682 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
684 $this->click('link=Add Membership Type');
685 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
687 $title = substr(sha1(rand()), 0, 7);
688 $membershipTypeTitle = "Membership Type $title";
689 $this->type('name', "Membership Type $title");
691 $this->select2('member_of_contact_id', 'Default Organization');
693 $this->type('minimum_fee', '100');
694 $this->select('financial_type_id', 'value=2');
695 $this->type('duration_interval', 1);
696 $this->select('duration_unit', 'label=year');
697 $this->select('period_type', 'value=rolling');
698 $this->click('CIVICRM_QFID_1_auto_renew');
700 $this->click('_qf_MembershipType_upload-bottom');
701 $this->waitForElementPresent('link=Add Membership Type');
702 $this->waitForText('crm-notification-container', "The membership type 'Membership Type $title' has been saved.");
704 $this->waitForElementPresent("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$membershipTypeTitle}']/../../td[12]/span/a[3][text()='Delete']/@href");
705 $url = $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$membershipTypeTitle}']/../../td[12]/span/a[3][text()='Delete']/@href");
707 preg_match('/id=([0-9]+)/', $url, $matches);
708 $membershipTypeId = $matches[1];
710 // Use default payment processor
711 $processorName = 'Test Processor';
713 // create contribution page with randomized title and default params
714 $hash = substr(sha1(rand()), 0, 7);
715 $rand = 2 * rand(2, 50);
716 $amountSection = FALSE;
721 $memberships = FALSE;
722 $memPriceSetId = NULL;
724 $profilePreId = NULL;
725 $profilePostId = NULL;
730 $contributionTitle = "Title $hash";
731 $pageId = $this->webtestAddContributionPage($hash,
734 array($processorName => 'Dummy'),
751 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_next');
753 //this contribution page for membership signup
754 $xpath = "xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]";
755 $this->waitForText('css=.crm-contribution-contributionpage-amount-form-block-payment_processor', $processorName);
756 $this->check($xpath);
758 //enable contribution amaount
759 $this->click('amount_block_is_active');
760 $this->waitForElementPresent('amount_label');
761 $this->type('amount_label', 'Additional Contribution');
762 $this->click('is_allow_other_amount');
763 $this->type('min_amount', '10');
764 $this->type('max_amount', '1000');
767 $this->waitForElementPresent('_qf_Amount_submit_savenext');
768 $this->click('_qf_Amount_submit_savenext');
769 $this->waitForPageToLoad();
771 //enable membership block
772 $this->waitForElementPresent("member_is_active");
773 $this->check("member_is_active");
774 $this->waitForElementPresent("new_title");
775 $this->type('new_title', 'Membership Levels');
776 $this->type('membership_type_label', 'Membership Levels');
777 $this->check("membership_type_$membershipTypeId");
778 $this->check("is_required");
779 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
781 //Scenario 1(a) - (is_separate_payment=FALSE + recurring contribution + non-renewal membership) on Amount page
782 $this->click('link=Amounts');
783 $this->waitForElementPresent("is_recur");
784 $this->click('is_recur');
785 $this->clickLink('_qf_Amount_next', '_qf_Amount_next-bottom');
786 $this->waitForElementPresent("is_recur");
787 $this->assertTrue($this->isTextPresent("You need to enable Separate Membership Payment when online contribution page is configured for both Membership and Recurring Contribution."));
789 //Scenario 1(b) - (is_separate_payment=FALSE + recurring contribution + non-renewal membership) on MembershipBlock page
790 $this->click('link=Memberships');
791 $this->waitForElementPresent("is_separate_payment");
792 $this->click('is_separate_payment');//enable is_separate_payment
793 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
794 $this->click('link=Amounts');//switch back to amount page
795 $this->waitForElementPresent("is_recur");
796 $this->click('is_recur');//enable recurring contribution
797 $this->clickLink('_qf_Amount_next', '_qf_Amount_next-bottom');
798 $this->click('link=Memberships');//switch back to MembershipBlock page
799 $this->waitForElementPresent("is_separate_payment");
800 $this->uncheck('is_separate_payment');//disable is_separate_payment
801 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
802 $this->waitForElementPresent("is_separate_payment");
803 $this->assertTrue($this->isTextPresent("You need to enable Separate Membership Payment when online contribution page is configured for both Membership and Recurring Contribution"));
805 //Scenario 2(a) - (is_separate_payment=TRUE + recurring contribution + auto-renewal membership) on MembershipBlock page
806 $this->click('is_separate_payment');//enable is_separate_payment
807 $this->select("auto_renew_$membershipTypeId", 'value=1');//choose auto-renew as optional
808 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
809 $this->assertTrue($this->isTextPresent("You cannot enable both Recurring Contributions and Auto-renew memberships on the same online contribution page"));
811 //Scenario 2(b) - (is_separate_payment=TRUE + recurring contribution + auto-renewal membership) on Amount page
812 $this->click('link=Amounts');//switch back to amount page
813 $this->waitForElementPresent("is_recur");
814 $this->uncheck('is_recur');//disable recurring contribution
815 $this->clickLink('_qf_Amount_next', '_qf_Amount_next-bottom');
816 $this->click('link=Memberships');//switch back to MembershipBlock page
817 $this->waitForElementPresent("auto_renew_$membershipTypeId");
818 $this->select("auto_renew_$membershipTypeId", 'value=1');//choose auto-renew as optional
819 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
820 $this->click('link=Amounts');//switch back to amount page
821 $this->waitForElementPresent("is_recur");
822 $this->click('is_recur');//enable recurring contribution
823 $this->clickLink('_qf_Amount_next', '_qf_Amount_next-bottom');
824 $this->waitForElementPresent("is_recur");
825 $this->assertTrue($this->isTextPresent("You cannot enable both Recurring Contributions and Auto-renew memberships on the same online contribution page"));
827 //Scenario 3 - Online Registration on
828 // (is_separate_payment=TRUE + non-recurring Additional contribution + auto-renewal membership) setting
829 $firstName = 'Eia' . substr(sha1(rand()), 0, 4);
830 $lastName = 'Ande' . substr(sha1(rand()), 0, 4);
831 $email = $firstName . '@test.com';
833 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom");
835 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div/span/label/span[1][contains(text(),'$membershipTypeTitle')]");
836 $this->waitForElementPresent("auto_renew");
837 $this->type("xpath=//div[@class='content other_amount-content']/input[@type='text']", '20');
838 $this->click("auto_renew");
841 $this->type('email-5', $email);
844 $this->select("credit_card_type", "value=Visa");
845 $this->select("credit_card_type", "label=Visa");
846 $this->type("credit_card_number", "4111111111111111");
847 $this->type("cvv2", "000");
848 $this->select("credit_card_exp_date[M]", "value=1");
849 $this->select("credit_card_exp_date[Y]", "value=2020");
852 $this->type("billing_first_name", $firstName . "billing");
853 $this->type("billing_last_name", $lastName . "billing");
854 $this->type("billing_street_address-5", "15 Main St.");
855 $this->type(" billing_city-5", "San Jose");
856 $this->select("billing_country_id-5", "value=1228");
857 $this->select("billing_state_province_id-5", "value=1004");
858 $this->type("billing_postal_code-5", "94129");
860 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
861 $this->assertTrue($this->isTextPresent("I want this membership to be renewed automatically every 1 year(s)."));
862 $this->click("_qf_Confirm_next-bottom");
863 $this->waitForPageToLoad($this->getTimeoutMsec());
865 $expectedParams = array(
867 'total_amount' => 100.00),
868 'Completed' => array(
869 'total_amount' => 20.00,
873 //Assert that additional contribution and auto-renewal membrship
874 $membership = $this->webtest_civicrm_api("Membership", "get", array('membership_type_id' => $membershipTypeId));
875 $this->assertEquals($membership['count'], 1);
876 $membershipId = $membership['id'];
877 $this->assertEquals($membership['values'][$membershipId]['membership_name'], $membershipTypeTitle);
878 //CRM-16165: if membership contribution status is pending then membership status should be pending
879 $pendingStatus = CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_MembershipStatus', 'Pending', 'id', 'name');
880 $this->assertEquals($membership['values'][$membershipId]['status_id'], $pendingStatus);
882 //check if the membership created is set to reccuring
883 $recurringContributionId = $membership['values'][$membershipId]['contribution_recur_id'];
884 $recurringContribution = $this->webtest_civicrm_api("ContributionRecur", "get", array('id' => $recurringContributionId));
885 $this->assertEquals($recurringContribution['count'], 1);
886 $this->assertEquals($recurringContribution['values'][$recurringContributionId]['auto_renew'], 1);
887 $this->assertEquals($recurringContribution['values'][$recurringContributionId]['frequency_unit'], 'year');
888 $this->assertEquals($recurringContribution['values'][$recurringContributionId]['frequency_interval'], 1);
890 $results = $this->webtest_civicrm_api("Contribution", "get", array('source' => array('LIKE' => "%$contributionTitle%")));
891 foreach ($results['values'] as $value) {
892 $status = $value['contribution_status'];
893 $this->assertEquals($value['total_amount'], $expectedParams[$status]['total_amount']);
894 $this->webtest_civicrm_api("Contribution", "delete", array('id' => $value['contribution_id']));
897 //Cleanup data before trying next combination
898 $this->webtest_civicrm_api("Membership", "delete", array('id' => $membershipId));
899 $this->webtest_civicrm_api("ContributionRecur", "delete", array('id' => $recurringContributionId));
901 //Scenario 4 - Online Registration on
902 // (is_separate_payment=TRUE + recurring Additional contribution + non auto-renewal membership) setting
903 $this->openCiviPage("admin/contribute/membership", "reset=1&action=update&id=$pageId");
904 $this->waitForElementPresent("auto_renew_$membershipTypeId");
905 $this->select("auto_renew_$membershipTypeId", 'value=0');
906 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
907 $this->click('link=Amounts');//switch back to amount page
908 $this->waitForElementPresent("is_recur");
909 $this->click('is_recur');//disable recurring contribution
910 $this->clickLink('_qf_Amount_next', '_qf_Amount_next-bottom');
912 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom");
913 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div/span/label/span[1][contains(text(),'$membershipTypeTitle')]");
914 $this->type("xpath=//div[@class='content other_amount-content']/input[@type='text']", '30');
915 $this->click("is_recur");
918 $this->select("credit_card_type", "value=Visa");
919 $this->select("credit_card_type", "label=Visa");
920 $this->type("credit_card_number", "4111111111111111");
921 $this->type("cvv2", "000");
922 $this->select("credit_card_exp_date[M]", "value=1");
923 $this->select("credit_card_exp_date[Y]", "value=2020");
925 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
926 $this->assertTrue($this->isTextPresent("I want to contribute this amount every month."));
927 $this->click("_qf_Confirm_next-bottom");
929 $this->waitForPageToLoad($this->getTimeoutMsec());
931 $expectedParams = array(
933 'total_amount' => 30.00),
934 'Completed' => array(
935 'total_amount' => 100.00,
939 //Assert that additional contribution and auto-renewal membrship
940 $membership = $this->webtest_civicrm_api("Membership", "get", array('membership_type_id' => $membershipTypeId));
941 $this->assertEquals($membership['count'], 1);
942 $membershipId = $membership['id'];
943 $this->assertEquals($membership['values'][$membershipId]['membership_name'], $membershipTypeTitle);
944 $this->assertEquals($membership['values'][$membershipId]['status_id'], 1);
945 $this->assertEquals($membership['values'][$membershipId]['source'], "Online Contribution: $contributionTitle");
947 $results = $this->webtest_civicrm_api("Contribution", "get", array('source' => array('LIKE' => "%$contributionTitle%")));
948 foreach ($results['values'] as $value) {
949 $status = $value['contribution_status'];
950 $this->assertEquals($value['total_amount'], $expectedParams[$status]['total_amount']);
951 if ($status == 'Pending') {
952 $recurringContributionId = $value['contribution_recur_id'];
953 $recurringContribution = $this->webtest_civicrm_api("ContributionRecur", "get", array('id' => $recurringContributionId));
954 $this->assertEquals($recurringContribution['count'], 1);
955 $this->assertEquals($recurringContribution['values'][$recurringContributionId]['frequency_unit'], 'month');
956 $this->assertEquals($recurringContribution['values'][$recurringContributionId]['frequency_interval'], 1);
958 $this->webtest_civicrm_api("Contribution", "delete", array('id' => $value['contribution_id']));