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