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