Update Copywrite year to be 2019
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / UpdatePendingContributionTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
2fe49090 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 +--------------------------------------------------------------------+
d25dd0ee 25 */
6a488035 26
6a488035 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Contribute_UpdatePendingContributionTest
31 */
6a488035
TO
32class WebTest_Contribute_UpdatePendingContributionTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
29cb4724 38 public function testPayNowLink() {
39 $this->webtestLogin();
40
41 //Offline Pay Later Contribution
42 $contact = $this->_testOfflineContribution();
43 $this->openCiviPage("contact/view", "reset=1&cid={$contact['id']}", "css=li#tab_contribute a");
44 $this->click("css=li#tab_contribute a");
45 $this->waitForElementPresent("xpath=//table[@class='selector row-highlight']/tbody//tr/td[8]/span/a");
46
47 $this->clickPopupLink("xpath=//table[@class='selector row-highlight']/tbody//tr/td[8]/span/a[@title='Edit Contribution']");
48 $this->waitForElementPresent('financial_type_id');
49
c6218cbd 50 $this->clickPopupLink("xpath=//a[contains(text(), 'Pay with Credit Card')]");
51 $this->assertElementContainsText("xpath=//span[@class='ui-dialog-title']", "Pay with Credit Card");
29cb4724 52 $this->assertElementNotPresent("xpath=//select[@id='currency']");
53 $this->assertNotEditable('total_amount');
54 $this->assertElementNotPresent("xpath=//select[@id='contribution_status_id']");
55
56 $this->webtestAddCreditCardDetails();
57 $this->webtestAddBillingDetails();
58
c6218cbd 59 //return to the edit contrib form
60 $this->clickAjaxLink('_qf_Contribution_upload-bottom');
61 $this->waitForText('crm-notification-container', "The contribution record has been saved.");
62
63 //save the edit form
29cb4724 64 $this->clickAjaxLink('_qf_Contribution_upload-bottom');
65 $this->waitForText('crm-notification-container', "The contribution record has been saved.");
66
67 $this->clickPopupLink("xpath=//table[@class='selector row-highlight']/tbody//tr/td[8]/span/a[@title='View Contribution']");
68
69 // View Contribution Record and test for expected values
70 $expected = array(
71 'From' => $contact['display_name'],
72 'Financial Type' => 'Donation',
73 'Total Amount' => '$ 100.00',
74 'Payment Method' => 'Credit Card (Test Processor)',
75 'Contribution Status' => 'Completed',
76 'Received Into' => 'Payment Processor Account',
77 'Net Amount' => '$ 98.50',
78 'Fee Amount' => '$ 1.50',
79 );
80 $this->webtestVerifyTabularData($expected);
81 }
82
00be9182 83 public function testUpdatePendingContribution() {
6a488035 84 $this->webtestLogin();
6a488035
TO
85
86 //Offline Pay Later Contribution
80f3b91d 87 $contact = $this->_testOfflineContribution();
6a488035
TO
88
89 //Online Pay Later Contribution
80f3b91d 90 $this->_testOnlineContribution($contact);
42daf119 91 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
fb34b4f5 92 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/../a[1]");
80f3b91d 93 $this->type("sort_name", $contact['sort_name']);
6a488035 94 $this->click("_qf_Search_refresh");
6a488035 95 $this->waitForPageToLoad($this->getTimeoutMsec());
fb34b4f5 96
6a488035 97 $this->click('radio_ts', 'ts_all');
2e27db7c 98 $contriIDOff = explode('&', $this->getAttribute("xpath=//div[@id='contributionSearch']/table/tbody/tr[1]//td/span/a@href"));
99 $contriIDOn = explode('&', $this->getAttribute("xpath=//div[@id='contributionSearch']/table/tbody/tr[1]//td/span/a@href"));
6a488035
TO
100 if (!empty($contriIDOff)) {
101 $contriIDOff = substr($contriIDOff[1], (strrpos($contriIDOff[1], '=') + 1));
102 }
103 if (!empty($contriIDOn)) {
104 $contriIDOn = substr($contriIDOn[1], (strrpos($contriIDOn[1], '=') + 1));
105 }
fb34b4f5 106 $this->select('task', "label=Update pending contribution status");
6a488035
TO
107 $this->click("_qf_Search_next_action");
108 $this->waitForPageToLoad($this->getTimeoutMsec());
109 $this->select('contribution_status_id', 'label=Completed');
110 $this->type("trxn_id_{$contriIDOff}", substr(sha1(rand()), 0, 5));
111 $this->type("trxn_id_{$contriIDOn}", substr(sha1(rand()), 0, 5));
112 $this->click('_qf_Status_next');
113 $this->waitForElementPresent("_qf_Result_done");
114 $this->click("_qf_Result_done");
115 $this->waitForPageToLoad($this->getTimeoutMsec());
116 $status = 'Completed';
2e27db7c 117 $this->verifyText("xpath=id('contributionSearch')/table[1]/tbody/tr[1]//td[@class='crm-contribution-status']", preg_quote($status));
118 $this->verifyText("xpath=id('contributionSearch')/table[1]/tbody/tr[2]//td[@class='crm-contribution-status']", preg_quote($status));
6a488035
TO
119 }
120
4cbe18b8 121 /**
a6c01b45 122 * @return array
16b10e64 123 * Array of contact details
4cbe18b8 124 */
00be9182 125 public function _testOfflineContribution() {
6a488035
TO
126 // Create a contact to be used as soft creditor
127 $softCreditFname = substr(sha1(rand()), 0, 7);
128 $softCreditLname = substr(sha1(rand()), 0, 7);
129 $this->webtestAddContact($softCreditFname, $softCreditLname, FALSE);
130
42daf119 131 $this->openCiviPage("contribute/add", "reset=1&context=standalone", "_qf_Contribution_upload");
6a488035 132
6a488035 133 // create new contact using dialog
80f3b91d 134 $contact = $this->createDialogContact();
6a488035
TO
135
136 // select financial type
481a74f4 137 $this->select("financial_type_id", "value=1");
6a488035
TO
138
139 // fill in Received Date
140 $this->webtestFillDate('receive_date');
141
142 //Contribution status
143 $this->select("contribution_status_id", "label=Pending");
144
145 // source
146 $this->type("source", "Mailer 1");
147
148 // total amount
149 $this->type("total_amount", "100");
150
151 // select payment instrument type = Check and enter chk number
152 $this->select("payment_instrument_id", "value=4");
153 $this->waitForElementPresent("check_number");
154 $this->type("check_number", "check #1041");
155
156 $this->type("trxn_id", "P20901X1" . rand(100, 10000));
157
158 // soft credit
0ecb5006 159 $this->webtestFillAutocomplete("{$softCreditLname}, {$softCreditFname}", 'soft_credit_contact_id_1');
160 $this->type("soft_credit_amount_1", "100");
6a488035
TO
161 //Custom Data
162 //$this->click('CIVICRM_QFID_3_6');
163
164 //Additional Detail section
165 $this->click("AdditionalDetail");
166 $this->waitForElementPresent("thankyou_date");
167
168 $this->type("note", "This is a test note.");
169 $this->type("non_deductible_amount", "10");
6a488035
TO
170 $this->type("invoice_id", time());
171 $this->webtestFillDate('thankyou_date');
172
6a488035
TO
173 //Premium section
174 $this->click("Premium");
175 $this->waitForElementPresent("fulfilled_date");
176 $this->select("product_name[0]", "label=Coffee Mug ( MUG-101 )");
177 $this->select("product_name[1]", "label=Black");
178 $this->webtestFillDate('fulfilled_date');
179
180 // Clicking save.
181 $this->click("_qf_Contribution_upload");
182 $this->waitForPageToLoad($this->getTimeoutMsec());
183
184 // Is status message correct?
185 $this->assertTrue($this->isTextPresent("The contribution record has been saved."), "Status message didn't show up after saving!");
186
187 // verify if Contribution is created
0ecb5006 188 $this->waitForElementPresent("xpath=//div[@class='view-content']//table[2]//tbody/tr[1]/td[8]/span/a[text()='View']");
6a488035
TO
189
190 //click through to the Contribution view screen
0ecb5006 191 $this->click("xpath=//div[@class='view-content']//table[2]/tbody/tr[1]/td[8]/span/a[text()='View']");
6a488035
TO
192 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
193
194 // View Contribution Record and test for expected values
195 $expected = array(
196 'Financial Type' => 'Donation',
29cb4724 197 'Total Amount' => '$ 100.00',
6a488035 198 'Contribution Status' => 'Pending',
4db803dd 199 'Payment Method' => 'Check',
6a488035 200 'Check Number' => 'check #1041',
6a488035
TO
201 );
202 $this->webtestVerifyTabularData($expected);
203
ce892f61
PJ
204 // go to soft creditor contact view page - this also does the soft credit check
205 $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 206
c900afb1 207 $this->waitForPageToLoad($this->getTimeoutMsec());
6a488035
TO
208 // go to contribution tab
209 $this->waitForElementPresent("css=li#tab_contribute a");
210 $this->click("css=li#tab_contribute a");
211 $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
212
213 // verify soft credit details
214 $expected = array(
0ecb5006 215 4 => 'Donation',
29cb4724 216 2 => '$ 100.00',
0ecb5006 217 6 => 'Pending',
80f3b91d 218 1 => $contact['display_name'],
6a488035
TO
219 );
220 foreach ($expected as $value => $label) {
221 $this->verifyText("xpath=id('Search')/div[2]/table[2]/tbody/tr[2]/td[$value]", preg_quote($label));
222 }
80f3b91d 223 return $contact;
6a488035
TO
224 }
225
4cbe18b8 226 /**
80f3b91d 227 * @param array $contact
4cbe18b8 228 */
00be9182 229 public function _testOnlineContribution($contact) {
6a488035 230
c3ad8633
CW
231 // Use default payment processor
232 $processorName = 'Test Processor';
6a488035 233 $processorType = 'Dummy';
42daf119
CW
234 $pageTitle = substr(sha1(rand()), 0, 7);
235 $rand = 2 * rand(2, 50);
236 $hash = substr(sha1(rand()), 0, 7);
6a488035 237 $amountSection = TRUE;
42daf119
CW
238 $payLater = TRUE;
239 $onBehalf = FALSE;
240 $pledges = FALSE;
241 $recurring = FALSE;
242 $memberships = FALSE;
243 $friend = FALSE;
244 $profilePreId = 1;
6a488035 245 $profilePostId = NULL;
42daf119
CW
246 $premiums = FALSE;
247 $widget = FALSE;
248 $pcp = FALSE;
6a488035
TO
249 $memPriceSetId = NULL;
250
251 // create a new online contribution page
252 // create contribution page with randomized title and default params
253 $pageId = $this->webtestAddContributionPage($hash,
254 $rand,
255 $pageTitle,
256 array($processorName => $processorType),
257 $amountSection,
258 $payLater,
259 $onBehalf,
260 $pledges,
261 $recurring,
262 $memberships,
263 $memPriceSetId,
264 $friend,
265 $profilePreId,
266 $profilePostId,
267 $premiums,
268 $widget,
269 $pcp
270 );
271
272 //logout
42daf119 273 $this->webtestLogout();
f1224701 274 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom");
6a488035 275
80f3b91d 276 $this->type("email-5", $contact['email']);
6a488035 277
80f3b91d
CW
278 $this->type("first_name", $contact['first_name']);
279 $this->type("last_name", $contact['last_name']);
76e86fd8 280
6a488035
TO
281 $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input");
282 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 100);
2e27db7c 283 $this->click("xpath=//label[text()='Pay later label {$hash}']");
284 $this->waitForAjaxContent();
6a488035
TO
285 $streetAddress = "100 Main Street";
286 $this->type("street_address-1", $streetAddress);
287 $this->type("city-1", "San Francisco");
288 $this->type("postal_code-1", "94117");
289 $this->select("country-1", "value=1228");
290 $this->select("state_province-1", "value=1001");
291
225a8648 292 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
6a488035
TO
293
294 $this->click("_qf_Confirm_next-bottom");
295 $this->waitForPageToLoad($this->getTimeoutMsec());
296
42daf119 297 //login to check contribution
6a488035
TO
298 $this->webtestLogin();
299
300 //Find Contribution
42daf119 301 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
f1224701 302 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
80f3b91d 303 $this->type("sort_name", $contact['sort_name']);
2e27db7c 304 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table/tbody/tr[1]//td/span/a[text()='View']", FALSE);
305 $this->click("xpath=//div[@id='contributionSearch']//table/tbody/tr[1]//td/span/a[text()='View']");
6a488035
TO
306 // View Contribution Record and test for expected values
307 $expected = array(
80f3b91d 308 'From' => $contact['display_name'],
42daf119
CW
309 'Financial Type' => 'Donation',
310 'Total Amount' => '100.00',
6a488035
TO
311 'Contribution Status' => 'Pending : Pay Later',
312 );
313 $this->webtestVerifyTabularData($expected);
314 }
96025800 315
6a488035 316}