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