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