Merge remote-tracking branch 'upstream/4.4' into 4.4-4.5-2014-10-01-19-08-00
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / StandaloneAddTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 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 = 'Asset';
52 $taxDeductible = FALSE;
53 $isActive = FALSE;
54 $isTax = TRUE;
55 $taxRate = 9.9999999;
56 $isDefault = FALSE;
57
58 //Add new organisation
59 if($orgName) {
60 $this->webtestAddOrganization($orgName);
61 }
62
63 $this->_testAddFinancialAccount($financialAccountTitle,
64 $financialAccountDescription,
65 $accountingCode,
66 $orgName,
67 $financialAccountType,
68 $taxDeductible,
69 $isActive,
70 $isTax,
71 $taxRate,
72 $isDefault
73 );
74
75 $this->openCiviPage("contribute/add", "reset=1&context=standalone", "_qf_Contribution_upload");
76
77 // create new contact using dialog
78 $contact = $this->createDialogContact();
79
80 // select financial type
81 $this->select("financial_type_id", "value=1");
82
83 // fill in Received Date
84 $this->webtestFillDate('receive_date');
85
86 // source
87 $this->type("source", "Mailer 1");
88
89 // total amount
90 $this->type("total_amount", "100");
91
92 // select payment instrument type = Check and enter chk number
93 $this->select("payment_instrument_id", "value=4");
94 $this->waitForElementPresent("check_number");
95 $this->type("check_number", "check #1041");
96 $this->click("is_email_receipt");
97 $this->assertTrue($this->isChecked("is_email_receipt"), 'Send Receipt checkbox should be checked.');
98 $this->type("trxn_id", "P20901X1" . rand(100, 10000));
99
100 // soft credit
101 $this->webtestFillAutocomplete("{$softCreditLname}, {$softCreditFname}", 's2id_soft_credit_contact_id_1');
102 $this->type("soft_credit_amount_1", "100");
103
104 //Custom Data
105 //$this->click('CIVICRM_QFID_3_6');
106
107 //Additional Detail section
108 $this->click("AdditionalDetail");
109 $this->waitForElementPresent("thankyou_date");
110
111 $this->type("note", "This is a test note.");
112 $this->type("non_deductible_amount", "10");
113 $this->type("fee_amount", "0");
114 $this->type("net_amount", "0");
115 $this->type("invoice_id", time());
116 $this->webtestFillDate('thankyou_date');
117
118
119 //Premium section
120 $this->click("Premium");
121 $this->waitForElementPresent("fulfilled_date");
122 $this->select("product_name[0]", "label=Coffee Mug ( MUG-101 )");
123 $this->select("product_name[1]", "label=Black");
124 $this->webtestFillDate('fulfilled_date');
125
126 // Clicking save.
127 $this->click("_qf_Contribution_upload");
128 // Ask for confirmation to send a receipt to the contributor on 'is_email_reciept' check
129 $this->assertTrue((bool)preg_match("/^Click OK to save this contribution record AND send a receipt to the contributor now./",$this->getConfirmation()));
130 $this->chooseOkOnNextConfirmation();
131 $this->waitForPageToLoad($this->getTimeoutMsec());
132
133 // Is status message correct?
134 $this->waitForText("crm-notification-container", "The contribution record has been saved.");
135
136 // verify if Membership is created
137 $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']");
138
139 //click through to the Membership view screen
140 $this->click("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']");
141 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
142
143 $expected = array(
144 'Financial Type' => 'Donation',
145 'Total Amount' => '$ 100.00',
146 'Contribution Status' => 'Completed',
147 'Paid By' => 'Check',
148 'Check Number' => 'check #1041',
149 );
150
151 foreach ($expected as $label => $value) {
152 $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody//tr/td[1][text()='$label']/../td[2]", preg_quote($value));
153 }
154
155 // verify if soft credit was created successfully
156 $expected = array(
157 'Soft Credit To' => "{$softCreditFname} {$softCreditLname}",
158 'Amount' => '100.00',
159 );
160
161 foreach ($expected as $value) {
162 $this->verifyText("css=table.crm-soft-credit-listing", preg_quote($value));
163 }
164
165 // go to first soft creditor contact view page
166 $this->clickLink("css=table.crm-soft-credit-listing tbody tr td a");
167
168 // go to contribution tab
169 $this->waitForElementPresent("css=li#tab_contribute a");
170 $this->click("css=li#tab_contribute a");
171 $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
172 $this->verifyText("xpath=id('Search')/div[2]/table[2]/tbody/tr[2]/td[1]/a", preg_quote($contact['display_name']));
173 // verify soft credit details
174 $expected = array(
175 4 => 'Donation',
176 2 => '100.00',
177 6 => 'Completed',
178 );
179 foreach ($expected as $value => $label) {
180 $this->verifyText("xpath=id('Search')/div[2]/table[2]/tbody/tr[2]/td[$value]", preg_quote($label));
181 }
182 }
183
184 function testfinancialTypeSearch() {
185 $this->webtestLogin();
186
187 $financialType = array(
188 'name' => 'Financial type' . substr(sha1(rand()), 0, 7),
189 'is_reserved' => FALSE,
190 'is_deductible' => FALSE,
191 );
192
193 $this->addeditFinancialType($financialType);
194 $this->addStandaloneContribution($financialType);
195 $this->addStandaloneContribution($financialType);
196
197 $this->openCiviPage("contribute/search", "reset=1", "_qf_Search_refresh");
198 // select group
199 $this->select("financial_type_id", "label={$financialType['name']}");
200 $this->clickLink("_qf_Search_refresh");
201 $this->assertElementContainsText("xpath=//div[@id='search-status']/table/tbody/tr[1]/td[1]", "2 Result");
202 $this->assertElementContainsText("xpath=//div[@id='search-status']/table/tbody/tr[1]/td[2]", "Financial Type IN {$financialType['name']}");
203
204 $this->openCiviPage("contact/search/advanced", "reset=1", "_qf_Advanced_refresh-top");
205 $this->clickAjaxLink('CiviContribute', "financial_type_id");
206
207 // select group
208 $this->select("financial_type_id", "label={$financialType['name']}");
209 $this->clickLink("_qf_Advanced_refresh-top");
210 $this->assertElementContainsText("xpath=//div[@id='search-status']//table/tbody/tr[1]/td[1]", "2 Contacts");
211 $this->assertElementContainsText("xpath=//div[@id='search-status']//table/tbody/tr[1]/td[2]", "Financial Type IN {$financialType['name']}");
212 }
213
214 /**
215 * @param $financialType
216 */
217 function addStandaloneContribution($financialType) {
218
219 $this->openCiviPage("contribute/add", "reset=1&context=standalone", "_qf_Contribution_upload");
220
221 // create new contact using dialog
222 $this->createDialogContact();
223
224 // select financial type
225 $this->select("financial_type_id", "label={$financialType['name']}");
226
227 // fill in Received Date
228 $this->webtestFillDate('receive_date');
229
230 // source
231 $this->type("source", "Mailer 1");
232
233 // total amount
234 $this->type("total_amount", "100");
235
236 // select payment instrument type = Check and enter chk number
237 $this->select("payment_instrument_id", "value=4");
238 $this->waitForElementPresent("check_number");
239 $this->type("check_number", "check #1041");
240
241 $this->type("trxn_id", "P20901X1" . rand(100, 10000));
242
243 //Additional Detail section
244 $this->click("AdditionalDetail");
245 $this->waitForElementPresent("thankyou_date");
246
247 $this->type("note", "This is a test note.");
248 $this->type("non_deductible_amount", "10");
249 $this->type("fee_amount", "0");
250 $this->type("net_amount", "0");
251 $this->type("invoice_id", time());
252 $this->webtestFillDate('thankyou_date');
253
254 // Clicking save.
255 $this->clickLink("_qf_Contribution_upload");
256
257 // Is status message correct?
258 $this->checkCRMAlert("The contribution record has been saved.");
259
260 // verify if Membership is created
261 $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']");
262
263 //click through to the Membership view screen
264 $this->click("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']");
265 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
266
267 $expected = array(
268 'Financial Type' => $financialType['name'],
269 'Total Amount' => '$ 100.00',
270 'Contribution Status' => 'Completed',
271 'Paid By' => 'Check',
272 'Check Number' => 'check #1041',
273 );
274
275 foreach ($expected as $label => $value) {
276 $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody//tr/td[1][text()='$label']/../td[2]", preg_quote($value));
277 }
278 }
279
280 function testAjaxCustomGroupLoad() {
281 $this->webtestLogin();
282 $triggerElement = array('name' => 'financial_type_id', 'type' => 'select');
283 $customSets = array(
284 array('entity' => 'Contribution', 'subEntity' => 'Donation', 'triggerElement' => $triggerElement),
285 array('entity' => 'Contribution', 'subEntity' => 'Member Dues', 'triggerElement' => $triggerElement)
286 );
287
288 $pageUrl = array('url' => 'contribute/add', 'args' => 'reset=1&action=add&context=standalone');
289 $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl);
290 }
291 }