4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License along with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
30 class WebTest_Contribute_OfflineContributionTest
extends CiviSeleniumTestCase
{
32 protected function setUp() {
36 function testStandaloneContributeAdd() {
37 $this->webtestLogin();
39 // Create a contact to be used as soft creditor
40 $softCreditFname = substr(sha1(rand()), 0, 7);
41 $softCreditLname = substr(sha1(rand()), 0, 7);
42 $this->webtestAddContact($softCreditFname, $softCreditLname, FALSE);
44 //financial account for check
45 $this->openCiviPage("admin/options/payment_instrument", "group=payment_instrument&reset=1");
46 $financialAccount = $this->getText("xpath=//div[@id='payment_instrument']/div[2]/table/tbody//tr/td[1][text()='Check']/../td[3]");
48 // Add new Financial Account
49 $orgName = 'Alberta ' . substr(sha1(rand()), 0, 7);
50 $financialAccountTitle = 'Financial Account ' . substr(sha1(rand()), 0, 4);
51 $financialAccountDescription = "{$financialAccountTitle} Description";
52 $accountingCode = 1033;
53 $financialAccountType = 'Asset';
54 $taxDeductible = FALSE;
60 //Add new organisation
62 $this->webtestAddOrganization($orgName);
65 $this->_testAddFinancialAccount($financialAccountTitle,
66 $financialAccountDescription,
69 $financialAccountType,
77 $firstName = 'John' . substr(sha1(rand()), 0, 7);
78 $lastName = 'Dsouza' . substr(sha1(rand()), 0, 7);
79 $this->webtestAddContact($firstName, $lastName);
81 $this->waitForElementPresent("css=li#tab_contribute a");
82 $this->click("css=li#tab_contribute a");
83 $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
84 $this->click("link=Record Contribution (Check, Cash, EFT ...)");
85 $this->waitForPageToLoad($this->getTimeoutMsec());
87 // select financial type
88 $this->select("financial_type_id", "value=1");
90 // fill in Received Date
91 $this->webtestFillDate('receive_date');
94 $this->type("source", "Mailer 1");
97 $this->type("total_amount", "100");
99 // select payment instrument type = Check and enter chk number
100 $this->select("payment_instrument_id", "value=4");
101 $this->waitForElementPresent("check_number");
102 $this->type("check_number", "check #1041");
104 $this->type("trxn_id", "P20901X1" . rand(100, 10000));
106 // create first soft credit
107 $this->webtestFillAutocomplete("{$softCreditLname}, {$softCreditFname}", 'soft_credit_contact_1');
108 $this->type("soft_credit_amount_1", "50");
110 // add second soft credit field
111 $this->click("addMoreSoftCredit");
112 $this->waitForElementPresent("soft_credit_amount_2");
113 // create new individual via soft credit
114 $softCreditSecondFname = substr(sha1(rand()), 0, 7);
115 $softCreditSecondLname = substr(sha1(rand()), 0, 7);
116 $this->webtestNewDialogContact($softCreditSecondFname, $softCreditSecondLname, NULL, 4, 'soft_credit_profiles_2', 'soft_credit_1');
117 // enter the second soft credit
118 $this->verifyText("soft_credit_amount_2", ""); // it should be blank cause first soft credit != total_amount
119 $this->type("soft_credit_amount_2", "100"); //the sum of the soft credit amounts can exceed total_amount
122 // $this->click('CIVICRM_QFID_3_6');
124 //Additional Detail section
125 $this->click("AdditionalDetail");
126 $this->waitForElementPresent("thankyou_date");
128 $this->type("note", "This is a test note.");
129 $this->type("non_deductible_amount", "10.00");
130 $this->type("fee_amount", "0");
131 $this->type("net_amount", "0");
132 $this->type("invoice_id", time());
133 $this->webtestFillDate('thankyou_date');
136 $this->click("Honoree");
137 $this->waitForElementPresent("honor_email");
139 $this->click("CIVICRM_QFID_1_2");
140 $this->select("honor_prefix_id", "label=Ms.");
141 $this->type("honor_first_name", "Foo");
142 $this->type("honor_last_name", "Bar");
143 $this->type("honor_email", "foo@bar.com");
146 $this->click("Premium");
147 $this->waitForElementPresent("fulfilled_date");
148 $this->select("product_name[0]", "label=Coffee Mug ( MUG-101 )");
149 $this->select("product_name[1]", "label=Black");
150 $this->webtestFillDate('fulfilled_date');
153 $this->click("_qf_Contribution_upload");
154 $this->waitForPageToLoad($this->getTimeoutMsec());
156 // Is status message correct?
157 //$this->assertTrue($this->isTextPresent("The contribution record has been saved."), "Status message didn't show up after saving!");
159 // verify if Contribution is created
160 $this->waitForElementPresent("xpath=//div[@id='Contributions']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
162 //click through to the Contribution view screen
163 $this->click("xpath=//div[@id='Contributions']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
164 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
167 'Financial Type' => 'Donation',
168 'Total Amount' => '100.00',
169 'Contribution Status' => 'Completed',
170 'Paid By' => 'Check',
171 'Check Number' => 'check #1041',
172 'Non-deductible Amount' => '10.00',
173 'Received Into' => $financialAccount,
176 $this->waitForElementPresent("xpath=/html/body/div[3]/div/div[2]/div/div[3]/div/div[2]/div/div/div/form/div[2]");
177 foreach ($expected as $value) {
178 $this->verifyText("xpath=/html/body/div[3]/div/div[2]/div/div[3]/div/div[2]/div/div/div/form/div[2]", preg_quote($value));
181 // verify if soft credit was created successfully
183 'Soft Credit To 1' => "{$softCreditFname} {$softCreditLname}",
184 'Soft Credit To 2' => "{$softCreditSecondFname} {$softCreditSecondLname}",
186 'Amount' => '100.00',
189 foreach ($expected as $value) {
190 $this->verifyText("css=table.crm-soft-credit-listing", preg_quote($value));
193 // go to first soft creditor contact view page
194 $this->click("css=table.crm-soft-credit-listing tbody tr td a");
196 // go to contribution tab
197 $this->waitForElementPresent("css=li#tab_contribute a");
198 $this->click("css=li#tab_contribute a");
199 $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
201 // verify soft credit details
206 1 => "{$firstName} {$lastName}"
208 foreach ($expected as $value => $label) {
209 $this->verifyText("xpath=id('Search')/div[2]/table[2]/tbody/tr[2]/td[$value]", preg_quote($label));
213 function testDeductibleAmount() {
214 $this->webtestLogin();
216 //add authorize .net payment processor
217 $processorName = 'Webtest AuthNet' . substr(sha1(rand()), 0, 7);
218 $this->webtestAddPaymentProcessor($processorName, 'AuthNet');
220 $this->openCiviPage("admin/contribute/managePremiums", "action=add&reset=1");
221 $premiumName = 'test Premium' . substr(sha1(rand()), 0, 7);
222 $this->addPremium($premiumName, 'SKU', 3, 12, NULL, NULL);
224 $firstName = 'John' . substr(sha1(rand()), 0, 7);
225 $lastName = 'Dsouza' . substr(sha1(rand()), 0, 7);
226 $this->webtestAddContact($firstName, $lastName);
228 //scenario 1 : is_deductible = 0 and non deductible amount is entered
230 'financial_type' => 'Campaign Contribution',
231 'total_amount' => 111,
232 'non_deductible_amount' => 15,
233 'sort_name' => "$lastName, $firstName",
235 $this->_doOfflineContribution($scenario1, $firstName, $lastName, $processorName);
237 $checkScenario1 = array(
238 'From' => "{$firstName} {$lastName}",
239 'Financial Type' => 'Campaign Contribution',
240 'Total Amount' => 111,
241 'Non-deductible Amount' => 15,
242 'sort_name' => "$lastName, $firstName",
244 $this->_verifyAmounts($checkScenario1);
246 //scenario 2 : is_deductible = TRUE and premium is set and premium is greater than total amount
248 'financial_type' => 'Donation',
249 'total_amount' => 10,
250 'premium' => "{$premiumName} ( SKU )",
251 'sort_name' => "$lastName, $firstName",
253 $this->_doOfflineContribution($scenario2, $firstName, $lastName, $processorName);
255 $checkScenario2 = array(
256 'From' => "{$firstName} {$lastName}",
257 'Financial Type' => 'Donation',
258 'Total Amount' => 10,
259 'Non-deductible Amount' => 10,
260 'sort_name' => "$lastName, $firstName",
262 $this->_verifyAmounts($checkScenario2);
264 //scenario 3 : is_deductible = TRUE and premium is set and premium is less than total amount
266 'financial_type' => 'Donation',
267 'total_amount' => 123,
268 'premium' => "{$premiumName} ( SKU )",
269 'sort_name' => "$lastName, $firstName",
271 $this->_doOfflineContribution($scenario3, $firstName, $lastName, $processorName);
273 $checkScenario3 = array(
274 'From' => "{$firstName} {$lastName}",
275 'Financial Type' => 'Donation',
276 'Total Amount' => 123,
277 'Non-deductible Amount' => 12,
278 'sort_name' => "$lastName, $firstName",
280 $this->_verifyAmounts($checkScenario3);
282 //scenario 4 : is_deductible = TRUE and premium is not set
284 'financial_type' => 'Donation',
285 'total_amount' => 123,
286 'sort_name' => "$lastName, $firstName",
288 $this->_doOfflineContribution($scenario4, $firstName, $lastName, $processorName);
290 $checkScenario4 = array(
291 'From' => "{$firstName} {$lastName}",
292 'Financial Type' => 'Donation',
293 'Total Amount' => 123,
294 'Non-deductible Amount' => '0.00',
295 'sort_name' => "$lastName, $firstName",
297 $this->_verifyAmounts($checkScenario4);
299 //scenario 5 : is_deductible = FALSE, non_deductible_amount = the total amount
301 'financial_type' => 'Campaign Contribution',
302 'total_amount' => 555,
303 'sort_name' => "$lastName, $firstName",
305 $this->_doOfflineContribution($scenario5, $firstName, $lastName, $processorName);
307 $checkScenario5 = array(
308 'From' => "{$firstName} {$lastName}",
309 'Financial Type' => 'Campaign Contribution',
310 'Total Amount' => 555,
311 'Non-deductible Amount' => 555,
312 'sort_name' => "$lastName, $firstName",
314 $this->_verifyAmounts($checkScenario5);
317 //common function for doing offline contribution
318 function _doOfflineContribution($params, $firstName, $lastName, $processorName) {
320 $this->waitForElementPresent("css=li#tab_contribute a");
321 $this->click("css=li#tab_contribute a");
322 $this->waitForElementPresent("link=Submit Credit Card Contribution");
323 $this->click("link=Submit Credit Card Contribution");
324 $this->waitForPageToLoad($this->getTimeoutMsec());
326 // since we don't have live credentials we will switch to test mode
327 $url = $this->getLocation();
328 $url = str_replace('mode=live', 'mode=test', $url);
330 $this->waitForPageToLoad($this->getTimeoutMsec());
332 // start filling out contribution form
333 $this->waitForElementPresent('payment_processor_id');
334 $this->select('payment_processor_id', "label={$processorName}");
336 // select financial type
337 $this->select("financial_type_id", "label={$params['financial_type']}");
340 $this->type("total_amount", "{$params['total_amount']}");
342 // enter credit card info on form
343 $this->webtestAddCreditCardDetails();
346 $this->webtestAddBillingDetails($firstName, NULL, $lastName);
348 if ($nonDeductibleAmt = CRM_Utils_Array
::value('non_deductible_amount', $params)) {
349 $this->click("AdditionalDetail");
350 $this->waitForElementPresent("thankyou_date");
351 $this->type("note", "This is a test note.");
352 $this->type("non_deductible_amount", "{$nonDeductibleAmt}");
355 if (CRM_Utils_Array
::value('premium', $params)) {
357 $this->click("Premium");
358 $this->waitForElementPresent("fulfilled_date");
359 $this->select("product_name[0]", "label={$params['premium']}");
362 $this->click("_qf_Contribution_upload");
363 $this->waitForPageToLoad($this->getTimeoutMsec());
365 // Is status message correct?
366 $this->assertTrue($this->isTextPresent("The contribution record has been processed."), "Status message didn't show up after saving!");
369 //common function for verifing total_amount, and non_deductible_amount
370 function _verifyAmounts($verifyData) {
371 // since we are doing test contributions we need to search for test contribution and select first contribution
372 // record for the contact
373 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
374 $this->type("sort_name", $verifyData['sort_name']);
376 // select show test contributions
377 $this->click("contribution_test", "value=1");
378 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
379 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom");
381 foreach ($verifyData as $label => $value) {
382 if ( $label == 'sort_name' ) {
385 $this->verifyText("xpath=//form[@id='ContributionView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
390 // now find contact and go back to contact summary
391 $this->openCiviPage("contact/search", "reset=1", "sort_name");
392 $this->type("sort_name", $verifyData['sort_name']);
393 $this->clickLink("_qf_Basic_refresh",
394 "xpath=//form[@id='Basic']/div[3]/div[1]/div[2]/table/tbody/tr[1]/td[11]/span/a[text()='View']");
396 $this->clickLink("xpath=//form[@id='Basic']/div[3]/div[1]/div[2]/table/tbody/tr[1]/td[11]/span/a[text()='View']",
397 'crm-contact-actions-link');
400 function testOnlineContributionWithZeroAmount() {
401 $this->webtestLogin();
403 // Create a contact to be used as soft creditor
404 $firstName = 'John' . substr(sha1(rand()), 0, 7);
405 $lastName = 'Peterson' . substr(sha1(rand()), 0, 7);
406 $this->webtestAddContact($firstName, $lastName);
407 $this->waitForElementPresent("css=li#tab_contribute a");
408 $this->click("css=li#tab_contribute a");
409 $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
410 $this->clickLink("link=Record Contribution (Check, Cash, EFT ...)");
412 // select financial type
413 $this->select("financial_type_id", "value=1");
416 $this->type("total_amount", "0.00");
418 // select payment instrument
419 $this->select("payment_instrument_id", "value=1");
421 $this->type("trxn_id", "X20901X1" . rand(100, 10000));
422 $this->clickLink('_qf_Contribution_upload-bottom');
423 $this->waitForText("crm-notification-container", "The contribution record has been saved.");
425 $this->waitForElementPresent("xpath=//div[@id='Contributions']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
426 $this->clickLink("xpath=//div[@id='Contributions']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
428 'Financial Type' => 'Donation',
429 'Total Amount' => '0.00',
430 'Contribution Status' => 'Completed',
431 'Paid By' => 'Credit Card'
433 $this->webtestVerifyTabularData($expected);