Commit | Line | Data |
---|---|---|
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 25 | */ |
6a488035 | 26 | |
6a488035 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Contribute_AddBatchesTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Contribute_AddBatchesTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
00be9182 | 38 | public function testBatchAddContribution() { |
6a488035 TO |
39 | $this->webtestLogin(); |
40 | $itemCount = 5; | |
41 | // create contact | |
42 | $contact = array(); | |
43 | ||
44 | //Open Live Contribution Page | |
071a6d2e | 45 | $this->openCiviPage("batch", "reset=1"); |
6a488035 TO |
46 | $this->click("xpath=//div[@class='crm-submit-buttons']/a"); |
47 | $this->waitForElementPresent("_qf_Batch_next"); | |
48 | $this->type("item_count", $itemCount); | |
49 | $this->type("total", 500); | |
50 | $this->click("_qf_Batch_next"); | |
51 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
e85b1a9c | 52 | $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); |
53 | $softCreditAmount = array(1 => 50, 2 => 60, 3 => 40, 4 => 70, 5 => 35); | |
6a488035 TO |
54 | // Add Contact Details |
55 | $data = array(); | |
09f61009 | 56 | for ($i = 1; $i <= $itemCount; $i++) { |
6a488035 | 57 | $data[$i] = array( |
09f61009 | 58 | 'first_name' => 'Ma' . substr(sha1(rand()), 0, 7), |
59 | 'last_name' => 'An' . substr(sha1(rand()), 0, 7), | |
6a488035 | 60 | 'financial_type' => 'Donation', |
76e86fd8 | 61 | 'amount' => 100, |
e85b1a9c | 62 | 'soft_credit_first_name' => 'Ar' . substr(sha1(rand()), 0, 7), |
63 | 'soft_credit_last_name' => 'Ki' . substr(sha1(rand()), 0, 7), | |
64 | 'soft_credit_amount' => $softCreditAmount[$i], | |
65 | 'soft_credit_type' => $softCreditTypes[$i], | |
76e86fd8 | 66 | |
6a488035 TO |
67 | ); |
68 | $this->_fillData($data[$i], $i, "Contribution"); | |
76e86fd8 CW |
69 | } |
70 | ||
6a488035 TO |
71 | $this->click("_qf_Entry_cancel"); |
72 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
73 | $this->_verifyData($data, "Contribution"); | |
74 | } | |
76e86fd8 | 75 | |
00be9182 | 76 | public function testBatchAddMembership() { |
6a488035 TO |
77 | $this->webtestLogin(); |
78 | $itemCount = 5; | |
e85b1a9c | 79 | $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); |
80 | $softCreditAmount = array(1 => 50, 2 => 60, 3 => 40, 4 => 70, 5 => 35); | |
6a488035 TO |
81 | // create contact |
82 | $contact = array(); | |
09f61009 | 83 | $batchTitle = 'Batch-' . substr(sha1(rand()), 0, 7); |
6a488035 TO |
84 | |
85 | //Open Live Contribution Page | |
071a6d2e | 86 | $this->openCiviPage("batch", "reset=1"); |
6a488035 TO |
87 | $this->click("xpath=//div[@class='crm-submit-buttons']/a"); |
88 | $this->waitForElementPresent("_qf_Batch_next"); | |
89 | $this->click("title"); | |
90 | $this->type("title", $batchTitle); | |
91 | $this->select("type_id", "Membership"); | |
92 | $this->type("item_count", $itemCount); | |
93 | $this->type("total", 500); | |
94 | $this->click("_qf_Batch_next"); | |
95 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
76e86fd8 | 96 | |
6a488035 TO |
97 | // Add Contact Details |
98 | $data = array(); | |
09f61009 | 99 | for ($i = 1; $i <= $itemCount; $i++) { |
6a488035 | 100 | $data[$i] = array( |
09f61009 | 101 | 'first_name' => 'Ma' . substr(sha1(rand()), 0, 7), |
102 | 'last_name' => 'An' . substr(sha1(rand()), 0, 7), | |
141d3170 | 103 | 'membership_type' => 'General', |
76e86fd8 | 104 | 'amount' => 100, |
6a488035 | 105 | 'financial_type' => 'Member Dues', |
e85b1a9c | 106 | 'soft_credit_first_name' => 'Ar' . substr(sha1(rand()), 0, 7), |
107 | 'soft_credit_last_name' => 'Ki' . substr(sha1(rand()), 0, 7), | |
108 | 'soft_credit_amount' => $softCreditAmount[$i], | |
109 | 'soft_credit_type' => $softCreditTypes[$i], | |
6a488035 TO |
110 | ); |
111 | $this->_fillData($data[$i], $i, "Membership"); | |
112 | } | |
113 | $this->click("_qf_Entry_cancel"); | |
76e86fd8 CW |
114 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
115 | ||
6a488035 TO |
116 | $this->_verifyData($data, "Membership"); |
117 | } | |
6a488035 | 118 | |
e3c14a3a | 119 | |
00be9182 | 120 | public function testBatchAddPledge() { |
e3c14a3a | 121 | $this->webtestLogin(); |
122 | ||
123 | // create a new pledge for contact | |
124 | $contact = WebTest_Pledge_StandaloneAddTest::testStandalonePledgeAdd(); | |
125 | ||
126 | $itemCount = 2; | |
127 | $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); | |
128 | // create contact | |
129 | $batchTitle = 'Batch-' . substr(sha1(rand()), 0, 7); | |
130 | ||
131 | //Open Live Contribution Page | |
132 | $this->openCiviPage("batch", "reset=1"); | |
133 | $this->click("xpath=//div[@class='crm-submit-buttons']/a"); | |
134 | $this->waitForElementPresent("_qf_Batch_next"); | |
135 | $this->click("title"); | |
136 | $this->type("title", $batchTitle); | |
3e5213ad | 137 | $this->select("type_id", "Pledge Payment"); |
e3c14a3a | 138 | $this->type("item_count", $itemCount); |
139 | $this->type("total", 200); | |
140 | $this->click("_qf_Batch_next"); | |
141 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
142 | ||
143 | // Add Contact Details | |
144 | $data = array(); | |
145 | for ($i = 1; $i <= $itemCount; $i++) { | |
146 | if ($i == 2) { | |
147 | $data[$i] = array('contact' => $contact, 'amount' => 100); | |
148 | } | |
149 | else { | |
150 | $data[$i] = array( | |
151 | 'first_name' => 'Ma' . substr(sha1(rand()), 0, 7), | |
152 | 'last_name' => 'An' . substr(sha1(rand()), 0, 7), | |
153 | 'amount' => 100, | |
154 | ); | |
155 | } | |
156 | $data[$i] += array( | |
157 | 'membership_type' => 'General', | |
158 | 'financial_type' => 'Member Dues', | |
159 | 'soft_credit_first_name' => 'Ar' . substr(sha1(rand()), 0, 7), | |
160 | 'soft_credit_last_name' => 'Ki' . substr(sha1(rand()), 0, 7), | |
161 | 'soft_credit_amount' => 10, | |
162 | 'soft_credit_type' => $softCreditTypes[$i], | |
163 | ); | |
164 | $this->_fillData($data[$i], $i, "Pledge Payment"); | |
165 | } | |
166 | $this->click("_qf_Entry_cancel"); | |
167 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
168 | ||
169 | $this->_verifyData($data, "Pledge"); | |
170 | } | |
171 | ||
4cbe18b8 EM |
172 | /** |
173 | * @param $data | |
174 | * @param $row | |
175 | * @param $type | |
176 | */ | |
00be9182 | 177 | public function _fillData($data, $row, $type) { |
e3c14a3a | 178 | if (!empty($data['contact'])) { |
179 | $this->select2("s2id_primary_contact_id_{$row}", $data['contact']['email']); | |
180 | } | |
181 | else { | |
182 | $email = $data['first_name'] . '@example.com'; | |
183 | $this->webtestNewDialogContact($data['first_name'], $data['last_name'], $email, 4, "s2id_primary_contact_id_{$row}", $row, 'primary'); | |
184 | } | |
76e86fd8 | 185 | |
e3c14a3a | 186 | if ($type == "Pledge Payment") { |
187 | $this->select("field_{$row}_financial_type", $data['financial_type']); | |
188 | $this->type("field_{$row}_total_amount", $data['amount']); | |
189 | $this->webtestFillDateTime("field_{$row}_receive_date", "+1 week"); | |
190 | $this->type("field_{$row}_contribution_source", substr(sha1(rand()), 0, 10)); | |
191 | $this->select("field_{$row}_payment_instrument", "Check"); | |
192 | $this->type("field_{$row}_check_number", rand()); | |
193 | $this->click("field[{$row}][send_receipt]"); | |
194 | $this->click("field_{$row}_invoice_id"); | |
195 | $this->type("field_{$row}_invoice_id", substr(sha1(rand()), 0, 10)); | |
196 | $softcreditemail = $data['soft_credit_first_name'] . '@example.com'; | |
197 | $this->webtestNewDialogContact($data['soft_credit_first_name'], | |
198 | $data['soft_credit_last_name'], | |
199 | $softcreditemail, 4, | |
200 | "s2id_soft_credit_contact_id_{$row}", | |
201 | $row, | |
202 | 'soft_credit' | |
203 | ); | |
204 | $this->type("soft_credit_amount_{$row}", $data['soft_credit_amount']); | |
205 | $this->select("soft_credit_type_{$row}", $data['soft_credit_type']); | |
206 | if (!empty($data['contact'])) { | |
207 | $pledgeID = CRM_Pledge_BAO_Pledge::getContactPledges($data['contact']['id']); | |
208 | $this->select("open_pledges_{$row}", "value={$pledgeID[0]}"); | |
92915c55 TO |
209 | $this->click("css=span#{$row}.pledge-adjust-option a"); |
210 | sleep(5); | |
e3c14a3a | 211 | $this->select("option_type_{$row}", "value=1"); |
212 | $this->click("css=span#{$row}.pledge-adjust-option a"); | |
213 | $this->type("field_{$row}_total_amount", $data['amount']); | |
214 | } | |
6c6e6187 | 215 | } |
e3c14a3a | 216 | elseif ($type == "Contribution") { |
6a488035 TO |
217 | $this->select("field_{$row}_financial_type", $data['financial_type']); |
218 | $this->type("field_{$row}_total_amount", $data['amount']); | |
219 | $this->webtestFillDateTime("field_{$row}_receive_date", "+1 week"); | |
220 | $this->type("field_{$row}_contribution_source", substr(sha1(rand()), 0, 10)); | |
221 | $this->select("field_{$row}_payment_instrument", "Check"); | |
222 | $this->type("field_{$row}_check_number", rand()); | |
223 | $this->click("field[{$row}][send_receipt]"); | |
224 | $this->click("field_{$row}_invoice_id"); | |
225 | $this->type("field_{$row}_invoice_id", substr(sha1(rand()), 0, 10)); | |
e85b1a9c | 226 | $softcreditemail = $data['soft_credit_first_name'] . '@example.com'; |
227 | $this->webtestNewDialogContact($data['soft_credit_first_name'], | |
228 | $data['soft_credit_last_name'], | |
229 | $softcreditemail, 4, | |
230 | "s2id_soft_credit_contact_id_{$row}", | |
231 | $row, | |
232 | 'soft_credit' | |
233 | ); | |
234 | $this->type("soft_credit_amount_{$row}", $data['soft_credit_amount']); | |
9e1854a1 | 235 | $this->select("soft_credit_type_{$row}", $data['soft_credit_type']); |
76e86fd8 | 236 | |
09f61009 | 237 | } |
238 | elseif ($type == "Membership") { | |
bec97f75 | 239 | $this->select("field[{$row}][membership_type][0]", "value=1"); |
141d3170 | 240 | $this->select("field[{$row}][membership_type][1]", $data['membership_type']); |
6a488035 TO |
241 | $this->webtestFillDate("field_{$row}_join_date", "now"); |
242 | $this->webtestFillDate("field_{$row}_membership_start_date", "now"); | |
243 | $this->webtestFillDate("field_{$row}_membership_end_date", "+1 month"); | |
244 | $this->type("field_{$row}_membership_source", substr(sha1(rand()), 0, 10)); | |
245 | $this->click("field[{$row}][send_receipt]"); | |
76e86fd8 CW |
246 | $this->select("field_{$row}_financial_type", $data['financial_type']); |
247 | ||
6a488035 TO |
248 | $this->webtestFillDateTime("field_{$row}_receive_date", "+1 week"); |
249 | $this->select("field_{$row}_payment_instrument", "Check"); | |
250 | $this->type("field_{$row}_check_number", rand()); | |
251 | $this->select("field_{$row}_contribution_status_id", "Completed"); | |
e85b1a9c | 252 | $softcreditemail = $data['soft_credit_first_name'] . '@example.com'; |
253 | $this->webtestNewDialogContact($data['soft_credit_first_name'], | |
254 | $data['soft_credit_last_name'], | |
255 | $softcreditemail, 4, | |
256 | "s2id_soft_credit_contact_id_{$row}", | |
257 | $row, 'soft_credit' | |
258 | ); | |
259 | $this->type("soft_credit_amount_{$row}", $data['soft_credit_amount']); | |
9e1854a1 | 260 | $this->select("soft_credit_type_{$row}", $data['soft_credit_type']); |
6a488035 TO |
261 | } |
262 | } | |
263 | ||
4cbe18b8 EM |
264 | /** |
265 | * @param $data | |
266 | * @param $type | |
267 | */ | |
00be9182 | 268 | public function _checkResult($data, $type) { |
6a488035 | 269 | if ($type == "Contribution") { |
42daf119 | 270 | $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low"); |
6080c83e | 271 | $this->type("sort_name", "{$data['last_name']} {$data['first_name']}"); |
225a8648 | 272 | $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']"); |
e85b1a9c | 273 | $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE); |
6a488035 | 274 | $expected = array( |
09f61009 | 275 | 'From' => "{$data['first_name']} {$data['last_name']}", |
276 | 'Financial Type' => $data['financial_type'], | |
277 | 'Total Amount' => $data['amount'], | |
6a488035 | 278 | 'Contribution Status' => 'Completed', |
76e86fd8 CW |
279 | ); |
280 | ||
6a488035 | 281 | $this->webtestVerifyTabularData($expected); |
e85b1a9c | 282 | $expectedSoft = array( |
283 | 'Soft Credit To' => "{$data['soft_credit_first_name']} {$data['soft_credit_last_name']}", | |
284 | 'Amount (Soft Credit Type)' => $data['soft_credit_amount'], | |
285 | 'Soft Credit Type' => $data['soft_credit_type'], | |
286 | ); | |
287 | foreach ($expectedSoft as $value) { | |
288 | $this->verifyText("css=table.crm-soft-credit-listing", preg_quote($value)); | |
289 | } | |
6a488035 TO |
290 | } |
291 | elseif ($type == "Membership") { | |
42daf119 | 292 | $this->openCiviPage("member/search", "reset=1", "member_join_date_low"); |
76e86fd8 | 293 | |
6a488035 | 294 | // select contact |
6080c83e | 295 | $this->type("sort_name", "{$data['last_name']} {$data['first_name']}"); |
225a8648 | 296 | $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']"); |
6a488035 TO |
297 | $this->click("xpath=//div[@id='memberSearch']//table/tbody/tr[1]/td[11]/span/a[text()='View']"); |
298 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); | |
299 | $expected = array( | |
300 | 2 => 'General', | |
21dfd5f5 | 301 | 4 => 'New', |
6a488035 TO |
302 | ); |
303 | foreach ($expected as $label => $value) { | |
304 | $this->verifyText("xpath=id('MembershipView')/div[2]/div/table[1]/tbody/tr[$label]/td[2]", preg_quote($value)); | |
305 | } | |
306 | //View Contribution | |
08f17a9f RK |
307 | $this->waitForElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/div[2]/div[2]/table/tbody/tr[1]/td[8]/span/a[1][text()='View']"); |
308 | $this->click("xpath=//form[@id='MembershipView']/div[2]/div/div[2]/div[2]/table/tbody/tr[1]/td[8]/span/a[1][text()='View']"); | |
6a488035 TO |
309 | $this->waitForElementPresent("_qf_ContributionView_cancel-bottom"); |
310 | $expected = array( | |
09f61009 | 311 | 'From' => "{$data['first_name']} {$data['last_name']}", |
312 | 'Financial Type' => $data['financial_type'], | |
313 | 'Total Amount' => $data['amount'], | |
6a488035 | 314 | 'Contribution Status' => 'Completed', |
76e86fd8 CW |
315 | ); |
316 | ||
6a488035 | 317 | $this->webtestVerifyTabularData($expected); |
e85b1a9c | 318 | $expectedSoft = array( |
319 | 'Soft Credit To' => "{$data['soft_credit_first_name']} {$data['soft_credit_last_name']}", | |
320 | 'Amount (Soft Credit Type)' => $data['soft_credit_amount'], | |
9e1854a1 | 321 | 'Soft Credit Type' => $data['soft_credit_type'], |
e85b1a9c | 322 | ); |
323 | foreach ($expectedSoft as $value) { | |
324 | $this->verifyText("css=table.crm-soft-credit-listing", preg_quote($value)); | |
325 | } | |
6a488035 TO |
326 | } |
327 | } | |
76e86fd8 | 328 | |
4cbe18b8 EM |
329 | /** |
330 | * @param $data | |
331 | * @param $type | |
332 | */ | |
00be9182 | 333 | public function _verifyData($data, $type) { |
47aea6bb RK |
334 | $this->waitForElementPresent("xpath=//table[@id='DataTables_Table_0']/tbody//tr/td[7]/span/a[1][text()='Enter records']"); |
335 | $this->click("xpath=//table[@id='DataTables_Table_0']/tbody//tr/td[7]/span/a[1][text()='Enter records']"); | |
336 | $this->waitForElementPresent('_qf_Entry_upload'); | |
6a488035 TO |
337 | $this->click("_qf_Entry_upload"); |
338 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
339 | foreach ($data as $value) { | |
340 | $this->_checkResult($value, $type); | |
341 | } | |
342 | } | |
96025800 | 343 | |
6a488035 | 344 | } |