Merge pull request #3268 from eileenmcnaughton/CRM-14626
[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 class WebTest_Contribute_UpdatePendingContributionTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testUpdatePendingContribution() {
35 $this->webtestLogin();
36 $firstName = substr(sha1(rand()), 0, 7);
37 $lastName = 'Contributor';
38 $email = $firstName . "@example.com";
39
40 //Offline Pay Later Contribution
41 $this->_testOfflineContribution($firstName, $lastName, $email);
42
43 //Online Pay Later Contribution
44 $this->_testOnlineContribution($firstName, $lastName, $email);
45 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
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
81 $this->openCiviPage("contribute/add", "reset=1&context=standalone", "_qf_Contribution_upload");
82
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
109 $this->webtestFillAutocomplete("{$softCreditLname}, {$softCreditFname}", 'soft_credit_contact_id_1');
110 $this->type("soft_credit_amount_1", "100");
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
126 //Premium section
127 $this->click("Premium");
128 $this->waitForElementPresent("fulfilled_date");
129 $this->select("product_name[0]", "label=Coffee Mug ( MUG-101 )");
130 $this->select("product_name[1]", "label=Black");
131 $this->webtestFillDate('fulfilled_date');
132
133 // Clicking save.
134 $this->click("_qf_Contribution_upload");
135 $this->waitForPageToLoad($this->getTimeoutMsec());
136
137 // Is status message correct?
138 $this->assertTrue($this->isTextPresent("The contribution record has been saved."), "Status message didn't show up after saving!");
139
140 // verify if Contribution is created
141 $this->waitForElementPresent("xpath=//div[@class='view-content']//table[2]//tbody/tr[1]/td[8]/span/a[text()='View']");
142
143 //click through to the Contribution view screen
144 $this->click("xpath=//div[@class='view-content']//table[2]/tbody/tr[1]/td[8]/span/a[text()='View']");
145 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
146
147 // View Contribution Record and test for expected values
148 $expected = array(
149 'Financial Type' => 'Donation',
150 'Total Amount' => '100.00',
151 'Contribution Status' => 'Pending',
152 'Paid By' => 'Check',
153 'Check Number' => 'check #1041',
154 );
155 $this->webtestVerifyTabularData($expected);
156
157 // go to soft creditor contact view page - this also does the soft credit check
158 $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}')]");
159
160 $this->waitForPageToLoad($this->getTimeoutMsec());
161 // go to contribution tab
162 $this->waitForElementPresent("css=li#tab_contribute a");
163 $this->click("css=li#tab_contribute a");
164 $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
165
166 // verify soft credit details
167 $expected = array(
168 4 => 'Donation',
169 2 => '100.00',
170 6 => 'Pending',
171 1 => "{$firstName} Contributor",
172 );
173 foreach ($expected as $value => $label) {
174 $this->verifyText("xpath=id('Search')/div[2]/table[2]/tbody/tr[2]/td[$value]", preg_quote($label));
175 }
176 }
177
178 function _testOnlineContribution($firstName, $lastName, $email) {
179
180 // We need a payment processor
181 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
182 $processorType = 'Dummy';
183 $pageTitle = substr(sha1(rand()), 0, 7);
184 $rand = 2 * rand(2, 50);
185 $hash = substr(sha1(rand()), 0, 7);
186 $amountSection = TRUE;
187 $payLater = TRUE;
188 $onBehalf = FALSE;
189 $pledges = FALSE;
190 $recurring = FALSE;
191 $memberships = FALSE;
192 $friend = FALSE;
193 $profilePreId = 1;
194 $profilePostId = NULL;
195 $premiums = FALSE;
196 $widget = FALSE;
197 $pcp = FALSE;
198 $memPriceSetId = NULL;
199
200 // create a new online contribution page
201 // create contribution page with randomized title and default params
202 $pageId = $this->webtestAddContributionPage($hash,
203 $rand,
204 $pageTitle,
205 array($processorName => $processorType),
206 $amountSection,
207 $payLater,
208 $onBehalf,
209 $pledges,
210 $recurring,
211 $memberships,
212 $memPriceSetId,
213 $friend,
214 $profilePreId,
215 $profilePostId,
216 $premiums,
217 $widget,
218 $pcp
219 );
220
221 //logout
222 $this->webtestLogout();
223 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
224
225 $this->type("email-5", $email);
226
227 $this->type("first_name", $firstName);
228 $this->type("last_name", $lastName);
229
230 $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input");
231 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 100);
232 $this->click("xpath=//div[@class='crm-section payment_processor-section']/div[2]//label[text()='Pay later label {$hash}']");
233 $streetAddress = "100 Main Street";
234 $this->type("street_address-1", $streetAddress);
235 $this->type("city-1", "San Francisco");
236 $this->type("postal_code-1", "94117");
237 $this->select("country-1", "value=1228");
238 $this->select("state_province-1", "value=1001");
239
240 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
241
242 $this->click("_qf_Confirm_next-bottom");
243 $this->waitForPageToLoad($this->getTimeoutMsec());
244
245 //login to check contribution
246 $this->webtestLogin();
247
248 //Find Contribution
249 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
250
251 $this->type("sort_name", "$lastName, $firstName");
252 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[2]/td[11]/span/a[text()='View']");
253 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[2]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
254 // View Contribution Record and test for expected values
255 $expected = array(
256 'From' => "{$firstName} {$lastName}",
257 'Financial Type' => 'Donation',
258 'Total Amount' => '100.00',
259 'Contribution Status' => 'Pending : Pay Later',
260 );
261 $this->webtestVerifyTabularData($expected);
262 }
263 }
264