Fixed webtest for civi-4.6
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / UpdateContributionTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
25 */
26
27
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29
30 /**
31 * Class WebTest_Contribute_UpdateContributionTest
32 */
33 class WebTest_Contribute_UpdateContributionTest extends CiviSeleniumTestCase {
34
35 protected function setUp() {
36 parent::setUp();
37 }
38
39 public function testChangeContributionAmount() {
40 $this->webtestLogin();
41 $amount = 100;
42 //Offline Pay Later Contribution
43 $contact = $this->_testOfflineContribution($amount, "Pending");
44
45 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
46
47 $this->type("sort_name", $contact['sort_name']);
48 $this->click("_qf_Search_refresh");
49
50 $this->waitForElementPresent("xpath=//*[@id='Search']//div[@id='contributionSearch']");
51 $contriIDOff = explode('&', $this->getAttribute("xpath=//div[@id='contributionSearch']//table[@class='selector row-highlight']/tbody/tr[1]/td[11]/span/a[1]@href"));
52 if (!empty($contriIDOff)) {
53 $contriIDOff = substr($contriIDOff[1], (strrpos($contriIDOff[1], '=') + 1));
54 }
55
56 $this->clickLink("xpath=//tr[@id='rowid{$contriIDOff}']/td[11]/span/a[2]", "total_amount", FALSE);
57 $this->type("total_amount", "90");
58 $this->clickLink('_qf_Contribution_upload', '', FALSE);
59 $this->waitForText('crm-notification-container', "The sum of fee amount and net amount must be equal to total amount");
60 $this->type("net_amount", "90");
61 $this->clickLink('_qf_Contribution_upload', '', FALSE);
62
63 // Is status message correct?
64 $this->waitForText('crm-notification-container', "The contribution record has been saved.");
65
66 //For Contribution
67 $searchParams = array('id' => $contriIDOff);
68 $compareParams = array('total_amount' => '90.00');
69 //For LineItem
70 $lineItemSearchParams = array('entity_id' => $contriIDOff);
71 $lineItemCompareParams = array('line_total' => '90.00');
72
73 $this->assertDBCompareValues('CRM_Contribute_DAO_Contribution', $searchParams, $compareParams);
74 $this->assertDBCompareValues('CRM_Price_DAO_LineItem', $lineItemSearchParams, $lineItemCompareParams);
75
76 $total = $this->_getTotalContributedAmount($contriIDOff);
77 $compare = array('total_amount' => $total);
78 $this->assertDBCompareValues('CRM_Contribute_DAO_Contribution', $searchParams, $compare);
79
80 $amount = $this->_getFinancialItemAmount($contriIDOff);
81 $compare = array('total_amount' => $amount);
82 $this->assertDBCompareValues('CRM_Contribute_DAO_Contribution', $searchParams, $compare);
83
84 $financialTrxnAmount = $this->_getFinancialTrxnAmount($contriIDOff);
85 $compare = array('total_amount' => $financialTrxnAmount);
86 $this->assertDBCompareValues('CRM_Contribute_DAO_Contribution', $searchParams, $compare);
87 }
88
89 public function testPayLater() {
90 $this->webtestLogin();
91 $amount = 100.00;
92 //Offline Pay Later Contribution
93 $this->_testOfflineContribution($amount, "Pending");
94 $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']");
95 $contId = $this->urlArg('id', $this->getAttribute("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']@href"));
96 $this->clickAjaxLink("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']", '_qf_Contribution_cancel-bottom');
97 $this->select("contribution_status_id", "label=Completed");
98 $this->clickAjaxLink("_qf_Contribution_upload", "xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']");
99 $this->checkCRMAlert("The contribution record has been saved.");
100
101 //Assertions
102 $search = array('id' => $contId);
103 $compare = array('contribution_status_id' => 1);
104 $this->assertDBCompareValues('CRM_Contribute_DAO_Contribution', $search, $compare);
105
106 $lineItem = key(CRM_Price_BAO_LineItem::getLineItems($contId, 'contribution'));
107 $search = array('entity_id' => $lineItem);
108 $compare = array('status_id' => 1);
109 $this->assertDBCompareValues("CRM_Financial_DAO_FinancialItem", $search, $compare);
110
111 $status = $this->_getPremiumActualCost($contId, 'Accounts Receivable', 'Payment Processor Account', NULL, "'civicrm_contribution'", "ft.status_id as status");
112 $this->assertEquals($status, '1', "Verify Completed Status");
113 }
114
115 public function testChangePremium() {
116 $this->webtestLogin();
117 $from = 'Premiums';
118 $to = 'Premiums inventory';
119 $financialType = array(
120 'name' => 'Test Financial' . substr(sha1(rand()), 0, 7),
121 'is_reserved' => 1,
122 'is_deductible' => 1,
123 );
124 $this->addeditFinancialType($financialType);
125 $this->waitForElementPresent("xpath=//div[@id='ltype']/div/table/tbody//tr/td/div[text()='" . $financialType['name'] . "']/../../td[7]/span/a[text()='Accounts']");
126 $this->click("xpath=//div[@id='ltype']/div/table/tbody//tr/td/div[text()='" . $financialType['name'] . "']/../../td[7]/span/a[text()='Accounts']");
127 $this->waitForElementPresent("xpath=//a[@id='newfinancialTypeAccount']");
128 $this->clickAjaxLink("xpath=//a[@id='newfinancialTypeAccount']", "_qf_FinancialTypeAccount_cancel-botttom");
129 $this->select("account_relationship", "label=Premiums Inventory Account is");
130 $this->waitForElementPresent("xpath=//select[@id='financial_account_id']/option[3][text()='Deposit Bank Account']");
131 $this->select("financial_account_id", "label=$to");
132 $this->clickAjaxLink("_qf_FinancialTypeAccount_next-botttom", "xpath=//a[@id='newfinancialTypeAccount']");
133
134 $premiumName = 'Premium' . substr(sha1(rand()), 0, 7);
135 $amount = 500;
136 $sku = 'SKU';
137 $price = 300;
138 $cost = 3.00;
139 $this->openCiviPage("admin/contribute/managePremiums", "action=add&reset=1");
140 // add premium
141 $this->addPremium($premiumName, $sku, $amount, $price, $cost, $financialType['name']);
142
143 //add second premium
144 $premiumName2 = 'Premium' . substr(sha1(rand()), 0, 7);
145 $amount2 = 600;
146 $sku2 = 'SKU';
147 $price2 = 200;
148 $cost2 = 2.00;
149 $this->openCiviPage("admin/contribute/managePremiums", "action=add&reset=1");
150 $this->addPremium($premiumName2, $sku2, $amount2, $price2, $cost2, $financialType['name']);
151
152 // add contribution with premium
153 $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone");
154
155 // create new contact using dialog
156 $this->createDialogContact();
157 // select financial type
158 $this->select("financial_type_id", "value=1");
159 // total amount
160 $this->type("total_amount", "100");
161 // fill Premium information
162 $this->clickAjaxLink("xpath=//div[@id='Premium']", "product_name_0");
163 $this->select('product_name_0', "label=$premiumName ( $sku )");
164 // Clicking save.
165 $this->clickAjaxLink("_qf_Contribution_upload", "xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']");
166 // Is status message correct?
167 $this->checkCRMAlert("The contribution record has been saved.");
168 // verify if Contribution is created
169 //click through to the Contribution edit screen
170 $contId = $this->urlArg('id', $this->getAttribute("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']@href"));
171 $this->clickAjaxLink("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']", "product_name_0");
172
173 $this->select('product_name_0', "label=$premiumName2 ( $sku2 )");
174 // Clicking save.
175 $this->clickAjaxLink("_qf_Contribution_upload", "xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[7][text()='$premiumName2']");
176 $this->checkCRMAlert("The contribution record has been saved.");
177
178 //Assertions
179 $actualAmount = $this->_getPremiumActualCost($contId, $to, $from, $cost2, "'civicrm_contribution'");
180 $this->assertEquals($actualAmount, NULL, "Verify actual cost for changed premium");
181
182 $deletedAmount = $this->_getPremiumActualCost($contId, $from, $to, $cost, "'civicrm_contribution'");
183 $this->assertEquals($deletedAmount, NULL, "Verify actual cost for deleted premium");
184 }
185
186 public function testDeletePremium() {
187 $this->webtestLogin();
188 $from = 'Premiums';
189 $to = 'Premiums inventory';
190 $financialType = array(
191 'name' => 'Test Financial' . substr(sha1(rand()), 0, 7),
192 'is_reserved' => 1,
193 'is_deductible' => 1,
194 );
195 $this->addeditFinancialType($financialType);
196 $this->waitForElementPresent("xpath=//div[@id='ltype']/div/table/tbody//tr/td/div[text()='" . $financialType['name'] . "']/../../td[7]/span/a[text()='Accounts']");
197 $this->click("xpath=//div[@id='ltype']/div/table/tbody//tr/td/div[text()='" . $financialType['name'] . "']/../../td[7]/span/a[text()='Accounts']");
198 $this->waitForElementPresent("xpath=//a[@id='newfinancialTypeAccount']");
199 $this->clickLink("xpath=//a[@id='newfinancialTypeAccount']", "_qf_FinancialTypeAccount_cancel-botttom", FALSE);
200
201 $this->select("account_relationship", "label=Premiums Inventory Account is");
202 $this->waitForElementPresent("xpath=//select[@id='financial_account_id']/option[3][text()='Deposit Bank Account']");
203 $this->select("financial_account_id", "label=$to");
204 $this->clickLink("_qf_FinancialTypeAccount_next-botttom", "xpath=//a[@id='newfinancialTypeAccount']", FALSE);
205 $premiumName = 'Premium' . substr(sha1(rand()), 0, 7);
206 $amount = 500;
207 $sku = 'SKU';
208 $price = 300;
209 $cost = 3.00;
210 $this->openCiviPage("admin/contribute/managePremiums", "action=add&reset=1");
211 // add premium
212 $this->addPremium($premiumName, $sku, $amount, $price, $cost, $financialType['name']);
213
214 // add contribution with premium
215 $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone");
216
217 // create new contact using dialog
218 $this->createDialogContact();
219 // select financial type
220 $this->select("financial_type_id", "value=1");
221 // total amount
222 $this->type("total_amount", "100");
223 // fill Premium information
224 $this->click("xpath=//div[@id='Premium']");
225 $this->waitForElementPresent("product_name_0");
226 $this->select('product_name_0', "label=$premiumName ( $sku )");
227 // Clicking save.
228 $this->clickLink("_qf_Contribution_upload");
229 // Is status message correct?
230 $this->waitForText('crm-notification-container', "The contribution record has been saved.");
231 // verify if Contribution is created
232 $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']");
233 //click through to the Contribution edit screen
234 $contId = explode('&id=', $this->getAttribute("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']@href"));
235 $contId = explode('&', $contId[1]);
236 $contId = $contId[0];
237 $this->clickLink("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']", "_qf_Contribution_upload-bottom", FALSE);
238 $this->waitForElementPresent("product_name_0");
239 $this->select('product_name_0', "value=0");
240 // Clicking save.
241 $this->clickLink("_qf_Contribution_upload", "xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[7][not(text())]", FALSE);
242
243 //Assertions
244 $actualAmount = $this->_getPremiumActualCost($contId, $from, $to, NULL, "'civicrm_contribution'");
245 $this->assertEquals($actualAmount, NULL, "Verify actual cost for deleted premium");
246 }
247
248 public function testChangePaymentInstrument() {
249 $this->webtestLogin();
250 $label = 'TEST' . substr(sha1(rand()), 0, 7);
251 $amount = 100.00;
252 $financialAccount = CRM_Contribute_PseudoConstant::financialAccount();
253 $to = array_search('Accounts Receivable', $financialAccount);
254 $from = array_search('Deposit Bank Account', $financialAccount);
255 $this->addPaymentInstrument($label, $to);
256 $this->_testOfflineContribution($amount);
257 $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']");
258 $this->clickLink("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']", '_qf_Contribution_cancel-bottom', FALSE);
259 $contId = explode('&id=', $this->getAttribute("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']@href"));
260 $contId = explode('&', $contId[1]);
261 $contId = $contId[0];
262 //change payment processor to newly created value
263 $this->select("payment_instrument_id", "label=$label");
264 $this->clickLink("_qf_Contribution_upload", "xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']", FALSE);
265 $this->waitForAjaxContent();
266 //Assertions
267 $subtractedTotal = $this->_getPremiumActualCost($contId, NULL, 'Payment Processor Account');
268 $this->assertEquals($subtractedTotal, -$amount, "Verify amount deleted from old account");
269 $totalAmount = $this->_getPremiumActualCost($contId, NULL, 'Accounts Receivable');
270 $this->assertEquals($totalAmount, $amount, "Verify amount for newly inserted values");
271 }
272
273 public function testRefundContribution() {
274 $this->webtestLogin();
275 $amount = 100.00;
276 $this->_testOfflineContribution($amount);
277 $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']");
278 $this->clickAjaxLink("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']", '_qf_Contribution_cancel-bottom');
279 //Contribution status
280 $this->select("contribution_status_id", "label=Refunded");
281 $contId = explode('&id=', $this->getAttribute("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']@href"));
282 $contId = explode('&', $contId[1]);
283 $contId = $contId[0];
284 $this->clickAjaxLink("_qf_Contribution_upload", "xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[6][text()='Refunded']");
285
286 //Assertions
287 $lineItem = key(CRM_Price_BAO_LineItem::getLineItems($contId, 'contribution'));
288 $search = array('entity_id' => $lineItem);
289 $compare = array(
290 'amount' => '100.00',
291 'status_id' => 1,
292 );
293 $this->assertDBCompareValues("CRM_Financial_DAO_FinancialItem", $search, $compare);
294 $amount = $this->_getPremiumActualCost($contId, NULL, 'Payment Processor Account', -100.00, "'civicrm_contribution'");
295 $this->assertEquals($amount, '-100.00', 'Verify Financial Trxn Amount.');
296 }
297
298 public function testCancelPayLater() {
299 $this->webtestLogin();
300 $amount = 100.00;
301 $this->_testOfflineContribution($amount, "Pending");
302 $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']");
303 $this->clickLink("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']", '_qf_Contribution_cancel-bottom', FALSE);
304 //Contribution status
305 $this->select("contribution_status_id", "label=Cancelled");
306 $contId = explode('&id=', $this->getAttribute("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']@href"));
307 $contId = explode('&', $contId[1]);
308 $contId = $contId[0];
309 $this->clickLink("_qf_Contribution_upload", "xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']", FALSE);
310 $this->waitForText('crm-notification-container', "The contribution record has been saved.");
311
312 //Assertions
313 $search = array('id' => $contId);
314 $compare = array('contribution_status_id' => 3);
315 $this->assertDBCompareValues('CRM_Contribute_DAO_Contribution', $search, $compare);
316 $lineItem = key(CRM_Price_BAO_LineItem::getLineItems($contId, 'contribution'));
317 $itemParams = array(
318 'amount' => '-100.00',
319 'entity_id' => $lineItem,
320 );
321 $defaults = array();
322 $items = CRM_Financial_BAO_FinancialItem::retrieve($itemParams, $defaults);
323 $this->assertEquals($items->amount, $itemParams['amount'], 'Verify Amount for financial Item');
324 $totalAmount = $this->_getPremiumActualCost($items->id, 'Accounts Receivable', NULL, "-100.00", "'civicrm_financial_item'");
325 $this->assertEquals($totalAmount, "-$amount", 'Verify Amount for Financial Trxn');
326 $totalAmount = $this->_getPremiumActualCost($contId, 'Accounts Receivable', NULL, "-100.00", "'civicrm_contribution'");
327 $this->assertEquals($totalAmount, "-$amount", 'Verify Amount for Financial Trxn');
328 }
329
330 public function testChangeFinancialType() {
331 $this->webtestLogin();
332 $amount = 100.00;
333 $this->_testOfflineContribution($amount);
334 $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']");
335 $this->clickLink("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']", '_qf_Contribution_cancel-bottom', FALSE);
336 //Contribution status
337 $this->select("financial_type_id", "value=3");
338 $contId = explode('&id=', $this->getAttribute("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']@href"));
339 $contId = explode('&', $contId[1]);
340 $contId = $contId[0];
341 $this->clickLink("_qf_Contribution_upload", "xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']", FALSE);
342 $this->waitForText('crm-notification-container', "The contribution record has been saved.");
343
344 //Assertions
345 $search = array('id' => $contId);
346 $compare = array('financial_type_id' => 3);
347 $this->assertDBCompareValues('CRM_Contribute_DAO_Contribution', $search, $compare);
348
349 $lineItem = key(CRM_Price_BAO_LineItem::getLineItems($contId, 'contribution'));
350 $itemParams = array(
351 'amount' => '-100.00',
352 'entity_id' => $lineItem,
353 );
354 $item1 = $item2 = array();
355 CRM_Financial_BAO_FinancialItem::retrieve($itemParams, $item1);
356 $this->assertEquals($item1['amount'], "-100.00", "Verify Amount for New Financial Item");
357 $itemParams['amount'] = '100.00';
358 CRM_Financial_BAO_FinancialItem::retrieve($itemParams, $item2);
359 $this->assertEquals($item2['amount'], "100.00", "Verify Amount for New Financial Item");
360
361 $cValue1 = $this->_getPremiumActualCost($contId, NULL, NULL, "-100.00", "'civicrm_contribution'");
362 $fValue1 = $this->_getPremiumActualCost($item1['id'], NULL, NULL, "-100.00", "'civicrm_financial_item'");
363 $this->assertEquals($cValue1, "-100.00", "Verify Amount");
364 $this->assertEquals($fValue1, "-100.00", "Verify Amount");
365 $cValue2 = $this->_getPremiumActualCost($contId, NULL, NULL, "100.00", "'civicrm_contribution'");
366 $fValue2 = $this->_getPremiumActualCost($item2['id'], NULL, NULL, "100.00", "'civicrm_financial_item'");
367 $this->assertEquals($cValue2, "100.00", "Verify Amount");
368 $this->assertEquals($fValue2, "100.00", "Verify Amount");
369 }
370
371 /**
372 * @param int $entityId
373 * @param null $from
374 * @param null $to
375 * @param null $cost
376 * @param null $entityTable
377 * @param string $select
378 *
379 * @return null|string
380 */
381 public function _getPremiumActualCost($entityId, $from = NULL, $to = NULL, $cost = NULL, $entityTable = NULL, $select = "ft.total_amount AS amount") {
382 $financialAccount = CRM_Contribute_PseudoConstant::financialAccount();
383 $query = "SELECT
384 {$select}
385 FROM civicrm_financial_trxn ft
386 INNER JOIN civicrm_entity_financial_trxn eft ON eft.financial_trxn_id = ft.id AND eft.entity_id = {$entityId}";
387 if ($entityTable) {
388 $query .= " AND eft.entity_table = {$entityTable}";
389 }
390 if (!empty($to)) {
391 $to = array_search($to, $financialAccount);
392 $query .= " AND ft.to_financial_account_id = {$to}";
393 }
394 if (!empty($from)) {
395 $from = array_search($from, $financialAccount);
396 $query .= " AND ft.from_financial_account_id = {$from}";
397 }
398 if (!empty($cost)) {
399 $query .= " AND eft.amount = {$cost}";
400 }
401 $query .= " ORDER BY ft.id DESC LIMIT 1";
402 $result = CRM_Core_DAO::singleValueQuery($query);
403 return $result;
404 }
405
406 /**
407 * @param int $contId
408 *
409 * @return null|string
410 */
411 public function _getFinancialTrxnAmount($contId) {
412 $query = "SELECT
413 SUM( ft.total_amount ) AS total
414 FROM civicrm_financial_trxn AS ft
415 LEFT JOIN civicrm_entity_financial_trxn AS ceft ON ft.id = ceft.financial_trxn_id
416 WHERE ceft.entity_table = 'civicrm_contribution'
417 AND ceft.entity_id = {$contId}";
418 $result = CRM_Core_DAO::singleValueQuery($query);
419 return $result;
420 }
421
422 /**
423 * @param int $contId
424 *
425 * @return null|string
426 */
427 public function _getFinancialItemAmount($contId) {
428 $lineItem = key(CRM_Price_BAO_LineItem::getLineItems($contId, 'contribution'));
429 $query = "SELECT
430 SUM(amount)
431 FROM civicrm_financial_item
432 WHERE entity_table = 'civicrm_line_item'
433 AND entity_id = {$lineItem}";
434 $result = CRM_Core_DAO::singleValueQuery($query);
435 return $result;
436 }
437
438 /**
439 * @param int $contId
440 *
441 * @return null|string
442 */
443 public function _getTotalContributedAmount($contId) {
444 $query = "SELECT
445 SUM(amount)
446 FROM civicrm_entity_financial_trxn
447 WHERE entity_table = 'civicrm_contribution'
448 AND entity_id = {$contId}";
449 $result = CRM_Core_DAO::singleValueQuery($query);
450 return $result;
451 }
452
453 /**
454 * @param $amount
455 * @param string $status
456 * @return array
457 */
458 public function _testOfflineContribution($amount, $status = "Completed") {
459
460 $this->openCiviPage("contribute/add", "reset=1&context=standalone", "_qf_Contribution_upload");
461
462 // create new contact using dialog
463 $contact = $this->createDialogContact();
464
465 // select financial type
466 $this->select("financial_type_id", "value=1");
467
468 //Contribution status
469 $this->select("contribution_status_id", "label=$status");
470
471 // total amount
472 $this->type("total_amount", $amount);
473
474 // select payment instrument type
475 $this->select("payment_instrument_id", "label=Credit Card");
476
477 $this->type("trxn_id", "P20901X1" . rand(100, 10000));
478
479 //Custom Data
480 //$this->click('CIVICRM_QFID_3_6');
481
482 // Clicking save.
483 $this->clickLink("_qf_Contribution_upload");
484
485 // Is status message correct?
486 $this->checkCRMAlert("The contribution record has been saved.");
487
488 $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']");
489 // verify if Membership is created
490
491 //click through to the Membership view screen
492 $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']");
493
494 $expected = array(
495 'Financial Type' => 'Donation',
496 'Total Amount' => '100.00',
497 'Contribution Status' => $status,
498 );
499 $this->webtestVerifyTabularData($expected);
500 $this->click("_qf_ContributionView_cancel-bottom");
501
502 return $contact;
503 }
504
505 }