Merge pull request #3317 from eileenmcnaughton/CRM-14197-postprocesfn
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / UpdatePendingContributionTest.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_UpdatePendingContributionTest
31 */
32 class WebTest_Contribute_UpdatePendingContributionTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testUpdatePendingContribution() {
39 $this->webtestLogin();
40 $firstName = substr(sha1(rand()), 0, 7);
41 $lastName = 'Contributor';
42 $email = $firstName . "@example.com";
43
44 //Offline Pay Later Contribution
45 $this->_testOfflineContribution($firstName, $lastName, $email);
46
47 //Online Pay Later Contribution
48 $this->_testOnlineContribution($firstName, $lastName, $email);
49 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
50
51 $this->type("sort_name", "$lastName, $firstName");
52 $this->click("_qf_Search_refresh");
53
54 $this->waitForPageToLoad($this->getTimeoutMsec());
55 $this->click('radio_ts', 'ts_all');
56 $contriIDOff = explode('&', $this->getAttribute("xpath=//div[@id='contributionSearch']/table/tbody/tr[1]/td[11]/span/a@href"));
57 $contriIDOn = explode('&', $this->getAttribute("xpath=//div[@id='contributionSearch']/table/tbody/tr[2]/td[11]/span/a@href"));
58 if (!empty($contriIDOff)) {
59 $contriIDOff = substr($contriIDOff[1], (strrpos($contriIDOff[1], '=') + 1));
60 }
61 if (!empty($contriIDOn)) {
62 $contriIDOn = substr($contriIDOn[1], (strrpos($contriIDOn[1], '=') + 1));
63 }
64 $this->select('task', "label=Update Pending Contribution Status");
65 $this->click("_qf_Search_next_action");
66 $this->waitForPageToLoad($this->getTimeoutMsec());
67 $this->select('contribution_status_id', 'label=Completed');
68 $this->type("trxn_id_{$contriIDOff}", substr(sha1(rand()), 0, 5));
69 $this->type("trxn_id_{$contriIDOn}", substr(sha1(rand()), 0, 5));
70 $this->click('_qf_Status_next');
71 $this->waitForElementPresent("_qf_Result_done");
72 $this->click("_qf_Result_done");
73 $this->waitForPageToLoad($this->getTimeoutMsec());
74 $status = 'Completed';
75 $this->verifyText("xpath=id('contributionSearch')/table[1]/tbody/tr[1]/td[9]", preg_quote($status));
76 $this->verifyText("xpath=id('contributionSearch')/table[1]/tbody/tr[2]/td[9]", preg_quote($status));
77 }
78
79 /**
80 * @param $firstName
81 * @param $lastName
82 * @param $email
83 */
84 function _testOfflineContribution($firstName, $lastName, $email) {
85 // Create a contact to be used as soft creditor
86 $softCreditFname = substr(sha1(rand()), 0, 7);
87 $softCreditLname = substr(sha1(rand()), 0, 7);
88 $this->webtestAddContact($softCreditFname, $softCreditLname, FALSE);
89
90 $this->openCiviPage("contribute/add", "reset=1&context=standalone", "_qf_Contribution_upload");
91
92 // create new contact using dialog
93 $this->webtestNewDialogContact($firstName, "Contributor", $email);
94
95 // select financial type
96 $this->select( "financial_type_id", "value=1" );
97
98 // fill in Received Date
99 $this->webtestFillDate('receive_date');
100
101 //Contribution status
102 $this->select("contribution_status_id", "label=Pending");
103
104 // source
105 $this->type("source", "Mailer 1");
106
107 // total amount
108 $this->type("total_amount", "100");
109
110 // select payment instrument type = Check and enter chk number
111 $this->select("payment_instrument_id", "value=4");
112 $this->waitForElementPresent("check_number");
113 $this->type("check_number", "check #1041");
114
115 $this->type("trxn_id", "P20901X1" . rand(100, 10000));
116
117 // soft credit
118 $this->webtestFillAutocomplete("{$softCreditLname}, {$softCreditFname}", 'soft_credit_contact_id_1');
119 $this->type("soft_credit_amount_1", "100");
120 //Custom Data
121 //$this->click('CIVICRM_QFID_3_6');
122
123 //Additional Detail section
124 $this->click("AdditionalDetail");
125 $this->waitForElementPresent("thankyou_date");
126
127 $this->type("note", "This is a test note.");
128 $this->type("non_deductible_amount", "10");
129 $this->type("fee_amount", "0");
130 $this->type("net_amount", "0");
131 $this->type("invoice_id", time());
132 $this->webtestFillDate('thankyou_date');
133
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[@class='view-content']//table[2]//tbody/tr[1]/td[8]/span/a[text()='View']");
151
152 //click through to the Contribution view screen
153 $this->click("xpath=//div[@class='view-content']//table[2]/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',
163 );
164 $this->webtestVerifyTabularData($expected);
165
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}')]");
168
169 $this->waitForPageToLoad($this->getTimeoutMsec());
170 // go to contribution tab
171 $this->waitForElementPresent("css=li#tab_contribute a");
172 $this->click("css=li#tab_contribute a");
173 $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
174
175 // verify soft credit details
176 $expected = array(
177 4 => 'Donation',
178 2 => '100.00',
179 6 => 'Pending',
180 1 => "{$firstName} Contributor",
181 );
182 foreach ($expected as $value => $label) {
183 $this->verifyText("xpath=id('Search')/div[2]/table[2]/tbody/tr[2]/td[$value]", preg_quote($label));
184 }
185 }
186
187 /**
188 * @param $firstName
189 * @param $lastName
190 * @param $email
191 */
192 function _testOnlineContribution($firstName, $lastName, $email) {
193
194 // We need a payment processor
195 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
196 $processorType = 'Dummy';
197 $pageTitle = substr(sha1(rand()), 0, 7);
198 $rand = 2 * rand(2, 50);
199 $hash = substr(sha1(rand()), 0, 7);
200 $amountSection = TRUE;
201 $payLater = TRUE;
202 $onBehalf = FALSE;
203 $pledges = FALSE;
204 $recurring = FALSE;
205 $memberships = FALSE;
206 $friend = FALSE;
207 $profilePreId = 1;
208 $profilePostId = NULL;
209 $premiums = FALSE;
210 $widget = FALSE;
211 $pcp = FALSE;
212 $memPriceSetId = NULL;
213
214 // create a new online contribution page
215 // create contribution page with randomized title and default params
216 $pageId = $this->webtestAddContributionPage($hash,
217 $rand,
218 $pageTitle,
219 array($processorName => $processorType),
220 $amountSection,
221 $payLater,
222 $onBehalf,
223 $pledges,
224 $recurring,
225 $memberships,
226 $memPriceSetId,
227 $friend,
228 $profilePreId,
229 $profilePostId,
230 $premiums,
231 $widget,
232 $pcp
233 );
234
235 //logout
236 $this->webtestLogout();
237 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
238
239 $this->type("email-5", $email);
240
241 $this->type("first_name", $firstName);
242 $this->type("last_name", $lastName);
243
244 $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input");
245 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 100);
246 $this->click("xpath=//div[@class='crm-section payment_processor-section']/div[2]//label[text()='Pay later label {$hash}']");
247 $streetAddress = "100 Main Street";
248 $this->type("street_address-1", $streetAddress);
249 $this->type("city-1", "San Francisco");
250 $this->type("postal_code-1", "94117");
251 $this->select("country-1", "value=1228");
252 $this->select("state_province-1", "value=1001");
253
254 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
255
256 $this->click("_qf_Confirm_next-bottom");
257 $this->waitForPageToLoad($this->getTimeoutMsec());
258
259 //login to check contribution
260 $this->webtestLogin();
261
262 //Find Contribution
263 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
264
265 $this->type("sort_name", "$lastName, $firstName");
266 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[2]/td[11]/span/a[text()='View']");
267 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[2]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
268 // View Contribution Record and test for expected values
269 $expected = array(
270 'From' => "{$firstName} {$lastName}",
271 'Financial Type' => 'Donation',
272 'Total Amount' => '100.00',
273 'Contribution Status' => 'Pending : Pay Later',
274 );
275 $this->webtestVerifyTabularData($expected);
276 }
277 }
278