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