Merge pull request #6551 from eileenmcnaughton/CRM-17060
[civicrm-core.git] / tests / phpunit / WebTest / Member / OnlineMembershipCreateTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28
29 /**
30 * Class WebTest_Member_OnlineMembershipCreateTest
31 */
32 class WebTest_Member_OnlineMembershipCreateTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
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);
42
43 // Log in as normal user
44 $this->webtestLogin();
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);
49
50 // Use default payment processor
51 $processorName = 'Test Processor';
52
53 // create contribution page with randomized title and default params
54 $amountSection = TRUE;
55 $payLater = TRUE;
56 $allowOtherAmount = FALSE;
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;
68 $isSeparatePayment = TRUE;
69 $contributionTitle = "Title $hash";
70 $pageId = $this->webtestAddContributionPage($hash,
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
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];
99
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];
104
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);
112
113 //logout
114 $this->webtestLogout();
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);
121
122 // Log in using webtestLogin() method
123 $this->webtestLogin();
124
125 //Find Member
126 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
127
128 $this->type("sort_name", "$lastName $firstName");
129 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']/table/tbody/tr");
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 }
142 else {
143
144 $verifyData['Status'] = 'New';
145 }
146 $this->webtestVerifyTabularData($verifyData);
147
148 // Click View action link on associated contribution record
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']");
151 $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[3]/span[2]");
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 }
160 else {
161 $verifyData['Contribution Status'] = 'Completed';
162 }
163 $this->webtestVerifyTabularData($verifyData);
164
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
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
184 $this->webtestLogout();
185
186 $this->_testOnlineMembershipSignup($pageId, $memTypeTitle2, $firstName, $lastName, $payLater, $hash);
187
188 // Log in using webtestLogin() method
189 $this->webtestLogin();
190
191 //Find Member
192 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
193
194 $this->type("sort_name", "$lastName $firstName");
195 $this->click("_qf_Search_refresh");
196
197 $this->waitForPageToLoad($this->getTimeoutMsec());
198 $this->assertElementContainsText('search-status', '2 Results', 'Missing text: ' . '2 Results');
199 }
200
201 /**
202 * @param int $pageId
203 * @param int $memTypeId
204 * @param string $firstName
205 * @param string $lastName
206 * @param $payLater
207 * @param $hash
208 * @param bool $otherAmount
209 */
210 public function _testOnlineMembershipSignup($pageId, $memTypeId, $firstName, $lastName, $payLater, $hash, $otherAmount = FALSE, $amountSection = TRUE, $freeMembership = FALSE) {
211 //Open Live Contribution Page
212 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
213 // Select membership type 1
214 $this->waitForElementPresent("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label");
215 if ($memTypeId != 'No thank you') {
216 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//div/span/label/span[1][contains(text(),'$memTypeId')]");
217 }
218
219 else {
220 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label[contains(text(),'$memTypeId')]");
221
222 }
223 if (!$otherAmount && $amountSection) {
224 $this->click("xpath=//div[@class='crm-section contribution_amount-section']/div[2]//span/label[text()='No thank you']");
225 }
226 elseif ($amountSection) {
227 $this->type("xpath=//div[@class='content other_amount-content']/input", $otherAmount);
228 }
229 if ($payLater) {
230 $this->click("xpath=//div[@class='crm-section payment_processor-section']/div[2]//label[text()='Pay later label {$hash}']");
231 }
232 $this->type("email-5", $firstName . "@example.com");
233 $this->waitForElementPresent("first_name");
234 $this->type("first_name", $firstName);
235 $this->waitForElementPresent("last_name");
236 $this->type("last_name", $lastName);
237
238 $streetAddress = "100 Main Street";
239 $this->waitForElementPresent("street_address-1");
240 $this->type("street_address-1", $streetAddress);
241 $this->type("city-1", "San Francisco");
242 $this->type("postal_code-1", "94117");
243 $this->select("country-1", "value=1228");
244 $this->select("state_province-1", "value=1001");
245
246 if ($freeMembership) {
247 $this->waitForElementPresent("xpath=//div[@id='payment_information'][@style='display: none;']");
248 }
249 else {
250 if (!$payLater && $amountSection) {
251 //Credit Card Info
252 $this->select("credit_card_type", "value=Visa");
253 $this->type("credit_card_number", "4111111111111111");
254 $this->type("cvv2", "000");
255 $this->select("credit_card_exp_date[M]", "value=1");
256 $this->select("credit_card_exp_date[Y]", "value=2020");
257
258 //Billing Info
259 $this->waitForElementPresent("billing_first_name");
260 $this->type("billing_first_name", $firstName . "billing");
261 $this->waitForElementPresent("billing_last_name");
262 $this->type("billing_last_name", $lastName . "billing");
263 $this->type("billing_street_address-5", "15 Main St.");
264 $this->type(" billing_city-5", "San Jose");
265 $this->select("billing_country_id-5", "value=1228");
266 $this->select("billing_state_province_id-5", "value=1004");
267 $this->type("billing_postal_code-5", "94129");
268 }
269 }
270 $this->click("_qf_Main_upload-bottom");
271 $this->waitForElementPresent("_qf_Confirm_next-bottom");
272
273 $this->click("_qf_Confirm_next-bottom");
274 $this->waitForPageToLoad($this->getTimeoutMsec());
275 }
276
277 public function testOnlineMembershipCreateWithContribution() {
278 //login with admin credentials & make sure we do have required permissions.
279 $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms");
280 $this->changePermissions($permissions);
281
282 $hash = substr(sha1(rand()), 0, 7);
283 $rand = 2 * rand(2, 50);
284 // Use default payment processor
285 $processorName = 'Test Processor';
286 $amountSection = TRUE;
287 $payLater = TRUE;
288 $allowOtherAmount = TRUE;
289 $onBehalf = FALSE;
290 $pledges = FALSE;
291 $recurring = FALSE;
292 $memberships = TRUE;
293 $memPriceSetId = NULL;
294 $friend = FALSE;
295 $profilePreId = 1;
296 $profilePostId = NULL;
297 $premiums = FALSE;
298 $widget = FALSE;
299 $pcp = FALSE;
300 $isSeparatePayment = FALSE;
301 $membershipsRequired = FALSE;
302 $fixedAmount = FALSE;
303 $contributionTitle = "Title $hash";
304 $pageId = $this->webtestAddContributionPage($hash,
305 $rand,
306 $contributionTitle,
307 array($processorName => 'Dummy'),
308 $amountSection,
309 $payLater,
310 $onBehalf,
311 $pledges,
312 $recurring,
313 $memberships,
314 $memPriceSetId,
315 $friend,
316 $profilePreId,
317 $profilePostId,
318 $premiums,
319 $widget,
320 $pcp,
321 TRUE,
322 FALSE,
323 $isSeparatePayment,
324 TRUE,
325 $allowOtherAmount,
326 TRUE,
327 'Donation',
328 $fixedAmount,
329 $membershipsRequired
330 );
331 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
332 $lastName = 'An' . substr(sha1(rand()), 0, 7);
333
334 //logout
335 $this->webtestLogout();
336
337 $this->_testOnlineMembershipSignup($pageId, 'No thank you', $firstName, $lastName, FALSE, $hash, 50);
338
339 // Log in using webtestLogin() method
340 $this->webtestLogin();
341
342 //Find Contribution
343 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
344
345 $this->type("sort_name", "$lastName $firstName");
346 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
347 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
348
349 //View Contribution Record and verify data
350 $expected = array(
351 'From' => "{$firstName} {$lastName}",
352 'Financial Type' => 'Donation',
353 'Total Amount' => '50.00',
354 'Contribution Status' => 'Completed',
355 'Received Into' => 'Deposit Bank Account',
356 'Source' => "Online Contribution: $contributionTitle",
357 'Online Contribution Page' => $contributionTitle,
358 );
359 $this->webtestVerifyTabularData($expected);
360 }
361
362 /**
363 * CRM-16302 - To check whether membership, contribution are
364 * created for free membership signup.
365 */
366 public function testOnlineMembershipCreateWithZeroContribution() {
367 //login with admin credentials & make sure we do have required permissions.
368 $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms");
369 $this->changePermissions($permissions);
370
371 $hash = substr(sha1(rand()), 0, 7);
372 $rand = 2 * rand(2, 50);
373 $amountSection = $payLater = $allowOtherAmount = $onBehalf = $pledges = $recurring = FALSE;
374 $premiums = $widget = $pcp = $isSeparatePayment = $membershipsRequired = $fixedAmount = $friend = FALSE;
375 $memberships = TRUE;
376 $memPriceSetId = NULL;
377 $profilePreId = 1;
378 $profilePostId = NULL;
379 $contributionTitle = "Title $hash";
380 $pageId = $this->webtestAddContributionPage($hash,
381 $rand,
382 $contributionTitle,
383 NULL,
384 $amountSection,
385 $payLater,
386 $onBehalf,
387 $pledges,
388 $recurring,
389 $memberships,
390 $memPriceSetId,
391 $friend,
392 $profilePreId,
393 $profilePostId,
394 $premiums,
395 $widget,
396 $pcp,
397 FALSE,
398 FALSE,
399 $isSeparatePayment,
400 FALSE,
401 $allowOtherAmount,
402 TRUE,
403 'Member Dues',
404 $fixedAmount,
405 $membershipsRequired
406 );
407 $memTypeParams = $this->webtestAddMembershipType('rolling', 1, 'year', 'no', 0);
408 $memTypeTitle = $memTypeParams['membership_type'];
409 $memTypeId = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$memTypeTitle}']/../../td[12]/span/a[3]@href"));
410 $memTypeId = $memTypeId[1];
411
412 // edit contribution page amounts tab to uncheck real time monetary transaction
413 $this->openCiviPage("admin/contribute/membership", "reset=1&action=update&id={$pageId}", '_qf_MembershipBlock_next-bottom');
414 $this->click("membership_type_$memTypeId");
415 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
416 $text = "'MembershipBlock' information has been saved.";
417 $this->waitForText('crm-notification-container', $text);
418
419 $processors = array(
420 'Test Processor',
421 'AuthNet',
422 'PayPal',
423 'PayPal_Standard',
424 );
425 foreach ($processors as $processor) {
426 if ($processor == 'Test Processor') {
427 $processorName = $processor;
428 }
429 else {
430 $processorName = $processor . substr(sha1(rand()), 0, 7);
431 $this->webtestAddPaymentProcessor($processorName, $processor);
432 }
433 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id={$pageId}", '_qf_Amount_upload_done-bottom');
434 $this->assertTrue($this->isTextPresent($processorName));
435 $this->check("xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]");
436 $this->clickLink('_qf_Amount_upload_done-bottom');
437 $this->waitForText('crm-notification-container', "'Amount' information has been saved.");
438
439 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
440 $lastName = 'An' . substr(sha1(rand()), 0, 7);
441
442 //logout
443 $this->webtestLogout();
444
445 $this->_testOnlineMembershipSignup($pageId, $memTypeTitle, $firstName, $lastName, $payLater, $hash, $allowOtherAmount, $amountSection, TRUE);
446
447 // Log in using webtestLogin() method
448 $this->webtestLogin();
449
450 //Find Contribution
451 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
452 $this->type("sort_name", "$lastName $firstName");
453 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
454 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
455
456 //View Contribution Record and verify data
457 $expected = array(
458 'From' => "{$firstName} {$lastName}",
459 'Financial Type' => 'Member Dues',
460 'Total Amount' => '0.00',
461 'Contribution Status' => 'Completed',
462 'Received Into' => 'Payment Processor Account',
463 'Source' => "Online Contribution: $contributionTitle",
464 'Online Contribution Page' => $contributionTitle,
465 );
466 $this->webtestVerifyTabularData($expected);
467
468 //Find Member
469 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
470
471 $this->type("sort_name", "$lastName $firstName");
472 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']/table/tbody/tr");
473 $this->click("xpath=//div[@id='memberSearch']/table/tbody/tr/td[11]/span/a[text()='View']");
474 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
475
476 //View Membership Record
477 $verifyData = array(
478 'Member' => $firstName . ' ' . $lastName,
479 'Membership Type' => $memTypeTitle,
480 'Source' => 'Online Contribution:' . ' ' . $contributionTitle,
481 'Status' => 'New',
482 );
483
484 $this->webtestVerifyTabularData($verifyData);
485 }
486 }
487
488 }