Merge pull request #11735 from mukeshcompucorp/CRM-21814-add-proper-container-to...
[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-2018 |
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 $this->waitForElementPresent("xpath=//div[@class='crm-group billing_name_address-group']//div[@class='crm-section no-label billing_name-section']");
135 $this->assertElementContainsText("xpath=//div[@class='crm-group billing_name_address-group']//div[@class='crm-section no-label billing_name-section']", $firstName . "billing");
136 $this->assertElementContainsText("xpath=//div[@class='crm-group billing_name_address-group']//div[@class='crm-section no-label billing_name-section']", $lastName . "billing");
137
138 $stateText = CRM_Core_PseudoConstant::stateProvinceAbbreviation(1004);
139 $countryText = CRM_Core_PseudoConstant::countryIsoCode(1228);
140 $billingDetails = array('15 Main St.', 'San Jose', '94129', $stateText, $countryText);
141 foreach ($billingDetails as $field) {
142 $this->assertElementContainsText("xpath=//div[@class='crm-group billing_name_address-group']//div[@class='crm-section no-label billing_address-section']", $field);
143 }
144
145 $this->click("_qf_Confirm_next-bottom");
146 $this->waitForPageToLoad($this->getTimeoutMsec());
147
148 $this->waitForElementPresent("xpath=//div[@class='crm-group billing_name_address-group']//div[@class='crm-section no-label billing_name-section']");
149 $this->assertElementContainsText("xpath=//div[@class='crm-group billing_name_address-group']//div[@class='crm-section no-label billing_name-section']", $firstName . "billing");
150 $this->assertElementContainsText("xpath=//div[@class='crm-group billing_name_address-group']//div[@class='crm-section no-label billing_name-section']", $lastName . "billing");
151
152 //login to check contribution
153
154 // Log in using webtestLogin() method
155 $this->webtestLogin();
156
157 //Find Contribution
158 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
159 $this->type("sort_name", "$lastName $firstName");
160 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
161 $this->clickLink("_qf_Search_refresh", "xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", FALSE);
162 $this->clickLink("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
163
164 //View Contribution Record and verify data
165 $expected = array(
166 'From' => "{$firstName} {$lastName}",
167 'Financial Type' => 'Donation',
168 'Total Amount' => '100.00',
169 'Contribution Status' => 'Completed',
170 );
171 $this->webtestVerifyTabularData($expected);
172 //View Soft Credit record of type 'Honor of'
173 $this->waitForTextPresent($honorDisplayName);
174 $this->waitForTextPresent('100.00 (In Honor of)');
175
176 // Check for Honoree contact created
177 $this->click("css=input#sort_name_navigation");
178 $this->type("css=input#sort_name_navigation", $honorSortName);
179 $this->typeKeys("css=input#sort_name_navigation", $honorSortName);
180
181 // wait for result list
182 $this->waitForElementPresent("css=ul.ui-autocomplete li");
183
184 // visit contact summary page
185 $this->click("css=ul.ui-autocomplete li");
186 $this->waitForPageToLoad($this->getTimeoutMsec());
187
188 // Is contact present?
189 $this->assertTrue($this->isTextPresent("$honorDisplayName"), "Honoree contact not found.");
190
191 // CRM-16064 - Contributions pricesets charge $1 more than selected
192 $contributionAmt = number_format($rand, 2);
193 $label = "Label $hash";
194 $this->_verifyContributionAmt($pageId, $contributionAmt, $label);
195
196 }
197
198 public function testOnlineContributionWithZeroAmount() {
199 $this->webtestLogin();
200
201 // Use default payment processor
202 $processorName = 'Test Processor';
203 $processorType = 'Dummy';
204 $pageTitle = substr(sha1(rand()), 0, 7);
205 $rand = 2 * rand(10, 50);
206 $hash = substr(sha1(rand()), 0, 7);
207 $amountSection = TRUE;
208 $payLater = FALSE;
209 $onBehalf = FALSE;
210 $pledges = FALSE;
211 $recurring = FALSE;
212 $memberships = FALSE;
213 $friend = FALSE;
214 $profilePreId = NULL;
215 $profilePostId = NULL;
216 $premiums = FALSE;
217 $widget = FALSE;
218 $pcp = FALSE;
219 $memPriceSetId = NULL;
220
221 // create a new online contribution page
222 // create contribution page with randomized title and default params
223 $pageId = $this->webtestAddContributionPage($hash,
224 $rand,
225 $pageTitle,
226 array($processorName => $processorType),
227 $amountSection,
228 $payLater,
229 $onBehalf,
230 $pledges,
231 $recurring,
232 $memberships,
233 $memPriceSetId,
234 $friend,
235 $profilePreId,
236 $profilePostId,
237 $premiums,
238 $widget,
239 $pcp
240 );
241
242 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_cancel-bottom');
243 $this->type('label_1', "Label $hash");
244 $this->type('value_1', 0);
245 $this->clickLink('_qf_Amount_upload_done-top');
246
247 //Contribution using Contribution Options
248 $this->_doContributionAndVerifyData($pageId);
249
250 //add priceset
251 $this->openCiviPage("admin/price", "reset=1&action=add", '_qf_Set_next-bottom');
252 $this->type('title', "Test Priceset $rand");
253 $this->check('extends_2');
254 $this->select("financial_type_id", "label=Donation");
255 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom', FALSE);
256 $sid = $this->urlArg('sid');
257 //add field
258 $this->type('label', "Testfield");
259 $this->select('html_type', "value=Radio");
260 $this->type('option_label_1', 'test Label');
261 $this->type('option_amount_1', 0.00);
262 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom', FALSE);
263 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_cancel-bottom');
264 $this->select('price_set_id', "value=$sid");
265 $this->clickLink('_qf_Amount_upload_done-bottom', FALSE);
266
267 //Contribution using priceset
268 $this->_doContributionAndVerifyData($pageId, TRUE);
269 }
270
271 /**
272 * @param int $pageId
273 * @param bool $priceSet
274 */
275 public function _doContributionAndVerifyData($pageId, $priceSet = FALSE) {
276 //logout
277 $this->webtestLogout();
278 $amountLabel = 'Total Amount';
279 $amountValue = '0.00';
280 //Open Live Contribution Page
281 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom");
282
283 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
284 $lastName = 'An' . substr(sha1(rand()), 0, 7);
285 $email = $firstName . "@example.com";
286 $this->type("email-5", $email);
287
288 if ($priceSet) {
289 $this->click("xpath=//div[@id='priceset']/div/div[2]/div/span/input");
290 $amountLabel = 'Contribution Amount';
291 $amountValue = 'Contribution Total: $ 0.00';
292 }
293
294 //Credit Card Info
295 $this->select("credit_card_type", "value=Visa");
296 $this->type("credit_card_number", "4111111111111111");
297 $this->type("cvv2", "000");
298 $this->select("credit_card_exp_date[M]", "value=1");
299 $this->select("credit_card_exp_date[Y]", "value=2020");
300
301 //Billing Info
302 $this->type("billing_first_name", $firstName);
303 $this->type("billing_last_name", $lastName);
304 $this->type("billing_street_address-5", "15 Main St.");
305 $this->type(" billing_city-5", "San Jose");
306 $this->select("billing_country_id-5", "value=1228");
307 $this->select("billing_state_province_id-5", "value=1004");
308 $this->type("billing_postal_code-5", "94129");
309 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
310
311 $this->clickLink("_qf_Confirm_next-bottom", NULL);
312
313 //login to check contribution
314
315 // Log in using webtestLogin() method
316 $this->webtestLogin();
317
318 //Find Contribution
319 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
320 $this->type("sort_name", "$email");
321 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
322 $this->waitForAjaxContent();
323 $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]");
324 $this->clickLink("_qf_Search_refresh", "xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", FALSE);
325 $this->clickLink("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
326
327 //View Contribution Record and verify data
328 $expected = array(
329 'From' => "{$firstName} {$lastName}",
330 'Financial Type' => 'Donation',
331 $amountLabel => $amountValue,
332 'Contribution Status' => 'Completed',
333 );
334 $this->webtestVerifyTabularData($expected);
335 }
336
337 public function _verifyContributionAmt($pageId, $contributionAmt, $label) {
338 // logout
339 $this->webtestLogout();
340
341 //Open Live Contribution Page
342 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom");
343 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
344 $lastName = 'An' . substr(sha1(rand()), 0, 7);
345 $this->type("email-5", $firstName . "@example.com");
346
347 $this->type("first_name", $firstName);
348 $this->type("last_name", $lastName);
349 $this->check("xpath=//div[@id='priceset']/div[contains(@class, 'contribution_amount-section')]//div[contains(@class, 'contribution_amount-row1')]/span/input");
350 $streetAddress = "100 Main Street";
351 $this->type("street_address-1", $streetAddress);
352 $this->type("city-1", "San Francisco");
353 $this->type("postal_code-1", "94117");
354 $this->select("country-1", "value=1228");
355 $this->select("state_province-1", "value=1001");
356
357 //Credit Card Info
358 $this->select("credit_card_type", "value=Visa");
359 $this->type("credit_card_number", "4111111111111111");
360 $this->type("cvv2", "000");
361 $this->select("credit_card_exp_date[M]", "value=1");
362 $this->select("credit_card_exp_date[Y]", "value=2020");
363
364 //Billing Info
365 $this->type("billing_first_name", $firstName . "billing");
366 $this->type("billing_last_name", $lastName . "billing");
367 $this->type("billing_street_address-5", "15 Main St.");
368 $this->type(" billing_city-5", "San Jose");
369 $this->select("billing_country_id-5", "value=1228");
370 $this->select("billing_state_province_id-5", "value=1004");
371 $this->type("billing_postal_code-5", "94129");
372 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
373
374 $this->assertElementContainsText("xpath=//div[contains(@class, 'amount_display-group')]//div[@class='display-block']/strong", "$ $contributionAmt - $label", "Contribution amount does not match");
375 $this->clickLink("_qf_Confirm_next-bottom");
376 $this->assertElementContainsText("xpath=//div[contains(@class, 'amount_display-group')]//div[@class='display-block']/strong", "$ $contributionAmt - $label", "Contribution amount does not match");
377 // Log in using webtestLogin() method
378 $this->webtestLogin();
379 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
380
381 $this->type("sort_name", "$lastName $firstName");
382 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
383 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table[@class='selector row-highlight']//tbody/tr[1]/td[10]/span/a[text()='View']");
384 $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);
385
386 //View Contribution Record and verify data
387 $expected = array(
388 'From' => "{$firstName} {$lastName}",
389 'Financial Type' => 'Donation',
390 'Total Amount' => $contributionAmt,
391 'Contribution Status' => 'Completed',
392 );
393 $this->webtestVerifyTabularData($expected);
394 }
395
396 public function testOnlineContributionWithPremium() {
397 //CRM-16713: Contribution search by premiums on find contribution form.
398 $this->webtestLogin();
399
400 // Use default payment processor
401 $processorName = 'Test Processor';
402 $processorType = 'Dummy';
403 $pageTitle = substr(sha1(rand()), 0, 7);
404 $rand = 2 * rand(10, 50);
405 $hash = substr(sha1(rand()), 0, 7);
406 $amountSection = TRUE;
407 $payLater = FALSE;
408 $onBehalf = FALSE;
409 $pledges = FALSE;
410 $recurring = FALSE;
411 $memberships = FALSE;
412 $friend = TRUE;
413 $profilePreId = 1;
414 $profilePostId = NULL;
415 $premiums = TRUE;
416 $widget = FALSE;
417 $pcp = FALSE;
418 $memPriceSetId = NULL;
419
420 // create a new online contribution page
421 // create contribution page with randomized title and default params
422 $pageId = $this->webtestAddContributionPage($hash,
423 $rand,
424 $pageTitle,
425 array($processorName => $processorType),
426 $amountSection,
427 $payLater,
428 $onBehalf,
429 $pledges,
430 $recurring,
431 $memberships,
432 $memPriceSetId,
433 $friend,
434 $profilePreId,
435 $profilePostId,
436 $premiums,
437 $widget,
438 $pcp
439 );
440
441 //logout
442 $this->webtestLogout();
443
444 //Open Live Contribution Page
445 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom");
446
447 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
448 $lastName = 'An' . substr(sha1(rand()), 0, 7);
449
450 $this->type("email-5", $firstName . "@example.com");
451
452 $this->waitForAjaxContent();
453 $this->click("xpath=//div[@id='premiums-listings']/div[2]/div[1]");
454 $this->waitForAjaxContent();
455 $this->select("xpath=//div[@id='premiums']/fieldset/div[@id='premiums-listings']/div[2]/div[2]/div[2]/div[4]/p/select", "value=Black");
456
457 $this->type("first_name", $firstName);
458 $this->type("last_name", $lastName);
459
460 $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input");
461 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 100);
462
463 $streetAddress = "100 Main Street";
464 $this->type("street_address-1", $streetAddress);
465 $this->type("city-1", "San Francisco");
466 $this->type("postal_code-1", "94117");
467 $this->select("country-1", "value=1228");
468 $this->select("state_province-1", "value=1001");
469
470 //Credit Card Info
471 $this->select("credit_card_type", "value=Visa");
472 $this->type("credit_card_number", "4111111111111111");
473 $this->type("cvv2", "000");
474 $this->select("credit_card_exp_date[M]", "value=1");
475 $this->select("credit_card_exp_date[Y]", "value=2020");
476
477 //Billing Info
478 $this->type("billing_first_name", $firstName . "billing");
479 $this->type("billing_last_name", $lastName . "billing");
480 $this->type("billing_street_address-5", "15 Main St.");
481 $this->type(" billing_city-5", "San Jose");
482 $this->select("billing_country_id-5", "value=1228");
483 $this->select("billing_state_province_id-5", "value=1004");
484 $this->type("billing_postal_code-5", "94129");
485 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
486
487 $this->click("_qf_Confirm_next-bottom");
488 $this->waitForPageToLoad($this->getTimeoutMsec());
489
490 // Log in using webtestLogin() method
491 $this->webtestLogin();
492
493 //Find Contribution
494 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
495 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
496 $this->type("sort_name", "$lastName $firstName");
497 $this->multiselect2('contribution_product_id', array('Coffee Mug'));
498 $this->click("_qf_Search_refresh");
499 $this->waitForAjaxContent();
500 $this->waitForElementPresent("xpath=//table[@class='selector row-highlight']/tbody//tr/td[10]/span//a[text()='View']");
501 $this->click("xpath=//table[@class='selector row-highlight']/tbody//tr/td[2]/a[text()='{$lastName}, {$firstName}']/../../td[10]/span//a[text()='View']");
502 $this->waitForElementPresent("xpath=//button//span[contains(text(),'Done')]");
503
504 //View Contribution Record and verify data
505 $expected = array(
506 'From' => "{$firstName} {$lastName}",
507 'Financial Type' => 'Donation',
508 'Total Amount' => '100.00',
509 'Contribution Status' => 'Completed',
510 'Premium' => 'Coffee Mug',
511 );
512 $this->webtestVerifyTabularData($expected);
513 }
514
515 /**
516 * CRM-19263 - Test online pay now functionality
517 */
518 public function testOnlineContributionWithPayNowLink() {
519 $this->webtestLogin();
520 $pageId = 1;
521 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", 'is_pay_later');
522 $this->check('is_pay_later');
523 $this->type('pay_later_text', "I will send payment by check");
524 $this->fillRichTextField('pay_later_receipt', "I will send payment by check");
525 $this->clickLink("_qf_Amount_upload_done-bottom");
526
527 //add financial type of account type expense
528 $financialType = 'Donation';
529 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
530 $usedFor = 'Contribution';
531 $setHelp = 'Select your conference options.';
532 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
533 $sid = $this->urlArg('sid');
534
535 $validateStrings = array();
536 $fields = array(
537 'Full Conference' => 'Text',
538 'Meal Choice' => 'Select',
539 'Pre-conference Meetup?' => 'Radio',
540 'Evening Sessions' => 'CheckBox',
541 );
542
543 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
544
545 //Add profile Details
546 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
547 $lastName = 'An' . substr(sha1(rand()), 0, 7);
548 $name = $this->_testCreateUser($firstName, $lastName);
549 $this->openCiviPage("admin/synchUser", "reset=1", NULL);
550 $this->clickLink("_qf_CMSUser_next-bottom");
551
552 $this->openCiviPage("admin/setting/preferences/contribute", "reset=1", "deferred_revenue_enabled");
553 $this->check('deferred_revenue_enabled');
554 $this->waitForElementPresent('default_invoice_page');
555 $this->select('default_invoice_page', "value=$pageId");
556 $this->clickLink("_qf_Contribute_next-bottom");
557
558 $this->webtestLogin($name, "Test12345");
559 $this->_testContributeWithPayLater($pageId, $firstName);
560
561 $this->_testContributeWithPayNow($firstName);
562
563 $this->openCiviPage("user", "reset=1");
564 $this->assertFalse($this->isTextPresent("Pay Now"));
565
566 $this->webtestLogin();
567
568 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", 'price_set_id');
569 $this->select('price_set_id', "value=9");
570 $this->clickLink("_qf_Amount_upload_done-bottom");
571
572 $this->webtestLogin($name, "Test12345");
573
574 $this->_testContributeWithPayLater($pageId, $firstName, TRUE);
575
576 $this->_testContributeWithPayNow($firstName, TRUE);
577
578 $this->openCiviPage("user", "reset=1");
579 $this->assertFalse($this->isTextPresent("Pay Now"));
580
581 // Type search name in autocomplete.
582 $this->webtestLogin();
583 $this->openCiviPage("civicrm/dashboard", "reset=1", 'sort_name_navigation');
584 $this->click('sort_name_navigation');
585 $this->type('css=input#sort_name_navigation', $firstName);
586 $this->typeKeys('css=input#sort_name_navigation', $firstName);
587 $this->waitForElementPresent("css=ul.ui-autocomplete li");
588 $this->clickLink("css=ul.ui-autocomplete li", 'tab_contribute');
589
590 $this->click('css=li#tab_contribute a');
591 $this->waitForElementPresent('link=Record Contribution (Check, Cash, EFT ...)');
592
593 $amountValues = array(
594 1 => '$ 588.50',
595 2 => '$ 98.50',
596 );
597 foreach ($amountValues as $row => $amount) {
598 $this->clickLink("xpath=//table[@class='selector row-highlight']/tbody/tr[{$row}]/td[8]/span//a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
599
600 // View Contribution Record and test for expected values
601 $expected = array(
602 'From' => "{$firstName} {$lastName}",
603 'Financial Type' => $financialType,
604 'Fee Amount' => '$ 1.50',
605 'Net Amount' => $amount,
606 'Received Into' => 'Payment Processor Account',
607 'Payment Method' => 'Credit Card (Test Processor)',
608 'Contribution Status' => 'Completed',
609 );
610 $this->webtestVerifyTabularData($expected);
611
612 $this->clickAjaxLink("xpath=//span[text()='Done']");
613 }
614 }
615
616 /**
617 * Contribute using pay now link
618 * @param string $firstName
619 * @param bool $priceSet
620 */
621 public function _testContributeWithPayNow($firstName, $priceSet = FALSE) {
622 //user dashboard
623 $this->openCiviPage("user", "reset=1");
624 $this->waitForElementPresent("xpath=//a/span[contains(text(), 'Pay Now')]");
625 $this->clickLink("xpath=//a/span[contains(text(), 'Pay Now')]");
626
627 if (empty($priceSet)) {
628 $this->waitForElementPresent("total_amount");
629 $this->assertTrue($this->isElementPresent("xpath=//input[@id='total_amount'][@readonly=1][@value='100.00']"));
630 }
631 else {
632 $this->assertElementContainsText("xpath=//div[@class='header-dark']", "Contribution Information");
633 $this->assertElementContainsText("xpath=//div[@class='crm-section no-label total_amount-section']", "Contribution Total: $ 590.00");
634 }
635
636 $this->assertFalse($this->isElementPresent("priceset"));
637 $this->assertFalse($this->isElementPresent("xpath=//div[@class='crm-public-form-item crm-section is_pledge-section']"));
638 $this->assertFalse($this->isElementPresent("xpath=//div[@class='crm-public-form-item crm-section premium_block-section']"));
639 $this->assertFalse($this->isElementPresent("xpath=//div[@class='crm-public-form-item crm-group custom_pre_profile-group']"));
640 $this->assertFalse($this->isElementPresent("xpath=//input[@id=email-5]"));
641 $this->assertFalse($this->isElementPresent("xpath=//input[@name='payment_processor_id'][@value=0]"));
642 $this->click("xpath=//input[@name='payment_processor_id'][@value=1]");
643 $this->waitForAjaxContent();
644
645 $this->webtestAddCreditCardDetails();
646 $this->webtestAddBillingDetails();
647 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
648
649 $this->clickLink("_qf_Confirm_next-bottom");
650 $firstName = strtolower($firstName);
651 $emailText = "An email receipt has also been sent to {$firstName}@example.com";
652 $this->waitForTextPresent($emailText);
653
654 }
655
656 /**
657 * Contribute with pay later
658 *
659 * @param int $pageId
660 * @param string $firstName
661 * @param bool $priceSet
662 */
663 public function _testContributeWithPayLater($pageId, $firstName, $priceSet = FALSE) {
664 $this->openCiviPage("contribute/transact", "reset=1&action=preview&id=$pageId", NULL);
665 $this->waitForElementPresent("email-5");
666
667 $this->type("email-5", $firstName . "@example.com");
668
669 if (empty($priceSet)) {
670 $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input");
671 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 100);
672 $this->typeKeys("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 100);
673 }
674 else {
675 $this->type("xpath=//input[@class='four crm-form-text required']", "1");
676 $this->click("xpath=//input[@class='crm-form-radio']");
677 $this->click("xpath=//input[@class='crm-form-checkbox']");
678 }
679
680 $this->waitForTextPresent("Payment Method");
681 $payLaterText = "I will send payment by check";
682 $this->click("xpath=//label[text() = '{$payLaterText}']/preceding-sibling::input[1]");
683
684 $this->waitForAjaxContent();
685 $this->clickLink("_qf_Main_upload-bottom");
686 $this->waitForElementPresent("xpath=//div[@class='bold pay_later_receipt-section']");
687
688 $payLaterInstructionsText = "I will send payment by check";
689 $this->assertElementContainsText("xpath=//div[@class='bold pay_later_receipt-section']/p", $payLaterInstructionsText);
690 $this->clickLink("_qf_Confirm_next-bottom");
691
692 $this->waitForElementPresent("xpath=//div[@class='help']/div/p");
693 $this->assertElementContainsText("xpath=//div[@class='help']/div/p", $payLaterInstructionsText);
694 }
695
696 /**
697 * Create test user
698 *
699 * @param string $firstName
700 * @param string $lastName
701 *
702 * @return string
703 */
704 public function _testCreateUser($firstName, $lastName) {
705 $this->open($this->sboxPath . "admin/people/create");
706
707 $this->waitForElementPresent("edit-submit");
708
709 $name = "TestUser" . substr(sha1(rand()), 0, 4);
710 $this->type("edit-name", $name);
711
712 $emailId = substr(sha1(rand()), 0, 7) . '@web.com';
713 $this->type("edit-mail", $emailId);
714 $this->type("edit-pass-pass1", "Test12345");
715 $this->type("edit-pass-pass2", "Test12345");
716
717 $this->type("first_name", $firstName);
718 $this->type("last_name", $lastName);
719
720 //Address Details
721 $this->type("street_address-1", "902C El Camino Way SW");
722 $this->type("city-1", "Dumfries");
723 $this->type("postal_code-1", "1234");
724 $this->select("state_province-1", "value=1019");
725
726 $this->click("edit-submit");
727 $this->waitForPageToLoad($this->getTimeoutMsec());
728 return $name;
729 }
730
731 }