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