Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
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 | +--------------------------------------------------------------------+ | |
25 | */ | |
26 | ||
6a488035 TO |
27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
28 | class WebTest_Contribute_StandaloneAddTest extends CiviSeleniumTestCase { | |
29 | ||
30 | protected function setUp() { | |
31 | parent::setUp(); | |
32 | } | |
33 | ||
34 | function testStandaloneContributeAdd() { | |
6a488035 TO |
35 | $this->webtestLogin(); |
36 | ||
37 | // Create a contact to be used as soft creditor | |
38 | $softCreditFname = substr(sha1(rand()), 0, 7); | |
39 | $softCreditLname = substr(sha1(rand()), 0, 7); | |
40 | $this->webtestAddContact($softCreditFname, $softCreditLname, FALSE); | |
41 | ||
42 | // Add new Financial Account | |
43 | $orgName = 'Alberta '.substr(sha1(rand()), 0, 7); | |
44 | $financialAccountTitle = 'Financial Account '.substr(sha1(rand()), 0, 4); | |
45 | $financialAccountDescription = "{$financialAccountTitle} Description"; | |
46 | $accountingCode = 1033; | |
47 | $financialAccountType = 'Asset'; | |
48 | $taxDeductible = FALSE; | |
49 | $isActive = FALSE; | |
50 | $isTax = TRUE; | |
51 | $taxRate = 9.9999999; | |
52 | $isDefault = FALSE; | |
76e86fd8 | 53 | |
6a488035 TO |
54 | //Add new organisation |
55 | if($orgName) { | |
56 | $this->webtestAddOrganization($orgName); | |
57 | } | |
76e86fd8 | 58 | |
6a488035 TO |
59 | $this->_testAddFinancialAccount($financialAccountTitle, |
60 | $financialAccountDescription, | |
61 | $accountingCode, | |
62 | $orgName, | |
63 | $financialAccountType, | |
64 | $taxDeductible, | |
65 | $isActive, | |
66 | $isTax, | |
67 | $taxRate, | |
68 | $isDefault | |
69 | ); | |
70 | ||
42daf119 | 71 | $this->openCiviPage("contribute/add", "reset=1&context=standalone", "_qf_Contribution_upload"); |
6a488035 | 72 | |
6a488035 TO |
73 | // create new contact using dialog |
74 | $firstName = substr(sha1(rand()), 0, 7); | |
75 | $this->webtestNewDialogContact($firstName, "Contributor", $firstName . "@example.com"); | |
76e86fd8 | 76 | |
6a488035 TO |
77 | // select financial type |
78 | $this->select("financial_type_id", "value=1"); | |
76e86fd8 | 79 | |
6a488035 TO |
80 | // fill in Received Date |
81 | $this->webtestFillDate('receive_date'); | |
82 | ||
83 | // source | |
84 | $this->type("source", "Mailer 1"); | |
85 | ||
86 | // total amount | |
87 | $this->type("total_amount", "100"); | |
88 | ||
89 | // select payment instrument type = Check and enter chk number | |
90 | $this->select("payment_instrument_id", "value=4"); | |
91 | $this->waitForElementPresent("check_number"); | |
92 | $this->type("check_number", "check #1041"); | |
76e86fd8 | 93 | |
6a488035 TO |
94 | $this->type("trxn_id", "P20901X1" . rand(100, 10000)); |
95 | ||
96 | // soft credit | |
fd40e2c2 | 97 | $this->webtestFillAutocomplete("{$softCreditLname}, {$softCreditFname}", 'soft_credit_contact_1'); |
6a488035 TO |
98 | |
99 | //Custom Data | |
100 | //$this->click('CIVICRM_QFID_3_6'); | |
101 | ||
102 | //Additional Detail section | |
103 | $this->click("AdditionalDetail"); | |
104 | $this->waitForElementPresent("thankyou_date"); | |
105 | ||
106 | $this->type("note", "This is a test note."); | |
107 | $this->type("non_deductible_amount", "10"); | |
108 | $this->type("fee_amount", "0"); | |
109 | $this->type("net_amount", "0"); | |
110 | $this->type("invoice_id", time()); | |
111 | $this->webtestFillDate('thankyou_date'); | |
112 | ||
113 | //Honoree section | |
114 | $this->click("Honoree"); | |
115 | $this->waitForElementPresent("honor_email"); | |
116 | ||
117 | $this->click("CIVICRM_QFID_1_2"); | |
118 | $this->select("honor_prefix_id", "label=Ms."); | |
119 | $this->type("honor_first_name", "Foo"); | |
120 | $this->type("honor_last_name", "Bar"); | |
121 | $this->type("honor_email", "foo@bar.com"); | |
122 | ||
123 | //Premium section | |
124 | $this->click("Premium"); | |
125 | $this->waitForElementPresent("fulfilled_date"); | |
126 | $this->select("product_name[0]", "label=Coffee Mug ( MUG-101 )"); | |
127 | $this->select("product_name[1]", "label=Black"); | |
128 | $this->webtestFillDate('fulfilled_date'); | |
129 | ||
130 | // Clicking save. | |
131 | $this->click("_qf_Contribution_upload"); | |
132 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
133 | ||
134 | // Is status message correct? | |
135 | $this->assertTrue($this->isTextPresent("The contribution record has been saved."), "Status message didn't show up after saving!"); | |
136 | ||
137 | // verify if Membership is created | |
138 | $this->waitForElementPresent("xpath=//div[@id='Contributions']//table//tbody/tr[1]/td[8]/span/a[text()='View']"); | |
139 | ||
140 | //click through to the Membership view screen | |
141 | $this->click("xpath=//div[@id='Contributions']//table/tbody/tr[1]/td[8]/span/a[text()='View']"); | |
142 | $this->waitForElementPresent("_qf_ContributionView_cancel-bottom"); | |
143 | ||
144 | $expected = array( | |
145 | 'Financial Type' => 'Donation', | |
146 | 'Total Amount' => '$ 100.00', | |
147 | 'Contribution Status' => 'Completed', | |
148 | 'Paid By' => 'Check', | |
149 | 'Check Number' => 'check #1041', | |
6a488035 TO |
150 | ); |
151 | ||
152 | foreach ($expected as $label => $value) { | |
153 | $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody//tr/td[1][text()='$label']/../td[2]", preg_quote($value)); | |
154 | } | |
155 | ||
73ec6821 | 156 | // verify if soft credit was created successfully |
157 | $expected = array( | |
158 | 'Soft Credit To' => "{$softCreditFname} {$softCreditLname}", | |
159 | 'Amount' => '100.00', | |
160 | ); | |
161 | ||
162 | foreach ($expected as $value) { | |
163 | $this->verifyText("css=table.crm-soft-credit-listing", preg_quote($value)); | |
164 | } | |
165 | ||
166 | // go to first soft creditor contact view page | |
167 | $this->click("css=table.crm-soft-credit-listing tbody tr td a"); | |
76e86fd8 | 168 | |
6a488035 TO |
169 | // go to contribution tab |
170 | $this->waitForElementPresent("css=li#tab_contribute a"); | |
171 | $this->click("css=li#tab_contribute a"); | |
172 | $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)"); | |
173 | ||
174 | // verify soft credit details | |
175 | $expected = array( | |
176 | 3 => 'Donation', | |
177 | 2 => '100.00', | |
178 | 5 => 'Completed', | |
179 | 1 => "{$firstName} Contributor", | |
180 | ); | |
181 | foreach ($expected as $value => $label) { | |
182 | $this->verifyText("xpath=id('Search')/div[2]/table[2]/tbody/tr[2]/td[$value]", preg_quote($label)); | |
183 | } | |
184 | } | |
6a488035 | 185 | |
1f0d8c92 PN |
186 | function testfinancialTypeSearch() { |
187 | $this->webtestLogin(); | |
188 | ||
189 | $financialType = array( | |
190 | 'name' => 'Financial type' . substr(sha1(rand()), 0, 7), | |
191 | 'is_reserved' => FALSE, | |
192 | 'is_deductible' => FALSE, | |
193 | ); | |
194 | ||
195 | $this->addeditFinancialType($financialType); | |
196 | $this->addStandaloneContribution($financialType); | |
197 | $this->addStandaloneContribution($financialType); | |
198 | ||
199 | $this->openCiviPage("contribute/search", "reset=1", "_qf_Search_refresh"); | |
200 | // select group | |
201 | $this->select("crmasmSelect2", "label={$financialType['name']}"); | |
202 | $this->clickLink("_qf_Search_refresh"); | |
203 | $this->assertElementContainsText("xpath=//div[@id='search-status']/table/tbody/tr[1]/td[1]", "2 Result"); | |
204 | $this->assertElementContainsText("xpath=//div[@id='search-status']/table/tbody/tr[1]/td[2]", "Financial Type IN {$financialType['name']}"); | |
205 | ||
206 | $this->openCiviPage("contact/search/advanced", "reset=1", "_qf_Advanced_refresh-top"); | |
207 | $this->click('CiviContribute'); | |
208 | $this->waitForElementPresent("crmasmSelect5"); | |
209 | ||
210 | // select group | |
211 | $this->select("crmasmSelect5", "label={$financialType['name']}"); | |
212 | $this->clickLink("_qf_Advanced_refresh-top"); | |
213 | $this->assertElementContainsText("xpath=//div[@id='search-status']//table/tbody/tr[1]/td[1]", "2 Contacts"); | |
214 | $this->assertElementContainsText("xpath=//div[@id='search-status']//table/tbody/tr[1]/td[2]", "Financial Type IN {$financialType['name']}"); | |
215 | } | |
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 | $firstName = substr(sha1(rand()), 0, 7); | |
223 | $this->webtestNewDialogContact($firstName, "Contributor", $firstName . "@example.com"); | |
224 | ||
225 | // select financial type | |
226 | $this->select("financial_type_id", "label={$financialType['name']}"); | |
227 | ||
228 | // fill in Received Date | |
229 | $this->webtestFillDate('receive_date'); | |
230 | ||
231 | // source | |
232 | $this->type("source", "Mailer 1"); | |
233 | ||
234 | // total amount | |
235 | $this->type("total_amount", "100"); | |
236 | ||
237 | // select payment instrument type = Check and enter chk number | |
238 | $this->select("payment_instrument_id", "value=4"); | |
239 | $this->waitForElementPresent("check_number"); | |
240 | $this->type("check_number", "check #1041"); | |
241 | ||
242 | $this->type("trxn_id", "P20901X1" . rand(100, 10000)); | |
243 | ||
244 | //Additional Detail section | |
245 | $this->click("AdditionalDetail"); | |
246 | $this->waitForElementPresent("thankyou_date"); | |
247 | ||
248 | $this->type("note", "This is a test note."); | |
249 | $this->type("non_deductible_amount", "10"); | |
250 | $this->type("fee_amount", "0"); | |
251 | $this->type("net_amount", "0"); | |
252 | $this->type("invoice_id", time()); | |
253 | $this->webtestFillDate('thankyou_date'); | |
254 | ||
255 | // Clicking save. | |
256 | $this->click("_qf_Contribution_upload"); | |
257 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
258 | ||
259 | // Is status message correct? | |
260 | $this->assertTrue($this->isTextPresent("The contribution record has been saved."), "Status message didn't show up after saving!"); | |
261 | ||
262 | // verify if Membership is created | |
263 | $this->waitForElementPresent("xpath=//div[@id='Contributions']//table//tbody/tr[1]/td[8]/span/a[text()='View']"); | |
264 | ||
265 | //click through to the Membership view screen | |
266 | $this->click("xpath=//div[@id='Contributions']//table/tbody/tr[1]/td[8]/span/a[text()='View']"); | |
267 | $this->waitForElementPresent("_qf_ContributionView_cancel-bottom"); | |
268 | ||
269 | $expected = array( | |
270 | 'Financial Type' => $financialType['name'], | |
271 | 'Total Amount' => '$ 100.00', | |
272 | 'Contribution Status' => 'Completed', | |
273 | 'Paid By' => 'Check', | |
274 | 'Check Number' => 'check #1041', | |
275 | ); | |
276 | ||
277 | foreach ($expected as $label => $value) { | |
278 | $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody//tr/td[1][text()='$label']/../td[2]", preg_quote($value)); | |
279 | } | |
280 | } | |
281 | ||
c4e6d4e8 PJ |
282 | function testAjaxCustomGroupLoad() { |
283 | $this->webtestLogin(); | |
284 | $triggerElement = array('name' => 'financial_type_id', 'type' => 'select'); | |
285 | $customSets = array( | |
286 | array('entity' => 'Contribution', 'subEntity' => 'Donation', 'triggerElement' => $triggerElement), | |
287 | array('entity' => 'Contribution', 'subEntity' => 'Member Dues', 'triggerElement' => $triggerElement) | |
288 | ); | |
289 | ||
290 | $pageUrl = array('url' => 'contribute/add', 'args' => 'reset=1&action=add&context=standalone'); | |
291 | $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl); | |
292 | } | |
232624b1 | 293 | } |