CRM-16064 - Contributions pricesets charge $1 more than selected
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / OnlineContributionTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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
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", "_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
111 // Honoree Info
112 $this->click("xpath=id('Main')/div[2]/fieldset/div[2]/div/label[text()='In Honor of']");
113
114 $this->select("honor[prefix_id]", "label=Ms.");
115 $this->type("honor[first_name]", $honorFirstName);
116 $this->type("honor[last_name]", $honorLastName);
117 $this->type("honor[email-1]", $honorEmail);
118
119 //Credit Card Info
120 $this->select("credit_card_type", "value=Visa");
121 $this->type("credit_card_number", "4111111111111111");
122 $this->type("cvv2", "000");
123 $this->select("credit_card_exp_date[M]", "value=1");
124 $this->select("credit_card_exp_date[Y]", "value=2020");
125
126 //Billing Info
127 $this->type("billing_first_name", $firstName . "billing");
128 $this->type("billing_last_name", $lastName . "billing");
129 $this->type("billing_street_address-5", "15 Main St.");
130 $this->type(" billing_city-5", "San Jose");
131 $this->select("billing_country_id-5", "value=1228");
132 $this->select("billing_state_province_id-5", "value=1004");
133 $this->type("billing_postal_code-5", "94129");
134 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
135
136 $this->click("_qf_Confirm_next-bottom");
137 $this->waitForPageToLoad($this->getTimeoutMsec());
138
139 //login to check contribution
140
141 // Log in using webtestLogin() method
142 $this->webtestLogin();
143
144 //Find Contribution
145 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
146
147 $this->type("sort_name", "$lastName $firstName");
148 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
149 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
150
151 //View Contribution Record and verify data
152 $expected = array(
153 'From' => "{$firstName} {$lastName}",
154 'Financial Type' => 'Donation',
155 'Total Amount' => '100.00',
156 'Contribution Status' => 'Completed',
157 );
158 $this->webtestVerifyTabularData($expected);
159
160 //View Soft Credit record of type 'Honor of'
161 $this->waitForTextPresent($honorDisplayName);
162 $this->waitForTextPresent('100.00 (In Honor of)');
163
164 // Check for Honoree contact created
165 $this->click("css=input#sort_name_navigation");
166 $this->type("css=input#sort_name_navigation", $honorSortName);
167 $this->typeKeys("css=input#sort_name_navigation", $honorSortName);
168
169 // wait for result list
170 $this->waitForElementPresent("css=ul.ui-autocomplete li");
171
172 // visit contact summary page
173 $this->click("css=ul.ui-autocomplete li");
174 $this->waitForPageToLoad($this->getTimeoutMsec());
175
176 // Is contact present?
177 $this->assertTrue($this->isTextPresent("$honorDisplayName"), "Honoree contact not found.");
178
179 // CRM-16064 - Contributions pricesets charge $1 more than selected
180 $contributionAmt = number_format($rand, 2);
181 $label = "Label $hash";
182 $this->_verifyContributionAmt($pageId, $contributionAmt, $label);
183
184 }
185
186 public function testOnlineContributionWithZeroAmount() {
187 $this->webtestLogin();
188
189 // Use default payment processor
190 $processorName = 'Test Processor';
191 $processorType = 'Dummy';
192 $pageTitle = substr(sha1(rand()), 0, 7);
193 $rand = 2 * rand(10, 50);
194 $hash = substr(sha1(rand()), 0, 7);
195 $amountSection = TRUE;
196 $payLater = FALSE;
197 $onBehalf = FALSE;
198 $pledges = FALSE;
199 $recurring = FALSE;
200 $memberships = FALSE;
201 $friend = FALSE;
202 $profilePreId = NULL;
203 $profilePostId = NULL;
204 $premiums = FALSE;
205 $widget = FALSE;
206 $pcp = FALSE;
207 $memPriceSetId = NULL;
208
209 // create a new online contribution page
210 // create contribution page with randomized title and default params
211 $pageId = $this->webtestAddContributionPage($hash,
212 $rand,
213 $pageTitle,
214 array($processorName => $processorType),
215 $amountSection,
216 $payLater,
217 $onBehalf,
218 $pledges,
219 $recurring,
220 $memberships,
221 $memPriceSetId,
222 $friend,
223 $profilePreId,
224 $profilePostId,
225 $premiums,
226 $widget,
227 $pcp
228 );
229
230 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_cancel-bottom');
231 $this->type('label_1', "Label $hash");
232 $this->type('value_1', 0);
233 $this->clickLink('_qf_Amount_upload_done-top');
234
235 //Contribution using Contribution Options
236 $this->_doContributionAndVerifyData($pageId);
237
238 //add priceset
239 $this->openCiviPage("admin/price", "reset=1&action=add", '_qf_Set_next-bottom');
240 $this->type('title', "Test Priceset $rand");
241 $this->check('extends_2');
242 $this->select("financial_type_id", "label=Donation");
243 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom', FALSE);
244 $sid = $this->urlArg('sid');
245 //add field
246 $this->type('label', "Testfield");
247 $this->select('html_type', "value=Radio");
248 $this->type('option_label_1', 'test Label');
249 $this->type('option_amount_1', 0.00);
250 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom', FALSE);
251 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_cancel-bottom');
252 $this->select('price_set_id', "value=$sid");
253 $this->clickLink('_qf_Amount_upload_done-bottom', FALSE);
254
255 //Contribution using priceset
256 $this->_doContributionAndVerifyData($pageId, TRUE);
257 }
258
259 /**
260 * @param int $pageId
261 * @param bool $priceSet
262 */
263 public function _doContributionAndVerifyData($pageId, $priceSet = FALSE) {
264 //logout
265 $this->webtestLogout();
266 $amountLabel = 'Total Amount';
267 $amountValue = '1.00';
268 //Open Live Contribution Page
269 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
270
271 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
272 $lastName = 'An' . substr(sha1(rand()), 0, 7);
273
274 $this->type("email-5", $firstName . "@example.com");
275
276 if ($priceSet) {
277 $this->click("xpath=//div[@id='priceset']/div/div[2]/div/span/input");
278 $amountLabel = 'Contribution Amount';
279 $amountValue = 'Contribution Total: $ 0.00';
280 }
281
282 //Credit Card Info
283 $this->select("credit_card_type", "value=Visa");
284 $this->type("credit_card_number", "4111111111111111");
285 $this->type("cvv2", "000");
286 $this->select("credit_card_exp_date[M]", "value=1");
287 $this->select("credit_card_exp_date[Y]", "value=2020");
288
289 //Billing Info
290 $this->type("billing_first_name", $firstName);
291 $this->type("billing_last_name", $lastName);
292 $this->type("billing_street_address-5", "15 Main St.");
293 $this->type(" billing_city-5", "San Jose");
294 $this->select("billing_country_id-5", "value=1228");
295 $this->select("billing_state_province_id-5", "value=1004");
296 $this->type("billing_postal_code-5", "94129");
297 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
298
299 $this->clickLink("_qf_Confirm_next-bottom", NULL);
300
301 //login to check contribution
302
303 // Log in using webtestLogin() method
304 $this->webtestLogin();
305
306 //Find Contribution
307 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
308
309 $this->type("sort_name", "$lastName $firstName");
310 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", FALSE);
311 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
312
313 //View Contribution Record and verify data
314 $expected = array(
315 'From' => "{$firstName} {$lastName}",
316 'Financial Type' => 'Donation',
317 $amountLabel => $amountValue,
318 'Contribution Status' => 'Completed',
319 );
320 $this->webtestVerifyTabularData($expected);
321 }
322
323 public function _verifyContributionAmt($pageId, $contributionAmt, $label) {
324 // logout
325 $this->webtestLogout();
326
327 //Open Live Contribution Page
328 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
329 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
330 $lastName = 'An' . substr(sha1(rand()), 0, 7);
331 $this->type("email-5", $firstName . "@example.com");
332
333 $this->type("first_name", $firstName);
334 $this->type("last_name", $lastName);
335 $this->check("xpath=//div[@id='priceset']/div[contains(@class, 'contribution_amount-section')]//div[contains(@class, 'contribution_amount-row1')]/span/input");
336 $streetAddress = "100 Main Street";
337 $this->type("street_address-1", $streetAddress);
338 $this->type("city-1", "San Francisco");
339 $this->type("postal_code-1", "94117");
340 $this->select("country-1", "value=1228");
341 $this->select("state_province-1", "value=1001");
342
343 //Credit Card Info
344 $this->select("credit_card_type", "value=Visa");
345 $this->type("credit_card_number", "4111111111111111");
346 $this->type("cvv2", "000");
347 $this->select("credit_card_exp_date[M]", "value=1");
348 $this->select("credit_card_exp_date[Y]", "value=2020");
349
350 //Billing Info
351 $this->type("billing_first_name", $firstName . "billing");
352 $this->type("billing_last_name", $lastName . "billing");
353 $this->type("billing_street_address-5", "15 Main St.");
354 $this->type(" billing_city-5", "San Jose");
355 $this->select("billing_country_id-5", "value=1228");
356 $this->select("billing_state_province_id-5", "value=1004");
357 $this->type("billing_postal_code-5", "94129");
358 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
359
360 $this->assertElementContainsText("xpath=//div[contains(@class, 'amount_display-group')]//div[@class='display-block']/strong", "$ $contributionAmt - $label", "Contribution amount does not match");
361 $this->clickLink("_qf_Confirm_next-bottom");
362 $this->assertElementContainsText("xpath=//div[contains(@class, 'amount_display-group')]//div[@class='display-block']/strong", "$ $contributionAmt - $label", "Contribution amount does not match");
363 // Log in using webtestLogin() method
364 $this->webtestLogin();
365 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
366
367 $this->type("sort_name", "$lastName $firstName");
368 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
369 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
370
371 //View Contribution Record and verify data
372 $expected = array(
373 'From' => "{$firstName} {$lastName}",
374 'Financial Type' => 'Donation',
375 'Total Amount' => $contributionAmt,
376 'Contribution Status' => 'Completed',
377 );
378 $this->webtestVerifyTabularData($expected);
379 }
380
381 }