Merge pull request #11735 from mukeshcompucorp/CRM-21814-add-proper-container-to...
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / OfflineContributionTest.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
81621fee 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
8c9251b3 6 | Copyright CiviCRM LLC (c) 2004-2018 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 25 */
6a488035
TO
26
27require_once 'CiviTest/CiviSeleniumTestCase.php';
28
e9479dcf
EM
29/**
30 * Class WebTest_Contribute_OfflineContributionTest
31 */
6a488035
TO
32class WebTest_Contribute_OfflineContributionTest extends CiviSeleniumTestCase {
33
6a488035
TO
34 protected function setUp() {
35 parent::setUp();
36 }
76e86fd8 37
00be9182 38 public function testStandaloneContributeAdd() {
6a488035
TO
39 $this->webtestLogin();
40
41 // Create a contact to be used as soft creditor
42 $softCreditFname = substr(sha1(rand()), 0, 7);
43 $softCreditLname = substr(sha1(rand()), 0, 7);
06321b47 44 $this->webtestAddContact($softCreditFname, $softCreditLname, FALSE);
76e86fd8 45
6a488035 46 //financial account for check
118e964e 47 $this->openCiviPage("admin/options/payment_instrument", "reset=1");
5c80555f 48 $financialAccount = $this->getText("xpath=//div[@id='payment_instrument']/table/tbody//tr/td[1]/div[text()='Check']/../../td[3]");
76e86fd8 49
6a488035 50 // Add new Financial Account
06321b47 51 $orgName = 'Alberta ' . substr(sha1(rand()), 0, 7);
52 $financialAccountTitle = 'Financial Account ' . substr(sha1(rand()), 0, 4);
6a488035
TO
53 $financialAccountDescription = "{$financialAccountTitle} Description";
54 $accountingCode = 1033;
55 $financialAccountType = 'Asset';
56 $taxDeductible = FALSE;
57 $isActive = FALSE;
58 $isTax = TRUE;
59 $taxRate = 9;
60 $isDefault = FALSE;
76e86fd8 61
6a488035 62 //Add new organisation
06321b47 63 if ($orgName) {
6a488035
TO
64 $this->webtestAddOrganization($orgName);
65 }
76e86fd8 66
6a488035
TO
67 $this->_testAddFinancialAccount($financialAccountTitle,
68 $financialAccountDescription,
69 $accountingCode,
70 $orgName,
71 $financialAccountType,
72 $taxDeductible,
73 $isActive,
74 $isTax,
75 $taxRate,
76 $isDefault
77 );
78
06321b47 79 $firstName = 'John' . substr(sha1(rand()), 0, 7);
80 $lastName = 'Dsouza' . substr(sha1(rand()), 0, 7);
6a488035 81 $this->webtestAddContact($firstName, $lastName);
76e86fd8 82
6a488035
TO
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 ...)");
3bbf7318 86 $this->clickLink("link=Record Contribution (Check, Cash, EFT ...)", "_qf_Contribution_cancel-bottom", FALSE);
6a488035
TO
87
88 // select financial type
89 $this->select("financial_type_id", "value=1");
76e86fd8 90
6a488035
TO
91 // fill in Received Date
92 $this->webtestFillDate('receive_date');
76e86fd8 93
6a488035
TO
94 // source
95 $this->type("source", "Mailer 1");
76e86fd8 96
6a488035
TO
97 // total amount
98 $this->type("total_amount", "100");
46d173ef
PN
99 // revenue recognition date (CRM-16189)
100 if (CRM_Contribute_BAO_Contribution::checkContributeSettings('deferred_revenue_enabled')) {
101 $this->webtestFillDate('revenue_recognition_date', 'now+4');
102 }
6a488035
TO
103
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");
108
109 $this->type("trxn_id", "P20901X1" . rand(100, 10000));
76e86fd8 110
5d48a234 111 // create first soft credit
3bbf7318 112 $this->click("softCredit");
113 $this->waitForElementPresent("soft_credit_amount_1");
114 $this->webtestFillAutocomplete("{$softCreditLname}, {$softCreditFname}", 's2id_soft_credit_contact_id_1');
5d48a234 115 $this->type("soft_credit_amount_1", "50");
06321b47 116
5d48a234
S
117 // add second soft credit field
118 $this->click("addMoreSoftCredit");
119 $this->waitForElementPresent("soft_credit_amount_2");
51fa20cb 120 // create new individual via soft credit
5d48a234 121 $softCreditSecondFname = substr(sha1(rand()), 0, 7);
06321b47 122 $softCreditSecondLname = substr(sha1(rand()), 0, 7);
3bbf7318 123 $this->webtestNewDialogContact($softCreditSecondFname, $softCreditSecondLname, NULL, 4, 's2id_soft_credit_contact_id_2', 'soft_credit_1');
5d48a234 124 // enter the second soft credit
06321b47 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
51fa20cb 127 $this->select("soft_credit_type[2]", "In Honor of");
6a488035
TO
128
129 //Custom Data
130 // $this->click('CIVICRM_QFID_3_6');
131
132 //Additional Detail section
133 $this->click("AdditionalDetail");
134 $this->waitForElementPresent("thankyou_date");
135
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');
76e86fd8 142
6a488035
TO
143 //Premium section
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');
149
150 // Clicking save.
151 $this->click("_qf_Contribution_upload");
6a488035
TO
152
153 // Is status message correct?
5d48a234 154 //$this->assertTrue($this->isTextPresent("The contribution record has been saved."), "Status message didn't show up after saving!");
76e86fd8 155
5d48a234 156 // verify if Contribution is created
3bbf7318 157 $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']");
76e86fd8 158
5d48a234 159 //click through to the Contribution view screen
3bbf7318 160 $this->click("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']");
6a488035 161 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
76e86fd8 162
06321b47 163 $expected = array(
164 'Financial Type' => 'Donation',
165 'Total Amount' => '100.00',
6a488035 166 'Contribution Status' => 'Completed',
4db803dd 167 'Payment Method' => 'Check',
06321b47 168 'Check Number' => 'check #1041',
6a488035 169 'Non-deductible Amount' => '10.00',
06321b47 170 'Received Into' => $financialAccount,
6a488035 171 );
06321b47 172
3bbf7318 173 $this->waitForElementPresent("xpath=//*[@id='ContributionView']/div[2]");
06321b47 174 foreach ($expected as $value) {
e684c1ae 175 $this->assertElementContainsText("xpath=//*[@id='ContributionView']/div[2]", $value);
6a488035
TO
176 }
177
06321b47 178 // verify if soft credit was created successfully
179 $expected = array(
180 'Soft Credit To 1' => "{$softCreditFname} {$softCreditLname}",
181 'Soft Credit To 2' => "{$softCreditSecondFname} {$softCreditSecondLname}",
51fa20cb 182 'Amount (Soft Credit Type)' => '100.00 (In Honor of)',
06321b47 183 );
184
185 foreach ($expected as $value) {
e684c1ae 186 $this->assertElementContainsText("css=table.crm-soft-credit-listing", $value);
06321b47 187 }
188
189 // go to first soft creditor contact view page
3bbf7318 190 $this->clickLink("xpath=//*[@id='ContributionView']/div[2]/div[2]/div[2]/table/tbody/tr[1]/td[1]/a", "css=li#tab_contribute a");
6a488035
TO
191
192 // go to contribution tab
6a488035
TO
193 $this->click("css=li#tab_contribute a");
194 $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
195
196 // verify soft credit details
06321b47 197 $expected = array(
51fa20cb 198 3 => 'Solicited',
199 4 => 'Donation',
06321b47 200 2 => '50.00',
51fa20cb 201 6 => 'Completed',
21dfd5f5 202 1 => "{$firstName} {$lastName}",
6a488035 203 );
06321b47 204 foreach ($expected as $value => $label) {
e684c1ae 205 $this->assertElementContainsText("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[2]/td[$value]", $label);
6a488035
TO
206 }
207 }
76e86fd8 208
00be9182 209 public function testDeductibleAmount() {
6a488035
TO
210 $this->webtestLogin();
211
c432c016 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());
217
6a488035
TO
218 //add authorize .net payment processor
219 $processorName = 'Webtest AuthNet' . substr(sha1(rand()), 0, 7);
220 $this->webtestAddPaymentProcessor($processorName, 'AuthNet');
76e86fd8 221
071a6d2e 222 $this->openCiviPage("admin/contribute/managePremiums", "action=add&reset=1");
6a488035
TO
223 $premiumName = 'test Premium' . substr(sha1(rand()), 0, 7);
224 $this->addPremium($premiumName, 'SKU', 3, 12, NULL, NULL);
76e86fd8 225
06321b47 226 $firstName = 'John' . substr(sha1(rand()), 0, 7);
227 $lastName = 'Dsouza' . substr(sha1(rand()), 0, 7);
6a488035
TO
228 $this->webtestAddContact($firstName, $lastName);
229
230 //scenario 1 : is_deductible = 0 and non deductible amount is entered
231 $scenario1 = array(
232 'financial_type' => 'Campaign Contribution',
233 'total_amount' => 111,
646957a3 234 'non_deductible_amount' => 15,
235 'sort_name' => "$lastName, $firstName",
6a488035
TO
236 );
237 $this->_doOfflineContribution($scenario1, $firstName, $lastName, $processorName);
76e86fd8 238
6a488035
TO
239 $checkScenario1 = array(
240 'From' => "{$firstName} {$lastName}",
241 'Financial Type' => 'Campaign Contribution',
242 'Total Amount' => 111,
646957a3 243 'Non-deductible Amount' => 15,
244 'sort_name' => "$lastName, $firstName",
6a488035
TO
245 );
246 $this->_verifyAmounts($checkScenario1);
76e86fd8 247
6a488035
TO
248 //scenario 2 : is_deductible = TRUE and premium is set and premium is greater than total amount
249 $scenario2 = array(
250 'financial_type' => 'Donation',
251 'total_amount' => 10,
646957a3 252 'premium' => "{$premiumName} ( SKU )",
253 'sort_name' => "$lastName, $firstName",
6a488035
TO
254 );
255 $this->_doOfflineContribution($scenario2, $firstName, $lastName, $processorName);
76e86fd8 256
6a488035
TO
257 $checkScenario2 = array(
258 'From' => "{$firstName} {$lastName}",
259 'Financial Type' => 'Donation',
260 'Total Amount' => 10,
646957a3 261 'Non-deductible Amount' => 10,
262 'sort_name' => "$lastName, $firstName",
6a488035
TO
263 );
264 $this->_verifyAmounts($checkScenario2);
76e86fd8 265
6a488035
TO
266 //scenario 3 : is_deductible = TRUE and premium is set and premium is less than total amount
267 $scenario3 = array(
268 'financial_type' => 'Donation',
269 'total_amount' => 123,
646957a3 270 'premium' => "{$premiumName} ( SKU )",
271 'sort_name' => "$lastName, $firstName",
6a488035
TO
272 );
273 $this->_doOfflineContribution($scenario3, $firstName, $lastName, $processorName);
76e86fd8 274
6a488035
TO
275 $checkScenario3 = array(
276 'From' => "{$firstName} {$lastName}",
277 'Financial Type' => 'Donation',
278 'Total Amount' => 123,
646957a3 279 'Non-deductible Amount' => 12,
280 'sort_name' => "$lastName, $firstName",
6a488035
TO
281 );
282 $this->_verifyAmounts($checkScenario3);
76e86fd8 283
6a488035
TO
284 //scenario 4 : is_deductible = TRUE and premium is not set
285 $scenario4 = array(
286 'financial_type' => 'Donation',
287 'total_amount' => 123,
646957a3 288 'sort_name' => "$lastName, $firstName",
6a488035
TO
289 );
290 $this->_doOfflineContribution($scenario4, $firstName, $lastName, $processorName);
76e86fd8 291
6a488035
TO
292 $checkScenario4 = array(
293 'From' => "{$firstName} {$lastName}",
294 'Financial Type' => 'Donation',
295 'Total Amount' => 123,
e42cfe9d 296 'Non-deductible Amount' => '0.00',
646957a3 297 'sort_name' => "$lastName, $firstName",
6a488035
TO
298 );
299 $this->_verifyAmounts($checkScenario4);
300
301 //scenario 5 : is_deductible = FALSE, non_deductible_amount = the total amount
302 $scenario5 = array(
303 'financial_type' => 'Campaign Contribution',
304 'total_amount' => 555,
646957a3 305 'sort_name' => "$lastName, $firstName",
6a488035
TO
306 );
307 $this->_doOfflineContribution($scenario5, $firstName, $lastName, $processorName);
76e86fd8 308
6a488035
TO
309 $checkScenario5 = array(
310 'From' => "{$firstName} {$lastName}",
311 'Financial Type' => 'Campaign Contribution',
312 'Total Amount' => 555,
646957a3 313 'Non-deductible Amount' => 555,
314 'sort_name' => "$lastName, $firstName",
6a488035
TO
315 );
316 $this->_verifyAmounts($checkScenario5);
317 }
76e86fd8 318
4cbe18b8 319 /**
eceb18cc 320 * common function for doing offline contribution.
c490a46a 321 * @param array $params
100fef9d
CW
322 * @param string $firstName
323 * @param string $lastName
4cbe18b8
EM
324 * @param $processorName
325 */
00be9182 326 public function _doOfflineContribution($params, $firstName, $lastName, $processorName) {
76e86fd8 327
6a488035
TO
328 $this->waitForElementPresent("css=li#tab_contribute a");
329 $this->click("css=li#tab_contribute a");
7542b691 330 $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
6a488035
TO
331
332 // since we don't have live credentials we will switch to test mode
7542b691 333 $url = $this->getAttribute("xpath=//*[@id='Search']/div[2]/div[2]/a[1]@href");
2e21c7ba 334 $url .= '&mode=test';
6a488035 335 $this->open($url);
a471a3b6 336 $this->waitForPageToLoad($this->getTimeoutMsec());
6a488035
TO
337
338 // start filling out contribution form
339 $this->waitForElementPresent('payment_processor_id');
340 $this->select('payment_processor_id', "label={$processorName}");
341
342 // select financial type
343 $this->select("financial_type_id", "label={$params['financial_type']}");
344
345 // total amount
346 $this->type("total_amount", "{$params['total_amount']}");
347
348 // enter credit card info on form
349 $this->webtestAddCreditCardDetails();
350
351 // billing address
352 $this->webtestAddBillingDetails($firstName, NULL, $lastName);
76e86fd8 353
6a488035
TO
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}");
359 }
360
a7488080 361 if (!empty($params['premium'])) {
6a488035
TO
362 //Premium section
363 $this->click("Premium");
364 $this->waitForElementPresent("fulfilled_date");
365 $this->select("product_name[0]", "label={$params['premium']}");
366 }
367 // Clicking save.
7542b691 368 $this->click("_qf_Contribution_upload-bottom");
6a488035
TO
369 $this->waitForPageToLoad($this->getTimeoutMsec());
370
371 // Is status message correct?
c432c016 372 $this->assertTrue($this->isTextPresent("The contribution record has been saved."), "Status message didn't show up after saving!");
6a488035 373 }
76e86fd8 374
4cbe18b8 375 /**
4f1f1f2a 376 * common function for verifing total_amount, and non_deductible_amount
4cbe18b8
EM
377 * @param $verifyData
378 */
00be9182 379 public function _verifyAmounts($verifyData) {
646957a3 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']);
384
385 // select show test contributions
386 $this->click("contribution_test", "value=1");
deeea38d
WA
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);
6a488035
TO
389
390 foreach ($verifyData as $label => $value) {
481a74f4 391 if ($label == 'sort_name') {
646957a3 392 continue;
393 }
88a80394 394 $this->assertElementContainsText("xpath=//form[@id='ContributionView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td", "{$value}");
6a488035
TO
395 }
396
646957a3 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']");
402
403 $this->clickLink("xpath=//form[@id='Basic']/div[3]/div[1]/div[2]/table/tbody/tr[1]/td[11]/span/a[text()='View']",
92915c55 404 'crm-contact-actions-link', FALSE);
6a488035 405 }
3fb990f4 406
00be9182 407 public function testOnlineContributionWithZeroAmount() {
3fb990f4
RN
408 $this->webtestLogin();
409
410 // Create a contact to be used as soft creditor
06321b47 411 $firstName = 'John' . substr(sha1(rand()), 0, 7);
412 $lastName = 'Peterson' . substr(sha1(rand()), 0, 7);
413 $this->webtestAddContact($firstName, $lastName);
3fb990f4
RN
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 ...)");
3bbf7318 417 $this->clickLink("link=Record Contribution (Check, Cash, EFT ...)", "_qf_Contribution_cancel-bottom", FALSE);
3fb990f4 418
06321b47 419 // select financial type
3fb990f4
RN
420 $this->select("financial_type_id", "value=1");
421
422 // total amount
423 $this->type("total_amount", "0.00");
424
425 // select payment instrument
426 $this->select("payment_instrument_id", "value=1");
427
428 $this->type("trxn_id", "X20901X1" . rand(100, 10000));
3bbf7318 429 $this->click('_qf_Contribution_upload-bottom');
3fb990f4
RN
430 $this->waitForText("crm-notification-container", "The contribution record has been saved.");
431
3bbf7318 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);
3fb990f4 434 $expected = array(
06321b47 435 'Financial Type' => 'Donation',
436 'Total Amount' => '0.00',
3fb990f4 437 'Contribution Status' => 'Completed',
4db803dd 438 'Payment Method' => 'Credit Card',
3fb990f4
RN
439 );
440 $this->webtestVerifyTabularData($expected);
441 }
96025800 442
b25b6f70
WA
443 public function testDefaultCurrancy() {
444 $this->webtestLogin();
445 $this->enableCurrency(array('GBP', 'EUR'));
446
447 //Create a contact.
448 $firstName = 'John' . substr(sha1(rand()), 0, 7);
449 $lastName = 'Peterson' . substr(sha1(rand()), 0, 7);
450 $this->webtestAddContact($firstName, $lastName);
451
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");
468 }
469
46d173ef
PN
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());
477
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);
482
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]");
486
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;
494 $isActive = FALSE;
495 $isTax = TRUE;
496 $taxRate = 9;
497 $isDefault = FALSE;
498
499 //Add new organisation
500 if ($orgName) {
501 $this->webtestAddOrganization($orgName);
502 }
503
504 $this->_testAddFinancialAccount($financialAccountTitle,
505 $financialAccountDescription,
506 $accountingCode,
507 $orgName,
508 $financialAccountType,
509 $taxDeductible,
510 $isActive,
511 $isTax,
512 $taxRate,
513 $isDefault
514 );
515
516 $firstName = 'John' . substr(sha1(rand()), 0, 7);
517 $lastName = 'Dsouza' . substr(sha1(rand()), 0, 7);
518 $this->webtestAddContact($firstName, $lastName);
519
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);
524
525 // select financial type
526 $this->select("financial_type_id", "value=1");
527
528 // fill in Received Date
529 $this->webtestFillDate('receive_date');
530
531 // source
532 $this->type("source", "Mailer 1");
533
534 // total amount
535 $this->type("total_amount", "100");
536
537 // revenue recognition date (CRM-16189)
538 $this->webtestFillDate('revenue_recognition_date', 'now');
539
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");
544
545 $this->type("trxn_id", "P20901X1" . rand(100, 10000));
546
547 //Additional Detail section
548 $this->click("AdditionalDetail");
549 $this->waitForElementPresent("thankyou_date");
550
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');
557
558 // Clicking save.
559 $this->click("_qf_Contribution_upload");
560
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']");
563
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);
569 }
570
42daf119 571}