Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | ||
6a488035 TO |
27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
28 | class WebTest_Contribute_AddPricesetTest extends CiviSeleniumTestCase { | |
29 | ||
30 | protected function setUp() { | |
31 | parent::setUp(); | |
32 | } | |
76e86fd8 | 33 | |
6a488035 | 34 | function testAddPriceSet() { |
6a488035 TO |
35 | // Log in using webtestLogin() method |
36 | $this->webtestLogin(); | |
37 | ||
38 | //add financial type of account type expense | |
76e86fd8 | 39 | |
6a488035 TO |
40 | $financialType = $this->_testAddFinancialType(); |
41 | ||
42 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); | |
42daf119 CW |
43 | $usedFor = 'Contribution'; |
44 | $setHelp = 'Select your conference options.'; | |
6a488035 TO |
45 | $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType); |
46 | ||
47 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form | |
48 | // which is where we are after adding Price Set. | |
a471a3b6 | 49 | $sid = $this->urlArg('sid'); |
6a488035 TO |
50 | $this->assertType('numeric', $sid); |
51 | ||
52 | $validStrings = array(); | |
53 | ||
54 | $fields = array( | |
55 | 'Full Conference' => 'Text', | |
56 | 'Meal Choice' => 'Select', | |
57 | 'Pre-conference Meetup?' => 'Radio', | |
58 | 'Evening Sessions' => 'CheckBox', | |
59 | ); | |
60 | $this->_testAddPriceFields( $fields, $validateStrings, $financialType ); | |
61 | // var_dump($validateStrings); | |
62 | ||
63 | // load the Price Set Preview and check for expected values | |
64 | $this->_testVerifyPriceSet($validateStrings, $sid); | |
65 | } | |
66 | ||
67 | function _testAddSet($setTitle, $usedFor, $setHelp, $financialType = NULL) { | |
42daf119 | 68 | $this->openCiviPage("admin/price", "reset=1&action=add", '_qf_Set_next-bottom'); |
6a488035 TO |
69 | |
70 | // Enter Priceset fields (Title, Used For ...) | |
71 | $this->type('title', $setTitle); | |
72 | if ($usedFor == 'Event') { | |
73 | $this->check('extends_1'); | |
74 | } | |
75 | elseif ($usedFor == 'Contribution') { | |
76 | $this->check('extends_2'); | |
77 | } | |
78 | ||
79 | if ($financialType) { | |
6d5f1345 | 80 | $this->select("financial_type_id", "label={$financialType}"); |
6a488035 TO |
81 | } |
82 | $this->type('help_pre', $setHelp); | |
83 | ||
84 | $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.'); | |
225a8648 | 85 | $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom'); |
6a488035 TO |
86 | } |
87 | ||
88 | function _testAddPriceFields(&$fields, &$validateString, $financialType, $dateSpecificFields = FALSE) { | |
89 | $validateStrings[] = $financialType; | |
90 | foreach ($fields as $label => $type) { | |
91 | $validateStrings[] = $label; | |
76e86fd8 | 92 | |
6a488035 TO |
93 | $this->type('label', $label); |
94 | $this->select('html_type', "value={$type}"); | |
95 | ||
96 | switch ($type) { | |
97 | case 'Text': | |
98 | $validateStrings[] = '525.00'; | |
99 | $this->type('price', '525.00'); | |
100 | if ($dateSpecificFields == TRUE) { | |
101 | $this->webtestFillDateTime('active_on', '+1 week'); | |
102 | } | |
103 | else { | |
104 | $this->check('is_required'); | |
105 | } | |
106 | break; | |
76e86fd8 | 107 | |
6a488035 TO |
108 | case 'Select': |
109 | $options = array( | |
110 | 1 => array('label' => 'Chicken', | |
111 | 'amount' => '30.00', | |
112 | ), | |
113 | 2 => array( | |
114 | 'label' => 'Vegetarian', | |
115 | 'amount' => '25.00', | |
116 | ), | |
117 | ); | |
118 | $this->addMultipleChoiceOptions($options, $validateStrings); | |
119 | if ($dateSpecificFields == TRUE) { | |
120 | $this->webtestFillDateTime('expire_on', '-1 week'); | |
121 | } | |
122 | break; | |
76e86fd8 | 123 | |
6a488035 TO |
124 | case 'Radio': |
125 | $options = array( | |
126 | 1 => array('label' => 'Yes', | |
127 | 'amount' => '50.00', | |
128 | ), | |
129 | 2 => array( | |
130 | 'label' => 'No', | |
131 | 'amount' => '0', | |
132 | ), | |
133 | ); | |
134 | $this->addMultipleChoiceOptions($options, $validateStrings); | |
135 | $this->check('is_required'); | |
136 | if ($dateSpecificFields == TRUE) { | |
137 | $this->webtestFillDateTime('active_on', '-1 week'); | |
138 | } | |
139 | break; | |
76e86fd8 | 140 | |
6a488035 TO |
141 | case 'CheckBox': |
142 | $options = array( | |
143 | 1 => array('label' => 'First Night', | |
144 | 'amount' => '15.00', | |
145 | ), | |
146 | 2 => array( | |
147 | 'label' => 'Second Night', | |
148 | 'amount' => '15.00', | |
149 | ), | |
150 | ); | |
151 | $this->addMultipleChoiceOptions($options, $validateStrings); | |
152 | if ($dateSpecificFields == TRUE) { | |
153 | $this->webtestFillDateTime('expire_on', '+1 week'); | |
154 | } | |
155 | break; | |
76e86fd8 | 156 | |
6a488035 TO |
157 | default: |
158 | break; | |
159 | } | |
160 | $this->select('financial_type_id', "label={$financialType}"); | |
225a8648 | 161 | $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom'); |
6a488035 TO |
162 | } |
163 | } | |
76e86fd8 | 164 | |
6a488035 | 165 | function _testAddFinancialType() { |
6a488035 TO |
166 | //Add new Financial Type |
167 | $financialType['name'] = 'FinancialType '.substr(sha1(rand()), 0, 4); | |
168 | $financialType['is_deductible'] = TRUE; | |
169 | $financialType['is_reserved'] = FALSE; | |
170 | $this->addeditFinancialType($financialType); | |
6a488035 TO |
171 | return $financialType['name']; |
172 | } | |
76e86fd8 | 173 | |
6a488035 TO |
174 | function _testVerifyPriceSet($validateStrings, $sid) { |
175 | // verify Price Set at Preview page | |
176 | // start at Manage Price Sets listing | |
071a6d2e | 177 | $this->openCiviPage("admin/price", "reset=1"); |
6a488035 TO |
178 | |
179 | // Use the price set id ($sid) to pick the correct row | |
225a8648 | 180 | $this->clickLink("css=tr#row_{$sid} a[title='View and Edit Price Fields']", 'Link=Add Price Field'); |
6a488035 TO |
181 | // Check for expected price set field strings |
182 | $this->assertStringsPresent($validateStrings); | |
183 | } | |
184 | ||
185 | function testContributeOfflineWithPriceSet() { | |
6a488035 TO |
186 | // Log in using webtestLogin() method |
187 | $this->webtestLogin(); | |
188 | ||
189 | //add financial type of account type expense | |
190 | $financialType = $this->_testAddFinancialType(); | |
76e86fd8 | 191 | |
6a488035 | 192 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); |
42daf119 CW |
193 | $usedFor = 'Contribution'; |
194 | $setHelp = 'Select your conference options.'; | |
6a488035 | 195 | $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType); |
76e86fd8 | 196 | |
6a488035 TO |
197 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form |
198 | // which is where we are after adding Price Set. | |
a471a3b6 | 199 | $sid = $this->urlArg('sid'); |
6a488035 TO |
200 | $this->assertType('numeric', $sid); |
201 | ||
202 | $validStrings = array(); | |
203 | $fields = array( | |
204 | 'Full Conference' => 'Text', | |
205 | 'Meal Choice' => 'Select', | |
206 | 'Pre-conference Meetup?' => 'Radio', | |
207 | 'Evening Sessions' => 'CheckBox', | |
208 | ); | |
209 | $this->_testAddPriceFields($fields, $validateStrings, $financialType); | |
210 | ||
211 | // load the Price Set Preview and check for expected values | |
212 | $this->_testVerifyPriceSet($validateStrings, $sid); | |
42daf119 | 213 | $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", '_qf_Contribution_upload'); |
6a488035 | 214 | |
6a488035 TO |
215 | // create new contact using dialog |
216 | $firstName = substr(sha1(rand()), 0, 7); | |
217 | $this->webtestNewDialogContact($firstName, 'Contributor', $firstName . '@example.com'); | |
218 | ||
219 | // select financial type | |
220 | $this->select('financial_type_id', "label={$financialType}"); | |
221 | ||
222 | // fill in Received Date | |
223 | $this->webtestFillDate('receive_date'); | |
224 | ||
225 | // source | |
226 | $this->type('source', 'Mailer 1'); | |
227 | ||
228 | // select price set items | |
229 | $this->select('price_set_id', "label=$setTitle"); | |
230 | $this->type("xpath=//input[@class='form-text four required']", "1"); | |
231 | $this->click("xpath=//input[@class='form-radio']"); | |
232 | $this->click("xpath=//input[@class='form-checkbox']"); | |
233 | // select payment instrument type = Check and enter chk number | |
234 | $this->select('payment_instrument_id', 'value=4'); | |
235 | $this->waitForElementPresent('check_number'); | |
236 | $this->type('check_number', 'check #1041'); | |
237 | ||
238 | $this->type('trxn_id', 'P20901X1' . rand(100, 10000)); | |
239 | ||
240 | //Additional Detail section | |
241 | $this->click('AdditionalDetail'); | |
242 | $this->waitForElementPresent('thankyou_date'); | |
243 | ||
244 | $this->type('note', 'This is a test note.'); | |
245 | $this->type('non_deductible_amount', '10'); | |
246 | $this->type('fee_amount', '0'); | |
247 | $this->type('net_amount', '0'); | |
248 | $this->type('invoice_id', time()); | |
249 | $this->webtestFillDate('thankyou_date'); | |
250 | ||
251 | // Clicking save. | |
252 | $this->click('_qf_Contribution_upload'); | |
253 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
254 | ||
255 | // Is status message correct? | |
256 | $this->assertTrue($this->isTextPresent('The contribution record has been saved.'), "Status message didn't show up after saving!"); | |
257 | ||
258 | $this->waitForElementPresent("xpath=//div[@id='Contributions']//table//tbody/tr[1]/td[8]/span/a[text()='View']"); | |
259 | ||
260 | //click through to the Membership view screen | |
261 | $this->click("xpath=//div[@id='Contributions']//table/tbody/tr[1]/td[8]/span/a[text()='View']"); | |
262 | $this->waitForElementPresent('_qf_ContributionView_cancel-bottom'); | |
263 | $expected = array( | |
264 | 2 => $financialType, | |
265 | 3 => '590.00', | |
266 | 9 => 'Completed', | |
267 | 10 => 'Check', | |
268 | 11 => 'check #1041', | |
269 | ); | |
270 | foreach ($expected as $label => $value) { | |
271 | $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[$label]/td[2]", preg_quote($value)); | |
272 | } | |
273 | ||
274 | $exp = array( | |
275 | 2 => '$ 525.00', | |
276 | 3 => '$ 50.00', | |
277 | 4 => '$ 15.00', | |
278 | ); | |
279 | ||
280 | foreach ($exp as $lab => $val) { | |
281 | $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[$lab]/td[3]", | |
282 | preg_quote($val) | |
283 | ); | |
284 | } | |
285 | } | |
286 | ||
6a488035 | 287 | function testContributeOnlineWithPriceSet() { |
6a488035 TO |
288 | $this->webtestLogin(); |
289 | ||
290 | //add financial type of account type expense | |
291 | $financialType = $this->_testAddFinancialType(); | |
6d5f1345 | 292 | |
6a488035 | 293 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); |
42daf119 CW |
294 | $usedFor = 'Contribution'; |
295 | $setHelp = 'Select your conference options.'; | |
6a488035 TO |
296 | $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType); |
297 | ||
298 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form | |
299 | // which is where we are after adding Price Set. | |
a471a3b6 | 300 | $sid = $this->urlArg('sid'); |
6a488035 TO |
301 | $this->assertType('numeric', $sid); |
302 | ||
303 | $validStrings = array(); | |
304 | $fields = array( | |
305 | 'Full Conference' => 'Text', | |
306 | 'Meal Choice' => 'Select', | |
307 | 'Pre-conference Meetup?' => 'Radio', | |
308 | 'Evening Sessions' => 'CheckBox', | |
309 | ); | |
76e86fd8 | 310 | |
6a488035 | 311 | $this->_testAddPriceFields($fields, $validateStrings, $financialType); |
76e86fd8 | 312 | |
6a488035 TO |
313 | // load the Price Set Preview and check for expected values |
314 | $this->_testVerifyPriceSet($validateStrings, $sid); | |
315 | ||
316 | // We need a payment processor | |
317 | $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7); | |
318 | $this->webtestAddPaymentProcessor($processorName); | |
319 | ||
071a6d2e | 320 | $this->openCiviPage("admin/contribute/add", "reset=1&action=add"); |
6a488035 TO |
321 | |
322 | $contributionTitle = substr(sha1(rand()), 0, 7); | |
323 | $rand = 2 * rand(2, 50); | |
324 | ||
325 | // fill in step 1 (Title and Settings) | |
326 | $contributionPageTitle = "Title $contributionTitle"; | |
327 | $this->type('title', $contributionPageTitle); | |
328 | $this->fillRichTextField('intro_text', 'This is Test Introductory Message', 'CKEditor'); | |
329 | $this->fillRichTextField('footer_text', 'This is Test Footer Message', 'CKEditor'); | |
330 | ||
331 | $this->select('financial_type_id', "label={$financialType}"); | |
b45c587e CW |
332 | |
333 | // Submit form | |
334 | $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom"); | |
335 | ||
336 | // Get contribution page id | |
337 | $pageId = $this->urlArg('id'); | |
6a488035 TO |
338 | |
339 | //this contribution page for online contribution | |
6a488035 TO |
340 | $this->click("xpath=//tr[@class='crm-contribution-contributionpage-amount-form-block-payment_processor']/td/label[text()='$processorName']"); |
341 | $this->select('price_set_id', 'label=' . $setTitle); | |
342 | $this->click('_qf_Amount_next-bottom'); | |
343 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
344 | ||
6a488035 | 345 | //logout |
42daf119 | 346 | $this->webtestLogout(); |
6a488035 TO |
347 | |
348 | //Open Live Contribution Page | |
b45c587e | 349 | $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom'); |
6a488035 TO |
350 | |
351 | $firstName = 'Ma' . substr(sha1(rand()), 0, 4); | |
352 | $lastName = 'An' . substr(sha1(rand()), 0, 7); | |
353 | $this->waitForElementPresent('_qf_Main_upload-bottom'); | |
354 | $this->type('email-5', $firstName . '@example.com'); | |
6a488035 TO |
355 | $this->type("xpath=//input[@class='form-text four required']", "1"); |
356 | $this->click("xpath=//input[@class='form-radio']"); | |
357 | $this->click("xpath=//input[@class='form-checkbox']"); | |
358 | ||
359 | $streetAddress = '100 Main Street'; | |
360 | $this->type('billing_street_address-5', $streetAddress); | |
361 | $this->type('billing_city-5', 'San Francisco'); | |
362 | $this->type('billing_postal_code-5', '94117'); | |
363 | $this->select('billing_country_id-5', 'value=1228'); | |
364 | $this->select('billing_state_province_id-5', 'value=1001'); | |
365 | ||
366 | //Credit Card Info | |
367 | $this->select('credit_card_type', 'value=Visa'); | |
368 | $this->type('credit_card_number', '4111111111111111'); | |
369 | $this->type('cvv2', '000'); | |
370 | $this->select('credit_card_exp_date[M]', 'value=1'); | |
371 | $this->select('credit_card_exp_date[Y]', 'value=2020'); | |
372 | ||
373 | //Billing Info | |
0054ead7 DG |
374 | $this->type('billing_first_name', $firstName); |
375 | $this->type('billing_last_name', $lastName); | |
6a488035 TO |
376 | $this->type('billing_street_address-5', '15 Main St.'); |
377 | $this->type('billing_city-5', 'San Jose'); | |
378 | $this->select('billing_country_id-5', 'value=1228'); | |
379 | $this->select('billing_state_province_id-5', 'value=1004'); | |
380 | $this->type('billing_postal_code-5', '94129'); | |
225a8648 | 381 | $this->clickLink('_qf_Main_upload-bottom', '_qf_Confirm_next-bottom'); |
6a488035 TO |
382 | |
383 | $this->click('_qf_Confirm_next-bottom'); | |
384 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
385 | ||
386 | //login to check contribution | |
6a488035 TO |
387 | |
388 | // Log in using webtestLogin() method | |
389 | $this->webtestLogin(); | |
390 | ||
391 | //Find Contribution | |
42daf119 | 392 | $this->openCiviPage("contribute/search", "reset=1", 'contribution_date_low'); |
6a488035 TO |
393 | |
394 | $this->type('sort_name', "$firstName $lastName"); | |
225a8648 CW |
395 | $this->clickLink('_qf_Search_refresh', "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']"); |
396 | $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom"); | |
6a488035 | 397 | |
0054ead7 | 398 | // View Contribution Record and test for expected values |
6a488035 | 399 | $expected = array( |
42daf119 CW |
400 | 'From' => "{$firstName} {$lastName}", |
401 | 'Financial Type' => $financialType, | |
402 | 'Net Amount' => '$ 590.00', | |
0054ead7 | 403 | 'Contribution Status' => 'Completed', |
6a488035 | 404 | ); |
0054ead7 DG |
405 | $this->webtestVerifyTabularData($expected); |
406 | ||
6a488035 TO |
407 | } |
408 | ||
409 | function testContributeWithDateSpecificPriceSet() { | |
6a488035 TO |
410 | $this->webtestLogin(); |
411 | ||
412 | //add financial type of account type expense | |
413 | $financialType= $this->_testAddFinancialType(); | |
76e86fd8 | 414 | |
6a488035 | 415 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); |
42daf119 CW |
416 | $usedFor = 'Contribution'; |
417 | $setHelp = 'Select your conference options.'; | |
6a488035 TO |
418 | $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType); |
419 | ||
420 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form | |
421 | // which is where we are after adding Price Set. | |
a471a3b6 | 422 | $sid = $this->urlArg('sid'); |
6a488035 TO |
423 | $this->assertType('numeric', $sid); |
424 | ||
425 | $validStrings = array(); | |
426 | $fields = array( | |
427 | 'Full Conference' => 'Text', | |
428 | 'Meal Choice' => 'Select', | |
429 | 'Pre-conference Meetup?' => 'Radio', | |
430 | 'Evening Sessions' => 'CheckBox', | |
431 | ); | |
432 | $this->_testAddPriceFields($fields, $validateStrings, $financialType, TRUE); | |
433 | ||
434 | // load the Price Set Preview and check for expected values | |
435 | $this->_testVerifyPriceSet($validateStrings, $sid); | |
436 | ||
437 | // We need a payment processor | |
438 | $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7); | |
439 | $this->webtestAddPaymentProcessor($processorName); | |
440 | ||
071a6d2e | 441 | $this->openCiviPage("admin/contribute/add", "reset=1&action=add"); |
6a488035 TO |
442 | |
443 | $contributionTitle = substr(sha1(rand()), 0, 7); | |
444 | $rand = 2 * rand(2, 50); | |
445 | ||
446 | // fill in step 1 (Title and Settings) | |
447 | $contributionPageTitle = "Title $contributionTitle"; | |
448 | $this->type('title', $contributionPageTitle); | |
449 | $this->select('financial_type_id', "label={$financialType}"); | |
450 | $this->fillRichTextField('intro_text', 'This is Test Introductory Message', 'CKEditor'); | |
451 | $this->fillRichTextField('footer_text', 'This is Test Footer Message', 'CKEditor'); | |
452 | ||
b45c587e CW |
453 | // Submit form |
454 | $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom"); | |
455 | ||
456 | // Get contribution page id | |
457 | $pageId = $this->urlArg('id'); | |
6a488035 TO |
458 | |
459 | //this contribution page for online contribution | |
6a488035 TO |
460 | $this->click("xpath=//tr[@class='crm-contribution-contributionpage-amount-form-block-payment_processor']/td/label[text()='$processorName']"); |
461 | $this->select('price_set_id', 'label=' . $setTitle); | |
b45c587e | 462 | $this->clickLink('_qf_Amount_next-bottom'); |
6a488035 TO |
463 | |
464 | //logout | |
42daf119 | 465 | $this->webtestLogout(); |
6a488035 TO |
466 | |
467 | //Open Live Contribution Page | |
b45c587e | 468 | $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom'); |
6a488035 TO |
469 | |
470 | $firstName = 'Ma' . substr(sha1(rand()), 0, 4); | |
471 | $lastName = 'An' . substr(sha1(rand()), 0, 7); | |
472 | $this->waitForElementPresent('_qf_Main_upload-bottom'); | |
473 | $this->type('email-5', $firstName . '@example.com'); | |
6a488035 TO |
474 | $this->click("xpath=//input[@class='form-radio']"); |
475 | $this->click("xpath=//input[@class='form-checkbox']"); | |
476 | ||
477 | $streetAddress = '100 Main Street'; | |
478 | $this->type('billing_street_address-5', $streetAddress); | |
479 | $this->type('billing_city-5', 'San Francisco'); | |
480 | $this->type('billing_postal_code-5', '94117'); | |
481 | $this->select('billing_country_id-5', 'value=1228'); | |
482 | $this->select('billing_state_province_id-5', 'value=1001'); | |
483 | ||
484 | //Credit Card Info | |
485 | $this->select('credit_card_type', 'value=Visa'); | |
486 | $this->type('credit_card_number', '4111111111111111'); | |
487 | $this->type('cvv2', '000'); | |
488 | $this->select('credit_card_exp_date[M]', 'value=1'); | |
489 | $this->select('credit_card_exp_date[Y]', 'value=2020'); | |
490 | ||
491 | //Billing Info | |
0054ead7 DG |
492 | $this->type('billing_first_name', $firstName); |
493 | $this->type('billing_last_name', $lastName); | |
6a488035 TO |
494 | $this->type('billing_street_address-5', '15 Main St.'); |
495 | $this->type(' billing_city-5', 'San Jose'); | |
496 | $this->select('billing_country_id-5', 'value=1228'); | |
497 | $this->select('billing_state_province_id-5', 'value=1004'); | |
498 | $this->type('billing_postal_code-5', '94129'); | |
225a8648 | 499 | $this->clickLink('_qf_Main_upload-bottom', '_qf_Confirm_next-bottom'); |
6a488035 TO |
500 | |
501 | $this->click('_qf_Confirm_next-bottom'); | |
502 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
503 | ||
504 | //login to check contribution | |
6a488035 TO |
505 | $this->webtestLogin(); |
506 | ||
507 | //Find Contribution | |
42daf119 | 508 | $this->openCiviPage("contribute/search", "reset=1", 'contribution_date_low'); |
6a488035 TO |
509 | |
510 | $this->type('sort_name', "$firstName $lastName"); | |
225a8648 CW |
511 | $this->clickLink('_qf_Search_refresh', "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']"); |
512 | $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", '_qf_ContributionView_cancel-bottom'); | |
6a488035 | 513 | |
0054ead7 | 514 | // View Contribution Record and test for expected values |
6a488035 | 515 | $expected = array( |
42daf119 CW |
516 | 'From' => "{$firstName} {$lastName}", |
517 | 'Financial Type' => $financialType, | |
518 | 'Net Amount' => '$ 65.00', | |
0054ead7 | 519 | 'Contribution Status' => 'Completed', |
6a488035 | 520 | ); |
0054ead7 | 521 | $this->webtestVerifyTabularData($expected); |
6a488035 TO |
522 | } |
523 | ||
524 | function testContributeOfflineforSoftcreditwithApi() { | |
6a488035 TO |
525 | // Log in using webtestLogin() method |
526 | $this->webtestLogin(); | |
76e86fd8 | 527 | |
6a488035 TO |
528 | //create a contact and return the contact id |
529 | $firstNameSoft = "John_".substr(sha1(rand()), 0, 5); | |
42daf119 | 530 | $lastNameSoft = "Doe_".substr(sha1(rand()), 0, 5); |
6a488035 TO |
531 | $this->webtestAddContact($firstNameSoft, $lastNameSoft); |
532 | $url = $this->parseURL(); | |
533 | $cid = $url['queryString']['cid']; | |
534 | $this->assertType('numeric', $cid); | |
76e86fd8 | 535 | |
6a488035 | 536 | $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); |
42daf119 CW |
537 | $usedFor = 'Contribution'; |
538 | $setHelp = 'Select your conference options.'; | |
6a488035 TO |
539 | $financialType = $this->_testAddFinancialType(); |
540 | $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType); | |
541 | ||
542 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form | |
543 | // which is where we are after adding Price Set. | |
a471a3b6 | 544 | $sid = $this->urlArg('sid'); |
6a488035 TO |
545 | $this->assertType('numeric', $sid); |
546 | ||
547 | $validStrings = array(); | |
548 | $fields = array( | |
549 | 'Full Conference' => 'Text', | |
550 | 'Meal Choice' => 'Select', | |
551 | 'Pre-conference Meetup?' => 'Radio', | |
552 | 'Evening Sessions' => 'CheckBox', | |
553 | ); | |
554 | $this->_testAddPriceFields($fields, $validateStrings, $financialType); | |
555 | ||
556 | // load the Price Set Preview and check for expected values | |
557 | $this->_testVerifyPriceSet($validateStrings, $sid); | |
558 | ||
42daf119 | 559 | $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", '_qf_Contribution_upload'); |
6a488035 | 560 | |
6a488035 TO |
561 | // create new contact using dialog |
562 | $firstName = substr(sha1(rand()), 0, 7); | |
563 | $this->webtestNewDialogContact($firstName, 'Contributor', $firstName . '@example.com'); | |
564 | ||
565 | // select contribution type | |
566 | $this->select('financial_type_id', "label={$financialType}"); | |
567 | ||
568 | // fill in Received Date | |
569 | $this->webtestFillDate('receive_date'); | |
570 | ||
571 | // source | |
572 | $this->type('source', 'Mailer 1'); | |
573 | ||
574 | // select price set items | |
575 | $this->select('price_set_id', "label=$setTitle"); | |
576 | $this->type("xpath=//input[@class='form-text four required']", "1"); | |
577 | $this->click("xpath=//input[@class='form-radio']"); | |
578 | $this->click("xpath=//input[@class='form-checkbox']"); | |
579 | // select payment instrument type = Check and enter chk number | |
580 | $this->select('payment_instrument_id', 'value=4'); | |
581 | $this->waitForElementPresent('check_number'); | |
0054ead7 | 582 | $this->type('check_number', '1041'); |
6a488035 TO |
583 | |
584 | $this->type('trxn_id', 'P20901X1' . rand(100, 10000)); | |
76e86fd8 | 585 | |
6a488035 TO |
586 | $this->type('soft_credit_to', "$lastNameSoft, $firstNameSoft"); |
587 | $this->click('soft_credit_to'); | |
588 | $this->waitForElementPresent("css=div.ac_results-inner li"); | |
589 | $this->click("css=div.ac_results-inner li"); | |
590 | //Additional Detail section | |
591 | $this->click('AdditionalDetail'); | |
592 | $this->waitForElementPresent('thankyou_date'); | |
593 | ||
594 | $this->type('note', 'This is a test note.'); | |
6a488035 TO |
595 | $this->type('invoice_id', time()); |
596 | $this->webtestFillDate('thankyou_date'); | |
597 | ||
598 | // Clicking save. | |
225a8648 | 599 | $this->clickLink('_qf_Contribution_upload', "xpath=//div[@id='Contributions']//table//tbody/tr[1]/td[8]/span/a[text()='View']"); |
0054ead7 | 600 | $this->assertTrue($this->isTextPresent('The contribution record has been saved.'), "Status message didn't show up after saving!"); |
6a488035 | 601 | |
0054ead7 | 602 | //click through to the Contribution view screen |
6a488035 TO |
603 | $this->click("xpath=//div[@id='Contributions']//table/tbody/tr[1]/td[8]/span/a[text()='View']"); |
604 | $this->waitForElementPresent('_qf_ContributionView_cancel-bottom'); | |
605 | ||
0054ead7 | 606 | // View Contribution Record and test for expected values |
6a488035 | 607 | $expected = array( |
42daf119 CW |
608 | 'From' => "{$firstName} Contributor", |
609 | 'Financial Type' => $financialType, | |
0054ead7 | 610 | 'Contribution Amount' => 'Contribution Total: $ 590.00', |
42daf119 CW |
611 | 'Paid By' => 'Check', |
612 | 'Check Number' => '1041', | |
0054ead7 | 613 | 'Contribution Status' => 'Completed', |
42daf119 | 614 | 'Soft Credit To' => "$firstNameSoft $lastNameSoft", |
6a488035 | 615 | ); |
0054ead7 | 616 | $this->webtestVerifyTabularData($expected); |
76e86fd8 | 617 | |
6a488035 TO |
618 | $exp = array( |
619 | 2 => '$ 525.00', | |
620 | 3 => '$ 50.00', | |
621 | 4 => '$ 15.00', | |
622 | ); | |
623 | ||
624 | foreach ($exp as $lab => $val) { | |
625 | $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[$lab]/td[3]", | |
626 | preg_quote($val) | |
627 | ); | |
628 | } | |
0054ead7 | 629 | |
6a488035 TO |
630 | // Check for Soft contact created |
631 | $this->click("css=input#sort_name_navigation"); | |
632 | $this->type("css=input#sort_name_navigation", "$lastNameSoft, $firstNameSoft"); | |
633 | $this->typeKeys("css=input#sort_name_navigation", "$lastNameSoft, $firstNameSoft"); | |
634 | // wait for result list | |
635 | $this->waitForElementPresent("css=div.ac_results-inner li"); | |
76e86fd8 | 636 | |
6a488035 TO |
637 | // visit contact summary page |
638 | $this->click("css=div.ac_results-inner li"); | |
639 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
640 | $this->click( 'css=li#tab_contribute a' ); | |
641 | $this->waitForElementPresent('link=Record Contribution (Check, Cash, EFT ...)'); | |
76e86fd8 | 642 | |
6a488035 TO |
643 | $id = explode('id=', $this->getAttribute("xpath=id('rowid')/td[7]/a[text()='View']@href")); |
644 | $id = substr($id[1], 0, strpos($id[1], '&')); | |
645 | $this->click("xpath=id('rowid')/td[7]/a"); | |
646 | $this->waitForElementPresent('_qf_ContributionView_cancel-bottom'); | |
76e86fd8 | 647 | |
0054ead7 | 648 | $this->webtestVerifyTabularData($expected); |
76e86fd8 | 649 | |
6a488035 TO |
650 | $params = array('contribution_id' => $id, |
651 | 'version' => 3, | |
652 | ); | |
76e86fd8 | 653 | |
0054ead7 | 654 | // Retrieve contribution from the DB via api and verify DB values against view contribution page |
6a488035 TO |
655 | require_once 'api/api.php'; |
656 | $fields = $this->webtest_civicrm_api('contribution','get',$params ); | |
76e86fd8 | 657 | |
6a488035 | 658 | $params['id'] = $params['contact_id'] = $fields['values'][$fields['id']]['soft_credit_to']; |
0054ead7 DG |
659 | $softCreditContact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, TRUE); |
660 | ||
661 | // View Contribution Record and test for expected values | |
662 | $expected = array( | |
42daf119 CW |
663 | 'From' => $fields['values'][$fields['id']]['display_name'], |
664 | 'Financial Type' => $fields['values'][$fields['id']]['financial_type'], | |
0054ead7 DG |
665 | 'Contribution Amount' => $fields['values'][$fields['id']]['total_amount'], |
666 | 'Contribution Status' => $fields['values'][$fields['id']]['contribution_status'], | |
42daf119 CW |
667 | 'Paid By' => $fields['values'][$fields['id']]['contribution_payment_instrument'], |
668 | 'Check Number' => $fields['values'][$fields['id']]['contribution_check_number'], | |
669 | 'Soft Credit To' => $softCreditContact->display_name, | |
6a488035 | 670 | ); |
0054ead7 | 671 | $this->webtestVerifyTabularData($expected); |
6a488035 TO |
672 | } |
673 | } | |
674 |