Merge remote-tracking branch 'upstream/4.3' into 4.3-4.4-2013-11-11-10-44-51
[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 $this->waitForElementPresent("honor_email");
110
111 $this->select("honor_prefix_id", "label=Ms.");
112 $this->type("honor_first_name", $honorFirstName);
113 $this->type("honor_last_name", $honorLastName);
114 $this->type("honor_email", $honorEmail);
115
116 //Credit Card Info
117 $this->select("credit_card_type", "value=Visa");
118 $this->type("credit_card_number", "4111111111111111");
119 $this->type("cvv2", "000");
120 $this->select("credit_card_exp_date[M]", "value=1");
121 $this->select("credit_card_exp_date[Y]", "value=2020");
122
123 //Billing Info
124 $this->type("billing_first_name", $firstName . "billing");
125 $this->type("billing_last_name", $lastName . "billing");
126 $this->type("billing_street_address-5", "15 Main St.");
127 $this->type(" billing_city-5", "San Jose");
128 $this->select("billing_country_id-5", "value=1228");
129 $this->select("billing_state_province_id-5", "value=1004");
130 $this->type("billing_postal_code-5", "94129");
131 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
132
133 $this->click("_qf_Confirm_next-bottom");
134 $this->waitForPageToLoad($this->getTimeoutMsec());
135
136 //login to check contribution
137
138 // Log in using webtestLogin() method
139 $this->webtestLogin();
140
141 //Find Contribution
142 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
143
144 $this->type("sort_name", "$firstName $lastName");
145 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
146 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom");
147
148 //View Contribution Record and verify data
149 $expected = array(
150 'From' => "{$firstName} {$lastName}",
151 'Financial Type' => 'Donation',
152 'Total Amount' => '100.00',
153 'Contribution Status' => 'Completed',
154 'In Honor of' => $honorDisplayName
155 );
156 $this->webtestVerifyTabularData($expected);
157
158 // Check for Honoree contact created
159 $this->click("css=input#sort_name_navigation");
160 $this->type("css=input#sort_name_navigation", $honorSortName);
161 $this->typeKeys("css=input#sort_name_navigation", $honorSortName);
162
163 // wait for result list
164 $this->waitForElementPresent("css=div.ac_results-inner li");
165
166 // visit contact summary page
167 $this->click("css=div.ac_results-inner li");
168 $this->waitForPageToLoad($this->getTimeoutMsec());
169
170 // Is contact present?
171 $this->assertTrue($this->isTextPresent("$honorDisplayName"), "Honoree contact not found.");
172
173 }
174
175 function testOnlineContributionWithZeroAmount () {
176 $this->webtestLogin();
177
178 // We need a payment processor
179 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
180 $processorType = 'Dummy';
181 $pageTitle = substr(sha1(rand()), 0, 7);
182 $rand = 2 * rand(10, 50);
183 $hash = substr(sha1(rand()), 0, 7);
184 $amountSection = TRUE;
185 $payLater = FALSE;
186 $onBehalf = FALSE;
187 $pledges = FALSE;
188 $recurring = FALSE;
189 $memberships = FALSE;
190 $friend = FALSE;
191 $profilePreId = NULL;
192 $profilePostId = NULL;
193 $premiums = FALSE;
194 $widget = FALSE;
195 $pcp = FALSE;
196 $memPriceSetId = NULL;
197
198 // create a new online contribution page
199 // create contribution page with randomized title and default params
200 $pageId = $this->webtestAddContributionPage($hash,
201 $rand,
202 $pageTitle,
203 array($processorName => $processorType),
204 $amountSection,
205 $payLater,
206 $onBehalf,
207 $pledges,
208 $recurring,
209 $memberships,
210 $memPriceSetId,
211 $friend,
212 $profilePreId,
213 $profilePostId,
214 $premiums,
215 $widget,
216 $pcp
217 );
218
219 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_cancel-bottom');
220 $this->type('label_1', "Label $hash");
221 $this->type('value_1', 0);
222 $this->clickLink('_qf_Amount_upload_done-top');
223
224 //Contribution using Contribution Options
225 $this->_doContributionAndVerifyData($pageId);
226
227 //add priceset
228 $this->openCiviPage("admin/price", "reset=1&action=add", '_qf_Set_next-bottom');
229 $this->type('title', "Test Priceset $rand");
230 $this->check('extends_2');
231 $this->select("financial_type_id", "label=Donation");
232 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom');
233 $sid = $this->urlArg('sid');
234 //add field
235 $this->type('label', "Testfield");
236 $this->select('html_type', "value=Radio");
237 $this->type('option_label_1', 'test Label');
238 $this->type('option_amount_1', 0.00);
239 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom');
240 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_cancel-bottom');
241 $this->select('price_set_id', "value=$sid");
242 $this->clickLink('_qf_Amount_upload_done-bottom');
243
244 //Contribution using priceset
245 $this->_doContributionAndVerifyData($pageId, TRUE);
246 }
247
248 function _doContributionAndVerifyData($pageId, $priceSet = FALSE) {
249 //logout
250 $this->webtestLogout();
251 $amountLabel = 'Total Amount';
252 $amountValue = '0.00';
253 //Open Live Contribution Page
254 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
255
256 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
257 $lastName = 'An' . substr(sha1(rand()), 0, 7);
258
259 $this->type("email-5", $firstName . "@example.com");
260
261 if ($priceSet) {
262 $this->click("xpath=//div[@id='priceset']/div/div[2]/div/span/input");
263 $amountLabel = 'Contribution Amount';
264 $amountValue = 'Contribution Total: $ 0.00';
265 }
266
267 //Credit Card Info
268 $this->select("credit_card_type", "value=Visa");
269 $this->type("credit_card_number", "4111111111111111");
270 $this->type("cvv2", "000");
271 $this->select("credit_card_exp_date[M]", "value=1");
272 $this->select("credit_card_exp_date[Y]", "value=2020");
273
274 //Billing Info
275 $this->type("billing_first_name", $firstName);
276 $this->type("billing_last_name", $lastName);
277 $this->type("billing_street_address-5", "15 Main St.");
278 $this->type(" billing_city-5", "San Jose");
279 $this->select("billing_country_id-5", "value=1228");
280 $this->select("billing_state_province_id-5", "value=1004");
281 $this->type("billing_postal_code-5", "94129");
282 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
283
284 $this->clickLink("_qf_Confirm_next-bottom", NULL);
285
286
287 //login to check contribution
288
289 // Log in using webtestLogin() method
290 $this->webtestLogin();
291
292 //Find Contribution
293 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
294
295 $this->type("sort_name", "$firstName $lastName");
296 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
297 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom");
298
299 //View Contribution Record and verify data
300 $expected = array(
301 'From' => "{$firstName} {$lastName}",
302 'Financial Type' => 'Donation',
303 $amountLabel => $amountValue,
304 'Contribution Status' => 'Completed'
305 );
306 $this->webtestVerifyTabularData($expected);
307 }
308 }
309