Merge pull request #205 from colemanw/clicklink
[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 $elements = $this->parseURL();
50 $sid = $elements['queryString']['sid'];
51 $this->assertType('numeric', $sid);
52
53 $validStrings = array();
54
55 $fields = array(
56 'Full Conference' => 'Text',
57 'Meal Choice' => 'Select',
58 'Pre-conference Meetup?' => 'Radio',
59 'Evening Sessions' => 'CheckBox',
60 );
61 $this->_testAddPriceFields( $fields, $validateStrings, $financialType );
62 // var_dump($validateStrings);
63
64 // load the Price Set Preview and check for expected values
65 $this->_testVerifyPriceSet($validateStrings, $sid);
66 }
67
68 function _testAddSet($setTitle, $usedFor, $setHelp, $financialType = NULL) {
69 $this->openCiviPage("admin/price", "reset=1&action=add", '_qf_Set_next-bottom');
70
71 // Enter Priceset fields (Title, Used For ...)
72 $this->type('title', $setTitle);
73 if ($usedFor == 'Event') {
74 $this->check('extends_1');
75 }
76 elseif ($usedFor == 'Contribution') {
77 $this->check('extends_2');
78 }
79
80 if ($financialType) {
81 $this->select("financial_type_id", "label={$financialType}");
82 }
83 $this->type('help_pre', $setHelp);
84
85 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
86 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom');
87 }
88
89 function _testAddPriceFields(&$fields, &$validateString, $financialType, $dateSpecificFields = FALSE) {
90 $validateStrings[] = $financialType;
91 foreach ($fields as $label => $type) {
92 $validateStrings[] = $label;
93
94 $this->type('label', $label);
95 $this->select('html_type', "value={$type}");
96
97 switch ($type) {
98 case 'Text':
99 $validateStrings[] = '525.00';
100 $this->type('price', '525.00');
101 if ($dateSpecificFields == TRUE) {
102 $this->webtestFillDateTime('active_on', '+1 week');
103 }
104 else {
105 $this->check('is_required');
106 }
107 break;
108
109 case 'Select':
110 $options = array(
111 1 => array('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('label' => 'Yes',
128 'amount' => '50.00',
129 ),
130 2 => array(
131 'label' => 'No',
132 'amount' => '0',
133 ),
134 );
135 $this->addMultipleChoiceOptions($options, $validateStrings);
136 $this->check('is_required');
137 if ($dateSpecificFields == TRUE) {
138 $this->webtestFillDateTime('active_on', '-1 week');
139 }
140 break;
141
142 case 'CheckBox':
143 $options = array(
144 1 => array('label' => 'First Night',
145 'amount' => '15.00',
146 ),
147 2 => array(
148 'label' => 'Second Night',
149 'amount' => '15.00',
150 ),
151 );
152 $this->addMultipleChoiceOptions($options, $validateStrings);
153 if ($dateSpecificFields == TRUE) {
154 $this->webtestFillDateTime('expire_on', '+1 week');
155 }
156 break;
157
158 default:
159 break;
160 }
161 $this->select('financial_type_id', "label={$financialType}");
162 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom');
163 }
164 }
165
166 function _testAddFinancialType() {
167 // Add new Financial Account
168 $orgName = 'Alberta '.substr(sha1(rand()), 0, 7);
169 $financialAccountTitle = 'Financial Account '.substr(sha1(rand()), 0, 4);
170 $financialAccountDescription = "{$financialAccountTitle} Description";
171 $accountingCode = 1033;
172 $financialAccountType = 'Revenue';
173 $taxDeductible = FALSE;
174 $isActive = FALSE;
175 $isTax = TRUE;
176 $taxRate = 9;
177 $isDefault = FALSE;
178
179 //Add new organisation
180 if($orgName) {
181 $this->webtestAddOrganization($orgName);
182 }
183
184 $this->_testAddFinancialAccount($financialAccountTitle,
185 $financialAccountDescription,
186 $accountingCode,
187 $orgName,
188 $financialAccountType,
189 $taxDeductible,
190 $isActive,
191 $isTax,
192 $taxRate,
193 $isDefault
194 );
195 $this->waitForElementPresent("xpath=//table/tbody//tr/td[1][text()='{$financialAccountTitle}']/../td[9]/span/a[text()='Edit']");
196
197 //Add new Financial Type
198 $financialType['name'] = 'FinancialType '.substr(sha1(rand()), 0, 4);
199 $financialType['is_deductible'] = TRUE;
200 $financialType['is_reserved'] = FALSE;
201 $this->addeditFinancialType($financialType);
202
203 $accountRelationship = "Income Account is";
204 $expected[] = array('financial_account' => $financialAccountTitle,
205
206 'account_relationship' => $accountRelationship
207 );
208
209 $this->select('account_relationship', "label={$accountRelationship}");
210 // Because it tends to cause problems, all uses of sleep() must be justified in comments
211 // Sleep should never be used for wait for anything to load from the server
212 // Justification for this instance: FIXME
213 sleep(2);
214 $this->select('financial_account_id', "label={$financialAccountTitle}");
215 $this->click('_qf_FinancialTypeAccount_next');
216 $this->waitForPageToLoad($this->getTimeoutMsec());
217 $text = 'The financial type Account has been saved.';
218 $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text);
219 return $financialType['name'];
220 }
221
222 function _testVerifyPriceSet($validateStrings, $sid) {
223 // verify Price Set at Preview page
224 // start at Manage Price Sets listing
225 $this->openCiviPage("admin/price", "reset=1");
226
227 // Use the price set id ($sid) to pick the correct row
228 $this->clickLink("css=tr#row_{$sid} a[title='View and Edit Price Fields']", 'Link=Add Price Field');
229 // Check for expected price set field strings
230 $this->assertStringsPresent($validateStrings);
231 }
232
233 function testContributeOfflineWithPriceSet() {
234 // Log in using webtestLogin() method
235 $this->webtestLogin();
236
237 //add financial type of account type expense
238 $financialType = $this->_testAddFinancialType();
239
240 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
241 $usedFor = 'Contribution';
242 $setHelp = 'Select your conference options.';
243 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
244
245 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
246 // which is where we are after adding Price Set.
247 $elements = $this->parseURL();
248 $sid = $elements['queryString']['sid'];
249 $this->assertType('numeric', $sid);
250
251 $validStrings = array();
252 $fields = array(
253 'Full Conference' => 'Text',
254 'Meal Choice' => 'Select',
255 'Pre-conference Meetup?' => 'Radio',
256 'Evening Sessions' => 'CheckBox',
257 );
258 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
259
260 // load the Price Set Preview and check for expected values
261 $this->_testVerifyPriceSet($validateStrings, $sid);
262 $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", '_qf_Contribution_upload');
263
264 // create new contact using dialog
265 $firstName = substr(sha1(rand()), 0, 7);
266 $this->webtestNewDialogContact($firstName, 'Contributor', $firstName . '@example.com');
267
268 // select financial type
269 $this->select('financial_type_id', "label={$financialType}");
270
271 // fill in Received Date
272 $this->webtestFillDate('receive_date');
273
274 // source
275 $this->type('source', 'Mailer 1');
276
277 // select price set items
278 $this->select('price_set_id', "label=$setTitle");
279 $this->type("xpath=//input[@class='form-text four required']", "1");
280 $this->click("xpath=//input[@class='form-radio']");
281 $this->click("xpath=//input[@class='form-checkbox']");
282 // select payment instrument type = Check and enter chk number
283 $this->select('payment_instrument_id', 'value=4');
284 $this->waitForElementPresent('check_number');
285 $this->type('check_number', 'check #1041');
286
287 $this->type('trxn_id', 'P20901X1' . rand(100, 10000));
288
289 //Additional Detail section
290 $this->click('AdditionalDetail');
291 $this->waitForElementPresent('thankyou_date');
292
293 $this->type('note', 'This is a test note.');
294 $this->type('non_deductible_amount', '10');
295 $this->type('fee_amount', '0');
296 $this->type('net_amount', '0');
297 $this->type('invoice_id', time());
298 $this->webtestFillDate('thankyou_date');
299
300 // Clicking save.
301 $this->click('_qf_Contribution_upload');
302 $this->waitForPageToLoad($this->getTimeoutMsec());
303
304 // Is status message correct?
305 $this->assertTrue($this->isTextPresent('The contribution record has been saved.'), "Status message didn't show up after saving!");
306
307 $this->waitForElementPresent("xpath=//div[@id='Contributions']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
308
309 //click through to the Membership view screen
310 $this->click("xpath=//div[@id='Contributions']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
311 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
312 $expected = array(
313 2 => $financialType,
314 3 => '590.00',
315 9 => 'Completed',
316 10 => 'Check',
317 11 => 'check #1041',
318 );
319 foreach ($expected as $label => $value) {
320 $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[$label]/td[2]", preg_quote($value));
321 }
322
323 $exp = array(
324 2 => '$ 525.00',
325 3 => '$ 50.00',
326 4 => '$ 15.00',
327 );
328
329 foreach ($exp as $lab => $val) {
330 $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[$lab]/td[3]",
331 preg_quote($val)
332 );
333 }
334 }
335
336 function testContributeOnlineWithPriceSet() {
337 $this->webtestLogin();
338
339 //add financial type of account type expense
340 $financialType = $this->_testAddFinancialType();
341
342 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
343 $usedFor = 'Contribution';
344 $setHelp = 'Select your conference options.';
345 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
346
347 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
348 // which is where we are after adding Price Set.
349 $elements = $this->parseURL();
350 $sid = $elements['queryString']['sid'];
351 $this->assertType('numeric', $sid);
352
353 $validStrings = array();
354 $fields = array(
355 'Full Conference' => 'Text',
356 'Meal Choice' => 'Select',
357 'Pre-conference Meetup?' => 'Radio',
358 'Evening Sessions' => 'CheckBox',
359 );
360
361 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
362
363 // load the Price Set Preview and check for expected values
364 $this->_testVerifyPriceSet($validateStrings, $sid);
365
366 // We need a payment processor
367 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
368 $this->webtestAddPaymentProcessor($processorName);
369
370 $this->openCiviPage("admin/contribute/add", "reset=1&action=add");
371
372 $contributionTitle = substr(sha1(rand()), 0, 7);
373 $rand = 2 * rand(2, 50);
374
375 // fill in step 1 (Title and Settings)
376 $contributionPageTitle = "Title $contributionTitle";
377 $this->type('title', $contributionPageTitle);
378 $this->fillRichTextField('intro_text', 'This is Test Introductory Message', 'CKEditor');
379 $this->fillRichTextField('footer_text', 'This is Test Footer Message', 'CKEditor');
380
381 $this->select('financial_type_id', "label={$financialType}");
382
383 // Submit form
384 $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom");
385
386 // Get contribution page id
387 $pageId = $this->urlArg('id');
388
389 //this contribution page for online contribution
390 $this->click("xpath=//tr[@class='crm-contribution-contributionpage-amount-form-block-payment_processor']/td/label[text()='$processorName']");
391 $this->select('price_set_id', 'label=' . $setTitle);
392 $this->click('_qf_Amount_next-bottom');
393 $this->waitForPageToLoad($this->getTimeoutMsec());
394
395 //logout
396 $this->webtestLogout();
397
398 //Open Live Contribution Page
399 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
400
401 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
402 $lastName = 'An' . substr(sha1(rand()), 0, 7);
403 $this->waitForElementPresent('_qf_Main_upload-bottom');
404 $this->type('email-5', $firstName . '@example.com');
405 $this->type("xpath=//input[@class='form-text four required']", "1");
406 $this->click("xpath=//input[@class='form-radio']");
407 $this->click("xpath=//input[@class='form-checkbox']");
408
409 $streetAddress = '100 Main Street';
410 $this->type('billing_street_address-5', $streetAddress);
411 $this->type('billing_city-5', 'San Francisco');
412 $this->type('billing_postal_code-5', '94117');
413 $this->select('billing_country_id-5', 'value=1228');
414 $this->select('billing_state_province_id-5', 'value=1001');
415
416 //Credit Card Info
417 $this->select('credit_card_type', 'value=Visa');
418 $this->type('credit_card_number', '4111111111111111');
419 $this->type('cvv2', '000');
420 $this->select('credit_card_exp_date[M]', 'value=1');
421 $this->select('credit_card_exp_date[Y]', 'value=2020');
422
423 //Billing Info
424 $this->type('billing_first_name', $firstName);
425 $this->type('billing_last_name', $lastName);
426 $this->type('billing_street_address-5', '15 Main St.');
427 $this->type('billing_city-5', 'San Jose');
428 $this->select('billing_country_id-5', 'value=1228');
429 $this->select('billing_state_province_id-5', 'value=1004');
430 $this->type('billing_postal_code-5', '94129');
431 $this->clickLink('_qf_Main_upload-bottom', '_qf_Confirm_next-bottom');
432
433 $this->click('_qf_Confirm_next-bottom');
434 $this->waitForPageToLoad($this->getTimeoutMsec());
435
436 //login to check contribution
437
438 // Log in using webtestLogin() method
439 $this->webtestLogin();
440
441 //Find Contribution
442 $this->openCiviPage("contribute/search", "reset=1", 'contribution_date_low');
443
444 $this->type('sort_name', "$firstName $lastName");
445 $this->clickLink('_qf_Search_refresh', "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
446 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom");
447
448 // View Contribution Record and test for expected values
449 $expected = array(
450 'From' => "{$firstName} {$lastName}",
451 'Financial Type' => $financialType,
452 'Net Amount' => '$ 590.00',
453 'Contribution Status' => 'Completed',
454 );
455 $this->webtestVerifyTabularData($expected);
456
457 }
458
459 function testContributeWithDateSpecificPriceSet() {
460 $this->webtestLogin();
461
462 //add financial type of account type expense
463 $financialType= $this->_testAddFinancialType();
464
465 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
466 $usedFor = 'Contribution';
467 $setHelp = 'Select your conference options.';
468 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
469
470 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
471 // which is where we are after adding Price Set.
472 $elements = $this->parseURL();
473 $sid = $elements['queryString']['sid'];
474 $this->assertType('numeric', $sid);
475
476 $validStrings = array();
477 $fields = array(
478 'Full Conference' => 'Text',
479 'Meal Choice' => 'Select',
480 'Pre-conference Meetup?' => 'Radio',
481 'Evening Sessions' => 'CheckBox',
482 );
483 $this->_testAddPriceFields($fields, $validateStrings, $financialType, TRUE);
484
485 // load the Price Set Preview and check for expected values
486 $this->_testVerifyPriceSet($validateStrings, $sid);
487
488 // We need a payment processor
489 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
490 $this->webtestAddPaymentProcessor($processorName);
491
492 $this->openCiviPage("admin/contribute/add", "reset=1&action=add");
493
494 $contributionTitle = substr(sha1(rand()), 0, 7);
495 $rand = 2 * rand(2, 50);
496
497 // fill in step 1 (Title and Settings)
498 $contributionPageTitle = "Title $contributionTitle";
499 $this->type('title', $contributionPageTitle);
500 $this->select('financial_type_id', "label={$financialType}");
501 $this->fillRichTextField('intro_text', 'This is Test Introductory Message', 'CKEditor');
502 $this->fillRichTextField('footer_text', 'This is Test Footer Message', 'CKEditor');
503
504 // Submit form
505 $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom");
506
507 // Get contribution page id
508 $pageId = $this->urlArg('id');
509
510 //this contribution page for online contribution
511 $this->click("xpath=//tr[@class='crm-contribution-contributionpage-amount-form-block-payment_processor']/td/label[text()='$processorName']");
512 $this->select('price_set_id', 'label=' . $setTitle);
513 $this->clickLink('_qf_Amount_next-bottom');
514
515 //logout
516 $this->webtestLogout();
517
518 //Open Live Contribution Page
519 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
520
521 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
522 $lastName = 'An' . substr(sha1(rand()), 0, 7);
523 $this->waitForElementPresent('_qf_Main_upload-bottom');
524 $this->type('email-5', $firstName . '@example.com');
525 $this->click("xpath=//input[@class='form-radio']");
526 $this->click("xpath=//input[@class='form-checkbox']");
527
528 $streetAddress = '100 Main Street';
529 $this->type('billing_street_address-5', $streetAddress);
530 $this->type('billing_city-5', 'San Francisco');
531 $this->type('billing_postal_code-5', '94117');
532 $this->select('billing_country_id-5', 'value=1228');
533 $this->select('billing_state_province_id-5', 'value=1001');
534
535 //Credit Card Info
536 $this->select('credit_card_type', 'value=Visa');
537 $this->type('credit_card_number', '4111111111111111');
538 $this->type('cvv2', '000');
539 $this->select('credit_card_exp_date[M]', 'value=1');
540 $this->select('credit_card_exp_date[Y]', 'value=2020');
541
542 //Billing Info
543 $this->type('billing_first_name', $firstName);
544 $this->type('billing_last_name', $lastName);
545 $this->type('billing_street_address-5', '15 Main St.');
546 $this->type(' billing_city-5', 'San Jose');
547 $this->select('billing_country_id-5', 'value=1228');
548 $this->select('billing_state_province_id-5', 'value=1004');
549 $this->type('billing_postal_code-5', '94129');
550 $this->clickLink('_qf_Main_upload-bottom', '_qf_Confirm_next-bottom');
551
552 $this->click('_qf_Confirm_next-bottom');
553 $this->waitForPageToLoad($this->getTimeoutMsec());
554
555 //login to check contribution
556 $this->webtestLogin();
557
558 //Find Contribution
559 $this->openCiviPage("contribute/search", "reset=1", 'contribution_date_low');
560
561 $this->type('sort_name', "$firstName $lastName");
562 $this->clickLink('_qf_Search_refresh', "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
563 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", '_qf_ContributionView_cancel-bottom');
564
565 // View Contribution Record and test for expected values
566 $expected = array(
567 'From' => "{$firstName} {$lastName}",
568 'Financial Type' => $financialType,
569 'Net Amount' => '$ 65.00',
570 'Contribution Status' => 'Completed',
571 );
572 $this->webtestVerifyTabularData($expected);
573 }
574
575 function testContributeOfflineforSoftcreditwithApi() {
576 // Log in using webtestLogin() method
577 $this->webtestLogin();
578
579 //create a contact and return the contact id
580 $firstNameSoft = "John_".substr(sha1(rand()), 0, 5);
581 $lastNameSoft = "Doe_".substr(sha1(rand()), 0, 5);
582 $this->webtestAddContact($firstNameSoft, $lastNameSoft);
583 $url = $this->parseURL();
584 $cid = $url['queryString']['cid'];
585 $this->assertType('numeric', $cid);
586
587 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
588 $usedFor = 'Contribution';
589 $setHelp = 'Select your conference options.';
590 $financialType = $this->_testAddFinancialType();
591 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
592
593 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
594 // which is where we are after adding Price Set.
595 $elements = $this->parseURL();
596 $sid = $elements['queryString']['sid'];
597 $this->assertType('numeric', $sid);
598
599 $validStrings = array();
600 $fields = array(
601 'Full Conference' => 'Text',
602 'Meal Choice' => 'Select',
603 'Pre-conference Meetup?' => 'Radio',
604 'Evening Sessions' => 'CheckBox',
605 );
606 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
607
608 // load the Price Set Preview and check for expected values
609 $this->_testVerifyPriceSet($validateStrings, $sid);
610
611 $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", '_qf_Contribution_upload');
612
613 // create new contact using dialog
614 $firstName = substr(sha1(rand()), 0, 7);
615 $this->webtestNewDialogContact($firstName, 'Contributor', $firstName . '@example.com');
616
617 // select contribution type
618 $this->select('financial_type_id', "label={$financialType}");
619
620 // fill in Received Date
621 $this->webtestFillDate('receive_date');
622
623 // source
624 $this->type('source', 'Mailer 1');
625
626 // select price set items
627 $this->select('price_set_id', "label=$setTitle");
628 $this->type("xpath=//input[@class='form-text four required']", "1");
629 $this->click("xpath=//input[@class='form-radio']");
630 $this->click("xpath=//input[@class='form-checkbox']");
631 // select payment instrument type = Check and enter chk number
632 $this->select('payment_instrument_id', 'value=4');
633 $this->waitForElementPresent('check_number');
634 $this->type('check_number', '1041');
635
636 $this->type('trxn_id', 'P20901X1' . rand(100, 10000));
637
638 $this->type('soft_credit_to', "$lastNameSoft, $firstNameSoft");
639 $this->click('soft_credit_to');
640 $this->waitForElementPresent("css=div.ac_results-inner li");
641 $this->click("css=div.ac_results-inner li");
642 //Additional Detail section
643 $this->click('AdditionalDetail');
644 $this->waitForElementPresent('thankyou_date');
645
646 $this->type('note', 'This is a test note.');
647 $this->type('invoice_id', time());
648 $this->webtestFillDate('thankyou_date');
649
650 // Clicking save.
651 $this->clickLink('_qf_Contribution_upload', "xpath=//div[@id='Contributions']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
652 $this->assertTrue($this->isTextPresent('The contribution record has been saved.'), "Status message didn't show up after saving!");
653
654 //click through to the Contribution view screen
655 $this->click("xpath=//div[@id='Contributions']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
656 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
657
658 // View Contribution Record and test for expected values
659 $expected = array(
660 'From' => "{$firstName} Contributor",
661 'Financial Type' => $financialType,
662 'Contribution Amount' => 'Contribution Total: $ 590.00',
663 'Paid By' => 'Check',
664 'Check Number' => '1041',
665 'Contribution Status' => 'Completed',
666 'Soft Credit To' => "$firstNameSoft $lastNameSoft",
667 );
668 $this->webtestVerifyTabularData($expected);
669
670 $exp = array(
671 2 => '$ 525.00',
672 3 => '$ 50.00',
673 4 => '$ 15.00',
674 );
675
676 foreach ($exp as $lab => $val) {
677 $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[$lab]/td[3]",
678 preg_quote($val)
679 );
680 }
681
682 // Check for Soft contact created
683 $this->click("css=input#sort_name_navigation");
684 $this->type("css=input#sort_name_navigation", "$lastNameSoft, $firstNameSoft");
685 $this->typeKeys("css=input#sort_name_navigation", "$lastNameSoft, $firstNameSoft");
686 // wait for result list
687 $this->waitForElementPresent("css=div.ac_results-inner li");
688
689 // visit contact summary page
690 $this->click("css=div.ac_results-inner li");
691 $this->waitForPageToLoad($this->getTimeoutMsec());
692 $this->click( 'css=li#tab_contribute a' );
693 $this->waitForElementPresent('link=Record Contribution (Check, Cash, EFT ...)');
694
695 $id = explode('id=', $this->getAttribute("xpath=id('rowid')/td[7]/a[text()='View']@href"));
696 $id = substr($id[1], 0, strpos($id[1], '&'));
697 $this->click("xpath=id('rowid')/td[7]/a");
698 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
699
700 $this->webtestVerifyTabularData($expected);
701
702 $params = array('contribution_id' => $id,
703 'version' => 3,
704 );
705
706 // Retrieve contribution from the DB via api and verify DB values against view contribution page
707 require_once 'api/api.php';
708 $fields = $this->webtest_civicrm_api('contribution','get',$params );
709
710 $params['id'] = $params['contact_id'] = $fields['values'][$fields['id']]['soft_credit_to'];
711 $softCreditContact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, TRUE);
712
713 // View Contribution Record and test for expected values
714 $expected = array(
715 'From' => $fields['values'][$fields['id']]['display_name'],
716 'Financial Type' => $fields['values'][$fields['id']]['financial_type'],
717 'Contribution Amount' => $fields['values'][$fields['id']]['total_amount'],
718 'Contribution Status' => $fields['values'][$fields['id']]['contribution_status'],
719 'Paid By' => $fields['values'][$fields['id']]['contribution_payment_instrument'],
720 'Check Number' => $fields['values'][$fields['id']]['contribution_check_number'],
721 'Soft Credit To' => $softCreditContact->display_name,
722 );
723 $this->webtestVerifyTabularData($expected);
724 }
725 }
726