Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | +--------------------------------------------------------------------+ | |
25 | */ | |
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 | ||
38 | function testOnlineContributionAdd() { | |
6a488035 TO |
39 | $this->webtestLogin(); |
40 | ||
41 | // We need a payment processor | |
42 | $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7); | |
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 | |
071a6d2e | 86 | $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_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"); | |
110 | ||
111 | // Honoree Info | |
ac6e0435 | 112 | $this->click("xpath=id('Main')/div[2]/fieldset/div[2]/div/label[text()='In Honor of']"); |
6a488035 | 113 | |
1421174e | 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); | |
76e86fd8 | 118 | |
6a488035 TO |
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"); | |
225a8648 | 134 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom"); |
6a488035 TO |
135 | |
136 | $this->click("_qf_Confirm_next-bottom"); | |
137 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
138 | ||
139 | //login to check contribution | |
6a488035 TO |
140 | |
141 | // Log in using webtestLogin() method | |
142 | $this->webtestLogin(); | |
143 | ||
144 | //Find Contribution | |
42daf119 | 145 | $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low"); |
6a488035 TO |
146 | |
147 | $this->type("sort_name", "$firstName $lastName"); | |
225a8648 CW |
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"); | |
6a488035 TO |
150 | |
151 | //View Contribution Record and verify data | |
152 | $expected = array( | |
42daf119 CW |
153 | 'From' => "{$firstName} {$lastName}", |
154 | 'Financial Type' => 'Donation', | |
155 | 'Total Amount' => '100.00', | |
6a488035 | 156 | 'Contribution Status' => 'Completed', |
6a488035 TO |
157 | ); |
158 | $this->webtestVerifyTabularData($expected); | |
159 | ||
1421174e | 160 | //View Soft Credit record of type 'Honor of' |
161 | $this->waitForTextPresent($honorDisplayName); | |
162 | $this->waitForTextPresent('100.00 (In Honor of)'); | |
163 | ||
6a488035 TO |
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 | |
0ecb5006 | 170 | $this->waitForElementPresent("css=ul.ui-autocomplete li"); |
6a488035 TO |
171 | |
172 | // visit contact summary page | |
0ecb5006 | 173 | $this->click("css=ul.ui-autocomplete li"); |
6a488035 TO |
174 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
175 | ||
176 | // Is contact present? | |
177 | $this->assertTrue($this->isTextPresent("$honorDisplayName"), "Honoree contact not found."); | |
76e86fd8 | 178 | |
6a488035 | 179 | } |
3fb990f4 RN |
180 | |
181 | function testOnlineContributionWithZeroAmount () { | |
182 | $this->webtestLogin(); | |
183 | ||
184 | // We need a payment processor | |
185 | $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7); | |
186 | $processorType = 'Dummy'; | |
187 | $pageTitle = substr(sha1(rand()), 0, 7); | |
188 | $rand = 2 * rand(10, 50); | |
189 | $hash = substr(sha1(rand()), 0, 7); | |
190 | $amountSection = TRUE; | |
191 | $payLater = FALSE; | |
192 | $onBehalf = FALSE; | |
193 | $pledges = FALSE; | |
194 | $recurring = FALSE; | |
195 | $memberships = FALSE; | |
196 | $friend = FALSE; | |
197 | $profilePreId = NULL; | |
198 | $profilePostId = NULL; | |
199 | $premiums = FALSE; | |
200 | $widget = FALSE; | |
201 | $pcp = FALSE; | |
202 | $memPriceSetId = NULL; | |
203 | ||
204 | // create a new online contribution page | |
205 | // create contribution page with randomized title and default params | |
206 | $pageId = $this->webtestAddContributionPage($hash, | |
207 | $rand, | |
208 | $pageTitle, | |
209 | array($processorName => $processorType), | |
210 | $amountSection, | |
211 | $payLater, | |
212 | $onBehalf, | |
213 | $pledges, | |
214 | $recurring, | |
215 | $memberships, | |
216 | $memPriceSetId, | |
217 | $friend, | |
218 | $profilePreId, | |
219 | $profilePostId, | |
220 | $premiums, | |
221 | $widget, | |
222 | $pcp | |
223 | ); | |
1421174e | 224 | |
3fb990f4 RN |
225 | $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_cancel-bottom'); |
226 | $this->type('label_1', "Label $hash"); | |
227 | $this->type('value_1', 0); | |
228 | $this->clickLink('_qf_Amount_upload_done-top'); | |
229 | ||
230 | //Contribution using Contribution Options | |
231 | $this->_doContributionAndVerifyData($pageId); | |
1421174e | 232 | |
3fb990f4 RN |
233 | //add priceset |
234 | $this->openCiviPage("admin/price", "reset=1&action=add", '_qf_Set_next-bottom'); | |
235 | $this->type('title', "Test Priceset $rand"); | |
236 | $this->check('extends_2'); | |
237 | $this->select("financial_type_id", "label=Donation"); | |
238 | $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom'); | |
239 | $sid = $this->urlArg('sid'); | |
240 | //add field | |
241 | $this->type('label', "Testfield"); | |
242 | $this->select('html_type', "value=Radio"); | |
243 | $this->type('option_label_1', 'test Label'); | |
244 | $this->type('option_amount_1', 0.00); | |
245 | $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom'); | |
246 | $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_cancel-bottom'); | |
247 | $this->select('price_set_id', "value=$sid"); | |
248 | $this->clickLink('_qf_Amount_upload_done-bottom'); | |
249 | ||
250 | //Contribution using priceset | |
1421174e | 251 | $this->_doContributionAndVerifyData($pageId, TRUE); |
3fb990f4 RN |
252 | } |
253 | ||
4cbe18b8 EM |
254 | /** |
255 | * @param $pageId | |
256 | * @param bool $priceSet | |
257 | */ | |
3fb990f4 RN |
258 | function _doContributionAndVerifyData($pageId, $priceSet = FALSE) { |
259 | //logout | |
260 | $this->webtestLogout(); | |
261 | $amountLabel = 'Total Amount'; | |
262 | $amountValue = '0.00'; | |
263 | //Open Live Contribution Page | |
264 | $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom"); | |
265 | ||
266 | $firstName = 'Ma' . substr(sha1(rand()), 0, 4); | |
267 | $lastName = 'An' . substr(sha1(rand()), 0, 7); | |
268 | ||
269 | $this->type("email-5", $firstName . "@example.com"); | |
270 | ||
271 | if ($priceSet) { | |
272 | $this->click("xpath=//div[@id='priceset']/div/div[2]/div/span/input"); | |
273 | $amountLabel = 'Contribution Amount'; | |
274 | $amountValue = 'Contribution Total: $ 0.00'; | |
275 | } | |
276 | ||
277 | //Credit Card Info | |
278 | $this->select("credit_card_type", "value=Visa"); | |
279 | $this->type("credit_card_number", "4111111111111111"); | |
280 | $this->type("cvv2", "000"); | |
281 | $this->select("credit_card_exp_date[M]", "value=1"); | |
282 | $this->select("credit_card_exp_date[Y]", "value=2020"); | |
283 | ||
284 | //Billing Info | |
285 | $this->type("billing_first_name", $firstName); | |
286 | $this->type("billing_last_name", $lastName); | |
287 | $this->type("billing_street_address-5", "15 Main St."); | |
288 | $this->type(" billing_city-5", "San Jose"); | |
289 | $this->select("billing_country_id-5", "value=1228"); | |
290 | $this->select("billing_state_province_id-5", "value=1004"); | |
291 | $this->type("billing_postal_code-5", "94129"); | |
292 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom"); | |
293 | ||
294 | $this->clickLink("_qf_Confirm_next-bottom", NULL); | |
295 | ||
1421174e | 296 | |
3fb990f4 RN |
297 | //login to check contribution |
298 | ||
299 | // Log in using webtestLogin() method | |
300 | $this->webtestLogin(); | |
301 | ||
302 | //Find Contribution | |
303 | $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low"); | |
304 | ||
305 | $this->type("sort_name", "$firstName $lastName"); | |
306 | $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']"); | |
307 | $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom"); | |
308 | ||
309 | //View Contribution Record and verify data | |
310 | $expected = array( | |
311 | 'From' => "{$firstName} {$lastName}", | |
312 | 'Financial Type' => 'Donation', | |
313 | $amountLabel => $amountValue, | |
314 | 'Contribution Status' => 'Completed' | |
315 | ); | |
316 | $this->webtestVerifyTabularData($expected); | |
6a488035 | 317 | } |
3fb990f4 | 318 | } |
6a488035 | 319 |