Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | ||
6a488035 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Member_OnlineMembershipCreateTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Member_OnlineMembershipCreateTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
38 | function testOnlineMembershipCreate() { | |
6a488035 TO |
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 | ||
42daf119 CW |
43 | // Log in as normal user |
44 | $this->webtestLogin(); | |
6a488035 TO |
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); | |
6a488035 | 49 | |
c3ad8633 CW |
50 | // Use default payment processor |
51 | $processorName = 'Test Processor'; | |
6a488035 TO |
52 | |
53 | // create contribution page with randomized title and default params | |
42daf119 CW |
54 | $amountSection = TRUE; |
55 | $payLater = TRUE; | |
6a488035 | 56 | $allowOtherAmmount = FALSE; |
42daf119 CW |
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; | |
6a488035 TO |
68 | $isSeparatePayment = TRUE; |
69 | $contributionTitle = "Title $hash"; | |
42daf119 | 70 | $pageId = $this->webtestAddContributionPage($hash, |
6a488035 TO |
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 | ||
6a488035 TO |
94 | // create two new membership types |
95 | $memTypeParams1 = $this->webtestAddMembershipType(); | |
42daf119 | 96 | $memTypeTitle1 = $memTypeParams1['membership_type']; |
343688b7 | 97 | $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1][text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href")); |
42daf119 | 98 | $memTypeId1 = $memTypeId1[1]; |
6a488035 TO |
99 | |
100 | $memTypeParams2 = $this->webtestAddMembershipType(); | |
42daf119 | 101 | $memTypeTitle2 = $memTypeParams2['membership_type']; |
343688b7 | 102 | $memTypeId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1][text()='{$memTypeTitle2}']/../td[12]/span/a[3]@href")); |
42daf119 | 103 | $memTypeId2 = $memTypeId2[1]; |
6a488035 TO |
104 | |
105 | // edit contribution page memberships tab to add two new membership types | |
1019390e | 106 | $this->openCiviPage("admin/contribute/membership", "reset=1&action=update&id={$pageId}", '_qf_MembershipBlock_next-bottom'); |
6a488035 TO |
107 | $this->click("membership_type_$memTypeId1"); |
108 | $this->click("membership_type_$memTypeId2"); | |
225a8648 | 109 | $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom'); |
6a488035 | 110 | $text = "'MembershipBlock' information has been saved."; |
6c5f7368 | 111 | $this->waitForText('crm-notification-container', $text); |
76e86fd8 | 112 | |
6a488035 | 113 | //logout |
42daf119 | 114 | $this->webtestLogout(); |
6a488035 TO |
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); | |
6a488035 TO |
121 | |
122 | // Log in using webtestLogin() method | |
123 | $this->webtestLogin(); | |
124 | ||
125 | //Find Member | |
1019390e | 126 | $this->openCiviPage("member/search", "reset=1", "member_end_date_high"); |
6a488035 TO |
127 | |
128 | $this->type("sort_name", "$firstName $lastName"); | |
225a8648 | 129 | $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']/table/tbody/tr"); |
6a488035 TO |
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 | } | |
76e86fd8 CW |
142 | else { |
143 | ||
1019390e PN |
144 | $verifyData['Status'] = 'New'; |
145 | } | |
96e6d962 | 146 | $this->webtestVerifyTabularData($verifyData); |
6a488035 TO |
147 | |
148 | // Click View action link on associated contribution record | |
343688b7 RK |
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]"); | |
6a488035 TO |
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 | } | |
1019390e PN |
160 | else { |
161 | $verifyData['Contribution Status'] = 'Completed'; | |
162 | } | |
96e6d962 | 163 | $this->webtestVerifyTabularData($verifyData); |
6a488035 TO |
164 | |
165 | // CRM-8141 signup for membership 2 with same anonymous user info (should create 2 separate membership records because membership orgs are different) | |
166 | //logout | |
42daf119 | 167 | $this->webtestLogout(); |
6a488035 TO |
168 | |
169 | $this->_testOnlineMembershipSignup($pageId, $memTypeTitle2, $firstName, $lastName, $payLater, $hash); | |
6a488035 TO |
170 | |
171 | // Log in using webtestLogin() method | |
172 | $this->webtestLogin(); | |
173 | ||
174 | //Find Member | |
1019390e | 175 | $this->openCiviPage("member/search", "reset=1", "member_end_date_high"); |
6a488035 TO |
176 | |
177 | $this->type("sort_name", "$firstName $lastName"); | |
178 | $this->click("_qf_Search_refresh"); | |
179 | ||
180 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
96e6d962 | 181 | $this->assertElementContainsText('search-status', '2 Results', 'Missing text: ' . '2 Results'); |
6a488035 TO |
182 | } |
183 | ||
4cbe18b8 | 184 | /** |
100fef9d CW |
185 | * @param int $pageId |
186 | * @param int $memTypeId | |
187 | * @param string $firstName | |
188 | * @param string $lastName | |
4cbe18b8 EM |
189 | * @param $payLater |
190 | * @param $hash | |
191 | * @param bool $otherAmount | |
192 | */ | |
1019390e | 193 | function _testOnlineMembershipSignup($pageId, $memTypeId, $firstName, $lastName, $payLater, $hash, $otherAmount = FALSE) { |
6a488035 | 194 | //Open Live Contribution Page |
1019390e | 195 | $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom"); |
6a488035 TO |
196 | // Select membership type 1 |
197 | $this->waitForElementPresent("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label"); | |
1019390e | 198 | if ($memTypeId != 'No thank you') { |
6a488035 | 199 | $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label/span[2][contains(text(),'$memTypeId')]"); |
76e86fd8 CW |
200 | } |
201 | ||
1019390e | 202 | else { |
76e86fd8 CW |
203 | $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label[contains(text(),'$memTypeId')]"); |
204 | ||
1019390e PN |
205 | } |
206 | if (!$otherAmount) { | |
207 | $this->click("xpath=//div[@class='crm-section contribution_amount-section']/div[2]//span/label[text()='No thank you']"); | |
208 | } | |
209 | else { | |
210 | $this->type("xpath=//div[@class='content other_amount-content']/input", $otherAmount); | |
211 | } | |
6a488035 TO |
212 | if ($payLater) { |
213 | $this->click("xpath=//div[@class='crm-section payment_processor-section']/div[2]//label[text()='Pay later label {$hash}']"); | |
214 | } | |
215 | $this->type("email-5", $firstName . "@example.com"); | |
343688b7 | 216 | $this->waitForElementPresent("first_name"); |
6a488035 | 217 | $this->type("first_name", $firstName); |
343688b7 | 218 | $this->waitForElementPresent("last_name"); |
6a488035 TO |
219 | $this->type("last_name", $lastName); |
220 | ||
221 | $streetAddress = "100 Main Street"; | |
343688b7 | 222 | $this->waitForElementPresent("street_address-1"); |
6a488035 TO |
223 | $this->type("street_address-1", $streetAddress); |
224 | $this->type("city-1", "San Francisco"); | |
225 | $this->type("postal_code-1", "94117"); | |
226 | $this->select("country-1", "value=1228"); | |
227 | $this->select("state_province-1", "value=1001"); | |
228 | if (!$payLater) { | |
229 | //Credit Card Info | |
230 | $this->select("credit_card_type", "value=Visa"); | |
231 | $this->type("credit_card_number", "4111111111111111"); | |
232 | $this->type("cvv2", "000"); | |
233 | $this->select("credit_card_exp_date[M]", "value=1"); | |
234 | $this->select("credit_card_exp_date[Y]", "value=2020"); | |
235 | ||
236 | //Billing Info | |
343688b7 | 237 | $this->waitForElementPresent("billing_first_name"); |
6a488035 | 238 | $this->type("billing_first_name", $firstName . "billing"); |
343688b7 | 239 | $this->waitForElementPresent("billing_last_name"); |
6a488035 TO |
240 | $this->type("billing_last_name", $lastName . "billing"); |
241 | $this->type("billing_street_address-5", "15 Main St."); | |
242 | $this->type(" billing_city-5", "San Jose"); | |
243 | $this->select("billing_country_id-5", "value=1228"); | |
244 | $this->select("billing_state_province_id-5", "value=1004"); | |
245 | $this->type("billing_postal_code-5", "94129"); | |
246 | } | |
247 | $this->click("_qf_Main_upload-bottom"); | |
6a488035 TO |
248 | $this->waitForElementPresent("_qf_Confirm_next-bottom"); |
249 | ||
250 | $this->click("_qf_Confirm_next-bottom"); | |
251 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
252 | } | |
76e86fd8 | 253 | |
1019390e PN |
254 | function testOnlineMembershipCreateWithContribution() { |
255 | //login with admin credentials & make sure we do have required permissions. | |
42daf119 CW |
256 | $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms"); |
257 | $this->changePermissions($permissions); | |
258 | ||
1019390e PN |
259 | $hash = substr(sha1(rand()), 0, 7); |
260 | $rand = 2 * rand(2, 50); | |
c3ad8633 CW |
261 | // Use default payment processor |
262 | $processorName = 'Test Processor'; | |
42daf119 CW |
263 | $amountSection = TRUE; |
264 | $payLater = TRUE; | |
1019390e | 265 | $allowOtherAmmount = TRUE; |
42daf119 CW |
266 | $onBehalf = FALSE; |
267 | $pledges = FALSE; | |
268 | $recurring = FALSE; | |
269 | $memberships = TRUE; | |
270 | $memPriceSetId = NULL; | |
271 | $friend = FALSE; | |
272 | $profilePreId = 1; | |
273 | $profilePostId = NULL; | |
274 | $premiums = FALSE; | |
275 | $widget = FALSE; | |
276 | $pcp = FALSE; | |
1019390e PN |
277 | $isSeparatePayment = FALSE; |
278 | $membershipsRequired = FALSE; | |
42daf119 | 279 | $fixedAmount = FALSE; |
1019390e | 280 | $contributionTitle = "Title $hash"; |
42daf119 | 281 | $pageId = $this->webtestAddContributionPage($hash, |
1019390e PN |
282 | $rand, |
283 | $contributionTitle, | |
284 | array($processorName => 'Dummy'), | |
285 | $amountSection, | |
286 | $payLater, | |
287 | $onBehalf, | |
288 | $pledges, | |
289 | $recurring, | |
290 | $memberships, | |
291 | $memPriceSetId, | |
292 | $friend, | |
293 | $profilePreId, | |
294 | $profilePostId, | |
295 | $premiums, | |
296 | $widget, | |
297 | $pcp, | |
298 | TRUE, | |
299 | FALSE, | |
300 | $isSeparatePayment, | |
301 | TRUE, | |
302 | $allowOtherAmmount, | |
303 | TRUE, | |
304 | 'Donation', | |
305 | $fixedAmount, | |
96e6d962 | 306 | $membershipsRequired |
1019390e PN |
307 | ); |
308 | $firstName = 'Ma' . substr(sha1(rand()), 0, 4); | |
309 | $lastName = 'An' . substr(sha1(rand()), 0, 7); | |
96e6d962 | 310 | |
1019390e | 311 | //logout |
42daf119 | 312 | $this->webtestLogout(); |
96e6d962 | 313 | |
1019390e | 314 | $this->_testOnlineMembershipSignup($pageId, 'No thank you', $firstName, $lastName, FALSE, $hash, 50); |
96e6d962 | 315 | |
1019390e | 316 | // Log in using webtestLogin() method |
96e6d962 | 317 | $this->webtestLogin(); |
1019390e PN |
318 | |
319 | //Find Contribution | |
320 | $this->openCiviPage("contribute/search","reset=1", "contribution_date_low"); | |
321 | ||
322 | $this->type("sort_name", "$firstName $lastName"); | |
225a8648 | 323 | $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']"); |
73072f84 | 324 | $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE); |
1019390e PN |
325 | |
326 | //View Contribution Record and verify data | |
327 | $expected = array( | |
328 | 'From' => "{$firstName} {$lastName}", | |
329 | 'Financial Type' => 'Donation', | |
330 | 'Total Amount' => '50.00', | |
331 | 'Contribution Status' => 'Completed', | |
332 | 'Received Into' => 'Deposit Bank Account', | |
333 | 'Source' => "Online Contribution: $contributionTitle", | |
334 | 'Online Contribution Page' => $contributionTitle, | |
335 | ); | |
336 | $this->webtestVerifyTabularData($expected); | |
337 | } | |
42daf119 | 338 | } |