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