Merge pull request #11877 from compucorp/CRM-21853-remove-implicit-is-multiple-change
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / AddPricesetTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
2fe49090 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
8c9251b3 6 | Copyright CiviCRM LLC (c) 2004-2018 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 25 */
6a488035 26
6a488035 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Contribute_AddPricesetTest
31 */
6a488035
TO
32class WebTest_Contribute_AddPricesetTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
76e86fd8 37
00be9182 38 public function testAddPriceSet() {
6a488035
TO
39 // Log in using webtestLogin() method
40 $this->webtestLogin();
41
42 //add financial type of account type expense
76e86fd8 43
6a488035
TO
44 $financialType = $this->_testAddFinancialType();
45
46 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
42daf119
CW
47 $usedFor = 'Contribution';
48 $setHelp = 'Select your conference options.';
6a488035
TO
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.
a471a3b6 53 $sid = $this->urlArg('sid');
6a488035
TO
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 );
d1c1ddc7 64 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
6a488035
TO
65 // var_dump($validateStrings);
66
67 // load the Price Set Preview and check for expected values
68 $this->_testVerifyPriceSet($validateStrings, $sid);
69 }
70
4cbe18b8
EM
71 /**
72 * @return string
73 */
00be9182 74 public function _testAddFinancialType() {
6a488035 75 //Add new Financial Type
d1c1ddc7 76 $financialType['name'] = 'FinancialType ' . substr(sha1(rand()), 0, 4);
6a488035
TO
77 $financialType['is_deductible'] = TRUE;
78 $financialType['is_reserved'] = FALSE;
79 $this->addeditFinancialType($financialType);
6a488035
TO
80 return $financialType['name'];
81 }
76e86fd8 82
4cbe18b8
EM
83 /**
84 * @param $validateStrings
100fef9d 85 * @param int $sid
4cbe18b8 86 */
00be9182 87 public function _testVerifyPriceSet($validateStrings, $sid) {
6a488035
TO
88 // verify Price Set at Preview page
89 // start at Manage Price Sets listing
071a6d2e 90 $this->openCiviPage("admin/price", "reset=1");
6a488035
TO
91
92 // Use the price set id ($sid) to pick the correct row
c1d1bf14 93 $this->clickLink("//*[@id='price_set-{$sid}']/td[4]/span[1]/a[1]", 'Link=Add Price Field');
6a488035
TO
94 // Check for expected price set field strings
95 $this->assertStringsPresent($validateStrings);
96 }
97
00be9182 98 public function testContributeOfflineWithPriceSet() {
6a488035
TO
99 // Log in using webtestLogin() method
100 $this->webtestLogin();
101
102 //add financial type of account type expense
103 $financialType = $this->_testAddFinancialType();
76e86fd8 104
6a488035 105 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
42daf119
CW
106 $usedFor = 'Contribution';
107 $setHelp = 'Select your conference options.';
6a488035 108 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
76e86fd8 109
6a488035
TO
110 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
111 // which is where we are after adding Price Set.
a471a3b6 112 $sid = $this->urlArg('sid');
6a488035
TO
113 $this->assertType('numeric', $sid);
114
115 $validStrings = array();
116 $fields = array(
117 'Full Conference' => 'Text',
118 'Meal Choice' => 'Select',
119 'Pre-conference Meetup?' => 'Radio',
120 'Evening Sessions' => 'CheckBox',
121 );
122 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
123
124 // load the Price Set Preview and check for expected values
125 $this->_testVerifyPriceSet($validateStrings, $sid);
42daf119 126 $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", '_qf_Contribution_upload');
6a488035 127
6a488035 128 // create new contact using dialog
80f3b91d 129 $this->createDialogContact();
6a488035
TO
130
131 // select financial type
132 $this->select('financial_type_id', "label={$financialType}");
133
134 // fill in Received Date
135 $this->webtestFillDate('receive_date');
136
137 // source
138 $this->type('source', 'Mailer 1');
139
140 // select price set items
141 $this->select('price_set_id', "label=$setTitle");
77a2a633 142 $this->type("xpath=//input[@class='four crm-form-text required']", "1");
143 $this->click("xpath=//input[@class='crm-form-radio']");
144 $this->click("xpath=//input[@class='crm-form-checkbox']");
6a488035
TO
145 // select payment instrument type = Check and enter chk number
146 $this->select('payment_instrument_id', 'value=4');
147 $this->waitForElementPresent('check_number');
148 $this->type('check_number', 'check #1041');
149
150 $this->type('trxn_id', 'P20901X1' . rand(100, 10000));
151
152 //Additional Detail section
153 $this->click('AdditionalDetail');
154 $this->waitForElementPresent('thankyou_date');
155
156 $this->type('note', 'This is a test note.');
157 $this->type('non_deductible_amount', '10');
158 $this->type('fee_amount', '0');
159 $this->type('net_amount', '0');
160 $this->type('invoice_id', time());
161 $this->webtestFillDate('thankyou_date');
162
163 // Clicking save.
164 $this->click('_qf_Contribution_upload');
165 $this->waitForPageToLoad($this->getTimeoutMsec());
166
167 // Is status message correct?
168 $this->assertTrue($this->isTextPresent('The contribution record has been saved.'), "Status message didn't show up after saving!");
deeea38d 169 $this->waitForElementPresent("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span//a[text()='View']");
6a488035
TO
170
171 //click through to the Membership view screen
deeea38d 172 $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span//a[text()='View']");
6a488035
TO
173 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
174 $expected = array(
175 2 => $financialType,
176 3 => '590.00',
177 9 => 'Completed',
178 10 => 'Check',
179 11 => 'check #1041',
180 );
181 foreach ($expected as $label => $value) {
b02d5792 182 $this->assertElementContainsText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[$label]/td[2]", $value);
6a488035
TO
183 }
184
185 $exp = array(
186 2 => '$ 525.00',
187 3 => '$ 50.00',
188 4 => '$ 15.00',
189 );
190
191 foreach ($exp as $lab => $val) {
b02d5792 192 $this->assertElementContainsText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[$lab]/td[3]", $val);
6a488035
TO
193 }
194 }
195
00be9182 196 public function testContributeOnlineWithPriceSet() {
6a488035
TO
197 $this->webtestLogin();
198
199 //add financial type of account type expense
200 $financialType = $this->_testAddFinancialType();
6d5f1345 201
6a488035 202 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
42daf119
CW
203 $usedFor = 'Contribution';
204 $setHelp = 'Select your conference options.';
6a488035
TO
205 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
206
207 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
208 // which is where we are after adding Price Set.
a471a3b6 209 $sid = $this->urlArg('sid');
6a488035
TO
210 $this->assertType('numeric', $sid);
211
212 $validStrings = array();
213 $fields = array(
214 'Full Conference' => 'Text',
215 'Meal Choice' => 'Select',
216 'Pre-conference Meetup?' => 'Radio',
217 'Evening Sessions' => 'CheckBox',
218 );
76e86fd8 219
6a488035 220 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
76e86fd8 221
6a488035
TO
222 // load the Price Set Preview and check for expected values
223 $this->_testVerifyPriceSet($validateStrings, $sid);
224
c3ad8633
CW
225 // Use default payment processor
226 $processorName = 'Test Processor';
6a488035
TO
227 $this->webtestAddPaymentProcessor($processorName);
228
071a6d2e 229 $this->openCiviPage("admin/contribute/add", "reset=1&action=add");
6a488035
TO
230
231 $contributionTitle = substr(sha1(rand()), 0, 7);
232 $rand = 2 * rand(2, 50);
233
234 // fill in step 1 (Title and Settings)
235 $contributionPageTitle = "Title $contributionTitle";
236 $this->type('title', $contributionPageTitle);
237 $this->fillRichTextField('intro_text', 'This is Test Introductory Message', 'CKEditor');
238 $this->fillRichTextField('footer_text', 'This is Test Footer Message', 'CKEditor');
239
240 $this->select('financial_type_id', "label={$financialType}");
b45c587e
CW
241
242 // Submit form
243 $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom");
244
245 // Get contribution page id
246 $pageId = $this->urlArg('id');
6a488035
TO
247
248 //this contribution page for online contribution
6a488035
TO
249 $this->click("xpath=//tr[@class='crm-contribution-contributionpage-amount-form-block-payment_processor']/td/label[text()='$processorName']");
250 $this->select('price_set_id', 'label=' . $setTitle);
251 $this->click('_qf_Amount_next-bottom');
252 $this->waitForPageToLoad($this->getTimeoutMsec());
253
6a488035 254 //logout
42daf119 255 $this->webtestLogout();
6a488035
TO
256
257 //Open Live Contribution Page
f1224701 258 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId&action=preview", '_qf_Main_upload-bottom');
6a488035
TO
259
260 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
261 $lastName = 'An' . substr(sha1(rand()), 0, 7);
08936462 262 $email = $firstName . "@example.com";
6a488035 263 $this->waitForElementPresent('_qf_Main_upload-bottom');
08936462 264 $this->type("email-5", $email);
77a2a633 265 $this->type("xpath=//input[@class='four crm-form-text required']", "1");
266 $this->click("xpath=//input[@class='crm-form-radio']");
267 $this->click("xpath=//input[@class='crm-form-checkbox']");
6a488035
TO
268
269 $streetAddress = '100 Main Street';
270 $this->type('billing_street_address-5', $streetAddress);
271 $this->type('billing_city-5', 'San Francisco');
272 $this->type('billing_postal_code-5', '94117');
deeea38d 273 $this->waitForAjaxContent();
6a488035
TO
274 $this->select('billing_country_id-5', 'value=1228');
275 $this->select('billing_state_province_id-5', 'value=1001');
276
277 //Credit Card Info
278 $this->select('credit_card_type', 'value=Visa');
279 $this->type('credit_card_number', '4111111111111111');
280 $this->type('cvv2', '000');
281 $this->select('credit_card_exp_date[M]', 'value=1');
282 $this->select('credit_card_exp_date[Y]', 'value=2020');
283
284 //Billing Info
0054ead7
DG
285 $this->type('billing_first_name', $firstName);
286 $this->type('billing_last_name', $lastName);
6a488035
TO
287 $this->type('billing_street_address-5', '15 Main St.');
288 $this->type('billing_city-5', 'San Jose');
289 $this->select('billing_country_id-5', 'value=1228');
290 $this->select('billing_state_province_id-5', 'value=1004');
291 $this->type('billing_postal_code-5', '94129');
225a8648 292 $this->clickLink('_qf_Main_upload-bottom', '_qf_Confirm_next-bottom');
6a488035
TO
293
294 $this->click('_qf_Confirm_next-bottom');
295 $this->waitForPageToLoad($this->getTimeoutMsec());
296
297 //login to check contribution
6a488035
TO
298
299 // Log in using webtestLogin() method
300 $this->webtestLogin();
301
302 //Find Contribution
42daf119 303 $this->openCiviPage("contribute/search", "reset=1", 'contribution_date_low');
6a488035 304
f1224701 305 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
08936462
WA
306 $this->type("sort_name", "$email");
307 $this->waitForAjaxContent();
308 $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]");
deeea38d
WA
309 $this->clickLink('_qf_Search_refresh', "xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']");
310 $this->clickLink("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
6a488035 311
0054ead7 312 // View Contribution Record and test for expected values
6a488035 313 $expected = array(
35f01dcb 314 'From' => "{$firstName} {$lastName}",
42daf119 315 'Financial Type' => $financialType,
687bced0 316 // as per changes made in CRM-15407
317 'Fee Amount' => '$ 1.50',
318 'Net Amount' => '$ 588.50',
0054ead7 319 'Contribution Status' => 'Completed',
6a488035 320 );
0054ead7
DG
321 $this->webtestVerifyTabularData($expected);
322
6a488035
TO
323 }
324
00be9182 325 public function testContributeWithDateSpecificPriceSet() {
6a488035
TO
326 $this->webtestLogin();
327
328 //add financial type of account type expense
d1c1ddc7 329 $financialType = $this->_testAddFinancialType();
76e86fd8 330
6a488035 331 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
42daf119
CW
332 $usedFor = 'Contribution';
333 $setHelp = 'Select your conference options.';
6a488035
TO
334 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
335
336 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
337 // which is where we are after adding Price Set.
a471a3b6 338 $sid = $this->urlArg('sid');
6a488035
TO
339 $this->assertType('numeric', $sid);
340
341 $validStrings = array();
342 $fields = array(
343 'Full Conference' => 'Text',
344 'Meal Choice' => 'Select',
345 'Pre-conference Meetup?' => 'Radio',
346 'Evening Sessions' => 'CheckBox',
347 );
348 $this->_testAddPriceFields($fields, $validateStrings, $financialType, TRUE);
349
350 // load the Price Set Preview and check for expected values
351 $this->_testVerifyPriceSet($validateStrings, $sid);
352
c3ad8633
CW
353 // Use default payment processor
354 $processorName = 'Test Processor';
6a488035
TO
355 $this->webtestAddPaymentProcessor($processorName);
356
071a6d2e 357 $this->openCiviPage("admin/contribute/add", "reset=1&action=add");
6a488035
TO
358
359 $contributionTitle = substr(sha1(rand()), 0, 7);
360 $rand = 2 * rand(2, 50);
361
362 // fill in step 1 (Title and Settings)
363 $contributionPageTitle = "Title $contributionTitle";
364 $this->type('title', $contributionPageTitle);
365 $this->select('financial_type_id', "label={$financialType}");
366 $this->fillRichTextField('intro_text', 'This is Test Introductory Message', 'CKEditor');
367 $this->fillRichTextField('footer_text', 'This is Test Footer Message', 'CKEditor');
368
b45c587e
CW
369 // Submit form
370 $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom");
371
372 // Get contribution page id
373 $pageId = $this->urlArg('id');
6a488035
TO
374
375 //this contribution page for online contribution
35f01dcb 376 $this->waitForElementPresent("xpath=//tr[@class='crm-contribution-contributionpage-amount-form-block-payment_processor']/td");
6a488035
TO
377 $this->click("xpath=//tr[@class='crm-contribution-contributionpage-amount-form-block-payment_processor']/td/label[text()='$processorName']");
378 $this->select('price_set_id', 'label=' . $setTitle);
b45c587e 379 $this->clickLink('_qf_Amount_next-bottom');
6a488035
TO
380
381 //logout
42daf119 382 $this->webtestLogout();
6a488035
TO
383
384 //Open Live Contribution Page
f1224701 385 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId&action=preview", '_qf_Main_upload-bottom');
6a488035
TO
386
387 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
388 $lastName = 'An' . substr(sha1(rand()), 0, 7);
08936462 389 $email = $firstName . "@example.com";
6a488035 390 $this->waitForElementPresent('_qf_Main_upload-bottom');
08936462 391 $this->type('email-5', $email);
77a2a633 392 $this->click("xpath=//input[@class='crm-form-radio']");
393 $this->click("xpath=//input[@class='crm-form-checkbox']");
6a488035
TO
394
395 $streetAddress = '100 Main Street';
396 $this->type('billing_street_address-5', $streetAddress);
397 $this->type('billing_city-5', 'San Francisco');
398 $this->type('billing_postal_code-5', '94117');
399 $this->select('billing_country_id-5', 'value=1228');
400 $this->select('billing_state_province_id-5', 'value=1001');
401
402 //Credit Card Info
403 $this->select('credit_card_type', 'value=Visa');
404 $this->type('credit_card_number', '4111111111111111');
405 $this->type('cvv2', '000');
406 $this->select('credit_card_exp_date[M]', 'value=1');
407 $this->select('credit_card_exp_date[Y]', 'value=2020');
408
409 //Billing Info
0054ead7
DG
410 $this->type('billing_first_name', $firstName);
411 $this->type('billing_last_name', $lastName);
6a488035
TO
412 $this->type('billing_street_address-5', '15 Main St.');
413 $this->type(' billing_city-5', 'San Jose');
414 $this->select('billing_country_id-5', 'value=1228');
415 $this->select('billing_state_province_id-5', 'value=1004');
416 $this->type('billing_postal_code-5', '94129');
225a8648 417 $this->clickLink('_qf_Main_upload-bottom', '_qf_Confirm_next-bottom');
6a488035
TO
418
419 $this->click('_qf_Confirm_next-bottom');
420 $this->waitForPageToLoad($this->getTimeoutMsec());
421
422 //login to check contribution
6a488035
TO
423 $this->webtestLogin();
424
425 //Find Contribution
42daf119 426 $this->openCiviPage("contribute/search", "reset=1", 'contribution_date_low');
f1224701 427 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
08936462
WA
428 $this->type("sort_name", "$email");
429 $this->waitForAjaxContent();
430 $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]");
deeea38d
WA
431 $this->clickLink('_qf_Search_refresh', "xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", FALSE);
432 $this->clickLink("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", '_qf_ContributionView_cancel-bottom', FALSE);
6a488035 433
0054ead7 434 // View Contribution Record and test for expected values
6a488035 435 $expected = array(
42daf119
CW
436 'From' => "{$firstName} {$lastName}",
437 'Financial Type' => $financialType,
687bced0 438 // as per changes made in CRM-15407
439 'Fee Amount' => '$ 1.50',
440 'Net Amount' => '$ 63.50',
0054ead7 441 'Contribution Status' => 'Completed',
6a488035 442 );
0054ead7 443 $this->webtestVerifyTabularData($expected);
6a488035
TO
444 }
445
00be9182 446 public function testContributeOfflineforSoftcreditwithApi() {
6a488035
TO
447 // Log in using webtestLogin() method
448 $this->webtestLogin();
76e86fd8 449
6a488035 450 //create a contact and return the contact id
d1c1ddc7 451 $firstNameSoft = "John_" . substr(sha1(rand()), 0, 5);
452 $lastNameSoft = "Doe_" . substr(sha1(rand()), 0, 5);
6a488035
TO
453 $this->webtestAddContact($firstNameSoft, $lastNameSoft);
454 $url = $this->parseURL();
455 $cid = $url['queryString']['cid'];
456 $this->assertType('numeric', $cid);
76e86fd8 457
6a488035 458 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
42daf119
CW
459 $usedFor = 'Contribution';
460 $setHelp = 'Select your conference options.';
6a488035
TO
461 $financialType = $this->_testAddFinancialType();
462 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
463
464 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
465 // which is where we are after adding Price Set.
a471a3b6 466 $sid = $this->urlArg('sid');
6a488035
TO
467 $this->assertType('numeric', $sid);
468
469 $validStrings = array();
470 $fields = array(
471 'Full Conference' => 'Text',
472 'Meal Choice' => 'Select',
473 'Pre-conference Meetup?' => 'Radio',
474 'Evening Sessions' => 'CheckBox',
475 );
476 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
477
478 // load the Price Set Preview and check for expected values
479 $this->_testVerifyPriceSet($validateStrings, $sid);
480
42daf119 481 $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", '_qf_Contribution_upload');
6a488035 482
6a488035 483 // create new contact using dialog
80f3b91d 484 $contact = $this->createDialogContact();
6a488035
TO
485
486 // select contribution type
487 $this->select('financial_type_id', "label={$financialType}");
488
489 // fill in Received Date
490 $this->webtestFillDate('receive_date');
491
492 // source
493 $this->type('source', 'Mailer 1');
494
495 // select price set items
496 $this->select('price_set_id', "label=$setTitle");
215ed9aa 497 $this->type("xpath=//input[@class='four crm-form-text required']", "1");
77a2a633 498 $this->click("xpath=//input[@class='crm-form-radio']");
499 $this->click("xpath=//input[@class='crm-form-checkbox']");
6a488035
TO
500 // select payment instrument type = Check and enter chk number
501 $this->select('payment_instrument_id', 'value=4');
502 $this->waitForElementPresent('check_number');
0054ead7 503 $this->type('check_number', '1041');
6a488035
TO
504
505 $this->type('trxn_id', 'P20901X1' . rand(100, 10000));
76e86fd8 506
77a2a633 507 $this->webtestFillAutocomplete("{$lastNameSoft}, {$firstNameSoft}", 'soft_credit_contact_id_1');
13dff995 508
215ed9aa 509 $this->type('soft_credit_amount_1', "65");
6a488035
TO
510 //Additional Detail section
511 $this->click('AdditionalDetail');
512 $this->waitForElementPresent('thankyou_date');
513
514 $this->type('note', 'This is a test note.');
6a488035
TO
515 $this->type('invoice_id', time());
516 $this->webtestFillDate('thankyou_date');
517
518 // Clicking save.
deeea38d 519 $this->clickLink('_qf_Contribution_upload', "xpath=//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span//a[text()='View']", FALSE);
0054ead7 520 $this->assertTrue($this->isTextPresent('The contribution record has been saved.'), "Status message didn't show up after saving!");
6a488035 521
0054ead7 522 //click through to the Contribution view screen
77a2a633 523 $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']");
6a488035
TO
524 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
525
0054ead7 526 // View Contribution Record and test for expected values
6a488035 527 $expected = array(
80f3b91d 528 'From' => $contact['display_name'],
42daf119 529 'Financial Type' => $financialType,
0054ead7 530 'Contribution Amount' => 'Contribution Total: $ 590.00',
4db803dd 531 'Payment Method' => 'Check',
42daf119 532 'Check Number' => '1041',
0054ead7 533 'Contribution Status' => 'Completed',
6a488035 534 );
0054ead7 535 $this->webtestVerifyTabularData($expected);
76e86fd8 536
6a488035
TO
537 $exp = array(
538 2 => '$ 525.00',
539 3 => '$ 50.00',
540 4 => '$ 15.00',
541 );
542
543 foreach ($exp as $lab => $val) {
b02d5792 544 $this->assertElementContainsText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[$lab]/td[3]", $val);
6a488035 545 }
0054ead7 546
c2768486 547 // verify if soft credit was created successfully
548 $softCreditValues = array(
549 'Soft Credit To' => "{$firstNameSoft} {$lastNameSoft}",
550 'Amount' => '65.00',
551 );
552
553 foreach ($softCreditValues as $value) {
b02d5792 554 $this->assertElementContainsText("css=table.crm-soft-credit-listing", $value);
c2768486 555 }
556
6a488035
TO
557 // Check for Soft contact created
558 $this->click("css=input#sort_name_navigation");
559 $this->type("css=input#sort_name_navigation", "$lastNameSoft, $firstNameSoft");
560 $this->typeKeys("css=input#sort_name_navigation", "$lastNameSoft, $firstNameSoft");
561 // wait for result list
77a2a633 562 $this->waitForElementPresent("css=ul.ui-autocomplete li");
76e86fd8 563
6a488035 564 // visit contact summary page
77a2a633 565 $this->click("css=ul.ui-autocomplete li");
6a488035 566 $this->waitForPageToLoad($this->getTimeoutMsec());
d1c1ddc7 567 $this->click('css=li#tab_contribute a');
6a488035 568 $this->waitForElementPresent('link=Record Contribution (Check, Cash, EFT ...)');
76e86fd8 569
77a2a633 570 $id = explode('id=', $this->getAttribute("xpath=//table[@class='selector row-highlight']/tbody//tr[@id='rowid']/td[8]/a[text()='View']@href"));
6a488035 571 $id = substr($id[1], 0, strpos($id[1], '&'));
77a2a633 572 $this->click("xpath=//table[@class='selector row-highlight']/tbody//tr[@id='rowid']/td[8]/a");
6a488035 573 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
76e86fd8 574
0054ead7 575 $this->webtestVerifyTabularData($expected);
76e86fd8 576
d1c1ddc7 577 $params = array(
578 'contribution_id' => $id,
6a488035
TO
579 'version' => 3,
580 );
76e86fd8 581
0054ead7 582 // Retrieve contribution from the DB via api and verify DB values against view contribution page
d1c1ddc7 583 $fields = $this->webtest_civicrm_api('contribution', 'get', $params);
76e86fd8 584
6a488035 585 $params['id'] = $params['contact_id'] = $fields['values'][$fields['id']]['soft_credit_to'];
0054ead7
DG
586 $softCreditContact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, TRUE);
587
588 // View Contribution Record and test for expected values
589 $expected = array(
42daf119
CW
590 'From' => $fields['values'][$fields['id']]['display_name'],
591 'Financial Type' => $fields['values'][$fields['id']]['financial_type'],
0054ead7
DG
592 'Contribution Amount' => $fields['values'][$fields['id']]['total_amount'],
593 'Contribution Status' => $fields['values'][$fields['id']]['contribution_status'],
4db803dd 594 'Payment Method' => $fields['values'][$fields['id']]['payment_instrument'],
42daf119 595 'Check Number' => $fields['values'][$fields['id']]['contribution_check_number'],
6a488035 596 );
c2768486 597
0054ead7 598 $this->webtestVerifyTabularData($expected);
c2768486 599
600 // verify if soft credit
601 $softCreditValues = array(
602 'Soft Credit To' => $softCreditContact->display_name,
603 'Amount' => '65.00',
604 );
605
606 foreach ($softCreditValues as $value) {
b02d5792 607 $this->assertElementContainsText("css=table.crm-soft-credit-listing", $value);
c2768486 608 }
6a488035 609 }
96025800 610
6a488035 611}