3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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&action=preview", "_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");
111 $this->click("xpath=id('Main')/div[3]/fieldset/div[2]/div/label[text()='In Honor of']");
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);
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");
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");
135 $this->waitForElementPresent("xpath=//div[@class='crm-section no-label billing_name-section']");
136 $this->assertElementContainsText("xpath=//div[@class='crm-section no-label billing_name-section']", $firstName . "billing");
137 $this->assertElementContainsText("xpath=//div[@class='crm-section no-label billing_name-section']", $lastName . "billing");
139 $this->click("_qf_Confirm_next-bottom");
140 $this->waitForPageToLoad($this->getTimeoutMsec());
142 $this->waitForElementPresent("xpath=//div[@class='crm-section no-label billing_name-section']");
143 $this->assertElementContainsText("xpath=//div[@class='crm-section no-label billing_name-section']", $firstName . "billing");
144 $this->assertElementContainsText("xpath=//div[@class='crm-section no-label billing_name-section']", $lastName . "billing");
146 //login to check contribution
148 // Log in using webtestLogin() method
149 $this->webtestLogin();
152 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
153 $this->type("sort_name", "$lastName $firstName");
154 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
155 $this->clickLink("_qf_Search_refresh", "xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']");
156 $this->clickLink("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
158 //View Contribution Record and verify data
160 'From' => "{$firstName} {$lastName}",
161 'Financial Type' => 'Donation',
162 'Total Amount' => '100.00',
163 'Contribution Status' => 'Completed',
165 $this->webtestVerifyTabularData($expected);
166 //View Soft Credit record of type 'Honor of'
167 $this->waitForTextPresent($honorDisplayName);
168 $this->waitForTextPresent('100.00 (In Honor of)');
170 // Check for Honoree contact created
171 $this->click("css=input#sort_name_navigation");
172 $this->type("css=input#sort_name_navigation", $honorSortName);
173 $this->typeKeys("css=input#sort_name_navigation", $honorSortName);
175 // wait for result list
176 $this->waitForElementPresent("css=ul.ui-autocomplete li");
178 // visit contact summary page
179 $this->click("css=ul.ui-autocomplete li");
180 $this->waitForPageToLoad($this->getTimeoutMsec());
182 // Is contact present?
183 $this->assertTrue($this->isTextPresent("$honorDisplayName"), "Honoree contact not found.");
185 // CRM-16064 - Contributions pricesets charge $1 more than selected
186 $contributionAmt = number_format($rand, 2);
187 $label = "Label $hash";
188 $this->_verifyContributionAmt($pageId, $contributionAmt, $label);
192 public function testOnlineContributionWithZeroAmount() {
193 $this->webtestLogin();
195 // Use default payment processor
196 $processorName = 'Test Processor';
197 $processorType = 'Dummy';
198 $pageTitle = substr(sha1(rand()), 0, 7);
199 $rand = 2 * rand(10, 50);
200 $hash = substr(sha1(rand()), 0, 7);
201 $amountSection = TRUE;
206 $memberships = FALSE;
208 $profilePreId = NULL;
209 $profilePostId = NULL;
213 $memPriceSetId = NULL;
215 // create a new online contribution page
216 // create contribution page with randomized title and default params
217 $pageId = $this->webtestAddContributionPage($hash,
220 array($processorName => $processorType),
236 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_cancel-bottom');
237 $this->type('label_1', "Label $hash");
238 $this->type('value_1', 0);
239 $this->clickLink('_qf_Amount_upload_done-top');
241 //Contribution using Contribution Options
242 $this->_doContributionAndVerifyData($pageId);
245 $this->openCiviPage("admin/price", "reset=1&action=add", '_qf_Set_next-bottom');
246 $this->type('title', "Test Priceset $rand");
247 $this->check('extends_2');
248 $this->select("financial_type_id", "label=Donation");
249 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom', FALSE);
250 $sid = $this->urlArg('sid');
252 $this->type('label', "Testfield");
253 $this->select('html_type', "value=Radio");
254 $this->type('option_label_1', 'test Label');
255 $this->type('option_amount_1', 0.00);
256 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom', FALSE);
257 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_cancel-bottom');
258 $this->select('price_set_id', "value=$sid");
259 $this->clickLink('_qf_Amount_upload_done-bottom', FALSE);
261 //Contribution using priceset
262 $this->_doContributionAndVerifyData($pageId, TRUE);
267 * @param bool $priceSet
269 public function _doContributionAndVerifyData($pageId, $priceSet = FALSE) {
271 $this->webtestLogout();
272 $amountLabel = 'Total Amount';
273 $amountValue = '0.00';
274 //Open Live Contribution Page
275 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom");
277 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
278 $lastName = 'An' . substr(sha1(rand()), 0, 7);
279 $email = $firstName . "@example.com";
280 $this->type("email-5", $email);
283 $this->click("xpath=//div[@id='priceset']/div/div[2]/div/span/input");
284 $amountLabel = 'Contribution Amount';
285 $amountValue = 'Contribution Total: $ 0.00';
289 $this->select("credit_card_type", "value=Visa");
290 $this->type("credit_card_number", "4111111111111111");
291 $this->type("cvv2", "000");
292 $this->select("credit_card_exp_date[M]", "value=1");
293 $this->select("credit_card_exp_date[Y]", "value=2020");
296 $this->type("billing_first_name", $firstName);
297 $this->type("billing_last_name", $lastName);
298 $this->type("billing_street_address-5", "15 Main St.");
299 $this->type(" billing_city-5", "San Jose");
300 $this->select("billing_country_id-5", "value=1228");
301 $this->select("billing_state_province_id-5", "value=1004");
302 $this->type("billing_postal_code-5", "94129");
303 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
305 $this->clickLink("_qf_Confirm_next-bottom", NULL);
307 //login to check contribution
309 // Log in using webtestLogin() method
310 $this->webtestLogin();
313 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
314 $this->type("sort_name", "$email");
315 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
316 $this->waitForAjaxContent();
317 $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]");
318 $this->clickLink("_qf_Search_refresh", "xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", FALSE);
319 $this->clickLink("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
321 //View Contribution Record and verify data
323 'From' => "{$firstName} {$lastName}",
324 'Financial Type' => 'Donation',
325 $amountLabel => $amountValue,
326 'Contribution Status' => 'Completed',
328 $this->webtestVerifyTabularData($expected);
331 public function _verifyContributionAmt($pageId, $contributionAmt, $label) {
333 $this->webtestLogout();
335 //Open Live Contribution Page
336 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom");
337 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
338 $lastName = 'An' . substr(sha1(rand()), 0, 7);
339 $this->type("email-5", $firstName . "@example.com");
341 $this->type("first_name", $firstName);
342 $this->type("last_name", $lastName);
343 $this->check("xpath=//div[@id='priceset']/div[contains(@class, 'contribution_amount-section')]//div[contains(@class, 'contribution_amount-row1')]/span/input");
344 $streetAddress = "100 Main Street";
345 $this->type("street_address-1", $streetAddress);
346 $this->type("city-1", "San Francisco");
347 $this->type("postal_code-1", "94117");
348 $this->select("country-1", "value=1228");
349 $this->select("state_province-1", "value=1001");
352 $this->select("credit_card_type", "value=Visa");
353 $this->type("credit_card_number", "4111111111111111");
354 $this->type("cvv2", "000");
355 $this->select("credit_card_exp_date[M]", "value=1");
356 $this->select("credit_card_exp_date[Y]", "value=2020");
359 $this->type("billing_first_name", $firstName . "billing");
360 $this->type("billing_last_name", $lastName . "billing");
361 $this->type("billing_street_address-5", "15 Main St.");
362 $this->type(" billing_city-5", "San Jose");
363 $this->select("billing_country_id-5", "value=1228");
364 $this->select("billing_state_province_id-5", "value=1004");
365 $this->type("billing_postal_code-5", "94129");
366 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
368 $this->assertElementContainsText("xpath=//div[contains(@class, 'amount_display-group')]//div[@class='display-block']/strong", "$ $contributionAmt - $label", "Contribution amount does not match");
369 $this->clickLink("_qf_Confirm_next-bottom");
370 $this->assertElementContainsText("xpath=//div[contains(@class, 'amount_display-group')]//div[@class='display-block']/strong", "$ $contributionAmt - $label", "Contribution amount does not match");
371 // Log in using webtestLogin() method
372 $this->webtestLogin();
373 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
375 $this->type("sort_name", "$lastName $firstName");
376 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
377 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table[@class='selector row-highlight']//tbody/tr[1]/td[10]/span/a[text()='View']");
378 $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);
380 //View Contribution Record and verify data
382 'From' => "{$firstName} {$lastName}",
383 'Financial Type' => 'Donation',
384 'Total Amount' => $contributionAmt,
385 'Contribution Status' => 'Completed',
387 $this->webtestVerifyTabularData($expected);
390 public function testOnlineContributionWithPremium() {
391 //CRM-16713: Contribution search by premiums on find contribution form.
392 $this->webtestLogin();
394 // Use default payment processor
395 $processorName = 'Test Processor';
396 $processorType = 'Dummy';
397 $pageTitle = substr(sha1(rand()), 0, 7);
398 $rand = 2 * rand(10, 50);
399 $hash = substr(sha1(rand()), 0, 7);
400 $amountSection = TRUE;
405 $memberships = FALSE;
408 $profilePostId = NULL;
412 $memPriceSetId = NULL;
414 // create a new online contribution page
415 // create contribution page with randomized title and default params
416 $pageId = $this->webtestAddContributionPage($hash,
419 array($processorName => $processorType),
436 $this->webtestLogout();
438 //Open Live Contribution Page
439 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom");
441 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
442 $lastName = 'An' . substr(sha1(rand()), 0, 7);
444 $this->type("email-5", $firstName . "@example.com");
446 $this->waitForAjaxContent();
447 $this->click("xpath=//div[@id='premiums-listings']/div[2]/div[1]");
448 $this->waitForAjaxContent();
449 $this->select("xpath=//div[@id='premiums']/fieldset/div[@id='premiums-listings']/div[2]/div[2]/div[2]/div[4]/p/select", "value=Black");
451 $this->type("first_name", $firstName);
452 $this->type("last_name", $lastName);
454 $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input");
455 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 100);
457 $streetAddress = "100 Main Street";
458 $this->type("street_address-1", $streetAddress);
459 $this->type("city-1", "San Francisco");
460 $this->type("postal_code-1", "94117");
461 $this->select("country-1", "value=1228");
462 $this->select("state_province-1", "value=1001");
465 $this->select("credit_card_type", "value=Visa");
466 $this->type("credit_card_number", "4111111111111111");
467 $this->type("cvv2", "000");
468 $this->select("credit_card_exp_date[M]", "value=1");
469 $this->select("credit_card_exp_date[Y]", "value=2020");
472 $this->type("billing_first_name", $firstName . "billing");
473 $this->type("billing_last_name", $lastName . "billing");
474 $this->type("billing_street_address-5", "15 Main St.");
475 $this->type(" billing_city-5", "San Jose");
476 $this->select("billing_country_id-5", "value=1228");
477 $this->select("billing_state_province_id-5", "value=1004");
478 $this->type("billing_postal_code-5", "94129");
479 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
481 $this->click("_qf_Confirm_next-bottom");
482 $this->waitForPageToLoad($this->getTimeoutMsec());
484 // Log in using webtestLogin() method
485 $this->webtestLogin();
488 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
489 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
490 $this->type("sort_name", "$lastName $firstName");
491 $this->multiselect2('contribution_product_id', array('Coffee Mug'));
492 $this->click("_qf_Search_refresh");
493 $this->waitForElementPresent("xpath=//table[@class='selector row-highlight']/tbody//tr/td[10]/span//a[text()='View']");
494 $this->click("xpath=//table[@class='selector row-highlight']/tbody//tr/td[2]/a[text()='{$lastName}, {$firstName}']/../../td[10]/span//a[text()='View']");
495 $this->waitForElementPresent("xpath=//button//span[contains(text(),'Done')]");
497 //View Contribution Record and verify data
499 'From' => "{$firstName} {$lastName}",
500 'Financial Type' => 'Donation',
501 'Total Amount' => '100.00',
502 'Contribution Status' => 'Completed',
503 'Premium' => 'Coffee Mug',
505 $this->webtestVerifyTabularData($expected);