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