7153abc7bf8c496820eddfcc9e859649c443e411
[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(
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);
137 $this->check('is_required');
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;
162 }
163 $this->select('financial_type_id', "label={$financialType}");
164 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom');
165 }
166 }
167
168 function _testAddFinancialType() {
169 //Add new Financial Type
170 $financialType['name'] = 'FinancialType ' . substr(sha1(rand()), 0, 4);
171 $financialType['is_deductible'] = TRUE;
172 $financialType['is_reserved'] = FALSE;
173 $this->addeditFinancialType($financialType);
174 return $financialType['name'];
175 }
176
177 function _testVerifyPriceSet($validateStrings, $sid) {
178 // verify Price Set at Preview page
179 // start at Manage Price Sets listing
180 $this->openCiviPage("admin/price", "reset=1");
181
182 // Use the price set id ($sid) to pick the correct row
183 $this->clickLink("css=tr#row_{$sid} a[title='View and Edit Price Fields']", 'Link=Add Price Field');
184 // Check for expected price set field strings
185 $this->assertStringsPresent($validateStrings);
186 }
187
188 function testContributeOfflineWithPriceSet() {
189 // Log in using webtestLogin() method
190 $this->webtestLogin();
191
192 //add financial type of account type expense
193 $financialType = $this->_testAddFinancialType();
194
195 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
196 $usedFor = 'Contribution';
197 $setHelp = 'Select your conference options.';
198 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
199
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.
202 $sid = $this->urlArg('sid');
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);
216 $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", '_qf_Contribution_upload');
217
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
290 function testContributeOnlineWithPriceSet() {
291 $this->webtestLogin();
292
293 //add financial type of account type expense
294 $financialType = $this->_testAddFinancialType();
295
296 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
297 $usedFor = 'Contribution';
298 $setHelp = 'Select your conference options.';
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.
303 $sid = $this->urlArg('sid');
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 );
313
314 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
315
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
323 $this->openCiviPage("admin/contribute/add", "reset=1&action=add");
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}");
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');
341
342 //this contribution page for online contribution
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
348 //logout
349 $this->webtestLogout();
350
351 //Open Live Contribution Page
352 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
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');
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
377 $this->type('billing_first_name', $firstName);
378 $this->type('billing_last_name', $lastName);
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');
384 $this->clickLink('_qf_Main_upload-bottom', '_qf_Confirm_next-bottom');
385
386 $this->click('_qf_Confirm_next-bottom');
387 $this->waitForPageToLoad($this->getTimeoutMsec());
388
389 //login to check contribution
390
391 // Log in using webtestLogin() method
392 $this->webtestLogin();
393
394 //Find Contribution
395 $this->openCiviPage("contribute/search", "reset=1", 'contribution_date_low');
396
397 $this->type('sort_name', "$firstName $lastName");
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");
400
401 // View Contribution Record and test for expected values
402 $expected = array(
403 'From' => "{$firstName} {$lastName}",
404 'Financial Type' => $financialType,
405 'Net Amount' => '$ 590.00',
406 'Contribution Status' => 'Completed',
407 );
408 $this->webtestVerifyTabularData($expected);
409
410 }
411
412 function testContributeWithDateSpecificPriceSet() {
413 $this->webtestLogin();
414
415 //add financial type of account type expense
416 $financialType = $this->_testAddFinancialType();
417
418 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
419 $usedFor = 'Contribution';
420 $setHelp = 'Select your conference options.';
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.
425 $sid = $this->urlArg('sid');
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
444 $this->openCiviPage("admin/contribute/add", "reset=1&action=add");
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
456 // Submit form
457 $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom");
458
459 // Get contribution page id
460 $pageId = $this->urlArg('id');
461
462 //this contribution page for online contribution
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);
465 $this->clickLink('_qf_Amount_next-bottom');
466
467 //logout
468 $this->webtestLogout();
469
470 //Open Live Contribution Page
471 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
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');
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
495 $this->type('billing_first_name', $firstName);
496 $this->type('billing_last_name', $lastName);
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');
502 $this->clickLink('_qf_Main_upload-bottom', '_qf_Confirm_next-bottom');
503
504 $this->click('_qf_Confirm_next-bottom');
505 $this->waitForPageToLoad($this->getTimeoutMsec());
506
507 //login to check contribution
508 $this->webtestLogin();
509
510 //Find Contribution
511 $this->openCiviPage("contribute/search", "reset=1", 'contribution_date_low');
512
513 $this->type('sort_name', "$firstName $lastName");
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');
516
517 // View Contribution Record and test for expected values
518 $expected = array(
519 'From' => "{$firstName} {$lastName}",
520 'Financial Type' => $financialType,
521 'Net Amount' => '$ 65.00',
522 'Contribution Status' => 'Completed',
523 );
524 $this->webtestVerifyTabularData($expected);
525 }
526
527 function testContributeOfflineforSoftcreditwithApi() {
528 // Log in using webtestLogin() method
529 $this->webtestLogin();
530
531 //create a contact and return the contact id
532 $firstNameSoft = "John_" . substr(sha1(rand()), 0, 5);
533 $lastNameSoft = "Doe_" . substr(sha1(rand()), 0, 5);
534 $this->webtestAddContact($firstNameSoft, $lastNameSoft);
535 $url = $this->parseURL();
536 $cid = $url['queryString']['cid'];
537 $this->assertType('numeric', $cid);
538
539 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
540 $usedFor = 'Contribution';
541 $setHelp = 'Select your conference options.';
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.
547 $sid = $this->urlArg('sid');
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
562 $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", '_qf_Contribution_upload');
563
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');
585 $this->type('check_number', '1041');
586
587 $this->type('trxn_id', 'P20901X1' . rand(100, 10000));
588
589 $this->webtestFillAutocomplete("{$lastNameSoft}, {$firstNameSoft}", 'soft_credit_contact_1');
590
591 //Additional Detail section
592 $this->click('AdditionalDetail');
593 $this->waitForElementPresent('thankyou_date');
594
595 $this->type('note', 'This is a test note.');
596 $this->type('invoice_id', time());
597 $this->webtestFillDate('thankyou_date');
598
599 // Clicking save.
600 $this->clickLink('_qf_Contribution_upload', "xpath=//div[@id='Contributions']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
601 $this->assertTrue($this->isTextPresent('The contribution record has been saved.'), "Status message didn't show up after saving!");
602
603 //click through to the Contribution view screen
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
607 // View Contribution Record and test for expected values
608 $expected = array(
609 'From' => "{$firstName} Contributor",
610 'Financial Type' => $financialType,
611 'Contribution Amount' => 'Contribution Total: $ 590.00',
612 'Paid By' => 'Check',
613 'Check Number' => '1041',
614 'Contribution Status' => 'Completed',
615 'Soft Credit To' => "$firstNameSoft $lastNameSoft",
616 );
617 $this->webtestVerifyTabularData($expected);
618
619 $exp = array(
620 2 => '$ 525.00',
621 3 => '$ 50.00',
622 4 => '$ 15.00',
623 );
624
625 foreach ($exp as $lab => $val) {
626 $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[$lab]/td[3]",
627 preg_quote($val)
628 );
629 }
630
631 // Check for Soft contact created
632 $this->click("css=input#sort_name_navigation");
633 $this->type("css=input#sort_name_navigation", "$lastNameSoft, $firstNameSoft");
634 $this->typeKeys("css=input#sort_name_navigation", "$lastNameSoft, $firstNameSoft");
635 // wait for result list
636 $this->waitForElementPresent("css=div.ac_results-inner li");
637
638 // visit contact summary page
639 $this->click("css=div.ac_results-inner li");
640 $this->waitForPageToLoad($this->getTimeoutMsec());
641 $this->click('css=li#tab_contribute a');
642 $this->waitForElementPresent('link=Record Contribution (Check, Cash, EFT ...)');
643
644 $id = explode('id=', $this->getAttribute("xpath=id('rowid')/td[7]/a[text()='View']@href"));
645 $id = substr($id[1], 0, strpos($id[1], '&'));
646 $this->click("xpath=id('rowid')/td[7]/a");
647 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
648
649 $this->webtestVerifyTabularData($expected);
650
651 $params = array(
652 'contribution_id' => $id,
653 'version' => 3,
654 );
655
656 // Retrieve contribution from the DB via api and verify DB values against view contribution page
657 require_once 'api/api.php';
658 $fields = $this->webtest_civicrm_api('contribution', 'get', $params);
659
660 $params['id'] = $params['contact_id'] = $fields['values'][$fields['id']]['soft_credit_to'];
661 $softCreditContact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, TRUE);
662
663 // View Contribution Record and test for expected values
664 $expected = array(
665 'From' => $fields['values'][$fields['id']]['display_name'],
666 'Financial Type' => $fields['values'][$fields['id']]['financial_type'],
667 'Contribution Amount' => $fields['values'][$fields['id']]['total_amount'],
668 'Contribution Status' => $fields['values'][$fields['id']]['contribution_status'],
669 'Paid By' => $fields['values'][$fields['id']]['contribution_payment_instrument'],
670 'Check Number' => $fields['values'][$fields['id']]['contribution_check_number'],
671 'Soft Credit To' => $softCreditContact->display_name,
672 );
673 $this->webtestVerifyTabularData($expected);
674 }
675 }
676