Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
fa938177 | 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
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 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Contribute_UpdatePendingContributionTest | |
31 | */ | |
6a488035 TO |
32 | class 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"); |
fb34b4f5 | 47 | $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/../a[1]"); |
80f3b91d | 48 | $this->type("sort_name", $contact['sort_name']); |
6a488035 | 49 | $this->click("_qf_Search_refresh"); |
6a488035 | 50 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
fb34b4f5 | 51 | |
6a488035 | 52 | $this->click('radio_ts', 'ts_all'); |
2e27db7c | 53 | $contriIDOff = explode('&', $this->getAttribute("xpath=//div[@id='contributionSearch']/table/tbody/tr[1]//td/span/a@href")); |
54 | $contriIDOn = explode('&', $this->getAttribute("xpath=//div[@id='contributionSearch']/table/tbody/tr[1]//td/span/a@href")); | |
6a488035 TO |
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 | } | |
fb34b4f5 | 61 | $this->select('task', "label=Update pending contribution status"); |
6a488035 TO |
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'; | |
2e27db7c | 72 | $this->verifyText("xpath=id('contributionSearch')/table[1]/tbody/tr[1]//td[@class='crm-contribution-status']", preg_quote($status)); |
73 | $this->verifyText("xpath=id('contributionSearch')/table[1]/tbody/tr[2]//td[@class='crm-contribution-status']", preg_quote($status)); | |
6a488035 TO |
74 | } |
75 | ||
4cbe18b8 | 76 | /** |
a6c01b45 | 77 | * @return array |
16b10e64 | 78 | * Array of contact details |
4cbe18b8 | 79 | */ |
00be9182 | 80 | public function _testOfflineContribution() { |
6a488035 TO |
81 | // Create a contact to be used as soft creditor |
82 | $softCreditFname = substr(sha1(rand()), 0, 7); | |
83 | $softCreditLname = substr(sha1(rand()), 0, 7); | |
84 | $this->webtestAddContact($softCreditFname, $softCreditLname, FALSE); | |
85 | ||
42daf119 | 86 | $this->openCiviPage("contribute/add", "reset=1&context=standalone", "_qf_Contribution_upload"); |
6a488035 | 87 | |
6a488035 | 88 | // create new contact using dialog |
80f3b91d | 89 | $contact = $this->createDialogContact(); |
6a488035 TO |
90 | |
91 | // select financial type | |
481a74f4 | 92 | $this->select("financial_type_id", "value=1"); |
6a488035 TO |
93 | |
94 | // fill in Received Date | |
95 | $this->webtestFillDate('receive_date'); | |
96 | ||
97 | //Contribution status | |
98 | $this->select("contribution_status_id", "label=Pending"); | |
99 | ||
100 | // source | |
101 | $this->type("source", "Mailer 1"); | |
102 | ||
103 | // total amount | |
104 | $this->type("total_amount", "100"); | |
105 | ||
106 | // select payment instrument type = Check and enter chk number | |
107 | $this->select("payment_instrument_id", "value=4"); | |
108 | $this->waitForElementPresent("check_number"); | |
109 | $this->type("check_number", "check #1041"); | |
110 | ||
111 | $this->type("trxn_id", "P20901X1" . rand(100, 10000)); | |
112 | ||
113 | // soft credit | |
0ecb5006 | 114 | $this->webtestFillAutocomplete("{$softCreditLname}, {$softCreditFname}", 'soft_credit_contact_id_1'); |
115 | $this->type("soft_credit_amount_1", "100"); | |
6a488035 TO |
116 | //Custom Data |
117 | //$this->click('CIVICRM_QFID_3_6'); | |
118 | ||
119 | //Additional Detail section | |
120 | $this->click("AdditionalDetail"); | |
121 | $this->waitForElementPresent("thankyou_date"); | |
122 | ||
123 | $this->type("note", "This is a test note."); | |
124 | $this->type("non_deductible_amount", "10"); | |
125 | $this->type("fee_amount", "0"); | |
126 | $this->type("net_amount", "0"); | |
127 | $this->type("invoice_id", time()); | |
128 | $this->webtestFillDate('thankyou_date'); | |
129 | ||
6a488035 TO |
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 | |
0ecb5006 | 145 | $this->waitForElementPresent("xpath=//div[@class='view-content']//table[2]//tbody/tr[1]/td[8]/span/a[text()='View']"); |
6a488035 TO |
146 | |
147 | //click through to the Contribution view screen | |
0ecb5006 | 148 | $this->click("xpath=//div[@class='view-content']//table[2]/tbody/tr[1]/td[8]/span/a[text()='View']"); |
6a488035 TO |
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', | |
4db803dd | 156 | 'Payment Method' => 'Check', |
6a488035 | 157 | 'Check Number' => 'check #1041', |
6a488035 TO |
158 | ); |
159 | $this->webtestVerifyTabularData($expected); | |
160 | ||
ce892f61 PJ |
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}')]"); | |
6a488035 | 163 | |
c900afb1 | 164 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
6a488035 TO |
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( | |
0ecb5006 | 172 | 4 => 'Donation', |
6a488035 | 173 | 2 => '100.00', |
0ecb5006 | 174 | 6 => 'Pending', |
80f3b91d | 175 | 1 => $contact['display_name'], |
6a488035 TO |
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 | } | |
80f3b91d | 180 | return $contact; |
6a488035 TO |
181 | } |
182 | ||
4cbe18b8 | 183 | /** |
80f3b91d | 184 | * @param array $contact |
4cbe18b8 | 185 | */ |
00be9182 | 186 | public function _testOnlineContribution($contact) { |
6a488035 | 187 | |
c3ad8633 CW |
188 | // Use default payment processor |
189 | $processorName = 'Test Processor'; | |
6a488035 | 190 | $processorType = 'Dummy'; |
42daf119 CW |
191 | $pageTitle = substr(sha1(rand()), 0, 7); |
192 | $rand = 2 * rand(2, 50); | |
193 | $hash = substr(sha1(rand()), 0, 7); | |
6a488035 | 194 | $amountSection = TRUE; |
42daf119 CW |
195 | $payLater = TRUE; |
196 | $onBehalf = FALSE; | |
197 | $pledges = FALSE; | |
198 | $recurring = FALSE; | |
199 | $memberships = FALSE; | |
200 | $friend = FALSE; | |
201 | $profilePreId = 1; | |
6a488035 | 202 | $profilePostId = NULL; |
42daf119 CW |
203 | $premiums = FALSE; |
204 | $widget = FALSE; | |
205 | $pcp = FALSE; | |
6a488035 TO |
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 | |
42daf119 | 230 | $this->webtestLogout(); |
f1224701 | 231 | $this->openCiviPage("contribute/transact", "reset=1&id=$pageId&action=preview", "_qf_Main_upload-bottom"); |
6a488035 | 232 | |
80f3b91d | 233 | $this->type("email-5", $contact['email']); |
6a488035 | 234 | |
80f3b91d CW |
235 | $this->type("first_name", $contact['first_name']); |
236 | $this->type("last_name", $contact['last_name']); | |
76e86fd8 | 237 | |
6a488035 TO |
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); | |
2e27db7c | 240 | $this->click("xpath=//label[text()='Pay later label {$hash}']"); |
241 | $this->waitForAjaxContent(); | |
6a488035 TO |
242 | $streetAddress = "100 Main Street"; |
243 | $this->type("street_address-1", $streetAddress); | |
244 | $this->type("city-1", "San Francisco"); | |
245 | $this->type("postal_code-1", "94117"); | |
246 | $this->select("country-1", "value=1228"); | |
247 | $this->select("state_province-1", "value=1001"); | |
248 | ||
225a8648 | 249 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom"); |
6a488035 TO |
250 | |
251 | $this->click("_qf_Confirm_next-bottom"); | |
252 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
253 | ||
42daf119 | 254 | //login to check contribution |
6a488035 TO |
255 | $this->webtestLogin(); |
256 | ||
257 | //Find Contribution | |
42daf119 | 258 | $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low"); |
f1224701 | 259 | $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]"); |
80f3b91d | 260 | $this->type("sort_name", $contact['sort_name']); |
2e27db7c | 261 | $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table/tbody/tr[1]//td/span/a[text()='View']", FALSE); |
262 | $this->click("xpath=//div[@id='contributionSearch']//table/tbody/tr[1]//td/span/a[text()='View']"); | |
6a488035 TO |
263 | // View Contribution Record and test for expected values |
264 | $expected = array( | |
80f3b91d | 265 | 'From' => $contact['display_name'], |
42daf119 CW |
266 | 'Financial Type' => 'Donation', |
267 | 'Total Amount' => '100.00', | |
6a488035 TO |
268 | 'Contribution Status' => 'Pending : Pay Later', |
269 | ); | |
270 | $this->webtestVerifyTabularData($expected); | |
271 | } | |
96025800 | 272 | |
6a488035 | 273 | } |