Merge pull request #1419 from kurund/CRM-13207
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / UpdatePendingContributionTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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
27require_once 'CiviTest/CiviSeleniumTestCase.php';
28class 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',
163 'Soft Credit To' => "{$softCreditFname} {$softCreditLname}",
164 );
165 $this->webtestVerifyTabularData($expected);
166
167 // go to soft creditor contact view page
168 $this->click("xpath=id('ContributionView')/div[2]/table[1]/tbody//tr/td[1][text()='Soft Credit To']/../td[2]/a[text()='{$softCreditFname} {$softCreditLname}']");
169
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 3 => 'Donation',
178 2 => '100.00',
179 5 => '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 function _testOnlineContribution($firstName, $lastName, $email) {
188
189 // We need a payment processor
190 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
191 $processorType = 'Dummy';
42daf119
CW
192 $pageTitle = substr(sha1(rand()), 0, 7);
193 $rand = 2 * rand(2, 50);
194 $hash = substr(sha1(rand()), 0, 7);
6a488035 195 $amountSection = TRUE;
42daf119
CW
196 $payLater = TRUE;
197 $onBehalf = FALSE;
198 $pledges = FALSE;
199 $recurring = FALSE;
200 $memberships = FALSE;
201 $friend = FALSE;
202 $profilePreId = 1;
6a488035 203 $profilePostId = NULL;
42daf119
CW
204 $premiums = FALSE;
205 $widget = FALSE;
206 $pcp = FALSE;
6a488035
TO
207 $memPriceSetId = NULL;
208
209 // create a new online contribution page
210 // create contribution page with randomized title and default params
211 $pageId = $this->webtestAddContributionPage($hash,
212 $rand,
213 $pageTitle,
214 array($processorName => $processorType),
215 $amountSection,
216 $payLater,
217 $onBehalf,
218 $pledges,
219 $recurring,
220 $memberships,
221 $memPriceSetId,
222 $friend,
223 $profilePreId,
224 $profilePostId,
225 $premiums,
226 $widget,
227 $pcp
228 );
229
230 //logout
42daf119
CW
231 $this->webtestLogout();
232 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
6a488035
TO
233
234 $this->type("email-5", $email);
235
236 $this->type("first_name", $firstName);
237 $this->type("last_name", $lastName);
76e86fd8 238
6a488035
TO
239 $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input");
240 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 100);
241 $this->click("xpath=//div[@class='crm-section payment_processor-section']/div[2]//label[text()='Pay later label {$hash}']");
242 $streetAddress = "100 Main Street";
243 $this->type("street_address-1", $streetAddress);
244 $this->type("city-1", "San Francisco");
245 $this->type("postal_code-1", "94117");
246 $this->select("country-1", "value=1228");
247 $this->select("state_province-1", "value=1001");
248
225a8648 249 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
6a488035
TO
250
251 $this->click("_qf_Confirm_next-bottom");
252 $this->waitForPageToLoad($this->getTimeoutMsec());
253
42daf119 254 //login to check contribution
6a488035
TO
255 $this->webtestLogin();
256
257 //Find Contribution
42daf119 258 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
6a488035
TO
259
260 $this->type("sort_name", "$lastName, $firstName");
225a8648
CW
261 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[2]/td[11]/span/a[text()='View']");
262 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[2]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom");
6a488035
TO
263 // View Contribution Record and test for expected values
264 $expected = array(
42daf119
CW
265 'From' => "{$firstName} {$lastName}",
266 'Financial Type' => 'Donation',
267 'Total Amount' => '100.00',
6a488035
TO
268 'Contribution Status' => 'Pending : Pay Later',
269 );
270 $this->webtestVerifyTabularData($expected);
271 }
272}
273