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