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