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_UpdatePendingContributionTest extends CiviSeleniumTestCase { | |
29 | ||
30 | protected function setUp() { | |
31 | parent::setUp(); | |
32 | } | |
33 | ||
34 | function testUpdatePendingContribution() { | |
6a488035 TO |
35 | $this->webtestLogin(); |
36 | $firstName = substr(sha1(rand()), 0, 7); | |
42daf119 CW |
37 | $lastName = 'Contributor'; |
38 | $email = $firstName . "@example.com"; | |
6a488035 TO |
39 | |
40 | //Offline Pay Later Contribution | |
41 | $this->_testOfflineContribution($firstName, $lastName, $email); | |
42 | ||
43 | //Online Pay Later Contribution | |
44 | $this->_testOnlineContribution($firstName, $lastName, $email); | |
42daf119 | 45 | $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low"); |
6a488035 TO |
46 | |
47 | $this->type("sort_name", "$lastName, $firstName"); | |
48 | $this->click("_qf_Search_refresh"); | |
49 | ||
50 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
51 | $this->click('radio_ts', 'ts_all'); | |
52 | $contriIDOff = explode('&', $this->getAttribute("xpath=//div[@id='contributionSearch']/table/tbody/tr[1]/td[11]/span/a@href")); | |
53 | $contriIDOn = explode('&', $this->getAttribute("xpath=//div[@id='contributionSearch']/table/tbody/tr[2]/td[11]/span/a@href")); | |
54 | if (!empty($contriIDOff)) { | |
55 | $contriIDOff = substr($contriIDOff[1], (strrpos($contriIDOff[1], '=') + 1)); | |
56 | } | |
57 | if (!empty($contriIDOn)) { | |
58 | $contriIDOn = substr($contriIDOn[1], (strrpos($contriIDOn[1], '=') + 1)); | |
59 | } | |
60 | $this->select('task', "label=Update Pending Contribution Status"); | |
61 | $this->click("_qf_Search_next_action"); | |
62 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
63 | $this->select('contribution_status_id', 'label=Completed'); | |
64 | $this->type("trxn_id_{$contriIDOff}", substr(sha1(rand()), 0, 5)); | |
65 | $this->type("trxn_id_{$contriIDOn}", substr(sha1(rand()), 0, 5)); | |
66 | $this->click('_qf_Status_next'); | |
67 | $this->waitForElementPresent("_qf_Result_done"); | |
68 | $this->click("_qf_Result_done"); | |
69 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
70 | $status = 'Completed'; | |
71 | $this->verifyText("xpath=id('contributionSearch')/table[1]/tbody/tr[1]/td[9]", preg_quote($status)); | |
72 | $this->verifyText("xpath=id('contributionSearch')/table[1]/tbody/tr[2]/td[9]", preg_quote($status)); | |
73 | } | |
74 | ||
75 | function _testOfflineContribution($firstName, $lastName, $email) { | |
76 | // Create a contact to be used as soft creditor | |
77 | $softCreditFname = substr(sha1(rand()), 0, 7); | |
78 | $softCreditLname = substr(sha1(rand()), 0, 7); | |
79 | $this->webtestAddContact($softCreditFname, $softCreditLname, FALSE); | |
80 | ||
42daf119 | 81 | $this->openCiviPage("contribute/add", "reset=1&context=standalone", "_qf_Contribution_upload"); |
6a488035 | 82 | |
6a488035 TO |
83 | // create new contact using dialog |
84 | $this->webtestNewDialogContact($firstName, "Contributor", $email); | |
85 | ||
86 | // select financial type | |
87 | $this->select( "financial_type_id", "value=1" ); | |
88 | ||
89 | // fill in Received Date | |
90 | $this->webtestFillDate('receive_date'); | |
91 | ||
92 | //Contribution status | |
93 | $this->select("contribution_status_id", "label=Pending"); | |
94 | ||
95 | // source | |
96 | $this->type("source", "Mailer 1"); | |
97 | ||
98 | // total amount | |
99 | $this->type("total_amount", "100"); | |
100 | ||
101 | // select payment instrument type = Check and enter chk number | |
102 | $this->select("payment_instrument_id", "value=4"); | |
103 | $this->waitForElementPresent("check_number"); | |
104 | $this->type("check_number", "check #1041"); | |
105 | ||
106 | $this->type("trxn_id", "P20901X1" . rand(100, 10000)); | |
107 | ||
108 | // soft credit | |
082bb742 | 109 | $this->webtestFillAutocomplete("{$softCreditLname}, {$softCreditFname}", 'soft_credit_contact_1'); |
6a488035 TO |
110 | |
111 | //Custom Data | |
112 | //$this->click('CIVICRM_QFID_3_6'); | |
113 | ||
114 | //Additional Detail section | |
115 | $this->click("AdditionalDetail"); | |
116 | $this->waitForElementPresent("thankyou_date"); | |
117 | ||
118 | $this->type("note", "This is a test note."); | |
119 | $this->type("non_deductible_amount", "10"); | |
120 | $this->type("fee_amount", "0"); | |
121 | $this->type("net_amount", "0"); | |
122 | $this->type("invoice_id", time()); | |
123 | $this->webtestFillDate('thankyou_date'); | |
124 | ||
125 | //Honoree section | |
126 | $this->click("Honoree"); | |
127 | $this->waitForElementPresent("honor_email"); | |
128 | ||
129 | $this->click("CIVICRM_QFID_1_2"); | |
130 | $this->select("honor_prefix_id", "label=Ms."); | |
131 | $this->type("honor_first_name", "Foo"); | |
132 | $this->type("honor_last_name", "Bar"); | |
133 | $this->type("honor_email", "foo@bar.com"); | |
134 | ||
135 | //Premium section | |
136 | $this->click("Premium"); | |
137 | $this->waitForElementPresent("fulfilled_date"); | |
138 | $this->select("product_name[0]", "label=Coffee Mug ( MUG-101 )"); | |
139 | $this->select("product_name[1]", "label=Black"); | |
140 | $this->webtestFillDate('fulfilled_date'); | |
141 | ||
142 | // Clicking save. | |
143 | $this->click("_qf_Contribution_upload"); | |
144 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
145 | ||
146 | // Is status message correct? | |
147 | $this->assertTrue($this->isTextPresent("The contribution record has been saved."), "Status message didn't show up after saving!"); | |
148 | ||
149 | // verify if Contribution is created | |
150 | $this->waitForElementPresent("xpath=//div[@id='Contributions']//table//tbody/tr[1]/td[8]/span/a[text()='View']"); | |
151 | ||
152 | //click through to the Contribution view screen | |
153 | $this->click("xpath=//div[@id='Contributions']//table/tbody/tr[1]/td[8]/span/a[text()='View']"); | |
154 | $this->waitForElementPresent("_qf_ContributionView_cancel-bottom"); | |
155 | ||
156 | // View Contribution Record and test for expected values | |
157 | $expected = array( | |
158 | 'Financial Type' => 'Donation', | |
159 | 'Total Amount' => '100.00', | |
160 | 'Contribution Status' => 'Pending', | |
161 | 'Paid By' => 'Check', | |
162 | 'Check Number' => 'check #1041', | |
6a488035 TO |
163 | ); |
164 | $this->webtestVerifyTabularData($expected); | |
165 | ||
ce892f61 PJ |
166 | // go to soft creditor contact view page - this also does the soft credit check |
167 | $this->click("xpath=id('ContributionView')/div[2]/div/div[1][contains(text(), 'Soft Credit')]/../div[2]/table[1]/tbody//tr/td[1]/a[contains(text(), '{$softCreditFname} {$softCreditLname}')]"); | |
6a488035 TO |
168 | |
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 => 'Pending', | |
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 | } | |
185 | ||
186 | function _testOnlineContribution($firstName, $lastName, $email) { | |
187 | ||
188 | // We need a payment processor | |
189 | $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7); | |
190 | $processorType = 'Dummy'; | |
42daf119 CW |
191 | $pageTitle = substr(sha1(rand()), 0, 7); |
192 | $rand = 2 * rand(2, 50); | |
193 | $hash = substr(sha1(rand()), 0, 7); | |
6a488035 | 194 | $amountSection = TRUE; |
42daf119 CW |
195 | $payLater = TRUE; |
196 | $onBehalf = FALSE; | |
197 | $pledges = FALSE; | |
198 | $recurring = FALSE; | |
199 | $memberships = FALSE; | |
200 | $friend = FALSE; | |
201 | $profilePreId = 1; | |
6a488035 | 202 | $profilePostId = NULL; |
42daf119 CW |
203 | $premiums = FALSE; |
204 | $widget = FALSE; | |
205 | $pcp = FALSE; | |
6a488035 TO |
206 | $memPriceSetId = NULL; |
207 | ||
208 | // create a new online contribution page | |
209 | // create contribution page with randomized title and default params | |
210 | $pageId = $this->webtestAddContributionPage($hash, | |
211 | $rand, | |
212 | $pageTitle, | |
213 | array($processorName => $processorType), | |
214 | $amountSection, | |
215 | $payLater, | |
216 | $onBehalf, | |
217 | $pledges, | |
218 | $recurring, | |
219 | $memberships, | |
220 | $memPriceSetId, | |
221 | $friend, | |
222 | $profilePreId, | |
223 | $profilePostId, | |
224 | $premiums, | |
225 | $widget, | |
226 | $pcp | |
227 | ); | |
228 | ||
229 | //logout | |
42daf119 CW |
230 | $this->webtestLogout(); |
231 | $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom"); | |
6a488035 TO |
232 | |
233 | $this->type("email-5", $email); | |
234 | ||
235 | $this->type("first_name", $firstName); | |
236 | $this->type("last_name", $lastName); | |
76e86fd8 | 237 | |
6a488035 TO |
238 | $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input"); |
239 | $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 100); | |
240 | $this->click("xpath=//div[@class='crm-section payment_processor-section']/div[2]//label[text()='Pay later label {$hash}']"); | |
241 | $streetAddress = "100 Main Street"; | |
242 | $this->type("street_address-1", $streetAddress); | |
243 | $this->type("city-1", "San Francisco"); | |
244 | $this->type("postal_code-1", "94117"); | |
245 | $this->select("country-1", "value=1228"); | |
246 | $this->select("state_province-1", "value=1001"); | |
247 | ||
225a8648 | 248 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom"); |
6a488035 TO |
249 | |
250 | $this->click("_qf_Confirm_next-bottom"); | |
251 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
252 | ||
42daf119 | 253 | //login to check contribution |
6a488035 TO |
254 | $this->webtestLogin(); |
255 | ||
256 | //Find Contribution | |
42daf119 | 257 | $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low"); |
6a488035 TO |
258 | |
259 | $this->type("sort_name", "$lastName, $firstName"); | |
225a8648 CW |
260 | $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[2]/td[11]/span/a[text()='View']"); |
261 | $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[2]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom"); | |
6a488035 TO |
262 | // View Contribution Record and test for expected values |
263 | $expected = array( | |
42daf119 CW |
264 | 'From' => "{$firstName} {$lastName}", |
265 | 'Financial Type' => 'Donation', | |
266 | 'Total Amount' => '100.00', | |
6a488035 TO |
267 | 'Contribution Status' => 'Pending : Pay Later', |
268 | ); | |
269 | $this->webtestVerifyTabularData($expected); | |
270 | } | |
271 | } | |
272 |