Merge pull request #2909 from jake-mw/crm-14472
[civicrm-core.git] / tests / phpunit / WebTest / Member / OnlineMembershipCreateTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 class WebTest_Member_OnlineMembershipCreateTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testOnlineMembershipCreate() {
35 //check for online contribution and profile listings permissions
36 $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms");
37 $this->changePermissions($permissions);
38
39 // Log in as normal user
40 $this->webtestLogin();
41
42 // a random 7-char string and an even number to make this pass unique
43 $hash = substr(sha1(rand()), 0, 7);
44 $rand = 2 * rand(2, 50);
45
46 // We need a payment processor
47 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
48
49 // create contribution page with randomized title and default params
50 $amountSection = TRUE;
51 $payLater = TRUE;
52 $allowOtherAmmount = FALSE;
53 $onBehalf = FALSE;
54 $pledges = FALSE;
55 $recurring = FALSE;
56 $memberships = TRUE;
57 $memPriceSetId = NULL;
58 $friend = TRUE;
59 $profilePreId = 1;
60 $profilePostId = NULL;
61 $premiums = TRUE;
62 $widget = FALSE;
63 $pcp = TRUE;
64 $isSeparatePayment = TRUE;
65 $contributionTitle = "Title $hash";
66 $pageId = $this->webtestAddContributionPage($hash,
67 $rand,
68 $contributionTitle,
69 array($processorName => 'Dummy'),
70 $amountSection,
71 $payLater,
72 $onBehalf,
73 $pledges,
74 $recurring,
75 $memberships,
76 $memPriceSetId,
77 $friend,
78 $profilePreId,
79 $profilePostId,
80 $premiums,
81 $widget,
82 $pcp,
83 TRUE,
84 FALSE,
85 $isSeparatePayment,
86 TRUE,
87 FALSE
88 );
89
90 // create two new membership types
91 $memTypeParams1 = $this->webtestAddMembershipType();
92 $memTypeTitle1 = $memTypeParams1['membership_type'];
93 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[1]/table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href"));
94 $memTypeId1 = $memTypeId1[1];
95
96 $memTypeParams2 = $this->webtestAddMembershipType();
97 $memTypeTitle2 = $memTypeParams2['membership_type'];
98 $memTypeId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[1]/table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[12]/span/a[3]@href"));
99 $memTypeId2 = $memTypeId2[1];
100
101 // edit contribution page memberships tab to add two new membership types
102 $this->openCiviPage("admin/contribute/membership", "reset=1&action=update&id={$pageId}", '_qf_MembershipBlock_next-bottom');
103 $this->click("membership_type_$memTypeId1");
104 $this->click("membership_type_$memTypeId2");
105 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
106 $text = "'MembershipBlock' information has been saved.";
107 $this->waitForText('crm-notification-container', $text);
108
109 //logout
110 $this->webtestLogout();
111
112 // signup for membership 1
113 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
114 $lastName = 'An' . substr(sha1(rand()), 0, 7);
115
116 $this->_testOnlineMembershipSignup($pageId, $memTypeTitle1, $firstName, $lastName, $payLater, $hash);
117
118 // Log in using webtestLogin() method
119 $this->webtestLogin();
120
121 //Find Member
122 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
123
124 $this->type("sort_name", "$firstName $lastName");
125 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']/table/tbody/tr");
126 $this->click("xpath=//div[@id='memberSearch']/table/tbody/tr/td[11]/span/a[text()='View']");
127 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
128
129 //View Membership Record
130 $verifyData = array(
131 'Member' => $firstName . ' ' . $lastName,
132 'Membership Type' => $memTypeTitle1,
133 'Source' => 'Online Contribution:' . ' ' . $contributionTitle,
134 );
135 if ($payLater) {
136 $verifyData['Status'] = 'Pending';
137 }
138 else {
139
140 $verifyData['Status'] = 'New';
141 }
142 $this->webtestVerifyTabularData($verifyData);
143
144 // Click View action link on associated contribution record
145 $this->waitForElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']");
146 $this->click("xpath=//form[@id='MembershipView']/div[2]/div/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']");
147 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
148 //View Contribution Record
149 $verifyData = array(
150 'From' => $firstName . ' ' . $lastName,
151 'Total Amount' => '$ 100.00',
152 );
153 if ($payLater) {
154 $verifyData['Contribution Status'] = 'Pending : Pay Later';
155 }
156 else {
157 $verifyData['Contribution Status'] = 'Completed';
158 }
159 $this->webtestVerifyTabularData($verifyData);
160
161 // CRM-8141 signup for membership 2 with same anonymous user info (should create 2 separate membership records because membership orgs are different)
162 //logout
163 $this->webtestLogout();
164
165 $this->_testOnlineMembershipSignup($pageId, $memTypeTitle2, $firstName, $lastName, $payLater, $hash);
166
167 // Log in using webtestLogin() method
168 $this->webtestLogin();
169
170 //Find Member
171 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
172
173 $this->type("sort_name", "$firstName $lastName");
174 $this->click("_qf_Search_refresh");
175
176 $this->waitForPageToLoad($this->getTimeoutMsec());
177 $this->assertElementContainsText('search-status', '2 Results', 'Missing text: ' . '2 Results');
178 }
179
180 function _testOnlineMembershipSignup($pageId, $memTypeId, $firstName, $lastName, $payLater, $hash, $otherAmount = FALSE) {
181 //Open Live Contribution Page
182 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
183 // Select membership type 1
184 $this->waitForElementPresent("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label");
185 if ($memTypeId != 'No thank you') {
186 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label/span[2][contains(text(),'$memTypeId')]");
187 }
188
189 else {
190 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label[contains(text(),'$memTypeId')]");
191
192 }
193 if (!$otherAmount) {
194 $this->click("xpath=//div[@class='crm-section contribution_amount-section']/div[2]//span/label[text()='No thank you']");
195 }
196 else {
197 $this->type("xpath=//div[@class='content other_amount-content']/input", $otherAmount);
198 }
199 if ($payLater) {
200 $this->click("xpath=//div[@class='crm-section payment_processor-section']/div[2]//label[text()='Pay later label {$hash}']");
201 }
202 $this->type("email-5", $firstName . "@example.com");
203
204 $this->type("first_name", $firstName);
205 $this->type("last_name", $lastName);
206
207 $streetAddress = "100 Main Street";
208 $this->type("street_address-1", $streetAddress);
209 $this->type("city-1", "San Francisco");
210 $this->type("postal_code-1", "94117");
211 $this->select("country-1", "value=1228");
212 $this->select("state_province-1", "value=1001");
213 if (!$payLater) {
214 //Credit Card Info
215 $this->select("credit_card_type", "value=Visa");
216 $this->type("credit_card_number", "4111111111111111");
217 $this->type("cvv2", "000");
218 $this->select("credit_card_exp_date[M]", "value=1");
219 $this->select("credit_card_exp_date[Y]", "value=2020");
220
221 //Billing Info
222 $this->type("billing_first_name", $firstName . "billing");
223 $this->type("billing_last_name", $lastName . "billing");
224 $this->type("billing_street_address-5", "15 Main St.");
225 $this->type(" billing_city-5", "San Jose");
226 $this->select("billing_country_id-5", "value=1228");
227 $this->select("billing_state_province_id-5", "value=1004");
228 $this->type("billing_postal_code-5", "94129");
229 }
230 $this->click("_qf_Main_upload-bottom");
231 $this->waitForElementPresent("_qf_Confirm_next-bottom");
232
233 $this->click("_qf_Confirm_next-bottom");
234 $this->waitForPageToLoad($this->getTimeoutMsec());
235 }
236
237 function testOnlineMembershipCreateWithContribution() {
238 //login with admin credentials & make sure we do have required permissions.
239 $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms");
240 $this->changePermissions($permissions);
241
242 $hash = substr(sha1(rand()), 0, 7);
243 $rand = 2 * rand(2, 50);
244 // We need a payment processor
245 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
246 $amountSection = TRUE;
247 $payLater = TRUE;
248 $allowOtherAmmount = TRUE;
249 $onBehalf = FALSE;
250 $pledges = FALSE;
251 $recurring = FALSE;
252 $memberships = TRUE;
253 $memPriceSetId = NULL;
254 $friend = FALSE;
255 $profilePreId = 1;
256 $profilePostId = NULL;
257 $premiums = FALSE;
258 $widget = FALSE;
259 $pcp = FALSE;
260 $isSeparatePayment = FALSE;
261 $membershipsRequired = FALSE;
262 $fixedAmount = FALSE;
263 $contributionTitle = "Title $hash";
264 $pageId = $this->webtestAddContributionPage($hash,
265 $rand,
266 $contributionTitle,
267 array($processorName => 'Dummy'),
268 $amountSection,
269 $payLater,
270 $onBehalf,
271 $pledges,
272 $recurring,
273 $memberships,
274 $memPriceSetId,
275 $friend,
276 $profilePreId,
277 $profilePostId,
278 $premiums,
279 $widget,
280 $pcp,
281 TRUE,
282 FALSE,
283 $isSeparatePayment,
284 TRUE,
285 $allowOtherAmmount,
286 TRUE,
287 'Donation',
288 $fixedAmount,
289 $membershipsRequired
290 );
291 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
292 $lastName = 'An' . substr(sha1(rand()), 0, 7);
293
294 //logout
295 $this->webtestLogout();
296
297 $this->_testOnlineMembershipSignup($pageId, 'No thank you', $firstName, $lastName, FALSE, $hash, 50);
298
299 // Log in using webtestLogin() method
300 $this->webtestLogin();
301
302 //Find Contribution
303 $this->openCiviPage("contribute/search","reset=1", "contribution_date_low");
304
305 $this->type("sort_name", "$firstName $lastName");
306 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
307 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
308
309 //View Contribution Record and verify data
310 $expected = array(
311 'From' => "{$firstName} {$lastName}",
312 'Financial Type' => 'Donation',
313 'Total Amount' => '50.00',
314 'Contribution Status' => 'Completed',
315 'Received Into' => 'Deposit Bank Account',
316 'Source' => "Online Contribution: $contributionTitle",
317 'Online Contribution Page' => $contributionTitle,
318 );
319 $this->webtestVerifyTabularData($expected);
320 }
321 }