Merge pull request #819 from mlutfy/mkdrupaltest3
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / AddPricesetTest.php
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
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Contribute_AddPricesetTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testAddPriceSet() {
35 // Log in using webtestLogin() method
36 $this->webtestLogin();
37
38 //add financial type of account type expense
39
40 $financialType = $this->_testAddFinancialType();
41
42 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
43 $usedFor = 'Contribution';
44 $setHelp = 'Select your conference options.';
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.
49 $sid = $this->urlArg('sid');
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) {
68 $this->openCiviPage("admin/price", "reset=1&action=add", '_qf_Set_next-bottom');
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) {
80 $this->select("financial_type_id", "label={$financialType}");
81 }
82 $this->type('help_pre', $setHelp);
83
84 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
85 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom');
86 }
87
88 function _testAddPriceFields(&$fields, &$validateString, $financialType, $dateSpecificFields = FALSE) {
89 $validateStrings[] = $financialType;
90 foreach ($fields as $label => $type) {
91 $validateStrings[] = $label;
92
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;
107
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;
123
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;
140
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;
156
157 default:
158 break;
159 }
160 $this->select('financial_type_id', "label={$financialType}");
161 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom');
162 }
163 }
164
165 function _testAddFinancialType() {
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);
171 return $financialType['name'];
172 }
173
174 function _testVerifyPriceSet($validateStrings, $sid) {
175 // verify Price Set at Preview page
176 // start at Manage Price Sets listing
177 $this->openCiviPage("admin/price", "reset=1");
178
179 // Use the price set id ($sid) to pick the correct row
180 $this->clickLink("css=tr#row_{$sid} a[title='View and Edit Price Fields']", 'Link=Add Price Field');
181 // Check for expected price set field strings
182 $this->assertStringsPresent($validateStrings);
183 }
184
185 function testContributeOfflineWithPriceSet() {
186 // Log in using webtestLogin() method
187 $this->webtestLogin();
188
189 //add financial type of account type expense
190 $financialType = $this->_testAddFinancialType();
191
192 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
193 $usedFor = 'Contribution';
194 $setHelp = 'Select your conference options.';
195 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
196
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.
199 $sid = $this->urlArg('sid');
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);
213 $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", '_qf_Contribution_upload');
214
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
287 function testContributeOnlineWithPriceSet() {
288 $this->webtestLogin();
289
290 //add financial type of account type expense
291 $financialType = $this->_testAddFinancialType();
292
293 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
294 $usedFor = 'Contribution';
295 $setHelp = 'Select your conference options.';
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.
300 $sid = $this->urlArg('sid');
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 );
310
311 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
312
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
320 $this->openCiviPage("admin/contribute/add", "reset=1&action=add");
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}");
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');
338
339 //this contribution page for online contribution
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
345 //logout
346 $this->webtestLogout();
347
348 //Open Live Contribution Page
349 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
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');
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
374 $this->type('billing_first_name', $firstName);
375 $this->type('billing_last_name', $lastName);
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');
381 $this->clickLink('_qf_Main_upload-bottom', '_qf_Confirm_next-bottom');
382
383 $this->click('_qf_Confirm_next-bottom');
384 $this->waitForPageToLoad($this->getTimeoutMsec());
385
386 //login to check contribution
387
388 // Log in using webtestLogin() method
389 $this->webtestLogin();
390
391 //Find Contribution
392 $this->openCiviPage("contribute/search", "reset=1", 'contribution_date_low');
393
394 $this->type('sort_name', "$firstName $lastName");
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");
397
398 // View Contribution Record and test for expected values
399 $expected = array(
400 'From' => "{$firstName} {$lastName}",
401 'Financial Type' => $financialType,
402 'Net Amount' => '$ 590.00',
403 'Contribution Status' => 'Completed',
404 );
405 $this->webtestVerifyTabularData($expected);
406
407 }
408
409 function testContributeWithDateSpecificPriceSet() {
410 $this->webtestLogin();
411
412 //add financial type of account type expense
413 $financialType= $this->_testAddFinancialType();
414
415 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
416 $usedFor = 'Contribution';
417 $setHelp = 'Select your conference options.';
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.
422 $sid = $this->urlArg('sid');
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
441 $this->openCiviPage("admin/contribute/add", "reset=1&action=add");
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
453 // Submit form
454 $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom");
455
456 // Get contribution page id
457 $pageId = $this->urlArg('id');
458
459 //this contribution page for online contribution
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);
462 $this->clickLink('_qf_Amount_next-bottom');
463
464 //logout
465 $this->webtestLogout();
466
467 //Open Live Contribution Page
468 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
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');
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
492 $this->type('billing_first_name', $firstName);
493 $this->type('billing_last_name', $lastName);
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');
499 $this->clickLink('_qf_Main_upload-bottom', '_qf_Confirm_next-bottom');
500
501 $this->click('_qf_Confirm_next-bottom');
502 $this->waitForPageToLoad($this->getTimeoutMsec());
503
504 //login to check contribution
505 $this->webtestLogin();
506
507 //Find Contribution
508 $this->openCiviPage("contribute/search", "reset=1", 'contribution_date_low');
509
510 $this->type('sort_name', "$firstName $lastName");
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');
513
514 // View Contribution Record and test for expected values
515 $expected = array(
516 'From' => "{$firstName} {$lastName}",
517 'Financial Type' => $financialType,
518 'Net Amount' => '$ 65.00',
519 'Contribution Status' => 'Completed',
520 );
521 $this->webtestVerifyTabularData($expected);
522 }
523
524 function testContributeOfflineforSoftcreditwithApi() {
525 // Log in using webtestLogin() method
526 $this->webtestLogin();
527
528 //create a contact and return the contact id
529 $firstNameSoft = "John_".substr(sha1(rand()), 0, 5);
530 $lastNameSoft = "Doe_".substr(sha1(rand()), 0, 5);
531 $this->webtestAddContact($firstNameSoft, $lastNameSoft);
532 $url = $this->parseURL();
533 $cid = $url['queryString']['cid'];
534 $this->assertType('numeric', $cid);
535
536 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
537 $usedFor = 'Contribution';
538 $setHelp = 'Select your conference options.';
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.
544 $sid = $this->urlArg('sid');
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
559 $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", '_qf_Contribution_upload');
560
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');
582 $this->type('check_number', '1041');
583
584 $this->type('trxn_id', 'P20901X1' . rand(100, 10000));
585
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.');
595 $this->type('invoice_id', time());
596 $this->webtestFillDate('thankyou_date');
597
598 // Clicking save.
599 $this->clickLink('_qf_Contribution_upload', "xpath=//div[@id='Contributions']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
600 $this->assertTrue($this->isTextPresent('The contribution record has been saved.'), "Status message didn't show up after saving!");
601
602 //click through to the Contribution view screen
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
606 // View Contribution Record and test for expected values
607 $expected = array(
608 'From' => "{$firstName} Contributor",
609 'Financial Type' => $financialType,
610 'Contribution Amount' => 'Contribution Total: $ 590.00',
611 'Paid By' => 'Check',
612 'Check Number' => '1041',
613 'Contribution Status' => 'Completed',
614 'Soft Credit To' => "$firstNameSoft $lastNameSoft",
615 );
616 $this->webtestVerifyTabularData($expected);
617
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 }
629
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");
636
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 ...)');
642
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');
647
648 $this->webtestVerifyTabularData($expected);
649
650 $params = array('contribution_id' => $id,
651 'version' => 3,
652 );
653
654 // Retrieve contribution from the DB via api and verify DB values against view contribution page
655 require_once 'api/api.php';
656 $fields = $this->webtest_civicrm_api('contribution','get',$params );
657
658 $params['id'] = $params['contact_id'] = $fields['values'][$fields['id']]['soft_credit_to'];
659 $softCreditContact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, TRUE);
660
661 // View Contribution Record and test for expected values
662 $expected = array(
663 'From' => $fields['values'][$fields['id']]['display_name'],
664 'Financial Type' => $fields['values'][$fields['id']]['financial_type'],
665 'Contribution Amount' => $fields['values'][$fields['id']]['total_amount'],
666 'Contribution Status' => $fields['values'][$fields['id']]['contribution_status'],
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,
670 );
671 $this->webtestVerifyTabularData($expected);
672 }
673 }
674