Merge pull request #4188 from colemanw/Race-condition
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / AddPricesetTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28
29 /**
30 * Class WebTest_Contribute_AddPricesetTest
31 */
32 class 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 $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 $firstName = substr(sha1(rand()), 0, 7);
246 $this->webtestNewDialogContact($firstName, 'Contributor', $firstName . '@example.com');
247
248 // select financial type
249 $this->select('financial_type_id', "label={$financialType}");
250
251 // fill in Received Date
252 $this->webtestFillDate('receive_date');
253
254 // source
255 $this->type('source', 'Mailer 1');
256
257 // select price set items
258 $this->select('price_set_id', "label=$setTitle");
259 $this->type("xpath=//input[@class='four crm-form-text required']", "1");
260 $this->click("xpath=//input[@class='crm-form-radio']");
261 $this->click("xpath=//input[@class='crm-form-checkbox']");
262 // select payment instrument type = Check and enter chk number
263 $this->select('payment_instrument_id', 'value=4');
264 $this->waitForElementPresent('check_number');
265 $this->type('check_number', 'check #1041');
266
267 $this->type('trxn_id', 'P20901X1' . rand(100, 10000));
268
269 //Additional Detail section
270 $this->click('AdditionalDetail');
271 $this->waitForElementPresent('thankyou_date');
272
273 $this->type('note', 'This is a test note.');
274 $this->type('non_deductible_amount', '10');
275 $this->type('fee_amount', '0');
276 $this->type('net_amount', '0');
277 $this->type('invoice_id', time());
278 $this->webtestFillDate('thankyou_date');
279
280 // Clicking save.
281 $this->click('_qf_Contribution_upload');
282 $this->waitForPageToLoad($this->getTimeoutMsec());
283
284 // Is status message correct?
285 $this->assertTrue($this->isTextPresent('The contribution record has been saved.'), "Status message didn't show up after saving!");
286
287 $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']");
288
289 //click through to the Membership view screen
290 $this->click("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']");
291 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
292 $expected = array(
293 2 => $financialType,
294 3 => '590.00',
295 9 => 'Completed',
296 10 => 'Check',
297 11 => 'check #1041',
298 );
299 foreach ($expected as $label => $value) {
300 $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[$label]/td[2]", preg_quote($value));
301 }
302
303 $exp = array(
304 2 => '$ 525.00',
305 3 => '$ 50.00',
306 4 => '$ 15.00',
307 );
308
309 foreach ($exp as $lab => $val) {
310 $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[$lab]/td[3]",
311 preg_quote($val)
312 );
313 }
314 }
315
316 function testContributeOnlineWithPriceSet() {
317 $this->webtestLogin();
318
319 //add financial type of account type expense
320 $financialType = $this->_testAddFinancialType();
321
322 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
323 $usedFor = 'Contribution';
324 $setHelp = 'Select your conference options.';
325 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
326
327 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
328 // which is where we are after adding Price Set.
329 $sid = $this->urlArg('sid');
330 $this->assertType('numeric', $sid);
331
332 $validStrings = array();
333 $fields = array(
334 'Full Conference' => 'Text',
335 'Meal Choice' => 'Select',
336 'Pre-conference Meetup?' => 'Radio',
337 'Evening Sessions' => 'CheckBox',
338 );
339
340 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
341
342 // load the Price Set Preview and check for expected values
343 $this->_testVerifyPriceSet($validateStrings, $sid);
344
345 // Use default payment processor
346 $processorName = 'Test Processor';
347 $this->webtestAddPaymentProcessor($processorName);
348
349 $this->openCiviPage("admin/contribute/add", "reset=1&action=add");
350
351 $contributionTitle = substr(sha1(rand()), 0, 7);
352 $rand = 2 * rand(2, 50);
353
354 // fill in step 1 (Title and Settings)
355 $contributionPageTitle = "Title $contributionTitle";
356 $this->type('title', $contributionPageTitle);
357 $this->fillRichTextField('intro_text', 'This is Test Introductory Message', 'CKEditor');
358 $this->fillRichTextField('footer_text', 'This is Test Footer Message', 'CKEditor');
359
360 $this->select('financial_type_id', "label={$financialType}");
361
362 // Submit form
363 $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom");
364
365 // Get contribution page id
366 $pageId = $this->urlArg('id');
367
368 //this contribution page for online contribution
369 $this->click("xpath=//tr[@class='crm-contribution-contributionpage-amount-form-block-payment_processor']/td/label[text()='$processorName']");
370 $this->select('price_set_id', 'label=' . $setTitle);
371 $this->click('_qf_Amount_next-bottom');
372 $this->waitForPageToLoad($this->getTimeoutMsec());
373
374 //logout
375 $this->webtestLogout();
376
377 //Open Live Contribution Page
378 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
379
380 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
381 $lastName = 'An' . substr(sha1(rand()), 0, 7);
382 $this->waitForElementPresent('_qf_Main_upload-bottom');
383 $this->type('email-5', $firstName . '@example.com');
384 $this->type("xpath=//input[@class='four crm-form-text required']", "1");
385 $this->click("xpath=//input[@class='crm-form-radio']");
386 $this->click("xpath=//input[@class='crm-form-checkbox']");
387
388 $streetAddress = '100 Main Street';
389 $this->type('billing_street_address-5', $streetAddress);
390 $this->type('billing_city-5', 'San Francisco');
391 $this->type('billing_postal_code-5', '94117');
392 $this->select('billing_country_id-5', 'value=1228');
393 $this->select('billing_state_province_id-5', 'value=1001');
394
395 //Credit Card Info
396 $this->select('credit_card_type', 'value=Visa');
397 $this->type('credit_card_number', '4111111111111111');
398 $this->type('cvv2', '000');
399 $this->select('credit_card_exp_date[M]', 'value=1');
400 $this->select('credit_card_exp_date[Y]', 'value=2020');
401
402 //Billing Info
403 $this->type('billing_first_name', $firstName);
404 $this->type('billing_last_name', $lastName);
405 $this->type('billing_street_address-5', '15 Main St.');
406 $this->type('billing_city-5', 'San Jose');
407 $this->select('billing_country_id-5', 'value=1228');
408 $this->select('billing_state_province_id-5', 'value=1004');
409 $this->type('billing_postal_code-5', '94129');
410 $this->clickLink('_qf_Main_upload-bottom', '_qf_Confirm_next-bottom');
411
412 $this->click('_qf_Confirm_next-bottom');
413 $this->waitForPageToLoad($this->getTimeoutMsec());
414
415 //login to check contribution
416
417 // Log in using webtestLogin() method
418 $this->webtestLogin();
419
420 //Find Contribution
421 $this->openCiviPage("contribute/search", "reset=1", 'contribution_date_low');
422
423 $this->type('sort_name', "$firstName $lastName");
424 $this->clickLink('_qf_Search_refresh', "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
425 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
426
427 // View Contribution Record and test for expected values
428 $expected = array(
429 'From' => "{$firstName} {$lastName}",
430 'Financial Type' => $financialType,
431 'Net Amount' => '$ 590.00',
432 'Contribution Status' => 'Completed',
433 );
434 $this->webtestVerifyTabularData($expected);
435
436 }
437
438 function testContributeWithDateSpecificPriceSet() {
439 $this->webtestLogin();
440
441 //add financial type of account type expense
442 $financialType = $this->_testAddFinancialType();
443
444 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
445 $usedFor = 'Contribution';
446 $setHelp = 'Select your conference options.';
447 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
448
449 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
450 // which is where we are after adding Price Set.
451 $sid = $this->urlArg('sid');
452 $this->assertType('numeric', $sid);
453
454 $validStrings = array();
455 $fields = array(
456 'Full Conference' => 'Text',
457 'Meal Choice' => 'Select',
458 'Pre-conference Meetup?' => 'Radio',
459 'Evening Sessions' => 'CheckBox',
460 );
461 $this->_testAddPriceFields($fields, $validateStrings, $financialType, TRUE);
462
463 // load the Price Set Preview and check for expected values
464 $this->_testVerifyPriceSet($validateStrings, $sid);
465
466 // Use default payment processor
467 $processorName = 'Test Processor';
468 $this->webtestAddPaymentProcessor($processorName);
469
470 $this->openCiviPage("admin/contribute/add", "reset=1&action=add");
471
472 $contributionTitle = substr(sha1(rand()), 0, 7);
473 $rand = 2 * rand(2, 50);
474
475 // fill in step 1 (Title and Settings)
476 $contributionPageTitle = "Title $contributionTitle";
477 $this->type('title', $contributionPageTitle);
478 $this->select('financial_type_id', "label={$financialType}");
479 $this->fillRichTextField('intro_text', 'This is Test Introductory Message', 'CKEditor');
480 $this->fillRichTextField('footer_text', 'This is Test Footer Message', 'CKEditor');
481
482 // Submit form
483 $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom");
484
485 // Get contribution page id
486 $pageId = $this->urlArg('id');
487
488 //this contribution page for online contribution
489 $this->click("xpath=//tr[@class='crm-contribution-contributionpage-amount-form-block-payment_processor']/td/label[text()='$processorName']");
490 $this->select('price_set_id', 'label=' . $setTitle);
491 $this->clickLink('_qf_Amount_next-bottom');
492
493 //logout
494 $this->webtestLogout();
495
496 //Open Live Contribution Page
497 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
498
499 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
500 $lastName = 'An' . substr(sha1(rand()), 0, 7);
501 $this->waitForElementPresent('_qf_Main_upload-bottom');
502 $this->type('email-5', $firstName . '@example.com');
503 $this->click("xpath=//input[@class='crm-form-radio']");
504 $this->click("xpath=//input[@class='crm-form-checkbox']");
505
506 $streetAddress = '100 Main Street';
507 $this->type('billing_street_address-5', $streetAddress);
508 $this->type('billing_city-5', 'San Francisco');
509 $this->type('billing_postal_code-5', '94117');
510 $this->select('billing_country_id-5', 'value=1228');
511 $this->select('billing_state_province_id-5', 'value=1001');
512
513 //Credit Card Info
514 $this->select('credit_card_type', 'value=Visa');
515 $this->type('credit_card_number', '4111111111111111');
516 $this->type('cvv2', '000');
517 $this->select('credit_card_exp_date[M]', 'value=1');
518 $this->select('credit_card_exp_date[Y]', 'value=2020');
519
520 //Billing Info
521 $this->type('billing_first_name', $firstName);
522 $this->type('billing_last_name', $lastName);
523 $this->type('billing_street_address-5', '15 Main St.');
524 $this->type(' billing_city-5', 'San Jose');
525 $this->select('billing_country_id-5', 'value=1228');
526 $this->select('billing_state_province_id-5', 'value=1004');
527 $this->type('billing_postal_code-5', '94129');
528 $this->clickLink('_qf_Main_upload-bottom', '_qf_Confirm_next-bottom');
529
530 $this->click('_qf_Confirm_next-bottom');
531 $this->waitForPageToLoad($this->getTimeoutMsec());
532
533 //login to check contribution
534 $this->webtestLogin();
535
536 //Find Contribution
537 $this->openCiviPage("contribute/search", "reset=1", 'contribution_date_low');
538
539 $this->type('sort_name', "$firstName $lastName");
540 $this->clickLink('_qf_Search_refresh', "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", FALSE);
541 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", '_qf_ContributionView_cancel-bottom', FALSE);
542
543 // View Contribution Record and test for expected values
544 $expected = array(
545 'From' => "{$firstName} {$lastName}",
546 'Financial Type' => $financialType,
547 'Net Amount' => '$ 65.00',
548 'Contribution Status' => 'Completed',
549 );
550 $this->webtestVerifyTabularData($expected);
551 }
552
553 function testContributeOfflineforSoftcreditwithApi() {
554 // Log in using webtestLogin() method
555 $this->webtestLogin();
556
557 //create a contact and return the contact id
558 $firstNameSoft = "John_" . substr(sha1(rand()), 0, 5);
559 $lastNameSoft = "Doe_" . substr(sha1(rand()), 0, 5);
560 $this->webtestAddContact($firstNameSoft, $lastNameSoft);
561 $url = $this->parseURL();
562 $cid = $url['queryString']['cid'];
563 $this->assertType('numeric', $cid);
564
565 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
566 $usedFor = 'Contribution';
567 $setHelp = 'Select your conference options.';
568 $financialType = $this->_testAddFinancialType();
569 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
570
571 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
572 // which is where we are after adding Price Set.
573 $sid = $this->urlArg('sid');
574 $this->assertType('numeric', $sid);
575
576 $validStrings = array();
577 $fields = array(
578 'Full Conference' => 'Text',
579 'Meal Choice' => 'Select',
580 'Pre-conference Meetup?' => 'Radio',
581 'Evening Sessions' => 'CheckBox',
582 );
583 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
584
585 // load the Price Set Preview and check for expected values
586 $this->_testVerifyPriceSet($validateStrings, $sid);
587
588 $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", '_qf_Contribution_upload');
589
590 // create new contact using dialog
591 $firstName = substr(sha1(rand()), 0, 7);
592 $this->webtestNewDialogContact($firstName, 'Contributor', $firstName . '@example.com');
593
594 // select contribution type
595 $this->select('financial_type_id', "label={$financialType}");
596
597 // fill in Received Date
598 $this->webtestFillDate('receive_date');
599
600 // source
601 $this->type('source', 'Mailer 1');
602
603 // select price set items
604 $this->select('price_set_id', "label=$setTitle");
605 $this->type("xpath=//input[@class='four crm-form-text required']", "1");
606 $this->click("xpath=//input[@class='crm-form-radio']");
607 $this->click("xpath=//input[@class='crm-form-checkbox']");
608 // select payment instrument type = Check and enter chk number
609 $this->select('payment_instrument_id', 'value=4');
610 $this->waitForElementPresent('check_number');
611 $this->type('check_number', '1041');
612
613 $this->type('trxn_id', 'P20901X1' . rand(100, 10000));
614
615 $this->webtestFillAutocomplete("{$lastNameSoft}, {$firstNameSoft}", 'soft_credit_contact_id_1');
616
617 $this->type('soft_credit_amount_1', "65");
618 //Additional Detail section
619 $this->click('AdditionalDetail');
620 $this->waitForElementPresent('thankyou_date');
621
622 $this->type('note', 'This is a test note.');
623 $this->type('invoice_id', time());
624 $this->webtestFillDate('thankyou_date');
625
626 // Clicking save.
627 $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);
628 $this->assertTrue($this->isTextPresent('The contribution record has been saved.'), "Status message didn't show up after saving!");
629
630 //click through to the Contribution view screen
631 $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']");
632 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
633
634 // View Contribution Record and test for expected values
635 $expected = array(
636 'From' => "{$firstName} Contributor",
637 'Financial Type' => $financialType,
638 'Contribution Amount' => 'Contribution Total: $ 590.00',
639 'Paid By' => 'Check',
640 'Check Number' => '1041',
641 'Contribution Status' => 'Completed',
642 );
643 $this->webtestVerifyTabularData($expected);
644
645 $exp = array(
646 2 => '$ 525.00',
647 3 => '$ 50.00',
648 4 => '$ 15.00',
649 );
650
651 foreach ($exp as $lab => $val) {
652 $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[$lab]/td[3]",
653 preg_quote($val)
654 );
655 }
656
657 // verify if soft credit was created successfully
658 $softCreditValues = array(
659 'Soft Credit To' => "{$firstNameSoft} {$lastNameSoft}",
660 'Amount' => '65.00',
661 );
662
663 foreach ($softCreditValues as $value) {
664 $this->verifyText("css=table.crm-soft-credit-listing", preg_quote($value));
665 }
666
667 // Check for Soft contact created
668 $this->click("css=input#sort_name_navigation");
669 $this->type("css=input#sort_name_navigation", "$lastNameSoft, $firstNameSoft");
670 $this->typeKeys("css=input#sort_name_navigation", "$lastNameSoft, $firstNameSoft");
671 // wait for result list
672 $this->waitForElementPresent("css=ul.ui-autocomplete li");
673
674 // visit contact summary page
675 $this->click("css=ul.ui-autocomplete li");
676 $this->waitForPageToLoad($this->getTimeoutMsec());
677 $this->click('css=li#tab_contribute a');
678 $this->waitForElementPresent('link=Record Contribution (Check, Cash, EFT ...)');
679
680 $id = explode('id=', $this->getAttribute("xpath=//table[@class='selector row-highlight']/tbody//tr[@id='rowid']/td[8]/a[text()='View']@href"));
681 $id = substr($id[1], 0, strpos($id[1], '&'));
682 $this->click("xpath=//table[@class='selector row-highlight']/tbody//tr[@id='rowid']/td[8]/a");
683 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
684
685 $this->webtestVerifyTabularData($expected);
686
687 $params = array(
688 'contribution_id' => $id,
689 'version' => 3,
690 );
691
692 // Retrieve contribution from the DB via api and verify DB values against view contribution page
693 require_once 'api/api.php';
694 $fields = $this->webtest_civicrm_api('contribution', 'get', $params);
695
696 $params['id'] = $params['contact_id'] = $fields['values'][$fields['id']]['soft_credit_to'];
697 $softCreditContact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, TRUE);
698
699 // View Contribution Record and test for expected values
700 $expected = array(
701 'From' => $fields['values'][$fields['id']]['display_name'],
702 'Financial Type' => $fields['values'][$fields['id']]['financial_type'],
703 'Contribution Amount' => $fields['values'][$fields['id']]['total_amount'],
704 'Contribution Status' => $fields['values'][$fields['id']]['contribution_status'],
705 'Paid By' => $fields['values'][$fields['id']]['contribution_payment_instrument'],
706 'Check Number' => $fields['values'][$fields['id']]['contribution_check_number'],
707 );
708
709 $this->webtestVerifyTabularData($expected);
710
711 // verify if soft credit
712 $softCreditValues = array(
713 'Soft Credit To' => $softCreditContact->display_name,
714 'Amount' => '65.00',
715 );
716
717 foreach ($softCreditValues as $value) {
718 $this->verifyText("css=table.crm-soft-credit-listing", preg_quote($value));
719 }
720 }
721 }
722