3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
30 * Class WebTest_Contribute_OnlineContributionTest
32 class WebTest_Contribute_OnlineContributionTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testOnlineContributionAdd() {
39 $this->webtestLogin();
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;
55 $profilePostId = NULL;
59 $memPriceSetId = NULL;
61 // create a new online contribution page
62 // create contribution page with randomized title and default params
63 $pageId = $this->webtestAddContributionPage($hash,
66 array($processorName => $processorType),
83 $this->webtestLogout();
85 //Open Live Contribution Page
86 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
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;
96 $this->type("email-5", $firstName . "@example.com");
98 $this->type("first_name", $firstName);
99 $this->type("last_name", $lastName);
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);
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");
112 $this->click("xpath=id('Main')/div[2]/fieldset/div[2]/div/label[text()='In Honor of']");
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);
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");
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");
136 $this->click("_qf_Confirm_next-bottom");
137 $this->waitForPageToLoad($this->getTimeoutMsec());
139 //login to check contribution
141 // Log in using webtestLogin() method
142 $this->webtestLogin();
145 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
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);
151 //View Contribution Record and verify data
153 'From' => "{$firstName} {$lastName}",
154 'Financial Type' => 'Donation',
155 'Total Amount' => '100.00',
156 'Contribution Status' => 'Completed',
158 $this->webtestVerifyTabularData($expected);
160 //View Soft Credit record of type 'Honor of'
161 $this->waitForTextPresent($honorDisplayName);
162 $this->waitForTextPresent('100.00 (In Honor of)');
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);
169 // wait for result list
170 $this->waitForElementPresent("css=ul.ui-autocomplete li");
172 // visit contact summary page
173 $this->click("css=ul.ui-autocomplete li");
174 $this->waitForPageToLoad($this->getTimeoutMsec());
176 // Is contact present?
177 $this->assertTrue($this->isTextPresent("$honorDisplayName"), "Honoree contact not found.");
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);
186 public function testOnlineContributionWithZeroAmount() {
187 $this->webtestLogin();
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;
200 $memberships = FALSE;
202 $profilePreId = NULL;
203 $profilePostId = NULL;
207 $memPriceSetId = NULL;
209 // create a new online contribution page
210 // create contribution page with randomized title and default params
211 $pageId = $this->webtestAddContributionPage($hash,
214 array($processorName => $processorType),
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');
235 //Contribution using Contribution Options
236 $this->_doContributionAndVerifyData($pageId);
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');
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);
255 //Contribution using priceset
256 $this->_doContributionAndVerifyData($pageId, TRUE);
261 * @param bool $priceSet
263 public function _doContributionAndVerifyData($pageId, $priceSet = FALSE) {
265 $this->webtestLogout();
266 $amountLabel = 'Total Amount';
267 $amountValue = '0.00';
268 //Open Live Contribution Page
269 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
271 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
272 $lastName = 'An' . substr(sha1(rand()), 0, 7);
274 $this->type("email-5", $firstName . "@example.com");
277 $this->click("xpath=//div[@id='priceset']/div/div[2]/div/span/input");
278 $amountLabel = 'Contribution Amount';
279 $amountValue = 'Contribution Total: $ 0.00';
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");
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");
299 $this->clickLink("_qf_Confirm_next-bottom", NULL);
301 //login to check contribution
303 // Log in using webtestLogin() method
304 $this->webtestLogin();
307 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
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);
313 //View Contribution Record and verify data
315 'From' => "{$firstName} {$lastName}",
316 'Financial Type' => 'Donation',
317 $amountLabel => $amountValue,
318 'Contribution Status' => 'Completed',
320 $this->webtestVerifyTabularData($expected);
323 public function _verifyContributionAmt($pageId, $contributionAmt, $label) {
325 $this->webtestLogout();
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");
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");
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");
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");
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");
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);
371 //View Contribution Record and verify data
373 'From' => "{$firstName} {$lastName}",
374 'Financial Type' => 'Donation',
375 'Total Amount' => $contributionAmt,
376 'Contribution Status' => 'Completed',
378 $this->webtestVerifyTabularData($expected);
381 //CRM-16713: Contribution search by premiums on find contribution form.
382 public function testOnlineContributionWithPremium() {
383 $this->webtestLogin();
385 // Use default payment processor
386 $processorName = 'Test Processor';
387 $processorType = 'Dummy';
388 $pageTitle = substr(sha1(rand()), 0, 7);
389 $rand = 2 * rand(10, 50);
390 $hash = substr(sha1(rand()), 0, 7);
391 $amountSection = TRUE;
396 $memberships = FALSE;
399 $profilePostId = NULL;
403 $memPriceSetId = NULL;
405 // create a new online contribution page
406 // create contribution page with randomized title and default params
407 $pageId = $this->webtestAddContributionPage($hash,
410 array($processorName => $processorType),
427 $this->webtestLogout();
429 //Open Live Contribution Page
430 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
432 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
433 $lastName = 'An' . substr(sha1(rand()), 0, 7);
435 $this->type("email-5", $firstName . "@example.com");
437 $this->waitForAjaxContent();
438 $this->click("xpath=//div[@id='premiums-listings']/div[2]/div[1]");
439 $this->waitForAjaxContent();
440 $this->select("xpath=//div[@id='premiums']/fieldset/div[@id='premiums-listings']/div[2]/div[2]/div[2]/div[4]/p/select", "value=Black");
442 $this->type("first_name", $firstName);
443 $this->type("last_name", $lastName);
445 $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input");
446 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 100);
448 $streetAddress = "100 Main Street";
449 $this->type("street_address-1", $streetAddress);
450 $this->type("city-1", "San Francisco");
451 $this->type("postal_code-1", "94117");
452 $this->select("country-1", "value=1228");
453 $this->select("state_province-1", "value=1001");
456 $this->select("credit_card_type", "value=Visa");
457 $this->type("credit_card_number", "4111111111111111");
458 $this->type("cvv2", "000");
459 $this->select("credit_card_exp_date[M]", "value=1");
460 $this->select("credit_card_exp_date[Y]", "value=2020");
463 $this->type("billing_first_name", $firstName . "billing");
464 $this->type("billing_last_name", $lastName . "billing");
465 $this->type("billing_street_address-5", "15 Main St.");
466 $this->type(" billing_city-5", "San Jose");
467 $this->select("billing_country_id-5", "value=1228");
468 $this->select("billing_state_province_id-5", "value=1004");
469 $this->type("billing_postal_code-5", "94129");
470 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
472 $this->click("_qf_Confirm_next-bottom");
473 $this->waitForPageToLoad($this->getTimeoutMsec());
475 // Log in using webtestLogin() method
476 $this->webtestLogin();
479 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
481 $this->type("sort_name", "$lastName $firstName");
482 $this->multiselect2('contribution_product_id', array('Coffee Mug'));
483 $this->click("_qf_Search_refresh");
484 $this->waitForElementPresent("xpath=//div[@id='contributionSearch']/table/tbody//tr/td[11]/span/a[text()='View']");
485 $this->click("xpath=//div[@id='contributionSearch']/table/tbody/tr[1]/td[3]/a[text()='{$lastName}, {$firstName}']/../../td[11]/span/a[text()='View']");
486 $this->waitForElementPresent("xpath=//button//span[contains(text(),'Done')]");
488 //View Contribution Record and verify data
490 'From' => "{$firstName} {$lastName}",
491 'Financial Type' => 'Donation',
492 'Total Amount' => '100.00',
493 'Contribution Status' => 'Completed',
494 'Premium' => 'Coffee Mug',
496 $this->webtestVerifyTabularData($expected);