Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
fa938177 | 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
6a488035 TO |
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 | */ |
6a488035 | 26 | |
6a488035 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Contribute_StandaloneAddTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Contribute_StandaloneAddTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
00be9182 | 38 | public function testStandaloneContributeAdd() { |
6a488035 TO |
39 | $this->webtestLogin(); |
40 | ||
41 | // Create a contact to be used as soft creditor | |
42 | $softCreditFname = substr(sha1(rand()), 0, 7); | |
43 | $softCreditLname = substr(sha1(rand()), 0, 7); | |
44 | $this->webtestAddContact($softCreditFname, $softCreditLname, FALSE); | |
45 | ||
46 | // Add new Financial Account | |
92fcb95f TO |
47 | $orgName = 'Alberta ' . substr(sha1(rand()), 0, 7); |
48 | $financialAccountTitle = 'Financial Account ' . substr(sha1(rand()), 0, 4); | |
6a488035 TO |
49 | $financialAccountDescription = "{$financialAccountTitle} Description"; |
50 | $accountingCode = 1033; | |
7a731220 | 51 | $financialAccountType = 'Liability'; |
52 | $taxDeductible = TRUE; | |
6a488035 TO |
53 | $isActive = FALSE; |
54 | $isTax = TRUE; | |
7a731220 | 55 | $taxRate = 10.00; |
6a488035 | 56 | $isDefault = FALSE; |
76e86fd8 | 57 | |
6a488035 | 58 | //Add new organisation |
7a731220 | 59 | $this->webtestAddOrganization($orgName); |
76e86fd8 | 60 | |
6a488035 TO |
61 | $this->_testAddFinancialAccount($financialAccountTitle, |
62 | $financialAccountDescription, | |
63 | $accountingCode, | |
64 | $orgName, | |
65 | $financialAccountType, | |
66 | $taxDeductible, | |
67 | $isActive, | |
68 | $isTax, | |
69 | $taxRate, | |
70 | $isDefault | |
71 | ); | |
72 | ||
7a731220 | 73 | //Add new Financial Type |
74 | $financialType['name'] = 'Taxable FinancialType ' . substr(sha1(rand()), 0, 4); | |
75 | $financialType['is_deductible'] = TRUE; | |
76 | $financialType['is_reserved'] = FALSE; | |
77 | $this->addeditFinancialType($financialType); | |
78 | ||
79 | // Assign the created Financial Account $financialAccountTitle to $financialType | |
1fd662d2 | 80 | $this->waitForElementPresent("xpath=id('ltype')"); |
c543dff8 WA |
81 | $this->click("xpath=id('ltype')/div/table/tbody/tr/td[1]/div[text()='$financialType[name]']/../../td[7]//span//a[text()='Accounts']"); |
82 | $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']//button//span[contains(text(), 'Assign Account')]"); | |
83 | $this->click("xpath=//div[@class='ui-dialog-buttonset']//button//span[contains(text(), 'Assign Account')]"); | |
7a731220 | 84 | $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()='Save']"); |
85 | $this->select('account_relationship', "label=Sales Tax Account is"); | |
33c81040 | 86 | $this->waitForAjaxContent(); |
7a731220 | 87 | $this->select('financial_account_id', "label=" . $financialAccountTitle); |
88 | $this->click("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()='Save']"); | |
c543dff8 | 89 | $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']//button//span[contains(text(), 'Assign Account')]"); |
7a731220 | 90 | |
42daf119 | 91 | $this->openCiviPage("contribute/add", "reset=1&context=standalone", "_qf_Contribution_upload"); |
6a488035 | 92 | |
6a488035 | 93 | // create new contact using dialog |
80f3b91d | 94 | $contact = $this->createDialogContact(); |
76e86fd8 | 95 | |
6a488035 | 96 | // select financial type |
7a731220 | 97 | $this->select("financial_type_id", "label=" . $financialType['name']); |
76e86fd8 | 98 | |
6a488035 TO |
99 | // fill in Received Date |
100 | $this->webtestFillDate('receive_date'); | |
101 | ||
102 | // source | |
103 | $this->type("source", "Mailer 1"); | |
104 | ||
105 | // total amount | |
106 | $this->type("total_amount", "100"); | |
107 | ||
108 | // select payment instrument type = Check and enter chk number | |
33c81040 WA |
109 | $this->select("payment_instrument_id", "value=4"); |
110 | $this->waitForElementPresent("check_number"); | |
111 | $this->type("check_number", "check #1041"); | |
ba797227 | 112 | $this->click("is_email_receipt"); |
16a9c6d8 | 113 | $this->assertTrue($this->isChecked("is_email_receipt"), 'Send Receipt checkbox should be checked.'); |
6a488035 TO |
114 | $this->type("trxn_id", "P20901X1" . rand(100, 10000)); |
115 | ||
116 | // soft credit | |
fc2fa8f8 | 117 | $this->webtestFillAutocomplete("{$softCreditLname}, {$softCreditFname}", 's2id_soft_credit_contact_id_1'); |
118 | $this->type("soft_credit_amount_1", "100"); | |
6a488035 | 119 | |
6a488035 TO |
120 | //Additional Detail section |
121 | $this->click("AdditionalDetail"); | |
122 | $this->waitForElementPresent("thankyou_date"); | |
123 | ||
124 | $this->type("note", "This is a test note."); | |
6a488035 TO |
125 | $this->type("invoice_id", time()); |
126 | $this->webtestFillDate('thankyou_date'); | |
127 | ||
6a488035 TO |
128 | //Premium section |
129 | $this->click("Premium"); | |
130 | $this->waitForElementPresent("fulfilled_date"); | |
131 | $this->select("product_name[0]", "label=Coffee Mug ( MUG-101 )"); | |
132 | $this->select("product_name[1]", "label=Black"); | |
133 | $this->webtestFillDate('fulfilled_date'); | |
134 | ||
135 | // Clicking save. | |
136 | $this->click("_qf_Contribution_upload"); | |
87fd4550 | 137 | // Ask for confirmation to send a receipt to the contributor on 'is_email_reciept' check |
6c6e6187 | 138 | $this->assertTrue((bool) preg_match("/^Click OK to save this contribution record AND send a receipt to the contributor now./", $this->getConfirmation())); |
87fd4550 | 139 | $this->chooseOkOnNextConfirmation(); |
6a488035 TO |
140 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
141 | ||
142 | // Is status message correct? | |
fc2fa8f8 | 143 | $this->waitForText("crm-notification-container", "The contribution record has been saved."); |
6a488035 TO |
144 | |
145 | // verify if Membership is created | |
e684c1ae | 146 | $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']"); |
6a488035 | 147 | |
c543dff8 WA |
148 | $contriID = $this->urlArg('id', $this->getAttribute("xpath=//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span//a[text()='Edit']@href")); |
149 | $contactID = $this->urlArg('cid', $this->getAttribute("xpath=//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span//a[text()='Edit']@href")); | |
7a731220 | 150 | |
6a488035 | 151 | //click through to the Membership view screen |
e684c1ae | 152 | $this->click("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']"); |
6a488035 TO |
153 | $this->waitForElementPresent("_qf_ContributionView_cancel-bottom"); |
154 | ||
155 | $expected = array( | |
7a731220 | 156 | 'Financial Type' => $financialType['name'], |
157 | 'Total Amount' => '$ 110.00', | |
6a488035 | 158 | 'Contribution Status' => 'Completed', |
4db803dd | 159 | 'Payment Method' => 'Check', |
6a488035 | 160 | 'Check Number' => 'check #1041', |
6a488035 TO |
161 | ); |
162 | ||
163 | foreach ($expected as $label => $value) { | |
1fd662d2 | 164 | $this->assertElementContainsText("xpath=id('ContributionView')/div[2]/table[1]/tbody//tr/td[1][text()='$label']/../td[2]", $value); |
6a488035 TO |
165 | } |
166 | ||
73ec6821 | 167 | // verify if soft credit was created successfully |
168 | $expected = array( | |
169 | 'Soft Credit To' => "{$softCreditFname} {$softCreditLname}", | |
170 | 'Amount' => '100.00', | |
171 | ); | |
172 | ||
173 | foreach ($expected as $value) { | |
1fd662d2 | 174 | $this->assertElementContainsText("css=table.crm-soft-credit-listing", $value); |
73ec6821 | 175 | } |
176 | ||
177 | // go to first soft creditor contact view page | |
d84aa55c | 178 | $this->clickLink("css=table.crm-soft-credit-listing tbody tr td a"); |
76e86fd8 | 179 | |
6a488035 TO |
180 | // go to contribution tab |
181 | $this->waitForElementPresent("css=li#tab_contribute a"); | |
182 | $this->click("css=li#tab_contribute a"); | |
183 | $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)"); | |
1fd662d2 | 184 | $this->assertElementContainsText("xpath=id('Search')/div[2]/table[2]/tbody/tr[2]/td[1]/a", $contact['display_name']); |
6a488035 TO |
185 | // verify soft credit details |
186 | $expected = array( | |
7a731220 | 187 | 4 => $financialType['name'], |
d84aa55c | 188 | 2 => '100.00', |
fc2fa8f8 | 189 | 6 => 'Completed', |
6a488035 TO |
190 | ); |
191 | foreach ($expected as $value => $label) { | |
1fd662d2 | 192 | $this->assertElementContainsText("xpath=id('Search')/div[2]/table[2]/tbody/tr[2]/td[$value]", $label); |
6a488035 | 193 | } |
7a731220 | 194 | |
195 | // CRM-17418 fix: Now cancel the contribution | |
196 | $this->openCiviPage("contact/view/contribution", "reset=1&action=update&id=$contriID&cid=$contactID&context=contribution", "_qf_Contribution_upload"); | |
197 | $this->select('contribution_status_id', 'label=Cancelled'); | |
198 | $this->waitForElementPresent('cancel_reason'); | |
199 | $this->click("_qf_Contribution_upload"); | |
200 | // Is status message correct? | |
201 | $this->waitForText("crm-notification-container", "The contribution record has been saved."); | |
202 | ||
203 | // 1. On first completed contribution the contribution_amount = 100 and Tax Amount = 10 | |
204 | // 2. After Cancellation contribution_amount = -100 and Tax Amount = -10 | |
205 | // So the sum of all the 4 created financial item's amount would be 0 | |
206 | $query = "SELECT SUM( amount ) FROM `civicrm_financial_item` WHERE entity_id = %1"; | |
207 | $sum = CRM_Core_DAO::singleValueQuery($query, array(1 => array($contriID, 'Integer'))); | |
208 | $this->assertEquals($sum, 0.00); | |
6a488035 | 209 | } |
6a488035 | 210 | |
00be9182 | 211 | public function testfinancialTypeSearch() { |
1f0d8c92 PN |
212 | $this->webtestLogin(); |
213 | ||
214 | $financialType = array( | |
215 | 'name' => 'Financial type' . substr(sha1(rand()), 0, 7), | |
216 | 'is_reserved' => FALSE, | |
217 | 'is_deductible' => FALSE, | |
218 | ); | |
4cbe18b8 | 219 | |
1f0d8c92 PN |
220 | $this->addeditFinancialType($financialType); |
221 | $this->addStandaloneContribution($financialType); | |
222 | $this->addStandaloneContribution($financialType); | |
223 | ||
224 | $this->openCiviPage("contribute/search", "reset=1", "_qf_Search_refresh"); | |
225 | // select group | |
fc2fa8f8 | 226 | $this->select("financial_type_id", "label={$financialType['name']}"); |
1f0d8c92 | 227 | $this->clickLink("_qf_Search_refresh"); |
66d3f51b | 228 | $this->assertElementContainsText("xpath=//div[@class='crm-content-block']//div[@id='search-status']/table/tbody/tr[1]/td[1]", "2 Result"); |
24f591b0 | 229 | $this->assertElementContainsText("xpath=//div[@class='crm-content-block']//div[@id='search-status']/table/tbody/tr[1]/td[2]", "Financial Type In {$financialType['name']}"); |
4cbe18b8 | 230 | |
1f0d8c92 | 231 | $this->openCiviPage("contact/search/advanced", "reset=1", "_qf_Advanced_refresh-top"); |
80f3b91d | 232 | $this->clickAjaxLink('CiviContribute', "financial_type_id"); |
4cbe18b8 | 233 | |
1f0d8c92 | 234 | // select group |
fc2fa8f8 | 235 | $this->select("financial_type_id", "label={$financialType['name']}"); |
1f0d8c92 | 236 | $this->clickLink("_qf_Advanced_refresh-top"); |
66d3f51b | 237 | $this->assertElementContainsText("xpath=//div[@class='crm-content-block']//div[@id='search-status']//table/tbody/tr[1]/td[1]", "2 Contacts"); |
24f591b0 | 238 | $this->assertElementContainsText("xpath=//div[@class='crm-content-block']//div[@id='search-status']//table/tbody/tr[1]/td[2]", "Financial Type In {$financialType['name']}"); |
1f0d8c92 PN |
239 | } |
240 | ||
4cbe18b8 EM |
241 | /** |
242 | * @param $financialType | |
243 | */ | |
00be9182 | 244 | public function addStandaloneContribution($financialType) { |
4cbe18b8 | 245 | |
1f0d8c92 PN |
246 | $this->openCiviPage("contribute/add", "reset=1&context=standalone", "_qf_Contribution_upload"); |
247 | ||
248 | // create new contact using dialog | |
80f3b91d | 249 | $this->createDialogContact(); |
1f0d8c92 PN |
250 | |
251 | // select financial type | |
252 | $this->select("financial_type_id", "label={$financialType['name']}"); | |
253 | ||
254 | // fill in Received Date | |
255 | $this->webtestFillDate('receive_date'); | |
256 | ||
257 | // source | |
258 | $this->type("source", "Mailer 1"); | |
259 | ||
260 | // total amount | |
261 | $this->type("total_amount", "100"); | |
262 | ||
263 | // select payment instrument type = Check and enter chk number | |
264 | $this->select("payment_instrument_id", "value=4"); | |
265 | $this->waitForElementPresent("check_number"); | |
266 | $this->type("check_number", "check #1041"); | |
267 | ||
268 | $this->type("trxn_id", "P20901X1" . rand(100, 10000)); | |
269 | ||
270 | //Additional Detail section | |
271 | $this->click("AdditionalDetail"); | |
272 | $this->waitForElementPresent("thankyou_date"); | |
273 | ||
274 | $this->type("note", "This is a test note."); | |
66d3f51b | 275 | $this->waitForElementPresent("non_deductible_amount"); |
1f0d8c92 PN |
276 | $this->type("non_deductible_amount", "10"); |
277 | $this->type("fee_amount", "0"); | |
278 | $this->type("net_amount", "0"); | |
279 | $this->type("invoice_id", time()); | |
280 | $this->webtestFillDate('thankyou_date'); | |
281 | ||
282 | // Clicking save. | |
66d3f51b | 283 | $this->click("_qf_Contribution_upload"); |
1f0d8c92 PN |
284 | |
285 | // Is status message correct? | |
80f3b91d | 286 | $this->checkCRMAlert("The contribution record has been saved."); |
1f0d8c92 PN |
287 | |
288 | // verify if Membership is created | |
deeea38d | 289 | $this->waitForElementPresent("xpath=//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span//a[text()='View']"); |
1f0d8c92 PN |
290 | |
291 | //click through to the Membership view screen | |
deeea38d | 292 | $this->click("xpath=//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span//a[text()='View']"); |
1f0d8c92 PN |
293 | $this->waitForElementPresent("_qf_ContributionView_cancel-bottom"); |
294 | ||
295 | $expected = array( | |
296 | 'Financial Type' => $financialType['name'], | |
297 | 'Total Amount' => '$ 100.00', | |
298 | 'Contribution Status' => 'Completed', | |
4db803dd | 299 | 'Payment Method' => 'Check', |
1f0d8c92 PN |
300 | 'Check Number' => 'check #1041', |
301 | ); | |
302 | ||
303 | foreach ($expected as $label => $value) { | |
1fd662d2 | 304 | $this->assertElementContainsText("xpath=id('ContributionView')/div[2]/table[1]/tbody//tr/td[1][text()='$label']/../td[2]", $value); |
1f0d8c92 PN |
305 | } |
306 | } | |
307 | ||
00be9182 | 308 | public function testAjaxCustomGroupLoad() { |
c4e6d4e8 PJ |
309 | $this->webtestLogin(); |
310 | $triggerElement = array('name' => 'financial_type_id', 'type' => 'select'); | |
311 | $customSets = array( | |
312 | array('entity' => 'Contribution', 'subEntity' => 'Donation', 'triggerElement' => $triggerElement), | |
21dfd5f5 | 313 | array('entity' => 'Contribution', 'subEntity' => 'Member Dues', 'triggerElement' => $triggerElement), |
c4e6d4e8 PJ |
314 | ); |
315 | ||
316 | $pageUrl = array('url' => 'contribute/add', 'args' => 'reset=1&action=add&context=standalone'); | |
317 | $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl); | |
318 | } | |
96025800 | 319 | |
232624b1 | 320 | } |