Merge pull request #2974 from jitendrapurohit/Contribute_Webtests
[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 // go to contribution tab
161 $this->waitForElementPresent("css=li#tab_contribute a");
162 $this->click("css=li#tab_contribute a");
163 $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
164
165 // verify soft credit details
166 $expected = array(
167 4 => 'Donation',
168 2 => '100.00',
169 6 => 'Pending',
170 1 => "{$firstName} Contributor",
171 );
172 foreach ($expected as $value => $label) {
173 $this->verifyText("xpath=id('Search')/div[2]/table[2]/tbody/tr[2]/td[$value]", preg_quote($label));
174 }
175 }
176
177 function _testOnlineContribution($firstName, $lastName, $email) {
178
179 // We need a payment processor
180 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
181 $processorType = 'Dummy';
182 $pageTitle = substr(sha1(rand()), 0, 7);
183 $rand = 2 * rand(2, 50);
184 $hash = substr(sha1(rand()), 0, 7);
185 $amountSection = TRUE;
186 $payLater = TRUE;
187 $onBehalf = FALSE;
188 $pledges = FALSE;
189 $recurring = FALSE;
190 $memberships = FALSE;
191 $friend = FALSE;
192 $profilePreId = 1;
193 $profilePostId = NULL;
194 $premiums = FALSE;
195 $widget = FALSE;
196 $pcp = FALSE;
197 $memPriceSetId = NULL;
198
199 // create a new online contribution page
200 // create contribution page with randomized title and default params
201 $pageId = $this->webtestAddContributionPage($hash,
202 $rand,
203 $pageTitle,
204 array($processorName => $processorType),
205 $amountSection,
206 $payLater,
207 $onBehalf,
208 $pledges,
209 $recurring,
210 $memberships,
211 $memPriceSetId,
212 $friend,
213 $profilePreId,
214 $profilePostId,
215 $premiums,
216 $widget,
217 $pcp
218 );
219
220 //logout
221 $this->webtestLogout();
222 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
223
224 $this->type("email-5", $email);
225
226 $this->type("first_name", $firstName);
227 $this->type("last_name", $lastName);
228
229 $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input");
230 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 100);
231 $this->click("xpath=//div[@class='crm-section payment_processor-section']/div[2]//label[text()='Pay later label {$hash}']");
232 $streetAddress = "100 Main Street";
233 $this->type("street_address-1", $streetAddress);
234 $this->type("city-1", "San Francisco");
235 $this->type("postal_code-1", "94117");
236 $this->select("country-1", "value=1228");
237 $this->select("state_province-1", "value=1001");
238
239 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
240
241 $this->click("_qf_Confirm_next-bottom");
242 $this->waitForPageToLoad($this->getTimeoutMsec());
243
244 //login to check contribution
245 $this->webtestLogin();
246
247 //Find Contribution
248 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
249
250 $this->type("sort_name", "$lastName, $firstName");
251 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[2]/td[11]/span/a[text()='View']");
252 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[2]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom");
253 // View Contribution Record and test for expected values
254 $expected = array(
255 'From' => "{$firstName} {$lastName}",
256 'Financial Type' => 'Donation',
257 'Total Amount' => '100.00',
258 'Contribution Status' => 'Pending : Pay Later',
259 );
260 $this->webtestVerifyTabularData($expected);
261 }
262 }
263