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