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_OfflineContributionTest
32 class WebTest_Contribute_OfflineContributionTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testStandaloneContributeAdd() {
39 $this->webtestLogin();
41 // Create a contact to be used as soft creditor
42 $softCreditFname = substr(sha1(rand()), 0, 7);
43 $softCreditLname = substr(sha1(rand()), 0, 7);
44 $this->webtestAddContact($softCreditFname, $softCreditLname, FALSE);
46 //financial account for check
47 $this->openCiviPage("admin/options/payment_instrument", "reset=1");
48 $financialAccount = $this->getText("xpath=//div[@id='payment_instrument']/table/tbody//tr/td[1]/div[text()='Check']/../../td[3]");
50 // Add new Financial Account
51 $orgName = 'Alberta ' . substr(sha1(rand()), 0, 7);
52 $financialAccountTitle = 'Financial Account ' . substr(sha1(rand()), 0, 4);
53 $financialAccountDescription = "{$financialAccountTitle} Description";
54 $accountingCode = 1033;
55 $financialAccountType = 'Asset';
56 $taxDeductible = FALSE;
62 //Add new organisation
64 $this->webtestAddOrganization($orgName);
67 $this->_testAddFinancialAccount($financialAccountTitle,
68 $financialAccountDescription,
71 $financialAccountType,
79 $firstName = 'John' . substr(sha1(rand()), 0, 7);
80 $lastName = 'Dsouza' . substr(sha1(rand()), 0, 7);
81 $this->webtestAddContact($firstName, $lastName);
83 $this->waitForElementPresent("css=li#tab_contribute a");
84 $this->click("css=li#tab_contribute a");
85 $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
86 $this->clickLink("link=Record Contribution (Check, Cash, EFT ...)", "_qf_Contribution_cancel-bottom", FALSE);
88 // select financial type
89 $this->select("financial_type_id", "value=1");
91 // fill in Received Date
92 $this->webtestFillDate('receive_date');
95 $this->type("source", "Mailer 1");
98 $this->type("total_amount", "100");
99 // revenue recognition date (CRM-16189)
100 if (CRM_Contribute_BAO_Contribution
::checkContributeSettings('deferred_revenue_enabled')) {
101 $this->webtestFillDate('revenue_recognition_date', 'now+4');
104 // select payment instrument type = Check and enter chk number
105 $this->select("payment_instrument_id", "value=4");
106 $this->waitForElementPresent("check_number");
107 $this->type("check_number", "check #1041");
109 $this->type("trxn_id", "P20901X1" . rand(100, 10000));
111 // create first soft credit
112 $this->click("softCredit");
113 $this->waitForElementPresent("soft_credit_amount_1");
114 $this->webtestFillAutocomplete("{$softCreditLname}, {$softCreditFname}", 's2id_soft_credit_contact_id_1');
115 $this->type("soft_credit_amount_1", "50");
117 // add second soft credit field
118 $this->click("addMoreSoftCredit");
119 $this->waitForElementPresent("soft_credit_amount_2");
120 // create new individual via soft credit
121 $softCreditSecondFname = substr(sha1(rand()), 0, 7);
122 $softCreditSecondLname = substr(sha1(rand()), 0, 7);
123 $this->webtestNewDialogContact($softCreditSecondFname, $softCreditSecondLname, NULL, 4, 's2id_soft_credit_contact_id_2', 'soft_credit_1');
124 // enter the second soft credit
125 $this->verifyText("soft_credit_amount_2", ""); // it should be blank cause first soft credit != total_amount
126 $this->type("soft_credit_amount_2", "100"); //the sum of the soft credit amounts can exceed total_amount
127 $this->select("soft_credit_type[2]", "In Honor of");
130 // $this->click('CIVICRM_QFID_3_6');
132 //Additional Detail section
133 $this->click("AdditionalDetail");
134 $this->waitForElementPresent("thankyou_date");
136 $this->type("note", "This is a test note.");
137 $this->type("non_deductible_amount", "10.00");
138 $this->type("fee_amount", "0");
139 $this->type("net_amount", "0");
140 $this->type("invoice_id", time());
141 $this->webtestFillDate('thankyou_date');
144 $this->click("Premium");
145 $this->waitForElementPresent("fulfilled_date");
146 $this->select("product_name[0]", "label=Coffee Mug ( MUG-101 )");
147 $this->select("product_name[1]", "label=Black");
148 $this->webtestFillDate('fulfilled_date');
151 $this->click("_qf_Contribution_upload");
153 // Is status message correct?
154 //$this->assertTrue($this->isTextPresent("The contribution record has been saved."), "Status message didn't show up after saving!");
156 // verify if Contribution is created
157 $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']");
159 //click through to the Contribution view screen
160 $this->click("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']");
161 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
164 'Financial Type' => 'Donation',
165 'Total Amount' => '100.00',
166 'Contribution Status' => 'Completed',
167 'Payment Method' => 'Check',
168 'Check Number' => 'check #1041',
169 'Non-deductible Amount' => '10.00',
170 'Received Into' => $financialAccount,
173 $this->waitForElementPresent("xpath=//*[@id='ContributionView']/div[2]");
174 foreach ($expected as $value) {
175 $this->assertElementContainsText("xpath=//*[@id='ContributionView']/div[2]", $value);
178 // verify if soft credit was created successfully
180 'Soft Credit To 1' => "{$softCreditFname} {$softCreditLname}",
181 'Soft Credit To 2' => "{$softCreditSecondFname} {$softCreditSecondLname}",
182 'Amount (Soft Credit Type)' => '100.00 (In Honor of)',
185 foreach ($expected as $value) {
186 $this->assertElementContainsText("css=table.crm-soft-credit-listing", $value);
189 // go to first soft creditor contact view page
190 $this->clickLink("xpath=//*[@id='ContributionView']/div[2]/div[2]/div[2]/table/tbody/tr[1]/td[1]/a", "css=li#tab_contribute a");
192 // go to contribution tab
193 $this->click("css=li#tab_contribute a");
194 $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
196 // verify soft credit details
202 1 => "{$firstName} {$lastName}",
204 foreach ($expected as $value => $label) {
205 $this->assertElementContainsText("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[2]/td[$value]", $label);
209 public function testDeductibleAmount() {
210 $this->webtestLogin();
212 // disable verify ssl when using authorize .net
213 $this->openCiviPage("admin/setting/url", "reset=1");
214 $this->click("id=CIVICRM_QFID_0_verifySSL");
215 $this->click("id=_qf_Url_next-bottom");
216 $this->waitForPageToLoad($this->getTimeoutMsec());
218 //add authorize .net payment processor
219 $processorName = 'Webtest AuthNet' . substr(sha1(rand()), 0, 7);
220 $this->webtestAddPaymentProcessor($processorName, 'AuthNet');
222 $this->openCiviPage("admin/contribute/managePremiums", "action=add&reset=1");
223 $premiumName = 'test Premium' . substr(sha1(rand()), 0, 7);
224 $this->addPremium($premiumName, 'SKU', 3, 12, NULL, NULL);
226 $firstName = 'John' . substr(sha1(rand()), 0, 7);
227 $lastName = 'Dsouza' . substr(sha1(rand()), 0, 7);
228 $this->webtestAddContact($firstName, $lastName);
230 //scenario 1 : is_deductible = 0 and non deductible amount is entered
232 'financial_type' => 'Campaign Contribution',
233 'total_amount' => 111,
234 'non_deductible_amount' => 15,
235 'sort_name' => "$lastName, $firstName",
237 $this->_doOfflineContribution($scenario1, $firstName, $lastName, $processorName);
239 $checkScenario1 = array(
240 'From' => "{$firstName} {$lastName}",
241 'Financial Type' => 'Campaign Contribution',
242 'Total Amount' => 111,
243 'Non-deductible Amount' => 15,
244 'sort_name' => "$lastName, $firstName",
246 $this->_verifyAmounts($checkScenario1);
248 //scenario 2 : is_deductible = TRUE and premium is set and premium is greater than total amount
250 'financial_type' => 'Donation',
251 'total_amount' => 10,
252 'premium' => "{$premiumName} ( SKU )",
253 'sort_name' => "$lastName, $firstName",
255 $this->_doOfflineContribution($scenario2, $firstName, $lastName, $processorName);
257 $checkScenario2 = array(
258 'From' => "{$firstName} {$lastName}",
259 'Financial Type' => 'Donation',
260 'Total Amount' => 10,
261 'Non-deductible Amount' => 10,
262 'sort_name' => "$lastName, $firstName",
264 $this->_verifyAmounts($checkScenario2);
266 //scenario 3 : is_deductible = TRUE and premium is set and premium is less than total amount
268 'financial_type' => 'Donation',
269 'total_amount' => 123,
270 'premium' => "{$premiumName} ( SKU )",
271 'sort_name' => "$lastName, $firstName",
273 $this->_doOfflineContribution($scenario3, $firstName, $lastName, $processorName);
275 $checkScenario3 = array(
276 'From' => "{$firstName} {$lastName}",
277 'Financial Type' => 'Donation',
278 'Total Amount' => 123,
279 'Non-deductible Amount' => 12,
280 'sort_name' => "$lastName, $firstName",
282 $this->_verifyAmounts($checkScenario3);
284 //scenario 4 : is_deductible = TRUE and premium is not set
286 'financial_type' => 'Donation',
287 'total_amount' => 123,
288 'sort_name' => "$lastName, $firstName",
290 $this->_doOfflineContribution($scenario4, $firstName, $lastName, $processorName);
292 $checkScenario4 = array(
293 'From' => "{$firstName} {$lastName}",
294 'Financial Type' => 'Donation',
295 'Total Amount' => 123,
296 'Non-deductible Amount' => '0.00',
297 'sort_name' => "$lastName, $firstName",
299 $this->_verifyAmounts($checkScenario4);
301 //scenario 5 : is_deductible = FALSE, non_deductible_amount = the total amount
303 'financial_type' => 'Campaign Contribution',
304 'total_amount' => 555,
305 'sort_name' => "$lastName, $firstName",
307 $this->_doOfflineContribution($scenario5, $firstName, $lastName, $processorName);
309 $checkScenario5 = array(
310 'From' => "{$firstName} {$lastName}",
311 'Financial Type' => 'Campaign Contribution',
312 'Total Amount' => 555,
313 'Non-deductible Amount' => 555,
314 'sort_name' => "$lastName, $firstName",
316 $this->_verifyAmounts($checkScenario5);
320 * common function for doing offline contribution.
321 * @param array $params
322 * @param string $firstName
323 * @param string $lastName
324 * @param $processorName
326 public function _doOfflineContribution($params, $firstName, $lastName, $processorName) {
328 $this->waitForElementPresent("css=li#tab_contribute a");
329 $this->click("css=li#tab_contribute a");
330 $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
332 // since we don't have live credentials we will switch to test mode
333 $url = $this->getAttribute("xpath=//*[@id='Search']/div[2]/div[2]/a[1]@href");
334 $url .= '&mode=test';
336 $this->waitForPageToLoad($this->getTimeoutMsec());
338 // start filling out contribution form
339 $this->waitForElementPresent('payment_processor_id');
340 $this->select('payment_processor_id', "label={$processorName}");
342 // select financial type
343 $this->select("financial_type_id", "label={$params['financial_type']}");
346 $this->type("total_amount", "{$params['total_amount']}");
348 // enter credit card info on form
349 $this->webtestAddCreditCardDetails();
352 $this->webtestAddBillingDetails($firstName, NULL, $lastName);
354 if ($nonDeductibleAmt = CRM_Utils_Array
::value('non_deductible_amount', $params)) {
355 $this->click("AdditionalDetail");
356 $this->waitForElementPresent("thankyou_date");
357 $this->type("note", "This is a test note.");
358 $this->type("non_deductible_amount", "{$nonDeductibleAmt}");
361 if (!empty($params['premium'])) {
363 $this->click("Premium");
364 $this->waitForElementPresent("fulfilled_date");
365 $this->select("product_name[0]", "label={$params['premium']}");
368 $this->click("_qf_Contribution_upload-bottom");
369 $this->waitForPageToLoad($this->getTimeoutMsec());
371 // Is status message correct?
372 $this->assertTrue($this->isTextPresent("The contribution record has been saved."), "Status message didn't show up after saving!");
376 * common function for verifing total_amount, and non_deductible_amount
379 public function _verifyAmounts($verifyData) {
380 // since we are doing test contributions we need to search for test contribution and select first contribution
381 // record for the contact
382 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
383 $this->type("sort_name", $verifyData['sort_name']);
385 // select show test contributions
386 $this->click("contribution_test", "value=1");
387 $this->clickLink("_qf_Search_refresh", "xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", FALSE);
388 $this->clickLink("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
390 foreach ($verifyData as $label => $value) {
391 if ($label == 'sort_name') {
394 $this->assertElementContainsText("xpath=//form[@id='ContributionView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td", "{$value}");
397 // now find contact and go back to contact summary
398 $this->openCiviPage("contact/search", "reset=1", "sort_name");
399 $this->type("sort_name", $verifyData['sort_name']);
400 $this->clickLink("_qf_Basic_refresh",
401 "xpath=//form[@id='Basic']/div[3]/div[1]/div[2]/table/tbody/tr[1]/td[11]/span/a[text()='View']");
403 $this->clickLink("xpath=//form[@id='Basic']/div[3]/div[1]/div[2]/table/tbody/tr[1]/td[11]/span/a[text()='View']",
404 'crm-contact-actions-link', FALSE);
407 public function testOnlineContributionWithZeroAmount() {
408 $this->webtestLogin();
410 // Create a contact to be used as soft creditor
411 $firstName = 'John' . substr(sha1(rand()), 0, 7);
412 $lastName = 'Peterson' . substr(sha1(rand()), 0, 7);
413 $this->webtestAddContact($firstName, $lastName);
414 $this->waitForElementPresent("css=li#tab_contribute a");
415 $this->click("css=li#tab_contribute a");
416 $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
417 $this->clickLink("link=Record Contribution (Check, Cash, EFT ...)", "_qf_Contribution_cancel-bottom", FALSE);
419 // select financial type
420 $this->select("financial_type_id", "value=1");
423 $this->type("total_amount", "0.00");
425 // select payment instrument
426 $this->select("payment_instrument_id", "value=1");
428 $this->type("trxn_id", "X20901X1" . rand(100, 10000));
429 $this->click('_qf_Contribution_upload-bottom');
430 $this->waitForText("crm-notification-container", "The contribution record has been saved.");
432 $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']");
433 $this->clickLink("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
435 'Financial Type' => 'Donation',
436 'Total Amount' => '0.00',
437 'Contribution Status' => 'Completed',
438 'Payment Method' => 'Credit Card',
440 $this->webtestVerifyTabularData($expected);
443 public function testDefaultCurrancy() {
444 $this->webtestLogin();
445 $this->enableCurrency(array('GBP', 'EUR'));
448 $firstName = 'John' . substr(sha1(rand()), 0, 7);
449 $lastName = 'Peterson' . substr(sha1(rand()), 0, 7);
450 $this->webtestAddContact($firstName, $lastName);
452 //Create contribution for contact
453 $this->waitForElementPresent("css=li#tab_contribute a");
454 $this->click("css=li#tab_contribute a");
455 $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
456 $this->click("link=Record Contribution (Check, Cash, EFT ...)");
457 $this->waitForElementPresent("financial_type_id");
458 $this->select("financial_type_id", "value=1");
459 $this->select("currency", "value=GBP");
460 $this->type("total_amount", "100");
461 $this->click("xpath=//div[@class='ui-dialog-buttonset']//button//span[text()='Save']");
462 $this->waitForAjaxContent();
463 $this->waitForElementPresent("xpath=//table[@class='selector row-highlight']");
464 $this->assertElementContainsText("xpath=//table[@class='selector row-highlight']/tbody/tr//td/a", "£ 100.00");
465 $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr//td/a", "£ 100.00");
466 $this->waitForElementPresent("xpath=//table[@id='info']");
467 $this->assertElementContainsText("xpath=//table[@id='info']/tbody/tr[2]/td[1]", "£ 100.00");
470 public function testRevenueRecognitionDateAdd() {
471 $this->webtestLogin();
472 $this->openCiviPage("admin/setting/preferences/contribute", "reset=1");
473 $this->waitForElementPresent("_qf_Contribute_next");
474 $this->click('deferred_revenue_enabled');
475 $this->click('_qf_Contribute_next');
476 $this->waitForPageToLoad($this->getTimeoutMsec());
478 // Create a contact to be used as soft creditor
479 $softCreditFname = substr(sha1(rand()), 0, 7);
480 $softCreditLname = substr(sha1(rand()), 0, 7);
481 $this->webtestAddContact($softCreditFname, $softCreditLname, FALSE);
483 //financial account for check
484 $this->openCiviPage("admin/options/payment_instrument", "reset=1");
485 $financialAccount = $this->getText("xpath=//div[@id='payment_instrument']/table/tbody//tr/td[1]/div[text()='Check']/../../td[3]");
487 // Add new Financial Account
488 $orgName = 'Alberta ' . substr(sha1(rand()), 0, 7);
489 $financialAccountTitle = 'Financial Account ' . substr(sha1(rand()), 0, 4);
490 $financialAccountDescription = "{$financialAccountTitle} Description";
491 $accountingCode = 1033;
492 $financialAccountType = 'Asset';
493 $taxDeductible = FALSE;
499 //Add new organisation
501 $this->webtestAddOrganization($orgName);
504 $this->_testAddFinancialAccount($financialAccountTitle,
505 $financialAccountDescription,
508 $financialAccountType,
516 $firstName = 'John' . substr(sha1(rand()), 0, 7);
517 $lastName = 'Dsouza' . substr(sha1(rand()), 0, 7);
518 $this->webtestAddContact($firstName, $lastName);
520 $this->waitForElementPresent("css=li#tab_contribute a");
521 $this->click("css=li#tab_contribute a");
522 $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
523 $this->clickLink("link=Record Contribution (Check, Cash, EFT ...)", "_qf_Contribution_cancel-bottom", FALSE);
525 // select financial type
526 $this->select("financial_type_id", "value=1");
528 // fill in Received Date
529 $this->webtestFillDate('receive_date');
532 $this->type("source", "Mailer 1");
535 $this->type("total_amount", "100");
537 // revenue recognition date (CRM-16189)
538 $this->webtestFillDate('revenue_recognition_date', 'now');
540 // select payment instrument type = Check and enter chk number
541 $this->select("payment_instrument_id", "value=4");
542 $this->waitForElementPresent("check_number");
543 $this->type("check_number", "check #1041");
545 $this->type("trxn_id", "P20901X1" . rand(100, 10000));
547 //Additional Detail section
548 $this->click("AdditionalDetail");
549 $this->waitForElementPresent("thankyou_date");
551 $this->type("note", "This is a test note.");
552 $this->type("non_deductible_amount", "10.00");
553 $this->type("fee_amount", "0");
554 $this->type("net_amount", "0");
555 $this->type("invoice_id", time());
556 $this->webtestFillDate('thankyou_date');
559 $this->click("_qf_Contribution_upload");
561 // verify if Contribution is created
562 $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='Edit']");
564 //click through to the Contribution edit screen
565 $this->click("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='Edit']");
566 $this->waitForElementPresent("_qf_Contribution_cancel");
567 $val = $this->getValue("xpath=//input[@id='revenue_recognition_date']");
568 $this->assertEquals(date('m/d/Y'), $val);