Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
fa938177 | 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 25 | */ |
6a488035 | 26 | |
6a488035 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Contribute_OnlineContributionTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Contribute_OnlineContributionTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
00be9182 | 38 | public function testOnlineContributionAdd() { |
6a488035 TO |
39 | $this->webtestLogin(); |
40 | ||
c3ad8633 CW |
41 | // Use default payment processor |
42 | $processorName = 'Test Processor'; | |
6a488035 | 43 | $processorType = 'Dummy'; |
42daf119 CW |
44 | $pageTitle = substr(sha1(rand()), 0, 7); |
45 | $rand = 2 * rand(10, 50); | |
46 | $hash = substr(sha1(rand()), 0, 7); | |
6a488035 | 47 | $amountSection = TRUE; |
42daf119 CW |
48 | $payLater = FALSE; |
49 | $onBehalf = FALSE; | |
50 | $pledges = FALSE; | |
51 | $recurring = FALSE; | |
52 | $memberships = FALSE; | |
53 | $friend = TRUE; | |
54 | $profilePreId = 1; | |
6a488035 | 55 | $profilePostId = NULL; |
42daf119 CW |
56 | $premiums = FALSE; |
57 | $widget = FALSE; | |
58 | $pcp = FALSE; | |
6a488035 TO |
59 | $memPriceSetId = NULL; |
60 | ||
61 | // create a new online contribution page | |
62 | // create contribution page with randomized title and default params | |
63 | $pageId = $this->webtestAddContributionPage($hash, | |
64 | $rand, | |
65 | $pageTitle, | |
66 | array($processorName => $processorType), | |
67 | $amountSection, | |
68 | $payLater, | |
69 | $onBehalf, | |
70 | $pledges, | |
71 | $recurring, | |
72 | $memberships, | |
73 | $memPriceSetId, | |
74 | $friend, | |
75 | $profilePreId, | |
76 | $profilePostId, | |
77 | $premiums, | |
78 | $widget, | |
79 | $pcp | |
80 | ); | |
81 | ||
82 | //logout | |
42daf119 | 83 | $this->webtestLogout(); |
6a488035 TO |
84 | |
85 | //Open Live Contribution Page | |
f1224701 | 86 | $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom"); |
6a488035 TO |
87 | |
88 | $firstName = 'Ma' . substr(sha1(rand()), 0, 4); | |
89 | $lastName = 'An' . substr(sha1(rand()), 0, 7); | |
90 | $honorFirstName = 'In' . substr(sha1(rand()), 0, 4); | |
91 | $honorLastName = 'Hon' . substr(sha1(rand()), 0, 7); | |
92 | $honorEmail = $honorFirstName . "@example.com"; | |
93 | $honorSortName = $honorLastName . ', ' . $honorFirstName; | |
76e86fd8 | 94 | $honorDisplayName = 'Ms. ' . $honorFirstName . ' ' . $honorLastName; |
6a488035 TO |
95 | |
96 | $this->type("email-5", $firstName . "@example.com"); | |
97 | ||
98 | $this->type("first_name", $firstName); | |
99 | $this->type("last_name", $lastName); | |
100 | ||
101 | $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input"); | |
102 | $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 100); | |
103 | ||
104 | $streetAddress = "100 Main Street"; | |
105 | $this->type("street_address-1", $streetAddress); | |
106 | $this->type("city-1", "San Francisco"); | |
107 | $this->type("postal_code-1", "94117"); | |
108 | $this->select("country-1", "value=1228"); | |
109 | $this->select("state_province-1", "value=1001"); | |
6a488035 | 110 | // Honoree Info |
f1224701 | 111 | $this->click("xpath=id('Main')/div[3]/fieldset/div[2]/div/label[text()='In Honor of']"); |
6a488035 | 112 | |
1421174e | 113 | $this->select("honor[prefix_id]", "label=Ms."); |
114 | $this->type("honor[first_name]", $honorFirstName); | |
115 | $this->type("honor[last_name]", $honorLastName); | |
116 | $this->type("honor[email-1]", $honorEmail); | |
76e86fd8 | 117 | |
6a488035 TO |
118 | //Credit Card Info |
119 | $this->select("credit_card_type", "value=Visa"); | |
120 | $this->type("credit_card_number", "4111111111111111"); | |
121 | $this->type("cvv2", "000"); | |
122 | $this->select("credit_card_exp_date[M]", "value=1"); | |
123 | $this->select("credit_card_exp_date[Y]", "value=2020"); | |
124 | ||
125 | //Billing Info | |
126 | $this->type("billing_first_name", $firstName . "billing"); | |
127 | $this->type("billing_last_name", $lastName . "billing"); | |
128 | $this->type("billing_street_address-5", "15 Main St."); | |
129 | $this->type(" billing_city-5", "San Jose"); | |
130 | $this->select("billing_country_id-5", "value=1228"); | |
131 | $this->select("billing_state_province_id-5", "value=1004"); | |
132 | $this->type("billing_postal_code-5", "94129"); | |
225a8648 | 133 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom"); |
2917a714 WA |
134 | $this->waitForElementPresent("xpath=//div[@class='crm-group billing_name_address-group']//div[@class='crm-section no-label billing_name-section']"); |
135 | $this->assertElementContainsText("xpath=//div[@class='crm-group billing_name_address-group']//div[@class='crm-section no-label billing_name-section']", $firstName . "billing"); | |
136 | $this->assertElementContainsText("xpath=//div[@class='crm-group billing_name_address-group']//div[@class='crm-section no-label billing_name-section']", $lastName . "billing"); | |
18a7161f | 137 | |
6a488035 TO |
138 | $this->click("_qf_Confirm_next-bottom"); |
139 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
140 | ||
2917a714 WA |
141 | $this->waitForElementPresent("xpath=//div[@class='crm-group billing_name_address-group']//div[@class='crm-section no-label billing_name-section']"); |
142 | $this->assertElementContainsText("xpath=//div[@class='crm-group billing_name_address-group']//div[@class='crm-section no-label billing_name-section']", $firstName . "billing"); | |
143 | $this->assertElementContainsText("xpath=//div[@class='crm-group billing_name_address-group']//div[@class='crm-section no-label billing_name-section']", $lastName . "billing"); | |
18a7161f | 144 | |
6a488035 | 145 | //login to check contribution |
6a488035 TO |
146 | |
147 | // Log in using webtestLogin() method | |
148 | $this->webtestLogin(); | |
149 | ||
150 | //Find Contribution | |
42daf119 | 151 | $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low"); |
8fb46c61 | 152 | $this->type("sort_name", "$lastName $firstName"); |
f1224701 | 153 | $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]"); |
16dc87ac | 154 | $this->clickLink("_qf_Search_refresh", "xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", FALSE); |
2815a5aa | 155 | $this->clickLink("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE); |
6a488035 TO |
156 | |
157 | //View Contribution Record and verify data | |
158 | $expected = array( | |
42daf119 CW |
159 | 'From' => "{$firstName} {$lastName}", |
160 | 'Financial Type' => 'Donation', | |
161 | 'Total Amount' => '100.00', | |
6a488035 | 162 | 'Contribution Status' => 'Completed', |
6a488035 TO |
163 | ); |
164 | $this->webtestVerifyTabularData($expected); | |
1421174e | 165 | //View Soft Credit record of type 'Honor of' |
166 | $this->waitForTextPresent($honorDisplayName); | |
167 | $this->waitForTextPresent('100.00 (In Honor of)'); | |
168 | ||
6a488035 TO |
169 | // Check for Honoree contact created |
170 | $this->click("css=input#sort_name_navigation"); | |
171 | $this->type("css=input#sort_name_navigation", $honorSortName); | |
172 | $this->typeKeys("css=input#sort_name_navigation", $honorSortName); | |
173 | ||
174 | // wait for result list | |
0ecb5006 | 175 | $this->waitForElementPresent("css=ul.ui-autocomplete li"); |
6a488035 TO |
176 | |
177 | // visit contact summary page | |
0ecb5006 | 178 | $this->click("css=ul.ui-autocomplete li"); |
6a488035 TO |
179 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
180 | ||
181 | // Is contact present? | |
182 | $this->assertTrue($this->isTextPresent("$honorDisplayName"), "Honoree contact not found."); | |
76e86fd8 | 183 | |
2b63342b | 184 | // CRM-16064 - Contributions pricesets charge $1 more than selected |
185 | $contributionAmt = number_format($rand, 2); | |
186 | $label = "Label $hash"; | |
187 | $this->_verifyContributionAmt($pageId, $contributionAmt, $label); | |
188 | ||
6c6e6187 | 189 | } |
3fb990f4 | 190 | |
92915c55 | 191 | public function testOnlineContributionWithZeroAmount() { |
3fb990f4 RN |
192 | $this->webtestLogin(); |
193 | ||
c3ad8633 CW |
194 | // Use default payment processor |
195 | $processorName = 'Test Processor'; | |
3fb990f4 RN |
196 | $processorType = 'Dummy'; |
197 | $pageTitle = substr(sha1(rand()), 0, 7); | |
198 | $rand = 2 * rand(10, 50); | |
199 | $hash = substr(sha1(rand()), 0, 7); | |
200 | $amountSection = TRUE; | |
201 | $payLater = FALSE; | |
202 | $onBehalf = FALSE; | |
203 | $pledges = FALSE; | |
204 | $recurring = FALSE; | |
205 | $memberships = FALSE; | |
206 | $friend = FALSE; | |
207 | $profilePreId = NULL; | |
208 | $profilePostId = NULL; | |
209 | $premiums = FALSE; | |
210 | $widget = FALSE; | |
211 | $pcp = FALSE; | |
212 | $memPriceSetId = NULL; | |
213 | ||
214 | // create a new online contribution page | |
215 | // create contribution page with randomized title and default params | |
216 | $pageId = $this->webtestAddContributionPage($hash, | |
217 | $rand, | |
218 | $pageTitle, | |
219 | array($processorName => $processorType), | |
220 | $amountSection, | |
221 | $payLater, | |
222 | $onBehalf, | |
223 | $pledges, | |
224 | $recurring, | |
225 | $memberships, | |
226 | $memPriceSetId, | |
227 | $friend, | |
228 | $profilePreId, | |
229 | $profilePostId, | |
230 | $premiums, | |
231 | $widget, | |
232 | $pcp | |
233 | ); | |
1421174e | 234 | |
3fb990f4 RN |
235 | $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_cancel-bottom'); |
236 | $this->type('label_1', "Label $hash"); | |
237 | $this->type('value_1', 0); | |
238 | $this->clickLink('_qf_Amount_upload_done-top'); | |
239 | ||
240 | //Contribution using Contribution Options | |
241 | $this->_doContributionAndVerifyData($pageId); | |
1421174e | 242 | |
3fb990f4 RN |
243 | //add priceset |
244 | $this->openCiviPage("admin/price", "reset=1&action=add", '_qf_Set_next-bottom'); | |
245 | $this->type('title', "Test Priceset $rand"); | |
246 | $this->check('extends_2'); | |
247 | $this->select("financial_type_id", "label=Donation"); | |
0512e9c6 | 248 | $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom', FALSE); |
3fb990f4 RN |
249 | $sid = $this->urlArg('sid'); |
250 | //add field | |
251 | $this->type('label', "Testfield"); | |
252 | $this->select('html_type', "value=Radio"); | |
253 | $this->type('option_label_1', 'test Label'); | |
254 | $this->type('option_amount_1', 0.00); | |
0512e9c6 | 255 | $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom', FALSE); |
3fb990f4 RN |
256 | $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_cancel-bottom'); |
257 | $this->select('price_set_id', "value=$sid"); | |
0512e9c6 | 258 | $this->clickLink('_qf_Amount_upload_done-bottom', FALSE); |
3fb990f4 RN |
259 | |
260 | //Contribution using priceset | |
1421174e | 261 | $this->_doContributionAndVerifyData($pageId, TRUE); |
3fb990f4 RN |
262 | } |
263 | ||
4cbe18b8 | 264 | /** |
100fef9d | 265 | * @param int $pageId |
4cbe18b8 EM |
266 | * @param bool $priceSet |
267 | */ | |
00be9182 | 268 | public function _doContributionAndVerifyData($pageId, $priceSet = FALSE) { |
3fb990f4 RN |
269 | //logout |
270 | $this->webtestLogout(); | |
271 | $amountLabel = 'Total Amount'; | |
b4a57e40 | 272 | $amountValue = '0.00'; |
3fb990f4 | 273 | //Open Live Contribution Page |
f1224701 | 274 | $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom"); |
3fb990f4 RN |
275 | |
276 | $firstName = 'Ma' . substr(sha1(rand()), 0, 4); | |
277 | $lastName = 'An' . substr(sha1(rand()), 0, 7); | |
08936462 WA |
278 | $email = $firstName . "@example.com"; |
279 | $this->type("email-5", $email); | |
3fb990f4 RN |
280 | |
281 | if ($priceSet) { | |
282 | $this->click("xpath=//div[@id='priceset']/div/div[2]/div/span/input"); | |
283 | $amountLabel = 'Contribution Amount'; | |
284 | $amountValue = 'Contribution Total: $ 0.00'; | |
285 | } | |
286 | ||
287 | //Credit Card Info | |
288 | $this->select("credit_card_type", "value=Visa"); | |
289 | $this->type("credit_card_number", "4111111111111111"); | |
290 | $this->type("cvv2", "000"); | |
291 | $this->select("credit_card_exp_date[M]", "value=1"); | |
292 | $this->select("credit_card_exp_date[Y]", "value=2020"); | |
293 | ||
294 | //Billing Info | |
295 | $this->type("billing_first_name", $firstName); | |
296 | $this->type("billing_last_name", $lastName); | |
297 | $this->type("billing_street_address-5", "15 Main St."); | |
298 | $this->type(" billing_city-5", "San Jose"); | |
299 | $this->select("billing_country_id-5", "value=1228"); | |
300 | $this->select("billing_state_province_id-5", "value=1004"); | |
301 | $this->type("billing_postal_code-5", "94129"); | |
302 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom"); | |
303 | ||
304 | $this->clickLink("_qf_Confirm_next-bottom", NULL); | |
305 | ||
3fb990f4 RN |
306 | //login to check contribution |
307 | ||
308 | // Log in using webtestLogin() method | |
309 | $this->webtestLogin(); | |
310 | ||
6c6e6187 | 311 | //Find Contribution |
3fb990f4 | 312 | $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low"); |
08936462 | 313 | $this->type("sort_name", "$email"); |
7051f2e5 | 314 | $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]"); |
08936462 WA |
315 | $this->waitForAjaxContent(); |
316 | $this->click("xpath=//div[@class='crm-accordion-wrapper crm-contribution_search_form-accordion ']/div[2]/table/tbody/tr[8]/td[1]/table/tbody/tr[3]/td[2]/label[1]"); | |
deeea38d WA |
317 | $this->clickLink("_qf_Search_refresh", "xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", FALSE); |
318 | $this->clickLink("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE); | |
3fb990f4 RN |
319 | |
320 | //View Contribution Record and verify data | |
321 | $expected = array( | |
6e677443 | 322 | 'From' => "{$firstName} {$lastName}", |
3fb990f4 RN |
323 | 'Financial Type' => 'Donation', |
324 | $amountLabel => $amountValue, | |
21dfd5f5 | 325 | 'Contribution Status' => 'Completed', |
3fb990f4 RN |
326 | ); |
327 | $this->webtestVerifyTabularData($expected); | |
6a488035 | 328 | } |
96025800 | 329 | |
2b63342b | 330 | public function _verifyContributionAmt($pageId, $contributionAmt, $label) { |
331 | // logout | |
332 | $this->webtestLogout(); | |
333 | ||
334 | //Open Live Contribution Page | |
f1224701 | 335 | $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom"); |
2b63342b | 336 | $firstName = 'Ma' . substr(sha1(rand()), 0, 4); |
337 | $lastName = 'An' . substr(sha1(rand()), 0, 7); | |
338 | $this->type("email-5", $firstName . "@example.com"); | |
339 | ||
340 | $this->type("first_name", $firstName); | |
341 | $this->type("last_name", $lastName); | |
342 | $this->check("xpath=//div[@id='priceset']/div[contains(@class, 'contribution_amount-section')]//div[contains(@class, 'contribution_amount-row1')]/span/input"); | |
343 | $streetAddress = "100 Main Street"; | |
344 | $this->type("street_address-1", $streetAddress); | |
345 | $this->type("city-1", "San Francisco"); | |
346 | $this->type("postal_code-1", "94117"); | |
347 | $this->select("country-1", "value=1228"); | |
348 | $this->select("state_province-1", "value=1001"); | |
349 | ||
350 | //Credit Card Info | |
351 | $this->select("credit_card_type", "value=Visa"); | |
352 | $this->type("credit_card_number", "4111111111111111"); | |
353 | $this->type("cvv2", "000"); | |
354 | $this->select("credit_card_exp_date[M]", "value=1"); | |
355 | $this->select("credit_card_exp_date[Y]", "value=2020"); | |
356 | ||
357 | //Billing Info | |
358 | $this->type("billing_first_name", $firstName . "billing"); | |
359 | $this->type("billing_last_name", $lastName . "billing"); | |
360 | $this->type("billing_street_address-5", "15 Main St."); | |
361 | $this->type(" billing_city-5", "San Jose"); | |
362 | $this->select("billing_country_id-5", "value=1228"); | |
363 | $this->select("billing_state_province_id-5", "value=1004"); | |
364 | $this->type("billing_postal_code-5", "94129"); | |
365 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom"); | |
366 | ||
367 | $this->assertElementContainsText("xpath=//div[contains(@class, 'amount_display-group')]//div[@class='display-block']/strong", "$ $contributionAmt - $label", "Contribution amount does not match"); | |
368 | $this->clickLink("_qf_Confirm_next-bottom"); | |
369 | $this->assertElementContainsText("xpath=//div[contains(@class, 'amount_display-group')]//div[@class='display-block']/strong", "$ $contributionAmt - $label", "Contribution amount does not match"); | |
370 | // Log in using webtestLogin() method | |
371 | $this->webtestLogin(); | |
372 | $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low"); | |
373 | ||
374 | $this->type("sort_name", "$lastName $firstName"); | |
f1224701 | 375 | $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]"); |
4dc8abb7 WA |
376 | $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table[@class='selector row-highlight']//tbody/tr[1]/td[10]/span/a[text()='View']"); |
377 | $this->clickLink("xpath=//div[@id='contributionSearch']//table[@class='selector row-highlight']//tbody/tr[1]/td[10]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE); | |
2b63342b | 378 | |
379 | //View Contribution Record and verify data | |
380 | $expected = array( | |
381 | 'From' => "{$firstName} {$lastName}", | |
382 | 'Financial Type' => 'Donation', | |
383 | 'Total Amount' => $contributionAmt, | |
384 | 'Contribution Status' => 'Completed', | |
385 | ); | |
386 | $this->webtestVerifyTabularData($expected); | |
387 | } | |
65158765 | 388 | |
feb02c31 | 389 | public function testOnlineContributionWithPremium() { |
810fa73d | 390 | //CRM-16713: Contribution search by premiums on find contribution form. |
feb02c31 WA |
391 | $this->webtestLogin(); |
392 | ||
393 | // Use default payment processor | |
394 | $processorName = 'Test Processor'; | |
395 | $processorType = 'Dummy'; | |
396 | $pageTitle = substr(sha1(rand()), 0, 7); | |
397 | $rand = 2 * rand(10, 50); | |
398 | $hash = substr(sha1(rand()), 0, 7); | |
399 | $amountSection = TRUE; | |
400 | $payLater = FALSE; | |
401 | $onBehalf = FALSE; | |
402 | $pledges = FALSE; | |
403 | $recurring = FALSE; | |
404 | $memberships = FALSE; | |
405 | $friend = TRUE; | |
406 | $profilePreId = 1; | |
407 | $profilePostId = NULL; | |
408 | $premiums = TRUE; | |
409 | $widget = FALSE; | |
410 | $pcp = FALSE; | |
411 | $memPriceSetId = NULL; | |
412 | ||
413 | // create a new online contribution page | |
414 | // create contribution page with randomized title and default params | |
415 | $pageId = $this->webtestAddContributionPage($hash, | |
416 | $rand, | |
417 | $pageTitle, | |
418 | array($processorName => $processorType), | |
419 | $amountSection, | |
420 | $payLater, | |
421 | $onBehalf, | |
422 | $pledges, | |
423 | $recurring, | |
424 | $memberships, | |
425 | $memPriceSetId, | |
426 | $friend, | |
427 | $profilePreId, | |
428 | $profilePostId, | |
429 | $premiums, | |
430 | $widget, | |
431 | $pcp | |
432 | ); | |
433 | ||
434 | //logout | |
435 | $this->webtestLogout(); | |
436 | ||
437 | //Open Live Contribution Page | |
f1224701 | 438 | $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom"); |
feb02c31 WA |
439 | |
440 | $firstName = 'Ma' . substr(sha1(rand()), 0, 4); | |
441 | $lastName = 'An' . substr(sha1(rand()), 0, 7); | |
442 | ||
443 | $this->type("email-5", $firstName . "@example.com"); | |
444 | ||
445 | $this->waitForAjaxContent(); | |
446 | $this->click("xpath=//div[@id='premiums-listings']/div[2]/div[1]"); | |
447 | $this->waitForAjaxContent(); | |
448 | $this->select("xpath=//div[@id='premiums']/fieldset/div[@id='premiums-listings']/div[2]/div[2]/div[2]/div[4]/p/select", "value=Black"); | |
449 | ||
450 | $this->type("first_name", $firstName); | |
451 | $this->type("last_name", $lastName); | |
452 | ||
453 | $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input"); | |
454 | $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 100); | |
455 | ||
456 | $streetAddress = "100 Main Street"; | |
457 | $this->type("street_address-1", $streetAddress); | |
458 | $this->type("city-1", "San Francisco"); | |
459 | $this->type("postal_code-1", "94117"); | |
460 | $this->select("country-1", "value=1228"); | |
461 | $this->select("state_province-1", "value=1001"); | |
462 | ||
463 | //Credit Card Info | |
464 | $this->select("credit_card_type", "value=Visa"); | |
465 | $this->type("credit_card_number", "4111111111111111"); | |
466 | $this->type("cvv2", "000"); | |
467 | $this->select("credit_card_exp_date[M]", "value=1"); | |
468 | $this->select("credit_card_exp_date[Y]", "value=2020"); | |
469 | ||
470 | //Billing Info | |
471 | $this->type("billing_first_name", $firstName . "billing"); | |
472 | $this->type("billing_last_name", $lastName . "billing"); | |
473 | $this->type("billing_street_address-5", "15 Main St."); | |
474 | $this->type(" billing_city-5", "San Jose"); | |
475 | $this->select("billing_country_id-5", "value=1228"); | |
476 | $this->select("billing_state_province_id-5", "value=1004"); | |
477 | $this->type("billing_postal_code-5", "94129"); | |
478 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom"); | |
479 | ||
480 | $this->click("_qf_Confirm_next-bottom"); | |
481 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
482 | ||
483 | // Log in using webtestLogin() method | |
484 | $this->webtestLogin(); | |
485 | ||
486 | //Find Contribution | |
487 | $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low"); | |
f1224701 | 488 | $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]"); |
feb02c31 WA |
489 | $this->type("sort_name", "$lastName $firstName"); |
490 | $this->multiselect2('contribution_product_id', array('Coffee Mug')); | |
491 | $this->click("_qf_Search_refresh"); | |
2917a714 | 492 | $this->waitForAjaxContent(); |
deeea38d WA |
493 | $this->waitForElementPresent("xpath=//table[@class='selector row-highlight']/tbody//tr/td[10]/span//a[text()='View']"); |
494 | $this->click("xpath=//table[@class='selector row-highlight']/tbody//tr/td[2]/a[text()='{$lastName}, {$firstName}']/../../td[10]/span//a[text()='View']"); | |
feb02c31 WA |
495 | $this->waitForElementPresent("xpath=//button//span[contains(text(),'Done')]"); |
496 | ||
497 | //View Contribution Record and verify data | |
498 | $expected = array( | |
499 | 'From' => "{$firstName} {$lastName}", | |
500 | 'Financial Type' => 'Donation', | |
501 | 'Total Amount' => '100.00', | |
502 | 'Contribution Status' => 'Completed', | |
503 | 'Premium' => 'Coffee Mug', | |
504 | ); | |
505 | $this->webtestVerifyTabularData($expected); | |
506 | } | |
507 | ||
2f44fc96 | 508 | /** |
509 | * CRM-19263 - Test online pay now functionality | |
510 | */ | |
511 | public function testOnlineContributionWithPayNowLink() { | |
58466af1 | 512 | $this->webtestLogin(); |
513 | $pageId = 1; | |
514 | $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", 'is_pay_later'); | |
515 | $this->check('is_pay_later'); | |
516 | $this->type('pay_later_text', "I will send payment by check"); | |
517 | $this->fillRichTextField('pay_later_receipt', "I will send payment by check"); | |
518 | $this->clickLink("_qf_Amount_upload_done-bottom"); | |
519 | ||
520 | //add financial type of account type expense | |
521 | $financialType = 'Donation'; | |
522 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); | |
523 | $usedFor = 'Contribution'; | |
524 | $setHelp = 'Select your conference options.'; | |
525 | $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType); | |
526 | $sid = $this->urlArg('sid'); | |
527 | ||
528 | $validateStrings = array(); | |
529 | $fields = array( | |
530 | 'Full Conference' => 'Text', | |
531 | 'Meal Choice' => 'Select', | |
532 | 'Pre-conference Meetup?' => 'Radio', | |
533 | 'Evening Sessions' => 'CheckBox', | |
534 | ); | |
535 | ||
536 | $this->_testAddPriceFields($fields, $validateStrings, $financialType); | |
537 | ||
538 | //Add profile Details | |
539 | $firstName = 'Ma' . substr(sha1(rand()), 0, 4); | |
540 | $lastName = 'An' . substr(sha1(rand()), 0, 7); | |
541 | $name = $this->_testCreateUser($firstName, $lastName); | |
542 | $this->openCiviPage("admin/synchUser", "reset=1", NULL); | |
543 | $this->clickLink("_qf_CMSUser_next-bottom"); | |
544 | ||
545 | $this->openCiviPage("admin/setting/preferences/contribute", "reset=1", "deferred_revenue_enabled"); | |
546 | $this->check('deferred_revenue_enabled'); | |
547 | $this->waitForElementPresent('default_invoice_page'); | |
548 | $this->select('default_invoice_page', "value=$pageId"); | |
549 | $this->clickLink("_qf_Contribute_next-bottom"); | |
550 | ||
551 | $this->webtestLogin($name, "Test12345"); | |
552 | $this->_testContributeWithPayLater($pageId, $firstName); | |
553 | ||
554 | $this->_testContributeWithPayNow($firstName); | |
555 | ||
556 | $this->openCiviPage("user", "reset=1"); | |
557 | $this->assertFalse($this->isTextPresent("Pay Now")); | |
558 | ||
559 | $this->webtestLogin(); | |
560 | ||
561 | $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", 'price_set_id'); | |
562 | $this->select('price_set_id', "value=9"); | |
563 | $this->clickLink("_qf_Amount_upload_done-bottom"); | |
564 | ||
565 | $this->webtestLogin($name, "Test12345"); | |
566 | ||
567 | $this->_testContributeWithPayLater($pageId, $firstName, TRUE); | |
568 | ||
569 | $this->_testContributeWithPayNow($firstName, TRUE); | |
570 | ||
571 | $this->openCiviPage("user", "reset=1"); | |
572 | $this->assertFalse($this->isTextPresent("Pay Now")); | |
573 | ||
574 | // Type search name in autocomplete. | |
575 | $this->webtestLogin(); | |
576 | $this->openCiviPage("civicrm/dashboard", "reset=1", 'sort_name_navigation'); | |
577 | $this->click('sort_name_navigation'); | |
578 | $this->type('css=input#sort_name_navigation', $firstName); | |
579 | $this->typeKeys('css=input#sort_name_navigation', $firstName); | |
580 | $this->waitForElementPresent("css=ul.ui-autocomplete li"); | |
581 | $this->clickLink("css=ul.ui-autocomplete li", 'tab_contribute'); | |
582 | ||
583 | $this->click('css=li#tab_contribute a'); | |
584 | $this->waitForElementPresent('link=Record Contribution (Check, Cash, EFT ...)'); | |
585 | ||
586 | $amountValues = array( | |
587 | 1 => '$ 588.50', | |
588 | 2 => '$ 98.50', | |
589 | ); | |
2f44fc96 | 590 | foreach ($amountValues as $row => $amount) { |
58466af1 | 591 | $this->clickLink("xpath=//table[@class='selector row-highlight']/tbody/tr[{$row}]/td[8]/span//a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE); |
592 | ||
593 | // View Contribution Record and test for expected values | |
594 | $expected = array( | |
595 | 'From' => "{$firstName} {$lastName}", | |
596 | 'Financial Type' => $financialType, | |
597 | 'Fee Amount' => '$ 1.50', | |
598 | 'Net Amount' => $amount, | |
599 | 'Received Into' => 'Payment Processor Account', | |
600 | 'Payment Method' => 'Credit Card (Test Processor)', | |
601 | 'Contribution Status' => 'Completed', | |
602 | ); | |
603 | $this->webtestVerifyTabularData($expected); | |
604 | ||
605 | $this->clickAjaxLink("xpath=//span[text()='Done']"); | |
606 | } | |
607 | } | |
608 | ||
2f44fc96 | 609 | /** |
610 | * Contribute using pay now link | |
611 | * @param string $firstName | |
612 | * @param bool $priceSet | |
613 | */ | |
58466af1 | 614 | public function _testContributeWithPayNow($firstName, $priceSet = FALSE) { |
615 | //user dashboard | |
616 | $this->openCiviPage("user", "reset=1"); | |
617 | $this->waitForElementPresent("xpath=//a/span[contains(text(), 'Pay Now')]"); | |
618 | $this->clickLink("xpath=//a/span[contains(text(), 'Pay Now')]"); | |
619 | ||
620 | if (empty($priceSet)) { | |
621 | $this->waitForElementPresent("total_amount"); | |
fe552de9 | 622 | $this->assertTrue($this->isElementPresent("xpath=//input[@id='total_amount'][@readonly=1][@value='100.00']")); |
58466af1 | 623 | } |
624 | else { | |
625 | $this->assertElementContainsText("xpath=//div[@class='header-dark']", "Contribution Information"); | |
626 | $this->assertElementContainsText("xpath=//div[@class='crm-section no-label total_amount-section']", "Contribution Total: $ 590.00"); | |
627 | } | |
628 | ||
629 | $this->assertFalse($this->isElementPresent("priceset")); | |
630 | $this->assertFalse($this->isElementPresent("xpath=//div[@class='crm-public-form-item crm-section is_pledge-section']")); | |
631 | $this->assertFalse($this->isElementPresent("xpath=//div[@class='crm-public-form-item crm-section premium_block-section']")); | |
632 | $this->assertFalse($this->isElementPresent("xpath=//div[@class='crm-public-form-item crm-group custom_pre_profile-group']")); | |
633 | $this->assertFalse($this->isElementPresent("xpath=//input[@id=email-5]")); | |
37e877b2 | 634 | $this->assertFalse($this->isElementPresent("xpath=//input[@name='payment_processor_id'][@value=0]")); |
58466af1 | 635 | $this->click("xpath=//input[@name='payment_processor_id'][@value=1]"); |
636 | $this->waitForAjaxContent(); | |
637 | ||
638 | $this->webtestAddCreditCardDetails(); | |
639 | $this->webtestAddBillingDetails(); | |
640 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom"); | |
641 | ||
642 | $this->clickLink("_qf_Confirm_next-bottom"); | |
643 | $firstName = strtolower($firstName); | |
644 | $emailText = "An email receipt has also been sent to {$firstName}@example.com"; | |
645 | $this->waitForTextPresent($emailText); | |
646 | ||
647 | } | |
648 | ||
2f44fc96 | 649 | /** |
650 | * Contribute with pay later | |
651 | * | |
652 | * @param int $pageId | |
653 | * @param string $firstName | |
654 | * @param bool $priceSet | |
655 | */ | |
58466af1 | 656 | public function _testContributeWithPayLater($pageId, $firstName, $priceSet = FALSE) { |
657 | $this->openCiviPage("contribute/transact", "reset=1&action=preview&id=$pageId", NULL); | |
658 | $this->waitForElementPresent("email-5"); | |
659 | ||
660 | $this->type("email-5", $firstName . "@example.com"); | |
661 | ||
662 | if (empty($priceSet)) { | |
663 | $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input"); | |
664 | $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 100); | |
665 | $this->typeKeys("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 100); | |
666 | } | |
667 | else { | |
668 | $this->type("xpath=//input[@class='four crm-form-text required']", "1"); | |
669 | $this->click("xpath=//input[@class='crm-form-radio']"); | |
670 | $this->click("xpath=//input[@class='crm-form-checkbox']"); | |
671 | } | |
672 | ||
673 | $this->waitForTextPresent("Payment Method"); | |
674 | $payLaterText = "I will send payment by check"; | |
675 | $this->click("xpath=//label[text() = '{$payLaterText}']/preceding-sibling::input[1]"); | |
676 | ||
677 | $this->waitForAjaxContent(); | |
678 | $this->clickLink("_qf_Main_upload-bottom"); | |
679 | $this->waitForElementPresent("xpath=//div[@class='bold pay_later_receipt-section']"); | |
680 | ||
681 | $payLaterInstructionsText = "I will send payment by check"; | |
682 | $this->assertElementContainsText("xpath=//div[@class='bold pay_later_receipt-section']/p", $payLaterInstructionsText); | |
683 | $this->clickLink("_qf_Confirm_next-bottom"); | |
684 | ||
685 | $this->waitForElementPresent("xpath=//div[@class='help']/div/p"); | |
686 | $this->assertElementContainsText("xpath=//div[@class='help']/div/p", $payLaterInstructionsText); | |
687 | } | |
688 | ||
2f44fc96 | 689 | /** |
690 | * Create test user | |
691 | * | |
692 | * @param string $firstName | |
693 | * @param string $lastName | |
694 | * | |
695 | * @return string | |
696 | */ | |
58466af1 | 697 | public function _testCreateUser($firstName, $lastName) { |
698 | $this->open($this->sboxPath . "admin/people/create"); | |
699 | ||
700 | $this->waitForElementPresent("edit-submit"); | |
701 | ||
702 | $name = "TestUser" . substr(sha1(rand()), 0, 4); | |
703 | $this->type("edit-name", $name); | |
704 | ||
705 | $emailId = substr(sha1(rand()), 0, 7) . '@web.com'; | |
706 | $this->type("edit-mail", $emailId); | |
707 | $this->type("edit-pass-pass1", "Test12345"); | |
708 | $this->type("edit-pass-pass2", "Test12345"); | |
709 | ||
710 | $this->type("first_name", $firstName); | |
711 | $this->type("last_name", $lastName); | |
712 | ||
713 | //Address Details | |
714 | $this->type("street_address-1", "902C El Camino Way SW"); | |
715 | $this->type("city-1", "Dumfries"); | |
716 | $this->type("postal_code-1", "1234"); | |
717 | $this->select("state_province-1", "value=1019"); | |
718 | ||
719 | $this->click("edit-submit"); | |
720 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
721 | return $name; | |
722 | } | |
723 | ||
3fb990f4 | 724 | } |