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