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