CRM-13981 additional fixes
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / OnlineContributionTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
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 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Contribute_OnlineContributionTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testOnlineContributionAdd() {
35 $this->webtestLogin();
36
37 // We need a payment processor
38 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
39 $processorType = 'Dummy';
40 $pageTitle = substr(sha1(rand()), 0, 7);
41 $rand = 2 * rand(10, 50);
42 $hash = substr(sha1(rand()), 0, 7);
43 $amountSection = TRUE;
44 $payLater = FALSE;
45 $onBehalf = FALSE;
46 $pledges = FALSE;
47 $recurring = FALSE;
48 $memberships = FALSE;
49 $friend = TRUE;
50 $profilePreId = 1;
51 $profilePostId = NULL;
52 $premiums = FALSE;
53 $widget = FALSE;
54 $pcp = FALSE;
55 $memPriceSetId = NULL;
56
57 // create a new online contribution page
58 // create contribution page with randomized title and default params
59 $pageId = $this->webtestAddContributionPage($hash,
60 $rand,
61 $pageTitle,
62 array($processorName => $processorType),
63 $amountSection,
64 $payLater,
65 $onBehalf,
66 $pledges,
67 $recurring,
68 $memberships,
69 $memPriceSetId,
70 $friend,
71 $profilePreId,
72 $profilePostId,
73 $premiums,
74 $widget,
75 $pcp
76 );
77
78 //logout
79 $this->webtestLogout();
80
81 //Open Live Contribution Page
82 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
83
84 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
85 $lastName = 'An' . substr(sha1(rand()), 0, 7);
86 $honorFirstName = 'In' . substr(sha1(rand()), 0, 4);
87 $honorLastName = 'Hon' . substr(sha1(rand()), 0, 7);
88 $honorEmail = $honorFirstName . "@example.com";
89 $honorSortName = $honorLastName . ', ' . $honorFirstName;
90 $honorDisplayName = 'Ms. ' . $honorFirstName . ' ' . $honorLastName;
91
92 $this->type("email-5", $firstName . "@example.com");
93
94 $this->type("first_name", $firstName);
95 $this->type("last_name", $lastName);
96
97 $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input");
98 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 100);
99
100 $streetAddress = "100 Main Street";
101 $this->type("street_address-1", $streetAddress);
102 $this->type("city-1", "San Francisco");
103 $this->type("postal_code-1", "94117");
104 $this->select("country-1", "value=1228");
105 $this->select("state_province-1", "value=1001");
106
107 // Honoree Info
108 $this->click("xpath=id('Main')/div[2]/fieldset/div[2]/div/label[text()='In Honor of']");
109
110 $this->select("honor[prefix_id]", "label=Ms.");
111 $this->type("honor[first_name]", $honorFirstName);
112 $this->type("honor[last_name]", $honorLastName);
113 $this->type("honor[email-1]", $honorEmail);
114
115 //Credit Card Info
116 $this->select("credit_card_type", "value=Visa");
117 $this->type("credit_card_number", "4111111111111111");
118 $this->type("cvv2", "000");
119 $this->select("credit_card_exp_date[M]", "value=1");
120 $this->select("credit_card_exp_date[Y]", "value=2020");
121
122 //Billing Info
123 $this->type("billing_first_name", $firstName . "billing");
124 $this->type("billing_last_name", $lastName . "billing");
125 $this->type("billing_street_address-5", "15 Main St.");
126 $this->type(" billing_city-5", "San Jose");
127 $this->select("billing_country_id-5", "value=1228");
128 $this->select("billing_state_province_id-5", "value=1004");
129 $this->type("billing_postal_code-5", "94129");
130 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
131
132 $this->click("_qf_Confirm_next-bottom");
133 $this->waitForPageToLoad($this->getTimeoutMsec());
134
135 //login to check contribution
136
137 // Log in using webtestLogin() method
138 $this->webtestLogin();
139
140 //Find Contribution
141 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
142
143 $this->type("sort_name", "$firstName $lastName");
144 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
145 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom");
146
147 //View Contribution Record and verify data
148 $expected = array(
149 'From' => "{$firstName} {$lastName}",
150 'Financial Type' => 'Donation',
151 'Total Amount' => '100.00',
152 'Contribution Status' => 'Completed',
153 );
154 $this->webtestVerifyTabularData($expected);
155
156 //View Soft Credit record of type 'Honor of'
157 $this->waitForTextPresent($honorDisplayName);
158 $this->waitForTextPresent('100.00 (In Honor of)');
159
160 // Check for Honoree contact created
161 $this->click("css=input#sort_name_navigation");
162 $this->type("css=input#sort_name_navigation", $honorSortName);
163 $this->typeKeys("css=input#sort_name_navigation", $honorSortName);
164
165 // wait for result list
166 $this->waitForElementPresent("css=div.ac_results-inner li");
167
168 // visit contact summary page
169 $this->click("css=div.ac_results-inner li");
170 $this->waitForPageToLoad($this->getTimeoutMsec());
171
172 // Is contact present?
173 $this->assertTrue($this->isTextPresent("$honorDisplayName"), "Honoree contact not found.");
174
175 }
176
177 function testOnlineContributionWithZeroAmount () {
178 $this->webtestLogin();
179
180 // We need a payment processor
181 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
182 $processorType = 'Dummy';
183 $pageTitle = substr(sha1(rand()), 0, 7);
184 $rand = 2 * rand(10, 50);
185 $hash = substr(sha1(rand()), 0, 7);
186 $amountSection = TRUE;
187 $payLater = FALSE;
188 $onBehalf = FALSE;
189 $pledges = FALSE;
190 $recurring = FALSE;
191 $memberships = FALSE;
192 $friend = FALSE;
193 $profilePreId = NULL;
194 $profilePostId = NULL;
195 $premiums = FALSE;
196 $widget = FALSE;
197 $pcp = FALSE;
198 $memPriceSetId = NULL;
199
200 // create a new online contribution page
201 // create contribution page with randomized title and default params
202 $pageId = $this->webtestAddContributionPage($hash,
203 $rand,
204 $pageTitle,
205 array($processorName => $processorType),
206 $amountSection,
207 $payLater,
208 $onBehalf,
209 $pledges,
210 $recurring,
211 $memberships,
212 $memPriceSetId,
213 $friend,
214 $profilePreId,
215 $profilePostId,
216 $premiums,
217 $widget,
218 $pcp
219 );
220
221 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_cancel-bottom');
222 $this->type('label_1', "Label $hash");
223 $this->type('value_1', 0);
224 $this->clickLink('_qf_Amount_upload_done-top');
225
226 //Contribution using Contribution Options
227 $this->_doContributionAndVerifyData($pageId);
228
229 //add priceset
230 $this->openCiviPage("admin/price", "reset=1&action=add", '_qf_Set_next-bottom');
231 $this->type('title', "Test Priceset $rand");
232 $this->check('extends_2');
233 $this->select("financial_type_id", "label=Donation");
234 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom');
235 $sid = $this->urlArg('sid');
236 //add field
237 $this->type('label', "Testfield");
238 $this->select('html_type', "value=Radio");
239 $this->type('option_label_1', 'test Label');
240 $this->type('option_amount_1', 0.00);
241 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom');
242 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_cancel-bottom');
243 $this->select('price_set_id', "value=$sid");
244 $this->clickLink('_qf_Amount_upload_done-bottom');
245
246 //Contribution using priceset
247 $this->_doContributionAndVerifyData($pageId, TRUE);
248 }
249
250 function _doContributionAndVerifyData($pageId, $priceSet = FALSE) {
251 //logout
252 $this->webtestLogout();
253 $amountLabel = 'Total Amount';
254 $amountValue = '0.00';
255 //Open Live Contribution Page
256 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
257
258 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
259 $lastName = 'An' . substr(sha1(rand()), 0, 7);
260
261 $this->type("email-5", $firstName . "@example.com");
262
263 if ($priceSet) {
264 $this->click("xpath=//div[@id='priceset']/div/div[2]/div/span/input");
265 $amountLabel = 'Contribution Amount';
266 $amountValue = 'Contribution Total: $ 0.00';
267 }
268
269 //Credit Card Info
270 $this->select("credit_card_type", "value=Visa");
271 $this->type("credit_card_number", "4111111111111111");
272 $this->type("cvv2", "000");
273 $this->select("credit_card_exp_date[M]", "value=1");
274 $this->select("credit_card_exp_date[Y]", "value=2020");
275
276 //Billing Info
277 $this->type("billing_first_name", $firstName);
278 $this->type("billing_last_name", $lastName);
279 $this->type("billing_street_address-5", "15 Main St.");
280 $this->type(" billing_city-5", "San Jose");
281 $this->select("billing_country_id-5", "value=1228");
282 $this->select("billing_state_province_id-5", "value=1004");
283 $this->type("billing_postal_code-5", "94129");
284 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
285
286 $this->clickLink("_qf_Confirm_next-bottom", NULL);
287
288
289 //login to check contribution
290
291 // Log in using webtestLogin() method
292 $this->webtestLogin();
293
294 //Find Contribution
295 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
296
297 $this->type("sort_name", "$firstName $lastName");
298 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
299 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom");
300
301 //View Contribution Record and verify data
302 $expected = array(
303 'From' => "{$firstName} {$lastName}",
304 'Financial Type' => 'Donation',
305 $amountLabel => $amountValue,
306 'Contribution Status' => 'Completed'
307 );
308 $this->webtestVerifyTabularData($expected);
309 }
310 }
311