phpcs - Fix error, "CONST keyword must be lowercase; expected const but found CONST"
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / AddPricesetTest.php
... / ...
CommitLineData
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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
27require_once 'CiviTest/CiviSeleniumTestCase.php';
28
29/**
30 * Class WebTest_Contribute_AddPricesetTest
31 */
32class WebTest_Contribute_AddPricesetTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testAddPriceSet() {
39 // Log in using webtestLogin() method
40 $this->webtestLogin();
41
42 //add financial type of account type expense
43
44 $financialType = $this->_testAddFinancialType();
45
46 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
47 $usedFor = 'Contribution';
48 $setHelp = 'Select your conference options.';
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.
53 $sid = $this->urlArg('sid');
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 );
64 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
65 // var_dump($validateStrings);
66
67 // load the Price Set Preview and check for expected values
68 $this->_testVerifyPriceSet($validateStrings, $sid);
69 }
70
71 /**
72 * @param $setTitle
73 * @param $usedFor
74 * @param $setHelp
75 * @param null $financialType
76 */
77 function _testAddSet($setTitle, $usedFor, $setHelp, $financialType = NULL) {
78 $this->openCiviPage("admin/price", "reset=1&action=add", '_qf_Set_next-bottom');
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) {
90 $this->select("financial_type_id", "label={$financialType}");
91 }
92 $this->type('help_pre', $setHelp);
93
94 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
95 $this->clickLink('_qf_Set_next-bottom');
96 }
97
98 /**
99 * @param $fields
100 * @param $validateString
101 * @param $financialType
102 * @param bool $dateSpecificFields
103 */
104 function _testAddPriceFields(&$fields, &$validateString, $financialType, $dateSpecificFields = FALSE) {
105 $validateStrings[] = $financialType;
106 $sid = $this->urlArg('sid');
107 $this->openCiviPage('admin/price/field', "reset=1&action=add&sid=$sid", 'label');
108 foreach ($fields as $label => $type) {
109 $validateStrings[] = $label;
110
111 $this->type('label', $label);
112 $this->select('html_type', "value={$type}");
113
114 switch ($type) {
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);
155 $this->check('is_required');
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;
180 }
181 $this->select('financial_type_id', "label={$financialType}");
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.");
184 }
185 }
186
187 /**
188 * @return string
189 */
190 function _testAddFinancialType() {
191 //Add new Financial Type
192 $financialType['name'] = 'FinancialType ' . substr(sha1(rand()), 0, 4);
193 $financialType['is_deductible'] = TRUE;
194 $financialType['is_reserved'] = FALSE;
195 $this->addeditFinancialType($financialType);
196 return $financialType['name'];
197 }
198
199 /**
200 * @param $validateStrings
201 * @param int $sid
202 */
203 function _testVerifyPriceSet($validateStrings, $sid) {
204 // verify Price Set at Preview page
205 // start at Manage Price Sets listing
206 $this->openCiviPage("admin/price", "reset=1");
207
208 // Use the price set id ($sid) to pick the correct row
209 $this->clickLink("//*[@id='price_set-{$sid}']/td[4]/span[1]/a[1]", 'Link=Add Price Field');
210 // Check for expected price set field strings
211 $this->assertStringsPresent($validateStrings);
212 }
213
214 function testContributeOfflineWithPriceSet() {
215 // Log in using webtestLogin() method
216 $this->webtestLogin();
217
218 //add financial type of account type expense
219 $financialType = $this->_testAddFinancialType();
220
221 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
222 $usedFor = 'Contribution';
223 $setHelp = 'Select your conference options.';
224 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
225
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.
228 $sid = $this->urlArg('sid');
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);
242 $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", '_qf_Contribution_upload');
243
244 // create new contact using dialog
245 $this->createDialogContact();
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");
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']");
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
286 $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']");
287
288 //click through to the Membership view screen
289 $this->click("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']");
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
315 function testContributeOnlineWithPriceSet() {
316 $this->webtestLogin();
317
318 //add financial type of account type expense
319 $financialType = $this->_testAddFinancialType();
320
321 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
322 $usedFor = 'Contribution';
323 $setHelp = 'Select your conference options.';
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.
328 $sid = $this->urlArg('sid');
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 );
338
339 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
340
341 // load the Price Set Preview and check for expected values
342 $this->_testVerifyPriceSet($validateStrings, $sid);
343
344 // Use default payment processor
345 $processorName = 'Test Processor';
346 $this->webtestAddPaymentProcessor($processorName);
347
348 $this->openCiviPage("admin/contribute/add", "reset=1&action=add");
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}");
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');
366
367 //this contribution page for online contribution
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
373 //logout
374 $this->webtestLogout();
375
376 //Open Live Contribution Page
377 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
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');
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']");
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
402 $this->type('billing_first_name', $firstName);
403 $this->type('billing_last_name', $lastName);
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');
409 $this->clickLink('_qf_Main_upload-bottom', '_qf_Confirm_next-bottom');
410
411 $this->click('_qf_Confirm_next-bottom');
412 $this->waitForPageToLoad($this->getTimeoutMsec());
413
414 //login to check contribution
415
416 // Log in using webtestLogin() method
417 $this->webtestLogin();
418
419 //Find Contribution
420 $this->openCiviPage("contribute/search", "reset=1", 'contribution_date_low');
421
422 $this->type('sort_name', "$lastName $firstName");
423 $this->clickLink('_qf_Search_refresh', "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
424 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
425
426 // View Contribution Record and test for expected values
427 $expected = array(
428 'From' => "{$firstName} {$lastName}",
429 'Financial Type' => $financialType,
430 'Net Amount' => '$ 590.00',
431 'Contribution Status' => 'Completed',
432 );
433 $this->webtestVerifyTabularData($expected);
434
435 }
436
437 function testContributeWithDateSpecificPriceSet() {
438 $this->webtestLogin();
439
440 //add financial type of account type expense
441 $financialType = $this->_testAddFinancialType();
442
443 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
444 $usedFor = 'Contribution';
445 $setHelp = 'Select your conference options.';
446 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
447
448 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
449 // which is where we are after adding Price Set.
450 $sid = $this->urlArg('sid');
451 $this->assertType('numeric', $sid);
452
453 $validStrings = array();
454 $fields = array(
455 'Full Conference' => 'Text',
456 'Meal Choice' => 'Select',
457 'Pre-conference Meetup?' => 'Radio',
458 'Evening Sessions' => 'CheckBox',
459 );
460 $this->_testAddPriceFields($fields, $validateStrings, $financialType, TRUE);
461
462 // load the Price Set Preview and check for expected values
463 $this->_testVerifyPriceSet($validateStrings, $sid);
464
465 // Use default payment processor
466 $processorName = 'Test Processor';
467 $this->webtestAddPaymentProcessor($processorName);
468
469 $this->openCiviPage("admin/contribute/add", "reset=1&action=add");
470
471 $contributionTitle = substr(sha1(rand()), 0, 7);
472 $rand = 2 * rand(2, 50);
473
474 // fill in step 1 (Title and Settings)
475 $contributionPageTitle = "Title $contributionTitle";
476 $this->type('title', $contributionPageTitle);
477 $this->select('financial_type_id', "label={$financialType}");
478 $this->fillRichTextField('intro_text', 'This is Test Introductory Message', 'CKEditor');
479 $this->fillRichTextField('footer_text', 'This is Test Footer Message', 'CKEditor');
480
481 // Submit form
482 $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom");
483
484 // Get contribution page id
485 $pageId = $this->urlArg('id');
486
487 //this contribution page for online contribution
488 $this->click("xpath=//tr[@class='crm-contribution-contributionpage-amount-form-block-payment_processor']/td/label[text()='$processorName']");
489 $this->select('price_set_id', 'label=' . $setTitle);
490 $this->clickLink('_qf_Amount_next-bottom');
491
492 //logout
493 $this->webtestLogout();
494
495 //Open Live Contribution Page
496 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
497
498 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
499 $lastName = 'An' . substr(sha1(rand()), 0, 7);
500 $this->waitForElementPresent('_qf_Main_upload-bottom');
501 $this->type('email-5', $firstName . '@example.com');
502 $this->click("xpath=//input[@class='crm-form-radio']");
503 $this->click("xpath=//input[@class='crm-form-checkbox']");
504
505 $streetAddress = '100 Main Street';
506 $this->type('billing_street_address-5', $streetAddress);
507 $this->type('billing_city-5', 'San Francisco');
508 $this->type('billing_postal_code-5', '94117');
509 $this->select('billing_country_id-5', 'value=1228');
510 $this->select('billing_state_province_id-5', 'value=1001');
511
512 //Credit Card Info
513 $this->select('credit_card_type', 'value=Visa');
514 $this->type('credit_card_number', '4111111111111111');
515 $this->type('cvv2', '000');
516 $this->select('credit_card_exp_date[M]', 'value=1');
517 $this->select('credit_card_exp_date[Y]', 'value=2020');
518
519 //Billing Info
520 $this->type('billing_first_name', $firstName);
521 $this->type('billing_last_name', $lastName);
522 $this->type('billing_street_address-5', '15 Main St.');
523 $this->type(' billing_city-5', 'San Jose');
524 $this->select('billing_country_id-5', 'value=1228');
525 $this->select('billing_state_province_id-5', 'value=1004');
526 $this->type('billing_postal_code-5', '94129');
527 $this->clickLink('_qf_Main_upload-bottom', '_qf_Confirm_next-bottom');
528
529 $this->click('_qf_Confirm_next-bottom');
530 $this->waitForPageToLoad($this->getTimeoutMsec());
531
532 //login to check contribution
533 $this->webtestLogin();
534
535 //Find Contribution
536 $this->openCiviPage("contribute/search", "reset=1", 'contribution_date_low');
537
538 $this->type('sort_name', "$lastName $firstName");
539 $this->clickLink('_qf_Search_refresh', "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", FALSE);
540 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", '_qf_ContributionView_cancel-bottom', FALSE);
541
542 // View Contribution Record and test for expected values
543 $expected = array(
544 'From' => "{$firstName} {$lastName}",
545 'Financial Type' => $financialType,
546 'Net Amount' => '$ 65.00',
547 'Contribution Status' => 'Completed',
548 );
549 $this->webtestVerifyTabularData($expected);
550 }
551
552 function testContributeOfflineforSoftcreditwithApi() {
553 // Log in using webtestLogin() method
554 $this->webtestLogin();
555
556 //create a contact and return the contact id
557 $firstNameSoft = "John_" . substr(sha1(rand()), 0, 5);
558 $lastNameSoft = "Doe_" . substr(sha1(rand()), 0, 5);
559 $this->webtestAddContact($firstNameSoft, $lastNameSoft);
560 $url = $this->parseURL();
561 $cid = $url['queryString']['cid'];
562 $this->assertType('numeric', $cid);
563
564 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
565 $usedFor = 'Contribution';
566 $setHelp = 'Select your conference options.';
567 $financialType = $this->_testAddFinancialType();
568 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
569
570 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
571 // which is where we are after adding Price Set.
572 $sid = $this->urlArg('sid');
573 $this->assertType('numeric', $sid);
574
575 $validStrings = array();
576 $fields = array(
577 'Full Conference' => 'Text',
578 'Meal Choice' => 'Select',
579 'Pre-conference Meetup?' => 'Radio',
580 'Evening Sessions' => 'CheckBox',
581 );
582 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
583
584 // load the Price Set Preview and check for expected values
585 $this->_testVerifyPriceSet($validateStrings, $sid);
586
587 $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", '_qf_Contribution_upload');
588
589 // create new contact using dialog
590 $contact = $this->createDialogContact();
591
592 // select contribution type
593 $this->select('financial_type_id', "label={$financialType}");
594
595 // fill in Received Date
596 $this->webtestFillDate('receive_date');
597
598 // source
599 $this->type('source', 'Mailer 1');
600
601 // select price set items
602 $this->select('price_set_id', "label=$setTitle");
603 $this->type("xpath=//input[@class='four crm-form-text required']", "1");
604 $this->click("xpath=//input[@class='crm-form-radio']");
605 $this->click("xpath=//input[@class='crm-form-checkbox']");
606 // select payment instrument type = Check and enter chk number
607 $this->select('payment_instrument_id', 'value=4');
608 $this->waitForElementPresent('check_number');
609 $this->type('check_number', '1041');
610
611 $this->type('trxn_id', 'P20901X1' . rand(100, 10000));
612
613 $this->webtestFillAutocomplete("{$lastNameSoft}, {$firstNameSoft}", 'soft_credit_contact_id_1');
614
615 $this->type('soft_credit_amount_1', "65");
616 //Additional Detail section
617 $this->click('AdditionalDetail');
618 $this->waitForElementPresent('thankyou_date');
619
620 $this->type('note', 'This is a test note.');
621 $this->type('invoice_id', time());
622 $this->webtestFillDate('thankyou_date');
623
624 // Clicking save.
625 $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);
626 $this->assertTrue($this->isTextPresent('The contribution record has been saved.'), "Status message didn't show up after saving!");
627
628 //click through to the Contribution view screen
629 $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']");
630 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
631
632 // View Contribution Record and test for expected values
633 $expected = array(
634 'From' => $contact['display_name'],
635 'Financial Type' => $financialType,
636 'Contribution Amount' => 'Contribution Total: $ 590.00',
637 'Paid By' => 'Check',
638 'Check Number' => '1041',
639 'Contribution Status' => 'Completed',
640 );
641 $this->webtestVerifyTabularData($expected);
642
643 $exp = array(
644 2 => '$ 525.00',
645 3 => '$ 50.00',
646 4 => '$ 15.00',
647 );
648
649 foreach ($exp as $lab => $val) {
650 $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[$lab]/td[3]",
651 preg_quote($val)
652 );
653 }
654
655 // verify if soft credit was created successfully
656 $softCreditValues = array(
657 'Soft Credit To' => "{$firstNameSoft} {$lastNameSoft}",
658 'Amount' => '65.00',
659 );
660
661 foreach ($softCreditValues as $value) {
662 $this->verifyText("css=table.crm-soft-credit-listing", preg_quote($value));
663 }
664
665 // Check for Soft contact created
666 $this->click("css=input#sort_name_navigation");
667 $this->type("css=input#sort_name_navigation", "$lastNameSoft, $firstNameSoft");
668 $this->typeKeys("css=input#sort_name_navigation", "$lastNameSoft, $firstNameSoft");
669 // wait for result list
670 $this->waitForElementPresent("css=ul.ui-autocomplete li");
671
672 // visit contact summary page
673 $this->click("css=ul.ui-autocomplete li");
674 $this->waitForPageToLoad($this->getTimeoutMsec());
675 $this->click('css=li#tab_contribute a');
676 $this->waitForElementPresent('link=Record Contribution (Check, Cash, EFT ...)');
677
678 $id = explode('id=', $this->getAttribute("xpath=//table[@class='selector row-highlight']/tbody//tr[@id='rowid']/td[8]/a[text()='View']@href"));
679 $id = substr($id[1], 0, strpos($id[1], '&'));
680 $this->click("xpath=//table[@class='selector row-highlight']/tbody//tr[@id='rowid']/td[8]/a");
681 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
682
683 $this->webtestVerifyTabularData($expected);
684
685 $params = array(
686 'contribution_id' => $id,
687 'version' => 3,
688 );
689
690 // Retrieve contribution from the DB via api and verify DB values against view contribution page
691 $fields = $this->webtest_civicrm_api('contribution', 'get', $params);
692
693 $params['id'] = $params['contact_id'] = $fields['values'][$fields['id']]['soft_credit_to'];
694 $softCreditContact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, TRUE);
695
696 // View Contribution Record and test for expected values
697 $expected = array(
698 'From' => $fields['values'][$fields['id']]['display_name'],
699 'Financial Type' => $fields['values'][$fields['id']]['financial_type'],
700 'Contribution Amount' => $fields['values'][$fields['id']]['total_amount'],
701 'Contribution Status' => $fields['values'][$fields['id']]['contribution_status'],
702 'Paid By' => $fields['values'][$fields['id']]['contribution_payment_instrument'],
703 'Check Number' => $fields['values'][$fields['id']]['contribution_check_number'],
704 );
705
706 $this->webtestVerifyTabularData($expected);
707
708 // verify if soft credit
709 $softCreditValues = array(
710 'Soft Credit To' => $softCreditContact->display_name,
711 'Amount' => '65.00',
712 );
713
714 foreach ($softCreditValues as $value) {
715 $this->verifyText("css=table.crm-soft-credit-listing", preg_quote($value));
716 }
717 }
718}
719