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_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) {
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')]");
212 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label[contains(text(),'$memTypeId')]");
215 if (!$otherAmount && $amountSection) {
216 $this->click("xpath=//div[@class='crm-section contribution_amount-section']/div[2]//span/label[text()='No thank you']");
218 elseif ($amountSection) {
219 $this->clickAt("xpath=//div[@class='content other_amount-content']/input");
220 $this->keyDown("xpath=//div[@class='content other_amount-content']/input", " ");
221 $this->type("xpath=//div[@class='content other_amount-content']/input", $otherAmount);
222 $this->typeKeys("xpath=//div[@class='content other_amount-content']/input", $otherAmount);
225 $this->waitForAjaxContent();
226 $this->click("xpath=//label[text()='Pay later label {$hash}']");
228 $this->type("email-5", $firstName . "@example.com");
229 $this->waitForElementPresent("first_name");
230 $this->type("first_name", $firstName);
231 $this->waitForElementPresent("last_name");
232 $this->type("last_name", $lastName);
234 $streetAddress = "100 Main Street";
235 $this->waitForElementPresent("street_address-1");
236 $this->type("street_address-1", $streetAddress);
237 $this->type("city-1", "San Francisco");
238 $this->type("postal_code-1", "94117");
239 $this->select("country-1", "value=1228");
240 $this->select("state_province-1", "value=1001");
242 if ($freeMembership) {
243 $this->waitForElementPresent("xpath=//div[@id='payment_information'][@style='display: none;']");
246 if (!$payLater && $amountSection) {
247 $this->click("xpath=//label[text()='Test Processor']");
248 $this->waitForAjaxContent();
250 $this->select("credit_card_type", "value=Visa");
251 $this->type("credit_card_number", "4111111111111111");
252 $this->type("cvv2", "000");
253 $this->select("credit_card_exp_date[M]", "value=1");
254 $this->select("credit_card_exp_date[Y]", "value=2020");
257 $this->waitForElementPresent("billing_first_name");
258 $this->type("billing_first_name", $firstName . "billing");
259 $this->waitForElementPresent("billing_last_name");
260 $this->type("billing_last_name", $lastName . "billing");
261 $this->type("billing_street_address-5", "15 Main St.");
262 $this->type(" billing_city-5", "San Jose");
263 $this->select("billing_country_id-5", "value=1228");
264 $this->select("billing_state_province_id-5", "value=1004");
265 $this->type("billing_postal_code-5", "94129");
268 $this->click("_qf_Main_upload-bottom");
269 $this->waitForElementPresent("_qf_Confirm_next-bottom");
271 $this->click("_qf_Confirm_next-bottom");
272 $this->waitForPageToLoad($this->getTimeoutMsec());
275 public function testOnlineMembershipCreateWithContribution() {
276 //login with admin credentials & make sure we do have required permissions.
277 $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms");
278 $this->changePermissions($permissions);
280 $hash = substr(sha1(rand()), 0, 7);
281 $rand = 2 * rand(2, 50);
282 // Use default payment processor
283 $processorName = 'Test Processor';
284 $amountSection = TRUE;
286 $allowOtherAmount = TRUE;
291 $memPriceSetId = NULL;
294 $profilePostId = NULL;
298 $isSeparatePayment = FALSE;
299 $membershipsRequired = FALSE;
300 $fixedAmount = FALSE;
301 $contributionTitle = "Title $hash";
302 $pageId = $this->webtestAddContributionPage($hash,
305 array($processorName => 'Dummy'),
329 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
330 $lastName = 'An' . substr(sha1(rand()), 0, 7);
333 $this->webtestLogout();
335 $this->_testOnlineMembershipSignup($pageId, 'No thank you', $firstName, $lastName, FALSE, $hash, 50);
337 // Log in using webtestLogin() method
338 $this->webtestLogin();
341 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
343 $this->type("sort_name", "$lastName $firstName");
344 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
345 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[10]/span/a[text()='View']");
347 // assert financial data - CRM-17863
348 $this->waitForElementPresent("xpath=//tr/td[@class='crm-contribution-amount']/a[@title='view payments']");
349 $this->click("xpath=//tr/td[@class='crm-contribution-amount']/a[@title='view payments']");
350 $this->waitForAjaxContent();
351 $verifyFinancialData = array(
356 foreach ($verifyFinancialData as $col => $data) {
357 $this->verifyText("xpath=//tr[@class='crm-child-row']/td/div/table/tbody/tr[2]/td[{$col}]", $data);
359 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[10]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
361 //View Contribution Record and verify data
363 'From' => "{$firstName} {$lastName}",
364 'Financial Type' => 'Donation',
365 'Total Amount' => '50.00',
366 'Contribution Status' => 'Completed',
367 'Received Into' => 'Deposit Bank Account',
368 'Source' => "Online Contribution: $contributionTitle",
369 'Online Contribution Page' => $contributionTitle,
371 $this->webtestVerifyTabularData($expected);
375 * CRM-16302 - To check whether membership, contribution are
376 * created for free membership signup.
378 public function testOnlineMembershipCreateWithZeroContribution() {
379 //login with admin credentials & make sure we do have required permissions.
380 $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms");
381 $this->changePermissions($permissions);
383 $hash = substr(sha1(rand()), 0, 7);
384 $rand = 2 * rand(2, 50);
385 $amountSection = $payLater = $allowOtherAmount = $onBehalf = $pledges = $recurring = FALSE;
386 $premiums = $widget = $pcp = $isSeparatePayment = $membershipsRequired = $fixedAmount = $friend = FALSE;
388 $memPriceSetId = NULL;
390 $profilePostId = NULL;
391 $contributionTitle = "Title $hash";
392 $pageId = $this->webtestAddContributionPage($hash,
419 $memTypeParams = $this->webtestAddMembershipType('rolling', 1, 'year', 'no', 0);
420 $memTypeTitle = $memTypeParams['membership_type'];
421 $memTypeId = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$memTypeTitle}']/../../td[12]/span/a[3]@href"));
422 $memTypeId = $memTypeId[1];
424 // edit contribution page amounts tab to uncheck real time monetary transaction
425 $this->openCiviPage("admin/contribute/membership", "reset=1&action=update&id={$pageId}", '_qf_MembershipBlock_next-bottom');
426 $this->click("membership_type_$memTypeId");
427 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
428 $text = "'MembershipBlock' information has been saved.";
429 $this->waitForText('crm-notification-container', $text);
437 foreach ($processors as $processor) {
438 if ($processor == 'Test Processor') {
439 $processorName = $processor;
442 $processorName = $processor . substr(sha1(rand()), 0, 7);
443 $this->webtestAddPaymentProcessor($processorName, $processor);
445 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id={$pageId}", '_qf_Amount_upload_done-bottom');
446 $this->assertTrue($this->isTextPresent($processorName));
447 $this->check("xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]");
448 $this->clickLink('_qf_Amount_upload_done-bottom');
449 $this->waitForText('crm-notification-container', "'Amount' information has been saved.");
451 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
452 $lastName = 'An' . substr(sha1(rand()), 0, 7);
455 $this->webtestLogout();
457 $this->_testOnlineMembershipSignup($pageId, $memTypeTitle, $firstName, $lastName, $payLater, $hash, $allowOtherAmount, $amountSection, TRUE);
459 // Log in using webtestLogin() method
460 $this->webtestLogin();
463 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
464 $this->type("sort_name", "$lastName $firstName");
465 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
466 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[10]/span/a[text()='View']");
468 // assert financial data - CRM-17863
469 $this->waitForElementPresent("xpath=//tr/td[@class='crm-contribution-amount']/a[@title='view payments']");
470 $this->click("xpath=//tr/td[@class='crm-contribution-amount']/a[@title='view payments']");
471 $this->waitForAjaxContent();
472 $verifyFinancialData = array(
478 foreach ($verifyFinancialData as $col => $data) {
479 $this->verifyText("xpath=//tr[@class='crm-child-row']/td/div/table/tbody/tr[2]/td[{$col}]", $data);
481 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[10]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
483 //View Contribution Record and verify data
485 'From' => "{$firstName} {$lastName}",
486 'Financial Type' => 'Member Dues (test) ',
487 'Total Amount' => '0.00',
488 'Contribution Status' => 'Completed',
489 'Source' => "Online Contribution: $contributionTitle",
490 'Online Contribution Page' => $contributionTitle,
492 $this->webtestVerifyTabularData($expected);
495 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
496 $this->click("xpath=//tr/td[1]/p/label[contains(text(),'Membership is a Test?')]/../label[contains(text(),'Yes')]/preceding-sibling::input[1]");
498 $this->type("sort_name", "$lastName $firstName");
499 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']/table/tbody/tr");
500 $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr/td[11]/span/a[text()='View']");
501 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
503 //View Membership Record
505 'Member' => $firstName . ' ' . $lastName,
506 'Membership Type' => $memTypeTitle,
507 'Source' => 'Online Contribution:' . ' ' . $contributionTitle,
511 $this->webtestVerifyTabularData($verifyData);