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