comment fixes
[civicrm-core.git] / tests / phpunit / WebTest / Member / OnlineMembershipCreateTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
81621fee 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25 */
26
6a488035 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Member_OnlineMembershipCreateTest
31 */
6a488035
TO
32class WebTest_Member_OnlineMembershipCreateTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
00be9182 38 public function testOnlineMembershipCreate() {
6a488035
TO
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);
42
42daf119
CW
43 // Log in as normal user
44 $this->webtestLogin();
6a488035
TO
45
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);
6a488035 49
c3ad8633
CW
50 // Use default payment processor
51 $processorName = 'Test Processor';
6a488035
TO
52
53 // create contribution page with randomized title and default params
42daf119
CW
54 $amountSection = TRUE;
55 $payLater = TRUE;
10525e44 56 $allowOtherAmount = FALSE;
42daf119
CW
57 $onBehalf = FALSE;
58 $pledges = FALSE;
59 $recurring = FALSE;
60 $memberships = TRUE;
61 $memPriceSetId = NULL;
62 $friend = TRUE;
63 $profilePreId = 1;
64 $profilePostId = NULL;
65 $premiums = TRUE;
66 $widget = FALSE;
67 $pcp = TRUE;
6a488035
TO
68 $isSeparatePayment = TRUE;
69 $contributionTitle = "Title $hash";
42daf119 70 $pageId = $this->webtestAddContributionPage($hash,
6a488035
TO
71 $rand,
72 $contributionTitle,
73 array($processorName => 'Dummy'),
74 $amountSection,
75 $payLater,
76 $onBehalf,
77 $pledges,
78 $recurring,
79 $memberships,
80 $memPriceSetId,
81 $friend,
82 $profilePreId,
83 $profilePostId,
84 $premiums,
85 $widget,
86 $pcp,
87 TRUE,
88 FALSE,
89 $isSeparatePayment,
90 TRUE,
91 FALSE
92 );
93
6a488035
TO
94 // create two new membership types
95 $memTypeParams1 = $this->webtestAddMembershipType();
42daf119 96 $memTypeTitle1 = $memTypeParams1['membership_type'];
5c80555f 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"));
42daf119 98 $memTypeId1 = $memTypeId1[1];
6a488035
TO
99
100 $memTypeParams2 = $this->webtestAddMembershipType();
42daf119 101 $memTypeTitle2 = $memTypeParams2['membership_type'];
5c80555f 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"));
42daf119 103 $memTypeId2 = $memTypeId2[1];
6a488035
TO
104
105 // edit contribution page memberships tab to add two new membership types
1019390e 106 $this->openCiviPage("admin/contribute/membership", "reset=1&action=update&id={$pageId}", '_qf_MembershipBlock_next-bottom');
6a488035
TO
107 $this->click("membership_type_$memTypeId1");
108 $this->click("membership_type_$memTypeId2");
225a8648 109 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
6a488035 110 $text = "'MembershipBlock' information has been saved.";
6c5f7368 111 $this->waitForText('crm-notification-container', $text);
76e86fd8 112
6a488035 113 //logout
42daf119 114 $this->webtestLogout();
6a488035
TO
115
116 // signup for membership 1
117 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
118 $lastName = 'An' . substr(sha1(rand()), 0, 7);
119
120 $this->_testOnlineMembershipSignup($pageId, $memTypeTitle1, $firstName, $lastName, $payLater, $hash);
6a488035
TO
121
122 // Log in using webtestLogin() method
123 $this->webtestLogin();
124
125 //Find Member
1019390e 126 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
f1224701 127 $this->click("xpath=//tr/td[1]/p/label[contains(text(),'Membership is a Test?')]/../label[contains(text(),'Yes')]/preceding-sibling::input[1]");
6080c83e 128 $this->type("sort_name", "$lastName $firstName");
225a8648 129 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']/table/tbody/tr");
6a488035
TO
130 $this->click("xpath=//div[@id='memberSearch']/table/tbody/tr/td[11]/span/a[text()='View']");
131 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
132
133 //View Membership Record
134 $verifyData = array(
135 'Member' => $firstName . ' ' . $lastName,
136 'Membership Type' => $memTypeTitle1,
137 'Source' => 'Online Contribution:' . ' ' . $contributionTitle,
138 );
139 if ($payLater) {
140 $verifyData['Status'] = 'Pending';
141 }
76e86fd8
CW
142 else {
143
1019390e
PN
144 $verifyData['Status'] = 'New';
145 }
96e6d962 146 $this->webtestVerifyTabularData($verifyData);
6a488035
TO
147
148 // Click View action link on associated contribution record
343688b7
RK
149 $this->waitForElementPresent("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[1][text()='View']");
150 $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[1][text()='View']");
a7011f01 151 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
6a488035
TO
152 //View Contribution Record
153 $verifyData = array(
154 'From' => $firstName . ' ' . $lastName,
155 'Total Amount' => '$ 100.00',
156 );
157 if ($payLater) {
158 $verifyData['Contribution Status'] = 'Pending : Pay Later';
159 }
1019390e
PN
160 else {
161 $verifyData['Contribution Status'] = 'Completed';
162 }
96e6d962 163 $this->webtestVerifyTabularData($verifyData);
6a488035 164
75339f53 165 //CRM-15735 - verify membership dates gets changed w.r.t receive_date of contribution.
166 if ($payLater) {
167 $receiveDate = date('F jS, Y', strtotime("-1 month"));
168 $endDate = date('F jS, Y', strtotime("+1 year -1 month -1 day"));
169 $this->clickAjaxLink("xpath=//button//span[contains(text(),'Edit')]", 'receive_date');
170 $this->select('contribution_status_id', 'Completed');
171 $this->webtestFillDate('receive_date', '-1 month');
172 $this->clickAjaxLink("xpath=//button//span[contains(text(),'Save')]", "xpath=//div[@class='ui-dialog-buttonset']/button[3]/span[2]");
173 $updatedData = array(
174 'Status' => 'New',
175 'Member Since' => $receiveDate,
176 'Start date' => $receiveDate,
177 'End date' => $endDate,
178 );
179 $this->webtestVerifyTabularData($updatedData);
180 }
181
6a488035
TO
182 // CRM-8141 signup for membership 2 with same anonymous user info (should create 2 separate membership records because membership orgs are different)
183 //logout
42daf119 184 $this->webtestLogout();
6a488035
TO
185
186 $this->_testOnlineMembershipSignup($pageId, $memTypeTitle2, $firstName, $lastName, $payLater, $hash);
6a488035
TO
187
188 // Log in using webtestLogin() method
189 $this->webtestLogin();
190
191 //Find Member
1019390e 192 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
6a488035 193
6080c83e 194 $this->type("sort_name", "$lastName $firstName");
810fa73d 195 $this->click("xpath=//tr/td[1]/p/label[contains(text(),'Membership is a Test?')]/../label[contains(text(),'Yes')]/preceding-sibling::input[1]");
6a488035
TO
196 $this->click("_qf_Search_refresh");
197
198 $this->waitForPageToLoad($this->getTimeoutMsec());
96e6d962 199 $this->assertElementContainsText('search-status', '2 Results', 'Missing text: ' . '2 Results');
6a488035
TO
200 }
201
4cbe18b8 202 /**
100fef9d
CW
203 * @param int $pageId
204 * @param int $memTypeId
205 * @param string $firstName
206 * @param string $lastName
4cbe18b8
EM
207 * @param $payLater
208 * @param $hash
209 * @param bool $otherAmount
210 */
599e7e41 211 public function _testOnlineMembershipSignup($pageId, $memTypeId, $firstName, $lastName, $payLater, $hash, $otherAmount = FALSE, $amountSection = TRUE, $freeMembership = FALSE) {
6a488035 212 //Open Live Contribution Page
f1224701 213 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom");
6a488035
TO
214 // Select membership type 1
215 $this->waitForElementPresent("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label");
1019390e 216 if ($memTypeId != 'No thank you') {
6c6e6187 217 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//div/span/label/span[1][contains(text(),'$memTypeId')]");
76e86fd8
CW
218 }
219
1019390e 220 else {
76e86fd8
CW
221 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label[contains(text(),'$memTypeId')]");
222
1019390e 223 }
4da07767 224 if (!$otherAmount && $amountSection) {
1019390e
PN
225 $this->click("xpath=//div[@class='crm-section contribution_amount-section']/div[2]//span/label[text()='No thank you']");
226 }
4da07767 227 elseif ($amountSection) {
1019390e
PN
228 $this->type("xpath=//div[@class='content other_amount-content']/input", $otherAmount);
229 }
6a488035
TO
230 if ($payLater) {
231 $this->click("xpath=//div[@class='crm-section payment_processor-section']/div[2]//label[text()='Pay later label {$hash}']");
232 }
233 $this->type("email-5", $firstName . "@example.com");
343688b7 234 $this->waitForElementPresent("first_name");
6a488035 235 $this->type("first_name", $firstName);
343688b7 236 $this->waitForElementPresent("last_name");
6a488035
TO
237 $this->type("last_name", $lastName);
238
239 $streetAddress = "100 Main Street";
343688b7 240 $this->waitForElementPresent("street_address-1");
6a488035
TO
241 $this->type("street_address-1", $streetAddress);
242 $this->type("city-1", "San Francisco");
243 $this->type("postal_code-1", "94117");
244 $this->select("country-1", "value=1228");
245 $this->select("state_province-1", "value=1001");
599e7e41 246
247 if ($freeMembership) {
248 $this->waitForElementPresent("xpath=//div[@id='payment_information'][@style='display: none;']");
249 }
250 else {
251 if (!$payLater && $amountSection) {
252 //Credit Card Info
253 $this->select("credit_card_type", "value=Visa");
254 $this->type("credit_card_number", "4111111111111111");
255 $this->type("cvv2", "000");
256 $this->select("credit_card_exp_date[M]", "value=1");
257 $this->select("credit_card_exp_date[Y]", "value=2020");
258
259 //Billing Info
260 $this->waitForElementPresent("billing_first_name");
261 $this->type("billing_first_name", $firstName . "billing");
262 $this->waitForElementPresent("billing_last_name");
263 $this->type("billing_last_name", $lastName . "billing");
264 $this->type("billing_street_address-5", "15 Main St.");
265 $this->type(" billing_city-5", "San Jose");
266 $this->select("billing_country_id-5", "value=1228");
267 $this->select("billing_state_province_id-5", "value=1004");
268 $this->type("billing_postal_code-5", "94129");
269 }
6a488035
TO
270 }
271 $this->click("_qf_Main_upload-bottom");
6a488035
TO
272 $this->waitForElementPresent("_qf_Confirm_next-bottom");
273
274 $this->click("_qf_Confirm_next-bottom");
275 $this->waitForPageToLoad($this->getTimeoutMsec());
276 }
76e86fd8 277
00be9182 278 public function testOnlineMembershipCreateWithContribution() {
1019390e 279 //login with admin credentials & make sure we do have required permissions.
42daf119
CW
280 $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms");
281 $this->changePermissions($permissions);
282
1019390e
PN
283 $hash = substr(sha1(rand()), 0, 7);
284 $rand = 2 * rand(2, 50);
c3ad8633
CW
285 // Use default payment processor
286 $processorName = 'Test Processor';
42daf119
CW
287 $amountSection = TRUE;
288 $payLater = TRUE;
10525e44 289 $allowOtherAmount = TRUE;
42daf119
CW
290 $onBehalf = FALSE;
291 $pledges = FALSE;
292 $recurring = FALSE;
293 $memberships = TRUE;
294 $memPriceSetId = NULL;
295 $friend = FALSE;
296 $profilePreId = 1;
297 $profilePostId = NULL;
298 $premiums = FALSE;
299 $widget = FALSE;
300 $pcp = FALSE;
1019390e
PN
301 $isSeparatePayment = FALSE;
302 $membershipsRequired = FALSE;
42daf119 303 $fixedAmount = FALSE;
1019390e 304 $contributionTitle = "Title $hash";
42daf119 305 $pageId = $this->webtestAddContributionPage($hash,
1019390e
PN
306 $rand,
307 $contributionTitle,
308 array($processorName => 'Dummy'),
309 $amountSection,
310 $payLater,
311 $onBehalf,
312 $pledges,
313 $recurring,
314 $memberships,
315 $memPriceSetId,
316 $friend,
317 $profilePreId,
318 $profilePostId,
319 $premiums,
320 $widget,
321 $pcp,
322 TRUE,
323 FALSE,
324 $isSeparatePayment,
325 TRUE,
10525e44 326 $allowOtherAmount,
1019390e
PN
327 TRUE,
328 'Donation',
329 $fixedAmount,
96e6d962 330 $membershipsRequired
1019390e
PN
331 );
332 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
333 $lastName = 'An' . substr(sha1(rand()), 0, 7);
96e6d962 334
1019390e 335 //logout
42daf119 336 $this->webtestLogout();
96e6d962 337
1019390e 338 $this->_testOnlineMembershipSignup($pageId, 'No thank you', $firstName, $lastName, FALSE, $hash, 50);
96e6d962 339
1019390e 340 // Log in using webtestLogin() method
96e6d962 341 $this->webtestLogin();
1019390e
PN
342
343 //Find Contribution
6c6e6187 344 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
1019390e 345
6080c83e 346 $this->type("sort_name", "$lastName $firstName");
f1224701 347 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
225a8648 348 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
73072f84 349 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
1019390e
PN
350
351 //View Contribution Record and verify data
352 $expected = array(
353 'From' => "{$firstName} {$lastName}",
354 'Financial Type' => 'Donation',
355 'Total Amount' => '50.00',
356 'Contribution Status' => 'Completed',
357 'Received Into' => 'Deposit Bank Account',
358 'Source' => "Online Contribution: $contributionTitle",
359 'Online Contribution Page' => $contributionTitle,
360 );
361 $this->webtestVerifyTabularData($expected);
362 }
96025800 363
93ba05e3 364 /**
5bb12682 365 * CRM-16302 - To check whether membership, contribution are
366 * created for free membership signup.
8cb616f6 367 */
4da07767 368 public function testOnlineMembershipCreateWithZeroContribution() {
369 //login with admin credentials & make sure we do have required permissions.
370 $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms");
371 $this->changePermissions($permissions);
372
373 $hash = substr(sha1(rand()), 0, 7);
374 $rand = 2 * rand(2, 50);
8cb616f6 375 $amountSection = $payLater = $allowOtherAmount = $onBehalf = $pledges = $recurring = FALSE;
376 $premiums = $widget = $pcp = $isSeparatePayment = $membershipsRequired = $fixedAmount = $friend = FALSE;
4da07767 377 $memberships = TRUE;
378 $memPriceSetId = NULL;
4da07767 379 $profilePreId = 1;
380 $profilePostId = NULL;
4da07767 381 $contributionTitle = "Title $hash";
382 $pageId = $this->webtestAddContributionPage($hash,
383 $rand,
384 $contributionTitle,
385 NULL,
386 $amountSection,
387 $payLater,
388 $onBehalf,
389 $pledges,
390 $recurring,
391 $memberships,
392 $memPriceSetId,
393 $friend,
394 $profilePreId,
395 $profilePostId,
396 $premiums,
397 $widget,
398 $pcp,
399 FALSE,
400 FALSE,
401 $isSeparatePayment,
402 FALSE,
403 $allowOtherAmount,
404 TRUE,
405 'Member Dues',
406 $fixedAmount,
407 $membershipsRequired
408 );
409 $memTypeParams = $this->webtestAddMembershipType('rolling', 1, 'year', 'no', 0);
410 $memTypeTitle = $memTypeParams['membership_type'];
411 $memTypeId = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$memTypeTitle}']/../../td[12]/span/a[3]@href"));
412 $memTypeId = $memTypeId[1];
413
414 // edit contribution page amounts tab to uncheck real time monetary transaction
415 $this->openCiviPage("admin/contribute/membership", "reset=1&action=update&id={$pageId}", '_qf_MembershipBlock_next-bottom');
416 $this->click("membership_type_$memTypeId");
417 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
418 $text = "'MembershipBlock' information has been saved.";
419 $this->waitForText('crm-notification-container', $text);
4da07767 420
599e7e41 421 $processors = array(
422 'Test Processor',
423 'AuthNet',
424 'PayPal',
425 'PayPal_Standard',
4da07767 426 );
599e7e41 427 foreach ($processors as $processor) {
428 if ($processor == 'Test Processor') {
429 $processorName = $processor;
430 }
431 else {
432 $processorName = $processor . substr(sha1(rand()), 0, 7);
433 $this->webtestAddPaymentProcessor($processorName, $processor);
434 }
435 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id={$pageId}", '_qf_Amount_upload_done-bottom');
436 $this->assertTrue($this->isTextPresent($processorName));
437 $this->check("xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]");
438 $this->clickLink('_qf_Amount_upload_done-bottom');
439 $this->waitForText('crm-notification-container', "'Amount' information has been saved.");
440
441 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
442 $lastName = 'An' . substr(sha1(rand()), 0, 7);
443
444 //logout
445 $this->webtestLogout();
446
447 $this->_testOnlineMembershipSignup($pageId, $memTypeTitle, $firstName, $lastName, $payLater, $hash, $allowOtherAmount, $amountSection, TRUE);
448
449 // Log in using webtestLogin() method
450 $this->webtestLogin();
451
452 //Find Contribution
453 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
454 $this->type("sort_name", "$lastName $firstName");
455 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
456 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
457
458 //View Contribution Record and verify data
459 $expected = array(
460 'From' => "{$firstName} {$lastName}",
461 'Financial Type' => 'Member Dues',
462 'Total Amount' => '0.00',
463 'Contribution Status' => 'Completed',
464 'Received Into' => 'Payment Processor Account',
465 'Source' => "Online Contribution: $contributionTitle",
466 'Online Contribution Page' => $contributionTitle,
467 );
468 $this->webtestVerifyTabularData($expected);
4da07767 469
599e7e41 470 //Find Member
471 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
4da07767 472
599e7e41 473 $this->type("sort_name", "$lastName $firstName");
474 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']/table/tbody/tr");
475 $this->click("xpath=//div[@id='memberSearch']/table/tbody/tr/td[11]/span/a[text()='View']");
476 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
4da07767 477
599e7e41 478 //View Membership Record
479 $verifyData = array(
480 'Member' => $firstName . ' ' . $lastName,
481 'Membership Type' => $memTypeTitle,
482 'Source' => 'Online Contribution:' . ' ' . $contributionTitle,
483 'Status' => 'New',
484 );
4da07767 485
599e7e41 486 $this->webtestVerifyTabularData($verifyData);
487 }
4da07767 488 }
489
42daf119 490}