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_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 | 114 | |
6a488035 TO |
115 | $this->_verifyData($data, "Membership"); |
116 | } | |
6a488035 | 117 | |
e3c14a3a | 118 | |
00be9182 | 119 | public function testBatchAddPledge() { |
e3c14a3a | 120 | $this->webtestLogin(); |
121 | ||
122 | // create a new pledge for contact | |
7051f2e5 | 123 | $contact = $this->webtestStandalonePledgeAdd(); |
e3c14a3a | 124 | |
125 | $itemCount = 2; | |
126 | $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); | |
127 | // create contact | |
128 | $batchTitle = 'Batch-' . substr(sha1(rand()), 0, 7); | |
129 | ||
130 | //Open Live Contribution Page | |
131 | $this->openCiviPage("batch", "reset=1"); | |
132 | $this->click("xpath=//div[@class='crm-submit-buttons']/a"); | |
133 | $this->waitForElementPresent("_qf_Batch_next"); | |
134 | $this->click("title"); | |
135 | $this->type("title", $batchTitle); | |
3e5213ad | 136 | $this->select("type_id", "Pledge Payment"); |
e3c14a3a | 137 | $this->type("item_count", $itemCount); |
138 | $this->type("total", 200); | |
139 | $this->click("_qf_Batch_next"); | |
140 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
141 | ||
142 | // Add Contact Details | |
143 | $data = array(); | |
144 | for ($i = 1; $i <= $itemCount; $i++) { | |
145 | if ($i == 2) { | |
146 | $data[$i] = array('contact' => $contact, 'amount' => 100); | |
147 | } | |
148 | else { | |
149 | $data[$i] = array( | |
150 | 'first_name' => 'Ma' . substr(sha1(rand()), 0, 7), | |
151 | 'last_name' => 'An' . substr(sha1(rand()), 0, 7), | |
152 | 'amount' => 100, | |
153 | ); | |
154 | } | |
155 | $data[$i] += array( | |
156 | 'membership_type' => 'General', | |
157 | 'financial_type' => 'Member Dues', | |
158 | 'soft_credit_first_name' => 'Ar' . substr(sha1(rand()), 0, 7), | |
159 | 'soft_credit_last_name' => 'Ki' . substr(sha1(rand()), 0, 7), | |
160 | 'soft_credit_amount' => 10, | |
161 | 'soft_credit_type' => $softCreditTypes[$i], | |
162 | ); | |
163 | $this->_fillData($data[$i], $i, "Pledge Payment"); | |
164 | } | |
165 | $this->click("_qf_Entry_cancel"); | |
166 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
167 | ||
168 | $this->_verifyData($data, "Pledge"); | |
169 | } | |
170 | ||
4cbe18b8 EM |
171 | /** |
172 | * @param $data | |
173 | * @param $row | |
174 | * @param $type | |
175 | */ | |
00be9182 | 176 | public function _fillData($data, $row, $type) { |
e3c14a3a | 177 | if (!empty($data['contact'])) { |
178 | $this->select2("s2id_primary_contact_id_{$row}", $data['contact']['email']); | |
179 | } | |
180 | else { | |
181 | $email = $data['first_name'] . '@example.com'; | |
182 | $this->webtestNewDialogContact($data['first_name'], $data['last_name'], $email, 4, "s2id_primary_contact_id_{$row}", $row, 'primary'); | |
183 | } | |
76e86fd8 | 184 | |
e3c14a3a | 185 | if ($type == "Pledge Payment") { |
186 | $this->select("field_{$row}_financial_type", $data['financial_type']); | |
187 | $this->type("field_{$row}_total_amount", $data['amount']); | |
188 | $this->webtestFillDateTime("field_{$row}_receive_date", "+1 week"); | |
189 | $this->type("field_{$row}_contribution_source", substr(sha1(rand()), 0, 10)); | |
190 | $this->select("field_{$row}_payment_instrument", "Check"); | |
191 | $this->type("field_{$row}_check_number", rand()); | |
192 | $this->click("field[{$row}][send_receipt]"); | |
193 | $this->click("field_{$row}_invoice_id"); | |
194 | $this->type("field_{$row}_invoice_id", substr(sha1(rand()), 0, 10)); | |
195 | $softcreditemail = $data['soft_credit_first_name'] . '@example.com'; | |
196 | $this->webtestNewDialogContact($data['soft_credit_first_name'], | |
197 | $data['soft_credit_last_name'], | |
198 | $softcreditemail, 4, | |
199 | "s2id_soft_credit_contact_id_{$row}", | |
200 | $row, | |
201 | 'soft_credit' | |
202 | ); | |
203 | $this->type("soft_credit_amount_{$row}", $data['soft_credit_amount']); | |
204 | $this->select("soft_credit_type_{$row}", $data['soft_credit_type']); | |
205 | if (!empty($data['contact'])) { | |
206 | $pledgeID = CRM_Pledge_BAO_Pledge::getContactPledges($data['contact']['id']); | |
207 | $this->select("open_pledges_{$row}", "value={$pledgeID[0]}"); | |
92915c55 TO |
208 | $this->click("css=span#{$row}.pledge-adjust-option a"); |
209 | sleep(5); | |
e3c14a3a | 210 | $this->select("option_type_{$row}", "value=1"); |
211 | $this->click("css=span#{$row}.pledge-adjust-option a"); | |
212 | $this->type("field_{$row}_total_amount", $data['amount']); | |
213 | } | |
6c6e6187 | 214 | } |
e3c14a3a | 215 | elseif ($type == "Contribution") { |
6a488035 TO |
216 | $this->select("field_{$row}_financial_type", $data['financial_type']); |
217 | $this->type("field_{$row}_total_amount", $data['amount']); | |
218 | $this->webtestFillDateTime("field_{$row}_receive_date", "+1 week"); | |
219 | $this->type("field_{$row}_contribution_source", substr(sha1(rand()), 0, 10)); | |
220 | $this->select("field_{$row}_payment_instrument", "Check"); | |
221 | $this->type("field_{$row}_check_number", rand()); | |
222 | $this->click("field[{$row}][send_receipt]"); | |
223 | $this->click("field_{$row}_invoice_id"); | |
224 | $this->type("field_{$row}_invoice_id", substr(sha1(rand()), 0, 10)); | |
e85b1a9c | 225 | $softcreditemail = $data['soft_credit_first_name'] . '@example.com'; |
226 | $this->webtestNewDialogContact($data['soft_credit_first_name'], | |
227 | $data['soft_credit_last_name'], | |
228 | $softcreditemail, 4, | |
229 | "s2id_soft_credit_contact_id_{$row}", | |
230 | $row, | |
231 | 'soft_credit' | |
232 | ); | |
233 | $this->type("soft_credit_amount_{$row}", $data['soft_credit_amount']); | |
9e1854a1 | 234 | $this->select("soft_credit_type_{$row}", $data['soft_credit_type']); |
76e86fd8 | 235 | |
09f61009 | 236 | } |
237 | elseif ($type == "Membership") { | |
bec97f75 | 238 | $this->select("field[{$row}][membership_type][0]", "value=1"); |
141d3170 | 239 | $this->select("field[{$row}][membership_type][1]", $data['membership_type']); |
6a488035 TO |
240 | $this->webtestFillDate("field_{$row}_join_date", "now"); |
241 | $this->webtestFillDate("field_{$row}_membership_start_date", "now"); | |
242 | $this->webtestFillDate("field_{$row}_membership_end_date", "+1 month"); | |
243 | $this->type("field_{$row}_membership_source", substr(sha1(rand()), 0, 10)); | |
244 | $this->click("field[{$row}][send_receipt]"); | |
76e86fd8 CW |
245 | $this->select("field_{$row}_financial_type", $data['financial_type']); |
246 | ||
6a488035 TO |
247 | $this->webtestFillDateTime("field_{$row}_receive_date", "+1 week"); |
248 | $this->select("field_{$row}_payment_instrument", "Check"); | |
249 | $this->type("field_{$row}_check_number", rand()); | |
250 | $this->select("field_{$row}_contribution_status_id", "Completed"); | |
e85b1a9c | 251 | $softcreditemail = $data['soft_credit_first_name'] . '@example.com'; |
252 | $this->webtestNewDialogContact($data['soft_credit_first_name'], | |
253 | $data['soft_credit_last_name'], | |
254 | $softcreditemail, 4, | |
255 | "s2id_soft_credit_contact_id_{$row}", | |
256 | $row, 'soft_credit' | |
257 | ); | |
258 | $this->type("soft_credit_amount_{$row}", $data['soft_credit_amount']); | |
9e1854a1 | 259 | $this->select("soft_credit_type_{$row}", $data['soft_credit_type']); |
6a488035 TO |
260 | } |
261 | } | |
262 | ||
4cbe18b8 EM |
263 | /** |
264 | * @param $data | |
265 | * @param $type | |
266 | */ | |
00be9182 | 267 | public function _checkResult($data, $type) { |
6a488035 | 268 | if ($type == "Contribution") { |
42daf119 | 269 | $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low"); |
6080c83e | 270 | $this->type("sort_name", "{$data['last_name']} {$data['first_name']}"); |
deeea38d WA |
271 | $this->clickLink("_qf_Search_refresh", "xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", FALSE); |
272 | $this->clickLink("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE); | |
6a488035 | 273 | $expected = array( |
09f61009 | 274 | 'From' => "{$data['first_name']} {$data['last_name']}", |
275 | 'Financial Type' => $data['financial_type'], | |
276 | 'Total Amount' => $data['amount'], | |
6a488035 | 277 | 'Contribution Status' => 'Completed', |
76e86fd8 CW |
278 | ); |
279 | ||
6a488035 | 280 | $this->webtestVerifyTabularData($expected); |
e85b1a9c | 281 | $expectedSoft = array( |
282 | 'Soft Credit To' => "{$data['soft_credit_first_name']} {$data['soft_credit_last_name']}", | |
a1fddd2c | 283 | 'Amount (Soft Credit Type)' => "{$data['soft_credit_amount']}", |
e85b1a9c | 284 | 'Soft Credit Type' => $data['soft_credit_type'], |
285 | ); | |
286 | foreach ($expectedSoft as $value) { | |
e684c1ae | 287 | $this->assertElementContainsText("css=table.crm-soft-credit-listing", $value); |
e85b1a9c | 288 | } |
6a488035 TO |
289 | } |
290 | elseif ($type == "Membership") { | |
42daf119 | 291 | $this->openCiviPage("member/search", "reset=1", "member_join_date_low"); |
76e86fd8 | 292 | |
6a488035 | 293 | // select contact |
6080c83e | 294 | $this->type("sort_name", "{$data['last_name']} {$data['first_name']}"); |
225a8648 | 295 | $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']"); |
6a488035 TO |
296 | $this->click("xpath=//div[@id='memberSearch']//table/tbody/tr[1]/td[11]/span/a[text()='View']"); |
297 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); | |
298 | $expected = array( | |
299 | 2 => 'General', | |
21dfd5f5 | 300 | 4 => 'New', |
6a488035 TO |
301 | ); |
302 | foreach ($expected as $label => $value) { | |
e684c1ae | 303 | $this->assertElementContainsText("xpath=id('MembershipView')/div[2]/div/table[1]/tbody/tr[$label]/td[2]", $value); |
6a488035 TO |
304 | } |
305 | //View Contribution | |
08f17a9f RK |
306 | $this->waitForElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/div[2]/div[2]/table/tbody/tr[1]/td[8]/span/a[1][text()='View']"); |
307 | $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 |
308 | $this->waitForElementPresent("_qf_ContributionView_cancel-bottom"); |
309 | $expected = array( | |
09f61009 | 310 | 'From' => "{$data['first_name']} {$data['last_name']}", |
311 | 'Financial Type' => $data['financial_type'], | |
312 | 'Total Amount' => $data['amount'], | |
6a488035 | 313 | 'Contribution Status' => 'Completed', |
76e86fd8 CW |
314 | ); |
315 | ||
6a488035 | 316 | $this->webtestVerifyTabularData($expected); |
e85b1a9c | 317 | $expectedSoft = array( |
318 | 'Soft Credit To' => "{$data['soft_credit_first_name']} {$data['soft_credit_last_name']}", | |
a1fddd2c | 319 | 'Amount (Soft Credit Type)' => "{$data['soft_credit_amount']}", |
9e1854a1 | 320 | 'Soft Credit Type' => $data['soft_credit_type'], |
e85b1a9c | 321 | ); |
322 | foreach ($expectedSoft as $value) { | |
e684c1ae | 323 | $this->assertElementContainsText("css=table.crm-soft-credit-listing", $value); |
e85b1a9c | 324 | } |
6a488035 TO |
325 | } |
326 | } | |
76e86fd8 | 327 | |
4cbe18b8 EM |
328 | /** |
329 | * @param $data | |
330 | * @param $type | |
331 | */ | |
00be9182 | 332 | public function _verifyData($data, $type) { |
acaa2fb9 WA |
333 | $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody//tr//td/span/a[1][contains(text(),'Enter records')]"); |
334 | $this->click("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody//tr//td/span/a[1]"); | |
47aea6bb | 335 | $this->waitForElementPresent('_qf_Entry_upload'); |
6a488035 TO |
336 | $this->click("_qf_Entry_upload"); |
337 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
338 | foreach ($data as $value) { | |
339 | $this->_checkResult($value, $type); | |
340 | } | |
341 | } | |
96025800 | 342 | |
6a488035 | 343 | } |