Merge pull request #8187 from kenwest/CRM-18275
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / OnlineContributionTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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_Contribute_OnlineContributionTest
31 */
32 class WebTest_Contribute_OnlineContributionTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 public function testOnlineContributionAdd() {
39 $this->webtestLogin();
40
41 // Use default payment processor
42 $processorName = 'Test Processor';
43 $processorType = 'Dummy';
44 $pageTitle = substr(sha1(rand()), 0, 7);
45 $rand = 2 * rand(10, 50);
46 $hash = substr(sha1(rand()), 0, 7);
47 $amountSection = TRUE;
48 $payLater = FALSE;
49 $onBehalf = FALSE;
50 $pledges = FALSE;
51 $recurring = FALSE;
52 $memberships = FALSE;
53 $friend = TRUE;
54 $profilePreId = 1;
55 $profilePostId = NULL;
56 $premiums = FALSE;
57 $widget = FALSE;
58 $pcp = FALSE;
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
83 $this->webtestLogout();
84
85 //Open Live Contribution Page
86 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom");
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;
94 $honorDisplayName = 'Ms. ' . $honorFirstName . ' ' . $honorLastName;
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");
110 // Honoree Info
111 $this->click("xpath=id('Main')/div[3]/fieldset/div[2]/div/label[text()='In Honor of']");
112
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);
117
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");
133 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
134
135 $this->waitForElementPresent("xpath=//div[@class='crm-section no-label billing_name-section']");
136 $this->assertElementContainsText("xpath=//div[@class='crm-section no-label billing_name-section']", $firstName . "billing");
137 $this->assertElementContainsText("xpath=//div[@class='crm-section no-label billing_name-section']", $lastName . "billing");
138
139 $this->click("_qf_Confirm_next-bottom");
140 $this->waitForPageToLoad($this->getTimeoutMsec());
141
142 $this->waitForElementPresent("xpath=//div[@class='crm-section no-label billing_name-section']");
143 $this->assertElementContainsText("xpath=//div[@class='crm-section no-label billing_name-section']", $firstName . "billing");
144 $this->assertElementContainsText("xpath=//div[@class='crm-section no-label billing_name-section']", $lastName . "billing");
145
146 //login to check contribution
147
148 // Log in using webtestLogin() method
149 $this->webtestLogin();
150
151 //Find Contribution
152 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
153 $this->type("sort_name", "$lastName $firstName");
154 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
155 $this->clickLink("_qf_Search_refresh", "xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']");
156 $this->clickLink("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
157
158 //View Contribution Record and verify data
159 $expected = array(
160 'From' => "{$firstName} {$lastName}",
161 'Financial Type' => 'Donation',
162 'Total Amount' => '100.00',
163 'Contribution Status' => 'Completed',
164 );
165 $this->webtestVerifyTabularData($expected);
166 //View Soft Credit record of type 'Honor of'
167 $this->waitForTextPresent($honorDisplayName);
168 $this->waitForTextPresent('100.00 (In Honor of)');
169
170 // Check for Honoree contact created
171 $this->click("css=input#sort_name_navigation");
172 $this->type("css=input#sort_name_navigation", $honorSortName);
173 $this->typeKeys("css=input#sort_name_navigation", $honorSortName);
174
175 // wait for result list
176 $this->waitForElementPresent("css=ul.ui-autocomplete li");
177
178 // visit contact summary page
179 $this->click("css=ul.ui-autocomplete li");
180 $this->waitForPageToLoad($this->getTimeoutMsec());
181
182 // Is contact present?
183 $this->assertTrue($this->isTextPresent("$honorDisplayName"), "Honoree contact not found.");
184
185 // CRM-16064 - Contributions pricesets charge $1 more than selected
186 $contributionAmt = number_format($rand, 2);
187 $label = "Label $hash";
188 $this->_verifyContributionAmt($pageId, $contributionAmt, $label);
189
190 }
191
192 public function testOnlineContributionWithZeroAmount() {
193 $this->webtestLogin();
194
195 // Use default payment processor
196 $processorName = 'Test Processor';
197 $processorType = 'Dummy';
198 $pageTitle = substr(sha1(rand()), 0, 7);
199 $rand = 2 * rand(10, 50);
200 $hash = substr(sha1(rand()), 0, 7);
201 $amountSection = TRUE;
202 $payLater = FALSE;
203 $onBehalf = FALSE;
204 $pledges = FALSE;
205 $recurring = FALSE;
206 $memberships = FALSE;
207 $friend = FALSE;
208 $profilePreId = NULL;
209 $profilePostId = NULL;
210 $premiums = FALSE;
211 $widget = FALSE;
212 $pcp = FALSE;
213 $memPriceSetId = NULL;
214
215 // create a new online contribution page
216 // create contribution page with randomized title and default params
217 $pageId = $this->webtestAddContributionPage($hash,
218 $rand,
219 $pageTitle,
220 array($processorName => $processorType),
221 $amountSection,
222 $payLater,
223 $onBehalf,
224 $pledges,
225 $recurring,
226 $memberships,
227 $memPriceSetId,
228 $friend,
229 $profilePreId,
230 $profilePostId,
231 $premiums,
232 $widget,
233 $pcp
234 );
235
236 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_cancel-bottom');
237 $this->type('label_1', "Label $hash");
238 $this->type('value_1', 0);
239 $this->clickLink('_qf_Amount_upload_done-top');
240
241 //Contribution using Contribution Options
242 $this->_doContributionAndVerifyData($pageId);
243
244 //add priceset
245 $this->openCiviPage("admin/price", "reset=1&action=add", '_qf_Set_next-bottom');
246 $this->type('title', "Test Priceset $rand");
247 $this->check('extends_2');
248 $this->select("financial_type_id", "label=Donation");
249 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom', FALSE);
250 $sid = $this->urlArg('sid');
251 //add field
252 $this->type('label', "Testfield");
253 $this->select('html_type', "value=Radio");
254 $this->type('option_label_1', 'test Label');
255 $this->type('option_amount_1', 0.00);
256 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom', FALSE);
257 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_cancel-bottom');
258 $this->select('price_set_id', "value=$sid");
259 $this->clickLink('_qf_Amount_upload_done-bottom', FALSE);
260
261 //Contribution using priceset
262 $this->_doContributionAndVerifyData($pageId, TRUE);
263 }
264
265 /**
266 * @param int $pageId
267 * @param bool $priceSet
268 */
269 public function _doContributionAndVerifyData($pageId, $priceSet = FALSE) {
270 //logout
271 $this->webtestLogout();
272 $amountLabel = 'Total Amount';
273 $amountValue = '0.00';
274 //Open Live Contribution Page
275 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom");
276
277 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
278 $lastName = 'An' . substr(sha1(rand()), 0, 7);
279 $email = $firstName . "@example.com";
280 $this->type("email-5", $email);
281
282 if ($priceSet) {
283 $this->click("xpath=//div[@id='priceset']/div/div[2]/div/span/input");
284 $amountLabel = 'Contribution Amount';
285 $amountValue = 'Contribution Total: $ 0.00';
286 }
287
288 //Credit Card Info
289 $this->select("credit_card_type", "value=Visa");
290 $this->type("credit_card_number", "4111111111111111");
291 $this->type("cvv2", "000");
292 $this->select("credit_card_exp_date[M]", "value=1");
293 $this->select("credit_card_exp_date[Y]", "value=2020");
294
295 //Billing Info
296 $this->type("billing_first_name", $firstName);
297 $this->type("billing_last_name", $lastName);
298 $this->type("billing_street_address-5", "15 Main St.");
299 $this->type(" billing_city-5", "San Jose");
300 $this->select("billing_country_id-5", "value=1228");
301 $this->select("billing_state_province_id-5", "value=1004");
302 $this->type("billing_postal_code-5", "94129");
303 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
304
305 $this->clickLink("_qf_Confirm_next-bottom", NULL);
306
307 //login to check contribution
308
309 // Log in using webtestLogin() method
310 $this->webtestLogin();
311
312 //Find Contribution
313 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
314 $this->type("sort_name", "$email");
315 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
316 $this->waitForAjaxContent();
317 $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]");
318 $this->clickLink("_qf_Search_refresh", "xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", FALSE);
319 $this->clickLink("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
320
321 //View Contribution Record and verify data
322 $expected = array(
323 'From' => "{$firstName} {$lastName}",
324 'Financial Type' => 'Donation',
325 $amountLabel => $amountValue,
326 'Contribution Status' => 'Completed',
327 );
328 $this->webtestVerifyTabularData($expected);
329 }
330
331 public function _verifyContributionAmt($pageId, $contributionAmt, $label) {
332 // logout
333 $this->webtestLogout();
334
335 //Open Live Contribution Page
336 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom");
337 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
338 $lastName = 'An' . substr(sha1(rand()), 0, 7);
339 $this->type("email-5", $firstName . "@example.com");
340
341 $this->type("first_name", $firstName);
342 $this->type("last_name", $lastName);
343 $this->check("xpath=//div[@id='priceset']/div[contains(@class, 'contribution_amount-section')]//div[contains(@class, 'contribution_amount-row1')]/span/input");
344 $streetAddress = "100 Main Street";
345 $this->type("street_address-1", $streetAddress);
346 $this->type("city-1", "San Francisco");
347 $this->type("postal_code-1", "94117");
348 $this->select("country-1", "value=1228");
349 $this->select("state_province-1", "value=1001");
350
351 //Credit Card Info
352 $this->select("credit_card_type", "value=Visa");
353 $this->type("credit_card_number", "4111111111111111");
354 $this->type("cvv2", "000");
355 $this->select("credit_card_exp_date[M]", "value=1");
356 $this->select("credit_card_exp_date[Y]", "value=2020");
357
358 //Billing Info
359 $this->type("billing_first_name", $firstName . "billing");
360 $this->type("billing_last_name", $lastName . "billing");
361 $this->type("billing_street_address-5", "15 Main St.");
362 $this->type(" billing_city-5", "San Jose");
363 $this->select("billing_country_id-5", "value=1228");
364 $this->select("billing_state_province_id-5", "value=1004");
365 $this->type("billing_postal_code-5", "94129");
366 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
367
368 $this->assertElementContainsText("xpath=//div[contains(@class, 'amount_display-group')]//div[@class='display-block']/strong", "$ $contributionAmt - $label", "Contribution amount does not match");
369 $this->clickLink("_qf_Confirm_next-bottom");
370 $this->assertElementContainsText("xpath=//div[contains(@class, 'amount_display-group')]//div[@class='display-block']/strong", "$ $contributionAmt - $label", "Contribution amount does not match");
371 // Log in using webtestLogin() method
372 $this->webtestLogin();
373 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
374
375 $this->type("sort_name", "$lastName $firstName");
376 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
377 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table[@class='selector row-highlight']//tbody/tr[1]/td[10]/span/a[text()='View']");
378 $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);
379
380 //View Contribution Record and verify data
381 $expected = array(
382 'From' => "{$firstName} {$lastName}",
383 'Financial Type' => 'Donation',
384 'Total Amount' => $contributionAmt,
385 'Contribution Status' => 'Completed',
386 );
387 $this->webtestVerifyTabularData($expected);
388 }
389
390 public function testOnlineContributionWithPremium() {
391 //CRM-16713: Contribution search by premiums on find contribution form.
392 $this->webtestLogin();
393
394 // Use default payment processor
395 $processorName = 'Test Processor';
396 $processorType = 'Dummy';
397 $pageTitle = substr(sha1(rand()), 0, 7);
398 $rand = 2 * rand(10, 50);
399 $hash = substr(sha1(rand()), 0, 7);
400 $amountSection = TRUE;
401 $payLater = FALSE;
402 $onBehalf = FALSE;
403 $pledges = FALSE;
404 $recurring = FALSE;
405 $memberships = FALSE;
406 $friend = TRUE;
407 $profilePreId = 1;
408 $profilePostId = NULL;
409 $premiums = TRUE;
410 $widget = FALSE;
411 $pcp = FALSE;
412 $memPriceSetId = NULL;
413
414 // create a new online contribution page
415 // create contribution page with randomized title and default params
416 $pageId = $this->webtestAddContributionPage($hash,
417 $rand,
418 $pageTitle,
419 array($processorName => $processorType),
420 $amountSection,
421 $payLater,
422 $onBehalf,
423 $pledges,
424 $recurring,
425 $memberships,
426 $memPriceSetId,
427 $friend,
428 $profilePreId,
429 $profilePostId,
430 $premiums,
431 $widget,
432 $pcp
433 );
434
435 //logout
436 $this->webtestLogout();
437
438 //Open Live Contribution Page
439 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom");
440
441 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
442 $lastName = 'An' . substr(sha1(rand()), 0, 7);
443
444 $this->type("email-5", $firstName . "@example.com");
445
446 $this->waitForAjaxContent();
447 $this->click("xpath=//div[@id='premiums-listings']/div[2]/div[1]");
448 $this->waitForAjaxContent();
449 $this->select("xpath=//div[@id='premiums']/fieldset/div[@id='premiums-listings']/div[2]/div[2]/div[2]/div[4]/p/select", "value=Black");
450
451 $this->type("first_name", $firstName);
452 $this->type("last_name", $lastName);
453
454 $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input");
455 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 100);
456
457 $streetAddress = "100 Main Street";
458 $this->type("street_address-1", $streetAddress);
459 $this->type("city-1", "San Francisco");
460 $this->type("postal_code-1", "94117");
461 $this->select("country-1", "value=1228");
462 $this->select("state_province-1", "value=1001");
463
464 //Credit Card Info
465 $this->select("credit_card_type", "value=Visa");
466 $this->type("credit_card_number", "4111111111111111");
467 $this->type("cvv2", "000");
468 $this->select("credit_card_exp_date[M]", "value=1");
469 $this->select("credit_card_exp_date[Y]", "value=2020");
470
471 //Billing Info
472 $this->type("billing_first_name", $firstName . "billing");
473 $this->type("billing_last_name", $lastName . "billing");
474 $this->type("billing_street_address-5", "15 Main St.");
475 $this->type(" billing_city-5", "San Jose");
476 $this->select("billing_country_id-5", "value=1228");
477 $this->select("billing_state_province_id-5", "value=1004");
478 $this->type("billing_postal_code-5", "94129");
479 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
480
481 $this->click("_qf_Confirm_next-bottom");
482 $this->waitForPageToLoad($this->getTimeoutMsec());
483
484 // Log in using webtestLogin() method
485 $this->webtestLogin();
486
487 //Find Contribution
488 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
489 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
490 $this->type("sort_name", "$lastName $firstName");
491 $this->multiselect2('contribution_product_id', array('Coffee Mug'));
492 $this->click("_qf_Search_refresh");
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']");
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
508 }