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 | 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 | ||
38 | 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 | |
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; | |
76e86fd8 | 57 | |
6a488035 TO |
58 | //Add new organisation |
59 | if($orgName) { | |
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 TO |
77 | // create new contact using dialog |
78 | $firstName = substr(sha1(rand()), 0, 7); | |
79 | $this->webtestNewDialogContact($firstName, "Contributor", $firstName . "@example.com"); | |
76e86fd8 | 80 | |
6a488035 TO |
81 | // select financial type |
82 | $this->select("financial_type_id", "value=1"); | |
76e86fd8 | 83 | |
6a488035 TO |
84 | // fill in Received Date |
85 | $this->webtestFillDate('receive_date'); | |
86 | ||
87 | // source | |
88 | $this->type("source", "Mailer 1"); | |
89 | ||
90 | // total amount | |
91 | $this->type("total_amount", "100"); | |
92 | ||
93 | // select payment instrument type = Check and enter chk number | |
94 | $this->select("payment_instrument_id", "value=4"); | |
95 | $this->waitForElementPresent("check_number"); | |
96 | $this->type("check_number", "check #1041"); | |
ba797227 | 97 | $this->click("is_email_receipt"); |
76e86fd8 | 98 | |
6a488035 TO |
99 | $this->type("trxn_id", "P20901X1" . rand(100, 10000)); |
100 | ||
101 | // soft credit | |
fc2fa8f8 | 102 | $this->webtestFillAutocomplete("{$softCreditLname}, {$softCreditFname}", 's2id_soft_credit_contact_id_1'); |
103 | $this->type("soft_credit_amount_1", "100"); | |
6a488035 TO |
104 | |
105 | //Custom Data | |
106 | //$this->click('CIVICRM_QFID_3_6'); | |
107 | ||
108 | //Additional Detail section | |
109 | $this->click("AdditionalDetail"); | |
110 | $this->waitForElementPresent("thankyou_date"); | |
111 | ||
112 | $this->type("note", "This is a test note."); | |
113 | $this->type("non_deductible_amount", "10"); | |
114 | $this->type("fee_amount", "0"); | |
115 | $this->type("net_amount", "0"); | |
116 | $this->type("invoice_id", time()); | |
117 | $this->webtestFillDate('thankyou_date'); | |
118 | ||
6a488035 TO |
119 | |
120 | //Premium section | |
121 | $this->click("Premium"); | |
122 | $this->waitForElementPresent("fulfilled_date"); | |
123 | $this->select("product_name[0]", "label=Coffee Mug ( MUG-101 )"); | |
124 | $this->select("product_name[1]", "label=Black"); | |
125 | $this->webtestFillDate('fulfilled_date'); | |
126 | ||
127 | // Clicking save. | |
128 | $this->click("_qf_Contribution_upload"); | |
129 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
130 | ||
131 | // Is status message correct? | |
fc2fa8f8 | 132 | $this->waitForText("crm-notification-container", "The contribution record has been saved."); |
6a488035 TO |
133 | |
134 | // verify if Membership is created | |
fc2fa8f8 | 135 | $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']"); |
6a488035 TO |
136 | |
137 | //click through to the Membership view screen | |
fc2fa8f8 | 138 | $this->click("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']"); |
6a488035 TO |
139 | $this->waitForElementPresent("_qf_ContributionView_cancel-bottom"); |
140 | ||
141 | $expected = array( | |
142 | 'Financial Type' => 'Donation', | |
143 | 'Total Amount' => '$ 100.00', | |
144 | 'Contribution Status' => 'Completed', | |
145 | 'Paid By' => 'Check', | |
146 | 'Check Number' => 'check #1041', | |
6a488035 TO |
147 | ); |
148 | ||
149 | foreach ($expected as $label => $value) { | |
150 | $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody//tr/td[1][text()='$label']/../td[2]", preg_quote($value)); | |
151 | } | |
152 | ||
73ec6821 | 153 | // verify if soft credit was created successfully |
154 | $expected = array( | |
155 | 'Soft Credit To' => "{$softCreditFname} {$softCreditLname}", | |
156 | 'Amount' => '100.00', | |
157 | ); | |
158 | ||
159 | foreach ($expected as $value) { | |
160 | $this->verifyText("css=table.crm-soft-credit-listing", preg_quote($value)); | |
161 | } | |
162 | ||
163 | // go to first soft creditor contact view page | |
164 | $this->click("css=table.crm-soft-credit-listing tbody tr td a"); | |
76e86fd8 | 165 | |
6a488035 TO |
166 | // go to contribution tab |
167 | $this->waitForElementPresent("css=li#tab_contribute a"); | |
168 | $this->click("css=li#tab_contribute a"); | |
169 | $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)"); | |
170 | ||
171 | // verify soft credit details | |
172 | $expected = array( | |
6a488035 | 173 | 1 => "{$firstName} Contributor", |
fc2fa8f8 | 174 | 2 => 'Donation', |
175 | 1 => '100.00', | |
176 | 6 => 'Completed', | |
6a488035 TO |
177 | ); |
178 | foreach ($expected as $value => $label) { | |
fc2fa8f8 | 179 | $this->verifyText("xpath=id('Search')/div[2]/table[2]/tbody/tr[1]/td[$value]", preg_quote($label)); |
6a488035 TO |
180 | } |
181 | } | |
6a488035 | 182 | |
1f0d8c92 PN |
183 | function testfinancialTypeSearch() { |
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"); | |
201 | $this->assertElementContainsText("xpath=//div[@id='search-status']/table/tbody/tr[1]/td[2]", "Financial Type IN {$financialType['name']}"); | |
4cbe18b8 | 202 | |
1f0d8c92 PN |
203 | $this->openCiviPage("contact/search/advanced", "reset=1", "_qf_Advanced_refresh-top"); |
204 | $this->click('CiviContribute'); | |
fc2fa8f8 | 205 | $this->waitForElementPresent("financial_type_id"); |
4cbe18b8 | 206 | |
1f0d8c92 | 207 | // select group |
fc2fa8f8 | 208 | $this->select("financial_type_id", "label={$financialType['name']}"); |
1f0d8c92 PN |
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 | ||
4cbe18b8 EM |
214 | /** |
215 | * @param $financialType | |
216 | */ | |
1f0d8c92 | 217 | function addStandaloneContribution($financialType) { |
4cbe18b8 | 218 | |
1f0d8c92 PN |
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 | |
fc2fa8f8 | 263 | $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']"); |
1f0d8c92 PN |
264 | |
265 | //click through to the Membership view screen | |
fc2fa8f8 | 266 | $this->click("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']"); |
1f0d8c92 PN |
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 | } |