Merge pull request #7709 from kcristiano/CRM-16421
[civicrm-core.git] / tests / phpunit / WebTest / Member / OnlineMembershipCreateTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
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 $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");
132
133 //View Membership Record
134 $verifyData = array(
135 'Member' => $firstName . ' ' . $lastName,
136 'Membership Type' => $memTypeTitle1,
137 'Source' => 'Online Contribution:' . ' ' . $contributionTitle,
138 'Status' => 'Pending',
139 );
140 $this->webtestVerifyTabularData($verifyData);
141
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
147 $verifyData = array(
148 'From' => $firstName . ' ' . $lastName,
149 'Total Amount' => '$ 100.00',
150 'Contribution Status' => 'Pending : Pay Later',
151 );
152 $this->webtestVerifyTabularData($verifyData);
153
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(
162 'Status' => 'New',
163 'Member Since' => $receiveDate,
164 'Start date' => $receiveDate,
165 'End date' => $endDate,
166 );
167 $this->webtestVerifyTabularData($updatedData);
168
169 // CRM-8141 signup for membership 2 with same anonymous user info (should create 2 separate membership records because membership orgs are different)
170 //logout
171 $this->webtestLogout();
172
173 $this->_testOnlineMembershipSignup($pageId, $memTypeTitle2, $firstName, $lastName, $payLater, $hash);
174
175 // Log in using webtestLogin() method
176 $this->webtestLogin();
177
178 //Find Member
179 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
180
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");
184
185 $this->waitForPageToLoad($this->getTimeoutMsec());
186 $this->assertElementContainsText('search-status', '2 Results', 'Missing text: ' . '2 Results');
187 }
188
189 /**
190 * Test online membership signup.
191 *
192 * @param int $pageId
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
201 */
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')]");
209 }
210
211 else {
212 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label[contains(text(),'$memTypeId')]");
213
214 }
215 if (!$otherAmount && $amountSection) {
216 $this->click("xpath=//div[@class='crm-section contribution_amount-section']/div[2]//span/label[text()='No thank you']");
217 }
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);
223 }
224 if ($payLater) {
225 $this->waitForAjaxContent();
226 $this->click("xpath=//label[text()='Pay later label {$hash}']");
227 }
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);
233
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");
241
242 if ($freeMembership) {
243 $this->waitForElementPresent("xpath=//div[@id='payment_information'][@style='display: none;']");
244 }
245 else {
246 if (!$payLater && $amountSection) {
247 $this->click("xpath=//label[text()='Test Processor']");
248 $this->waitForAjaxContent();
249 //Credit Card Info
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");
255
256 //Billing Info
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");
266 }
267 }
268 $this->click("_qf_Main_upload-bottom");
269 $this->waitForElementPresent("_qf_Confirm_next-bottom");
270
271 $this->click("_qf_Confirm_next-bottom");
272 $this->waitForPageToLoad($this->getTimeoutMsec());
273 }
274
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);
279
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;
285 $payLater = TRUE;
286 $allowOtherAmount = TRUE;
287 $onBehalf = FALSE;
288 $pledges = FALSE;
289 $recurring = FALSE;
290 $memberships = TRUE;
291 $memPriceSetId = NULL;
292 $friend = FALSE;
293 $profilePreId = 1;
294 $profilePostId = NULL;
295 $premiums = FALSE;
296 $widget = FALSE;
297 $pcp = FALSE;
298 $isSeparatePayment = FALSE;
299 $membershipsRequired = FALSE;
300 $fixedAmount = FALSE;
301 $contributionTitle = "Title $hash";
302 $pageId = $this->webtestAddContributionPage($hash,
303 $rand,
304 $contributionTitle,
305 array($processorName => 'Dummy'),
306 $amountSection,
307 $payLater,
308 $onBehalf,
309 $pledges,
310 $recurring,
311 $memberships,
312 $memPriceSetId,
313 $friend,
314 $profilePreId,
315 $profilePostId,
316 $premiums,
317 $widget,
318 $pcp,
319 TRUE,
320 FALSE,
321 $isSeparatePayment,
322 TRUE,
323 $allowOtherAmount,
324 TRUE,
325 'Donation',
326 $fixedAmount,
327 $membershipsRequired
328 );
329 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
330 $lastName = 'An' . substr(sha1(rand()), 0, 7);
331
332 //logout
333 $this->webtestLogout();
334
335 $this->_testOnlineMembershipSignup($pageId, 'No thank you', $firstName, $lastName, FALSE, $hash, 50);
336
337 // Log in using webtestLogin() method
338 $this->webtestLogin();
339
340 //Find Contribution
341 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
342
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']");
346
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(
352 1 => '50.00',
353 2 => 'Donation',
354 6 => 'Completed',
355 );
356 foreach ($verifyFinancialData as $col => $data) {
357 $this->verifyText("xpath=//tr[@class='crm-child-row']/td/div/table/tbody/tr[2]/td[{$col}]", $data);
358 }
359 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[10]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
360
361 //View Contribution Record and verify data
362 $expected = array(
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,
370 );
371 $this->webtestVerifyTabularData($expected);
372 }
373
374 /**
375 * CRM-16302 - To check whether membership, contribution are
376 * created for free membership signup.
377 */
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);
382
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;
387 $memberships = TRUE;
388 $memPriceSetId = NULL;
389 $profilePreId = 1;
390 $profilePostId = NULL;
391 $contributionTitle = "Title $hash";
392 $pageId = $this->webtestAddContributionPage($hash,
393 $rand,
394 $contributionTitle,
395 NULL,
396 $amountSection,
397 $payLater,
398 $onBehalf,
399 $pledges,
400 $recurring,
401 $memberships,
402 $memPriceSetId,
403 $friend,
404 $profilePreId,
405 $profilePostId,
406 $premiums,
407 $widget,
408 $pcp,
409 FALSE,
410 FALSE,
411 $isSeparatePayment,
412 FALSE,
413 $allowOtherAmount,
414 TRUE,
415 'Member Dues',
416 $fixedAmount,
417 $membershipsRequired
418 );
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];
423
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);
430
431 $processors = array(
432 'Test Processor',
433 'AuthNet',
434 'PayPal',
435 'PayPal_Standard',
436 );
437 foreach ($processors as $processor) {
438 if ($processor == 'Test Processor') {
439 $processorName = $processor;
440 }
441 else {
442 $processorName = $processor . substr(sha1(rand()), 0, 7);
443 $this->webtestAddPaymentProcessor($processorName, $processor);
444 }
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.");
450
451 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
452 $lastName = 'An' . substr(sha1(rand()), 0, 7);
453
454 //logout
455 $this->webtestLogout();
456
457 $this->_testOnlineMembershipSignup($pageId, $memTypeTitle, $firstName, $lastName, $payLater, $hash, $allowOtherAmount, $amountSection, TRUE);
458
459 // Log in using webtestLogin() method
460 $this->webtestLogin();
461
462 //Find Contribution
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']");
467
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(
473 1 => '0.00',
474 2 => 'Member Dues',
475 3 => 'Credit Card',
476 6 => 'Completed',
477 );
478 foreach ($verifyFinancialData as $col => $data) {
479 $this->verifyText("xpath=//tr[@class='crm-child-row']/td/div/table/tbody/tr[2]/td[{$col}]", $data);
480 }
481 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[10]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
482
483 //View Contribution Record and verify data
484 $expected = array(
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,
491 );
492 $this->webtestVerifyTabularData($expected);
493
494 //Find Member
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]");
497
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");
502
503 //View Membership Record
504 $verifyData = array(
505 'Member' => $firstName . ' ' . $lastName,
506 'Membership Type' => $memTypeTitle,
507 'Source' => 'Online Contribution:' . ' ' . $contributionTitle,
508 'Status' => 'New',
509 );
510
511 $this->webtestVerifyTabularData($verifyData);
512 }
513 }
514
515 }