3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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_OnlineMembershipCreateTest
32 class WebTest_Member_OnlineMembershipCreateTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testOnlineMembershipCreate() {
39 //check for online contribution and profile listings permissions
40 $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms");
41 $this->changePermissions($permissions);
43 // Log in as normal user
44 $this->webtestLogin();
46 // a random 7-char string and an even number to make this pass unique
47 $hash = substr(sha1(rand()), 0, 7);
48 $rand = 2 * rand(2, 50);
50 // Use default payment processor
51 $processorName = 'Test Processor';
53 // create contribution page with randomized title and default params
54 $amountSection = TRUE;
56 $allowOtherAmount = FALSE;
61 $memPriceSetId = NULL;
64 $profilePostId = NULL;
68 $isSeparatePayment = TRUE;
69 $contributionTitle = "Title $hash";
70 $pageId = $this->webtestAddContributionPage($hash,
73 array($processorName => 'Dummy'),
94 // create two new membership types
95 $memTypeParams1 = $this->webtestAddMembershipType();
96 $memTypeTitle1 = $memTypeParams1['membership_type'];
97 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$memTypeTitle1}']/../../td[12]/span/a[3]@href"));
98 $memTypeId1 = $memTypeId1[1];
100 $memTypeParams2 = $this->webtestAddMembershipType();
101 $memTypeTitle2 = $memTypeParams2['membership_type'];
102 $memTypeId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$memTypeTitle2}']/../../td[12]/span/a[3]@href"));
103 $memTypeId2 = $memTypeId2[1];
105 // edit contribution page memberships tab to add two new membership types
106 $this->openCiviPage("admin/contribute/membership", "reset=1&action=update&id={$pageId}", '_qf_MembershipBlock_next-bottom');
107 $this->click("membership_type_$memTypeId1");
108 $this->click("membership_type_$memTypeId2");
109 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
110 $text = "'MembershipBlock' information has been saved.";
111 $this->waitForText('crm-notification-container', $text);
114 $this->webtestLogout();
116 // signup for membership 1
117 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
118 $lastName = 'An' . substr(sha1(rand()), 0, 7);
120 $this->_testOnlineMembershipSignup($pageId, $memTypeTitle1, $firstName, $lastName, $payLater, $hash);
122 // Log in using webtestLogin() method
123 $this->webtestLogin();
126 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
127 $this->click("xpath=//tr/td[1]/p/label[contains(text(),'Membership is a Test?')]/../label[contains(text(),'Yes')]/preceding-sibling::input[1]");
128 $this->type("sort_name", "$lastName $firstName");
129 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']/table/tbody/tr");
130 $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr/td[11]/span/a[text()='View']");
131 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
133 //View Membership Record
135 'Member' => $firstName . ' ' . $lastName,
136 'Membership Type' => $memTypeTitle1,
137 'Source' => 'Online Contribution:' . ' ' . $contributionTitle,
138 'Status' => 'Pending',
140 $this->webtestVerifyTabularData($verifyData);
142 // Click View action link on associated contribution record
143 $this->waitForElementPresent("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[1][text()='View']");
144 $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[1][text()='View']");
145 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
146 //View Contribution Record
148 'From' => $firstName . ' ' . $lastName,
149 'Total Amount' => '$ 100.00',
150 'Contribution Status' => 'Pending : Pay Later',
152 $this->webtestVerifyTabularData($verifyData);
154 //CRM-15735 - verify membership dates gets changed w.r.t receive_date of contribution.
155 $receiveDate = date('F jS, Y', strtotime("-1 month"));
156 $endDate = date('F jS, Y', strtotime("+1 year -1 month -1 day"));
157 $this->clickAjaxLink("xpath=//button//span[contains(text(),'Edit')]", 'receive_date');
158 $this->select('contribution_status_id', 'Completed');
159 $this->webtestFillDate('receive_date', '-1 month');
160 $this->clickAjaxLink("xpath=//button//span[contains(text(),'Save')]", "xpath=//div[@class='ui-dialog-buttonset']/button[3]/span[2]");
161 $updatedData = array(
163 'Member Since' => $receiveDate,
164 'Start date' => $receiveDate,
165 'End date' => $endDate,
167 $this->webtestVerifyTabularData($updatedData);
169 // CRM-8141 signup for membership 2 with same anonymous user info (should create 2 separate membership records because membership orgs are different)
171 $this->webtestLogout();
173 $this->_testOnlineMembershipSignup($pageId, $memTypeTitle2, $firstName, $lastName, $payLater, $hash);
175 // Log in using webtestLogin() method
176 $this->webtestLogin();
179 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
181 $this->type("sort_name", "$lastName $firstName");
182 $this->click("xpath=//tr/td[1]/p/label[contains(text(),'Membership is a Test?')]/../label[contains(text(),'Yes')]/preceding-sibling::input[1]");
183 $this->click("_qf_Search_refresh");
185 $this->waitForPageToLoad($this->getTimeoutMsec());
186 $this->assertElementContainsText('search-status', '2 Results', 'Missing text: ' . '2 Results');
190 * Test online membership signup.
193 * @param int $memTypeId
194 * @param string $firstName
195 * @param string $lastName
196 * @param bool $payLater
197 * @param string $hash
198 * @param bool $otherAmount
199 * @param bool $amountSection
200 * @param bool $freeMembership
202 public function _testOnlineMembershipSignup($pageId, $memTypeId, $firstName, $lastName, $payLater, $hash, $otherAmount = FALSE, $amountSection = TRUE, $freeMembership = FALSE, $onBehalf = FALSE, $onBehalfParams = array()) {
203 //Open Live Contribution Page
204 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom");
205 // Select membership type 1
206 $this->waitForElementPresent("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label");
207 if ($memTypeId != 'No thank you') {
208 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//div/span/label/span[1][contains(text(),'$memTypeId')]");
211 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label[contains(text(),'$memTypeId')]");
213 if (!$otherAmount && $amountSection) {
214 $this->click("xpath=//div[@class='crm-section contribution_amount-section']/div[2]//span/label[text()='No thank you']");
216 elseif ($amountSection) {
217 $this->clickAt("xpath=//div[@class='content other_amount-content']/input");
218 $this->keyDown("xpath=//div[@class='content other_amount-content']/input", " ");
219 $this->type("xpath=//div[@class='content other_amount-content']/input", $otherAmount);
220 $this->typeKeys("xpath=//div[@class='content other_amount-content']/input", $otherAmount);
223 $this->waitForAjaxContent();
224 $this->click("xpath=//label[text()='Pay later label {$hash}']");
226 if ($onBehalf && $onBehalfParams) {
227 if ($onBehalfParams['mode'] == 'optional') {
228 $this->click("is_for_organization");
230 $this->type("onbehalf[organization_name]", $onBehalfParams['org_name']);
231 $this->type("onbehalf[phone-3-1]", $onBehalfParams['org_phone']);
232 $this->type("onbehalf[email-3]", $onBehalfParams['org_email']);
233 $this->type("onbehalf[street_address-3]", "100 Main Street");
234 $this->type("onbehalf[city-3]", "San Francisco");
235 $this->type("onbehalf[postal_code-3]", $onBehalfParams['org_postal_code']);
236 $this->select("onbehalf[country-3]", "value=1228");
237 $this->select("onbehalf[state_province-3]", "value=1001");
239 $this->type("email-5", $firstName . "@example.com");
240 $this->waitForElementPresent("first_name");
241 $this->type("first_name", $firstName);
242 $this->waitForElementPresent("last_name");
243 $this->type("last_name", $lastName);
245 $streetAddress = "100 Main Street";
246 $this->waitForElementPresent("street_address-1");
247 $this->type("street_address-1", $streetAddress);
248 $this->type("city-1", "San Francisco");
249 $this->type("postal_code-1", "94117");
250 $this->select("country-1", "value=1228");
251 $this->select("state_province-1", "value=1001");
253 if ($freeMembership) {
254 $this->waitForElementPresent("xpath=//div[@id='payment_information'][@style='display: none;']");
257 if (!$payLater && $amountSection) {
258 $this->click("xpath=//label[text()='Test Processor']");
259 $this->waitForAjaxContent();
261 $this->select("credit_card_type", "value=Visa");
262 $this->type("credit_card_number", "4111111111111111");
263 $this->type("cvv2", "000");
264 $this->select("credit_card_exp_date[M]", "value=1");
265 $this->select("credit_card_exp_date[Y]", "value=2020");
268 $this->waitForElementPresent("billing_first_name");
269 $this->type("billing_first_name", $firstName . "billing");
270 $this->waitForElementPresent("billing_last_name");
271 $this->type("billing_last_name", $lastName . "billing");
272 $this->type("billing_street_address-5", "15 Main St.");
273 $this->type(" billing_city-5", "San Jose");
274 $this->select("billing_country_id-5", "value=1228");
275 $this->select("billing_state_province_id-5", "value=1004");
276 $this->type("billing_postal_code-5", "94129");
279 $this->click("_qf_Main_upload-bottom");
280 $this->waitForElementPresent("_qf_Confirm_next-bottom");
282 $this->click("_qf_Confirm_next-bottom");
283 $this->waitForPageToLoad($this->getTimeoutMsec());
286 public function testOnlineMembershipCreateWithContribution() {
287 //login with admin credentials & make sure we do have required permissions.
288 $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms");
289 $this->changePermissions($permissions);
291 $hash = substr(sha1(rand()), 0, 7);
292 $rand = 2 * rand(2, 50);
293 // Use default payment processor
294 $processorName = 'Test Processor';
295 $amountSection = TRUE;
297 $allowOtherAmount = TRUE;
302 $memPriceSetId = NULL;
305 $profilePostId = NULL;
309 $isSeparatePayment = FALSE;
310 $membershipsRequired = FALSE;
311 $fixedAmount = FALSE;
312 $contributionTitle = "Title $hash";
313 $pageId = $this->webtestAddContributionPage($hash,
316 array($processorName => 'Dummy'),
340 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
341 $lastName = 'An' . substr(sha1(rand()), 0, 7);
344 $this->webtestLogout();
346 $this->_testOnlineMembershipSignup($pageId, 'No thank you', $firstName, $lastName, FALSE, $hash, 50);
348 // Log in using webtestLogin() method
349 $this->webtestLogin();
352 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
354 $this->type("sort_name", "$lastName $firstName");
355 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
356 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[10]/span/a[text()='View']");
358 // assert financial data - CRM-17863
359 $this->waitForElementPresent("xpath=//tr/td[@class='crm-contribution-amount']/a[@title='view payments']");
360 $this->click("xpath=//tr/td[@class='crm-contribution-amount']/a[@title='view payments']");
361 $this->waitForAjaxContent();
362 $verifyFinancialData = array(
367 foreach ($verifyFinancialData as $col => $data) {
368 $this->verifyText("xpath=//tr[@class='crm-child-row']/td/div/table/tbody/tr[2]/td[{$col}]", $data);
370 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[10]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
372 //View Contribution Record and verify data
374 'From' => "{$firstName} {$lastName}",
375 'Financial Type' => 'Donation',
376 'Total Amount' => '50.00',
377 'Contribution Status' => 'Completed',
378 'Received Into' => 'Deposit Bank Account',
379 'Source' => "Online Contribution: $contributionTitle",
380 'Online Contribution Page' => $contributionTitle,
382 $this->webtestVerifyTabularData($expected);
386 * CRM-16302 - To check whether membership, contribution are
387 * created for free membership signup.
389 public function testOnlineMembershipCreateWithZeroContribution() {
390 //login with admin credentials & make sure we do have required permissions.
391 $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms");
392 $this->changePermissions($permissions);
394 $hash = substr(sha1(rand()), 0, 7);
395 $rand = 2 * rand(2, 50);
396 $amountSection = $payLater = $allowOtherAmount = $pledges = $recurring = FALSE;
397 $premiums = $widget = $pcp = $isSeparatePayment = $membershipsRequired = $fixedAmount = $friend = FALSE;
399 $memPriceSetId = NULL;
402 $profilePostId = NULL;
403 $contributionTitle = "Title $hash";
404 $pageId = $this->webtestAddContributionPage($hash,
431 $memTypeParams = $this->webtestAddMembershipType('rolling', 1, 'year', 'no', 0);
432 $memTypeTitle = $memTypeParams['membership_type'];
433 $memTypeId = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$memTypeTitle}']/../../td[12]/span/a[3]@href"));
434 $memTypeId = $memTypeId[1];
436 // edit contribution page amounts tab to uncheck real time monetary transaction
437 $this->openCiviPage("admin/contribute/membership", "reset=1&action=update&id={$pageId}", '_qf_MembershipBlock_next-bottom');
438 $this->click("membership_type_$memTypeId");
439 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
440 $text = "'MembershipBlock' information has been saved.";
441 $this->waitForText('crm-notification-container', $text);
449 foreach ($processors as $processor) {
450 if ($processor == 'Test Processor') {
451 $processorName = $processor;
454 $processorName = $processor . substr(sha1(rand()), 0, 7);
455 $this->webtestAddPaymentProcessor($processorName, $processor);
457 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id={$pageId}", '_qf_Amount_upload_done-bottom');
458 $this->assertTrue($this->isTextPresent($processorName));
459 $this->check("xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]");
460 $this->clickLink('_qf_Amount_upload_done-bottom');
461 $this->waitForText('crm-notification-container', "'Amount' information has been saved.");
463 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
464 $lastName = 'An' . substr(sha1(rand()), 0, 7);
467 $this->webtestLogout();
469 $this->_testOnlineMembershipSignup($pageId, $memTypeTitle, $firstName, $lastName, $payLater, $hash, $allowOtherAmount, $amountSection, TRUE);
471 // Log in using webtestLogin() method
472 $this->webtestLogin();
475 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
476 $this->type("sort_name", "$lastName $firstName");
477 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
478 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[10]/span/a[text()='View']");
480 // assert financial data - CRM-17863
481 $this->waitForElementPresent("xpath=//tr/td[@class='crm-contribution-amount']/a[@title='view payments']");
482 $this->click("xpath=//tr/td[@class='crm-contribution-amount']/a[@title='view payments']");
483 $this->waitForAjaxContent();
484 $verifyFinancialData = array(
490 foreach ($verifyFinancialData as $col => $data) {
491 $this->verifyText("xpath=//tr[@class='crm-child-row']/td/div/table/tbody/tr[2]/td[{$col}]", $data);
493 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[10]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
495 //View Contribution Record and verify data
497 'From' => "{$firstName} {$lastName}",
498 'Financial Type' => 'Member Dues (test) ',
499 'Total Amount' => '0.00',
500 'Contribution Status' => 'Completed',
501 'Source' => "Online Contribution: $contributionTitle",
502 'Online Contribution Page' => $contributionTitle,
504 $this->webtestVerifyTabularData($expected);
507 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
508 $this->click("xpath=//tr/td[1]/p/label[contains(text(),'Membership is a Test?')]/../label[contains(text(),'Yes')]/preceding-sibling::input[1]");
510 $this->type("sort_name", "$lastName $firstName");
511 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']/table/tbody/tr");
512 $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr/td[11]/span/a[text()='View']");
513 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
515 //View Membership Record
517 'Member' => $firstName . ' ' . $lastName,
518 'Membership Type' => $memTypeTitle,
519 'Source' => 'Online Contribution:' . ' ' . $contributionTitle,
523 $this->webtestVerifyTabularData($verifyData);
528 * CRM-18163 - To check whether multiple organizations with same name
529 * are created based on dedupe rule other than org name.
531 public function testOnlineMembershipCreateOnBehalfWithOrgDedupe() {
532 // Add unsupervised dedupe rule.
533 $this->webtestLogin();
534 $this->openCiviPage("contact/deduperules", "reset=1");
535 $this->waitForElementPresent("xpath=//div[@id='option13_wrapper']/table/tbody/tr[2]/td[3]/span/a[2][text()='Edit Rule']");
536 $this->click("xpath=//div[@id='option13_wrapper']/table/tbody/tr[2]/td[3]/span/a[2][text()='Edit Rule']");
537 $this->waitForElementPresent('_qf_DedupeRules_next');
539 $this->type('title', "Postal Code unsupervised dedupe rule");
540 $this->click('CIVICRM_QFID_Unsupervised_used');
541 $this->select('where_0', "Organization Name");
542 $this->type('weight_0', 10);
543 $this->select('where_1', "Postal Code");
544 $this->type('length_1', 3);
545 $this->type('weight_1', 10);
546 $this->type('threshold', 20);
547 $this->click('_qf_DedupeRules_next');
548 $this->webtestLogout();
550 //login with admin credentials & make sure we do have required permissions.
551 $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms");
552 $this->changePermissions($permissions);
554 $hash = substr(sha1(rand()), 0, 7);
555 $rand = 2 * rand(2, 50);
556 $amountSection = $payLater = $allowOtherAmount = $pledges = $recurring = $membershipsRequired = FALSE;
557 $premiums = $widget = $pcp = $isSeparatePayment = $fixedAmount = $friend = FALSE;
558 $memberships = FALSE;
559 $memPriceSetId = NULL;
561 $profilePostId = NULL;
562 $onBehalf = 'optional';
563 $contributionTitle = "Title $hash";
564 $pageId = $this->webtestAddContributionPage(
592 $memTypeParams = $this->webtestAddMembershipType('rolling', 1, 'year', 'no', 0);
593 $memTypeTitle = $memTypeParams['membership_type'];
594 $memTypeId = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$memTypeTitle}']/../../td[12]/span/a[3]@href"));
595 $memTypeId = $memTypeId[1];
597 $this->openCiviPage("admin/contribute/membership", "reset=1&action=update&id={$pageId}", '_qf_MembershipBlock_submit_savenext');
598 $this->click('member_is_active');
599 $this->waitForElementPresent('displayFee');
600 $this->type('new_title', "Title - New Membership $hash");
601 $this->type('renewal_title', "Title - Renewals $hash");
602 $this->click("membership_type_$memTypeId");
603 $this->clickLink('_qf_MembershipBlock_submit_savenext');
605 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
606 $lastName = 'An' . substr(sha1(rand()), 0, 7);
608 $onBehalfParams = array(
609 'org_name' => 'Test Org Dedupe', // Same Org Name.
610 'org_phone' => '123-456-789',
611 'org_email' => 'testorgdedupe@test.com', // Same Email address.
612 'org_postal_code' => 'ABC 123',
613 'mode' => 'optional',
616 $this->_testOnlineMembershipSignup($pageId, $memTypeTitle, $firstName, $lastName, $payLater, $hash, $allowOtherAmount, $amountSection, TRUE, TRUE, $onBehalfParams);
617 $onBehalfParams['org_postal_code'] = 'XYZ 123';
618 $this->_testOnlineMembershipSignup($pageId, $memTypeTitle, $firstName, $lastName, $payLater, $hash, $allowOtherAmount, $amountSection, TRUE, TRUE, $onBehalfParams);
620 $this->webtestLogin();
621 $this->openCiviPage("contact/search", "reset=1");
622 $this->waitForElementPresent("_qf_Basic_refresh");
623 $this->type('sort_name', $onBehalfParams['org_email']);
624 $this->click("_qf_Basic_refresh");
625 $this->waitForElementPresent("xpath=//div[@class='crm-search-results']");
626 $this->assertElementContainsText("xpath=//div[@id='search-status']/table/tbody/tr[2]/td[2]/label[1]", "All 2 records");