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