3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Contribute_AddPricesetTest
extends CiviSeleniumTestCase
{
31 protected function setUp() {
35 function testAddPriceSet() {
36 // Log in using webtestLogin() method
37 $this->webtestLogin();
39 //add financial type of account type expense
41 $financialType = $this->_testAddFinancialType();
43 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
44 $usedFor = 'Contribution';
45 $setHelp = 'Select your conference options.';
46 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
48 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
49 // which is where we are after adding Price Set.
50 $elements = $this->parseURL();
51 $sid = $elements['queryString']['sid'];
52 $this->assertType('numeric', $sid);
54 $validStrings = array();
57 'Full Conference' => 'Text',
58 'Meal Choice' => 'Select',
59 'Pre-conference Meetup?' => 'Radio',
60 'Evening Sessions' => 'CheckBox',
62 $this->_testAddPriceFields( $fields, $validateStrings, $financialType );
63 // var_dump($validateStrings);
65 // load the Price Set Preview and check for expected values
66 $this->_testVerifyPriceSet($validateStrings, $sid);
69 function _testAddSet($setTitle, $usedFor, $setHelp, $financialType = NULL) {
70 $this->open($this->sboxPath
. 'civicrm/admin/price?reset=1&action=add');
71 $this->waitForPageToLoad($this->getTimeoutMsec());
72 $this->waitForElementPresent('_qf_Set_next-bottom');
74 // Enter Priceset fields (Title, Used For ...)
75 $this->type('title', $setTitle);
76 if ($usedFor == 'Event') {
77 $this->check('extends_1');
79 elseif ($usedFor == 'Contribution') {
80 $this->check('extends_2');
84 $this->select("financial_type_id", "label={$financialType}");
86 $this->type('help_pre', $setHelp);
88 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
89 $this->click('_qf_Set_next-bottom');
91 $this->waitForPageToLoad($this->getTimeoutMsec());
92 $this->waitForElementPresent('_qf_Field_next-bottom');
95 function _testAddPriceFields(&$fields, &$validateString, $financialType, $dateSpecificFields = FALSE) {
96 $validateStrings[] = $financialType;
97 foreach ($fields as $label => $type) {
98 $validateStrings[] = $label;
100 $this->type('label', $label);
101 $this->select('html_type', "value={$type}");
105 $validateStrings[] = '525.00';
106 $this->type('price', '525.00');
107 if ($dateSpecificFields == TRUE) {
108 $this->webtestFillDateTime('active_on', '+1 week');
111 $this->check('is_required');
117 1 => array('label' => 'Chicken',
121 'label' => 'Vegetarian',
125 $this->addMultipleChoiceOptions($options, $validateStrings);
126 if ($dateSpecificFields == TRUE) {
127 $this->webtestFillDateTime('expire_on', '-1 week');
133 1 => array('label' => 'Yes',
141 $this->addMultipleChoiceOptions($options, $validateStrings);
142 $this->check('is_required');
143 if ($dateSpecificFields == TRUE) {
144 $this->webtestFillDateTime('active_on', '-1 week');
150 1 => array('label' => 'First Night',
154 'label' => 'Second Night',
158 $this->addMultipleChoiceOptions($options, $validateStrings);
159 if ($dateSpecificFields == TRUE) {
160 $this->webtestFillDateTime('expire_on', '+1 week');
167 $this->select('financial_type_id', "label={$financialType}");
168 $this->click('_qf_Field_next_new-bottom');
169 $this->waitForPageToLoad($this->getTimeoutMsec());
170 $this->waitForElementPresent('_qf_Field_next-bottom');
174 function _testAddFinancialType() {
175 // Add new Financial Account
176 $orgName = 'Alberta '.substr(sha1(rand()), 0, 7);
177 $financialAccountTitle = 'Financial Account '.substr(sha1(rand()), 0, 4);
178 $financialAccountDescription = "{$financialAccountTitle} Description";
179 $accountingCode = 1033;
180 $financialAccountType = 'Revenue';
181 $taxDeductible = FALSE;
187 //Add new organisation
189 $this->webtestAddOrganization($orgName);
192 $this->_testAddFinancialAccount($financialAccountTitle,
193 $financialAccountDescription,
196 $financialAccountType,
203 $this->waitForElementPresent("xpath=//table/tbody//tr/td[1][text()='{$financialAccountTitle}']/../td[9]/span/a[text()='Edit']");
205 //Add new Financial Type
206 $financialType['name'] = 'FinancialType '.substr(sha1(rand()), 0, 4);
207 $financialType['is_deductible'] = TRUE;
208 $financialType['is_reserved'] = FALSE;
209 $this->addeditFinancialType($financialType);
211 $accountRelationship = "Income Account is";
212 $expected[] = array('financial_account' => $financialAccountTitle,
213 'account_relationship' => $accountRelationship
216 $this->select('account_relationship', "label={$accountRelationship}");
218 $this->select('financial_account_id', "label={$financialAccountTitle}");
219 $this->click('_qf_FinancialTypeAccount_next');
220 $this->waitForPageToLoad($this->getTimeoutMsec());
221 $text = 'The financial type Account has been saved.';
222 $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text);
223 return $financialType['name'];
226 function _testVerifyPriceSet($validateStrings, $sid) {
227 // verify Price Set at Preview page
228 // start at Manage Price Sets listing
229 $this->open($this->sboxPath
. 'civicrm/admin/price?reset=1');
230 $this->waitForPageToLoad($this->getTimeoutMsec());
232 // Use the price set id ($sid) to pick the correct row
233 $this->click("css=tr#row_{$sid} a[title='View and Edit Price Fields']");
235 $this->waitForPageToLoad($this->getTimeoutMsec());
236 // Look for Register button
237 $this->waitForElementPresent('Link=Add Price Field');
238 // Check for expected price set field strings
239 $this->assertStringsPresent($validateStrings);
242 function testContributeOfflineWithPriceSet() {
243 // Log in using webtestLogin() method
244 $this->webtestLogin();
246 //add financial type of account type expense
247 $financialType = $this->_testAddFinancialType();
249 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
250 $usedFor = 'Contribution';
251 $setHelp = 'Select your conference options.';
252 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
254 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
255 // which is where we are after adding Price Set.
256 $elements = $this->parseURL();
257 $sid = $elements['queryString']['sid'];
258 $this->assertType('numeric', $sid);
260 $validStrings = array();
262 'Full Conference' => 'Text',
263 'Meal Choice' => 'Select',
264 'Pre-conference Meetup?' => 'Radio',
265 'Evening Sessions' => 'CheckBox',
267 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
269 // load the Price Set Preview and check for expected values
270 $this->_testVerifyPriceSet($validateStrings, $sid);
271 $this->open($this->sboxPath
. 'civicrm/contribute/add?reset=1&action=add&context=standalone');
273 // As mentioned before, waitForPageToLoad is not always reliable. Below, we're waiting for the submit
274 // button at the end of this page to show up, to make sure it's fully loaded.
275 $this->waitForElementPresent('_qf_Contribution_upload');
277 // Let's start filling the form with values.
279 // create new contact using dialog
280 $firstName = substr(sha1(rand()), 0, 7);
281 $this->webtestNewDialogContact($firstName, 'Contributor', $firstName . '@example.com');
283 // select financial type
284 $this->select('financial_type_id', "label={$financialType}");
286 // fill in Received Date
287 $this->webtestFillDate('receive_date');
290 $this->type('source', 'Mailer 1');
292 // select price set items
293 $this->select('price_set_id', "label=$setTitle");
294 $this->type("xpath=//input[@class='form-text four required']", "1");
295 $this->click("xpath=//input[@class='form-radio']");
296 $this->click("xpath=//input[@class='form-checkbox']");
297 // select payment instrument type = Check and enter chk number
298 $this->select('payment_instrument_id', 'value=4');
299 $this->waitForElementPresent('check_number');
300 $this->type('check_number', 'check #1041');
302 $this->type('trxn_id', 'P20901X1' . rand(100, 10000));
304 //Additional Detail section
305 $this->click('AdditionalDetail');
306 $this->waitForElementPresent('thankyou_date');
308 $this->type('note', 'This is a test note.');
309 $this->type('non_deductible_amount', '10');
310 $this->type('fee_amount', '0');
311 $this->type('net_amount', '0');
312 $this->type('invoice_id', time());
313 $this->webtestFillDate('thankyou_date');
316 $this->click('_qf_Contribution_upload');
317 $this->waitForPageToLoad($this->getTimeoutMsec());
319 // Is status message correct?
320 $this->assertTrue($this->isTextPresent('The contribution record has been saved.'), "Status message didn't show up after saving!");
322 $this->waitForElementPresent("xpath=//div[@id='Contributions']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
324 //click through to the Membership view screen
325 $this->click("xpath=//div[@id='Contributions']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
326 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
334 foreach ($expected as $label => $value) {
335 $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[$label]/td[2]", preg_quote($value));
344 foreach ($exp as $lab => $val) {
345 $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[$lab]/td[3]",
351 function _testVerifyRegisterPage($contributionPageTitle) {
352 $this->open($this->sboxPath
. 'civicrm/admin/contribute?reset=1');
353 $this->waitForElementPresent('_qf_SearchContribution_refresh');
354 $this->type('title', $contributionPageTitle);
355 $this->click('_qf_SearchContribution_refresh');
356 $this->waitForPageToLoad('50000');
357 $id = $this->getAttribute("//div[@id='configure_contribution_page']//div[@class='dataTables_wrapper']/table/tbody/tr@id");
358 $id = explode('_', $id);
359 $registerUrl = "civicrm/contribute/transact?reset=1&id=$id[1]";
363 function testContributeOnlineWithPriceSet() {
364 // This is the path where our testing install resides.
365 // The rest of URL is defined in CiviSeleniumTestCase base class, in
367 $this->open($this->sboxPath
);
369 // Logging in. Remember to wait for page to load. In most cases,
370 // you can rely on 30000 as the value that allows your test to pass, however,
371 // sometimes your test might fail because of this. In such cases, it's better to pick one element
372 // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
373 // page contents loaded and you can continue your test execution.
374 $this->webtestLogin();
376 //add financial type of account type expense
377 $financialType = $this->_testAddFinancialType();
379 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
380 $usedFor = 'Contribution';
381 $setHelp = 'Select your conference options.';
382 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
384 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
385 // which is where we are after adding Price Set.
386 $elements = $this->parseURL();
387 $sid = $elements['queryString']['sid'];
388 $this->assertType('numeric', $sid);
390 $validStrings = array();
392 'Full Conference' => 'Text',
393 'Meal Choice' => 'Select',
394 'Pre-conference Meetup?' => 'Radio',
395 'Evening Sessions' => 'CheckBox',
398 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
400 // load the Price Set Preview and check for expected values
401 $this->_testVerifyPriceSet($validateStrings, $sid);
403 // We need a payment processor
404 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
405 $this->webtestAddPaymentProcessor($processorName);
407 $this->open($this->sboxPath
. 'civicrm/admin/contribute/add?reset=1&action=add');
409 $contributionTitle = substr(sha1(rand()), 0, 7);
410 $rand = 2 * rand(2, 50);
412 // fill in step 1 (Title and Settings)
413 $contributionPageTitle = "Title $contributionTitle";
414 $this->type('title', $contributionPageTitle);
415 $this->fillRichTextField('intro_text', 'This is Test Introductory Message', 'CKEditor');
416 $this->fillRichTextField('footer_text', 'This is Test Footer Message', 'CKEditor');
418 $this->select('financial_type_id', "label={$financialType}");
420 $this->click('_qf_Settings_next');
421 $this->waitForElementPresent('_qf_Amount_next-bottom');
423 //this contribution page for online contribution
424 //$this->select( 'payment_processor_id', 'label=' . $processorName );
425 $this->click("xpath=//tr[@class='crm-contribution-contributionpage-amount-form-block-payment_processor']/td/label[text()='$processorName']");
426 $this->select('price_set_id', 'label=' . $setTitle);
427 $this->click('_qf_Amount_next-bottom');
428 $this->waitForPageToLoad($this->getTimeoutMsec());
430 //get Url for Live Contribution Page
431 $registerUrl = $this->_testVerifyRegisterPage($contributionPageTitle);
434 $this->open($this->sboxPath
. 'civicrm/logout?reset=1');
435 $this->waitForPageToLoad($this->getTimeoutMsec());
437 //Open Live Contribution Page
438 $this->open($this->sboxPath
. $registerUrl);
439 $this->waitForElementPresent('_qf_Main_upload-bottom');
441 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
442 $lastName = 'An' . substr(sha1(rand()), 0, 7);
443 $this->waitForElementPresent('_qf_Main_upload-bottom');
444 $this->type('email-5', $firstName . '@example.com');
445 $this->type("xpath=//input[@class='form-text four required']", "1");
446 $this->click("xpath=//input[@class='form-radio']");
447 $this->click("xpath=//input[@class='form-checkbox']");
449 $streetAddress = '100 Main Street';
450 $this->type('billing_street_address-5', $streetAddress);
451 $this->type('billing_city-5', 'San Francisco');
452 $this->type('billing_postal_code-5', '94117');
453 $this->select('billing_country_id-5', 'value=1228');
454 $this->select('billing_state_province_id-5', 'value=1001');
457 $this->select('credit_card_type', 'value=Visa');
458 $this->type('credit_card_number', '4111111111111111');
459 $this->type('cvv2', '000');
460 $this->select('credit_card_exp_date[M]', 'value=1');
461 $this->select('credit_card_exp_date[Y]', 'value=2020');
464 $this->type('billing_first_name', $firstName);
465 $this->type('billing_last_name', $lastName);
466 $this->type('billing_street_address-5', '15 Main St.');
467 $this->type('billing_city-5', 'San Jose');
468 $this->select('billing_country_id-5', 'value=1228');
469 $this->select('billing_state_province_id-5', 'value=1004');
470 $this->type('billing_postal_code-5', '94129');
471 $this->click('_qf_Main_upload-bottom');
473 $this->waitForPageToLoad($this->getTimeoutMsec());
474 $this->waitForElementPresent('_qf_Confirm_next-bottom');
476 $this->click('_qf_Confirm_next-bottom');
477 $this->waitForPageToLoad($this->getTimeoutMsec());
479 //login to check contribution
480 $this->open($this->sboxPath
);
482 // Log in using webtestLogin() method
483 $this->webtestLogin();
486 $this->open($this->sboxPath
. 'civicrm/contribute/search?reset=1');
488 $this->waitForElementPresent('contribution_date_low');
490 $this->type('sort_name', "$firstName $lastName");
491 $this->click('_qf_Search_refresh');
493 $this->waitForPageToLoad($this->getTimeoutMsec());
495 $this->waitForElementPresent("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
496 $this->click("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
497 $this->waitForPageToLoad($this->getTimeoutMsec());
498 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
500 // View Contribution Record and test for expected values
502 'From' => "{$firstName} {$lastName}",
503 'Financial Type' => $financialType,
504 'Net Amount' => '$ 590.00',
505 'Contribution Status' => 'Completed',
507 $this->webtestVerifyTabularData($expected);
511 function testContributeWithDateSpecificPriceSet() {
512 $this->webtestLogin();
514 //add financial type of account type expense
515 $financialType= $this->_testAddFinancialType();
517 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
518 $usedFor = 'Contribution';
519 $setHelp = 'Select your conference options.';
520 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
522 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
523 // which is where we are after adding Price Set.
524 $elements = $this->parseURL();
525 $sid = $elements['queryString']['sid'];
526 $this->assertType('numeric', $sid);
528 $validStrings = array();
530 'Full Conference' => 'Text',
531 'Meal Choice' => 'Select',
532 'Pre-conference Meetup?' => 'Radio',
533 'Evening Sessions' => 'CheckBox',
535 $this->_testAddPriceFields($fields, $validateStrings, $financialType, TRUE);
537 // load the Price Set Preview and check for expected values
538 $this->_testVerifyPriceSet($validateStrings, $sid);
540 // We need a payment processor
541 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
542 $this->webtestAddPaymentProcessor($processorName);
544 $this->open($this->sboxPath
. 'civicrm/admin/contribute/add?reset=1&action=add');
546 $contributionTitle = substr(sha1(rand()), 0, 7);
547 $rand = 2 * rand(2, 50);
549 // fill in step 1 (Title and Settings)
550 $contributionPageTitle = "Title $contributionTitle";
551 $this->type('title', $contributionPageTitle);
552 $this->select('financial_type_id', "label={$financialType}");
553 $this->fillRichTextField('intro_text', 'This is Test Introductory Message', 'CKEditor');
554 $this->fillRichTextField('footer_text', 'This is Test Footer Message', 'CKEditor');
557 $this->click('_qf_Settings_next');
558 $this->waitForElementPresent('_qf_Amount_next-bottom');
560 //this contribution page for online contribution
561 //$this->select( 'payment_processor_id', 'label=' . $processorName );
562 $this->click("xpath=//tr[@class='crm-contribution-contributionpage-amount-form-block-payment_processor']/td/label[text()='$processorName']");
563 $this->select('price_set_id', 'label=' . $setTitle);
564 $this->click('_qf_Amount_next-bottom');
565 $this->waitForPageToLoad($this->getTimeoutMsec());
567 //get Url for Live Contribution Page
568 $registerUrl = $this->_testVerifyRegisterPage($contributionPageTitle);
571 $this->open($this->sboxPath
. 'civicrm/logout?reset=1');
572 $this->waitForPageToLoad($this->getTimeoutMsec());
574 //Open Live Contribution Page
575 $this->open($this->sboxPath
. $registerUrl);
576 $this->waitForElementPresent('_qf_Main_upload-bottom');
578 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
579 $lastName = 'An' . substr(sha1(rand()), 0, 7);
580 $this->waitForElementPresent('_qf_Main_upload-bottom');
581 $this->type('email-5', $firstName . '@example.com');
582 $this->click("xpath=//input[@class='form-radio']");
583 $this->click("xpath=//input[@class='form-checkbox']");
585 $streetAddress = '100 Main Street';
586 $this->type('billing_street_address-5', $streetAddress);
587 $this->type('billing_city-5', 'San Francisco');
588 $this->type('billing_postal_code-5', '94117');
589 $this->select('billing_country_id-5', 'value=1228');
590 $this->select('billing_state_province_id-5', 'value=1001');
593 $this->select('credit_card_type', 'value=Visa');
594 $this->type('credit_card_number', '4111111111111111');
595 $this->type('cvv2', '000');
596 $this->select('credit_card_exp_date[M]', 'value=1');
597 $this->select('credit_card_exp_date[Y]', 'value=2020');
600 $this->type('billing_first_name', $firstName);
601 $this->type('billing_last_name', $lastName);
602 $this->type('billing_street_address-5', '15 Main St.');
603 $this->type(' billing_city-5', 'San Jose');
604 $this->select('billing_country_id-5', 'value=1228');
605 $this->select('billing_state_province_id-5', 'value=1004');
606 $this->type('billing_postal_code-5', '94129');
607 $this->click('_qf_Main_upload-bottom');
609 $this->waitForPageToLoad($this->getTimeoutMsec());
610 $this->waitForElementPresent('_qf_Confirm_next-bottom');
612 $this->click('_qf_Confirm_next-bottom');
613 $this->waitForPageToLoad($this->getTimeoutMsec());
615 //login to check contribution
616 $this->open($this->sboxPath
);
618 // Log in using webtestLogin() method
619 $this->webtestLogin();
622 $this->open($this->sboxPath
. 'civicrm/contribute/search?reset=1');
624 $this->waitForElementPresent('contribution_date_low');
626 $this->type('sort_name', "$firstName $lastName");
627 $this->click('_qf_Search_refresh');
629 $this->waitForPageToLoad($this->getTimeoutMsec());
631 $this->waitForElementPresent("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
632 $this->click("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
633 $this->waitForPageToLoad($this->getTimeoutMsec());
634 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
636 // View Contribution Record and test for expected values
638 'From' => "{$firstName} {$lastName}",
639 'Financial Type' => $financialType,
640 'Net Amount' => '$ 65.00',
641 'Contribution Status' => 'Completed',
643 $this->webtestVerifyTabularData($expected);
646 function testContributeOfflineforSoftcreditwithApi() {
647 // Log in using webtestLogin() method
648 $this->webtestLogin();
650 //create a contact and return the contact id
651 $firstNameSoft = "John_".substr(sha1(rand()), 0, 5);
652 $lastNameSoft = "Doe_".substr(sha1(rand()), 0, 5);
653 $this->webtestAddContact($firstNameSoft, $lastNameSoft);
654 $url = $this->parseURL();
655 $cid = $url['queryString']['cid'];
656 $this->assertType('numeric', $cid);
658 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
659 $usedFor = 'Contribution';
660 $setHelp = 'Select your conference options.';
661 $financialType = $this->_testAddFinancialType();
662 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
664 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
665 // which is where we are after adding Price Set.
666 $elements = $this->parseURL();
667 $sid = $elements['queryString']['sid'];
668 $this->assertType('numeric', $sid);
670 $validStrings = array();
672 'Full Conference' => 'Text',
673 'Meal Choice' => 'Select',
674 'Pre-conference Meetup?' => 'Radio',
675 'Evening Sessions' => 'CheckBox',
677 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
679 // load the Price Set Preview and check for expected values
680 $this->_testVerifyPriceSet($validateStrings, $sid);
682 $this->open($this->sboxPath
. 'civicrm/contribute/add?reset=1&action=add&context=standalone');
684 // As mentioned before, waitForPageToLoad is not always reliable. Below, we're waiting for the submit
685 // button at the end of this page to show up, to make sure it's fully loaded.
686 $this->waitForElementPresent('_qf_Contribution_upload');
688 // Let's start filling the form with values.
690 // create new contact using dialog
691 $firstName = substr(sha1(rand()), 0, 7);
692 $this->webtestNewDialogContact($firstName, 'Contributor', $firstName . '@example.com');
694 // select contribution type
695 $this->select('financial_type_id', "label={$financialType}");
697 // fill in Received Date
698 $this->webtestFillDate('receive_date');
701 $this->type('source', 'Mailer 1');
703 // select price set items
704 $this->select('price_set_id', "label=$setTitle");
705 $this->type("xpath=//input[@class='form-text four required']", "1");
706 $this->click("xpath=//input[@class='form-radio']");
707 $this->click("xpath=//input[@class='form-checkbox']");
708 // select payment instrument type = Check and enter chk number
709 $this->select('payment_instrument_id', 'value=4');
710 $this->waitForElementPresent('check_number');
711 $this->type('check_number', '1041');
713 $this->type('trxn_id', 'P20901X1' . rand(100, 10000));
715 $this->type('soft_credit_to', "$lastNameSoft, $firstNameSoft");
716 $this->click('soft_credit_to');
717 $this->waitForElementPresent("css=div.ac_results-inner li");
718 $this->click("css=div.ac_results-inner li");
719 //Additional Detail section
720 $this->click('AdditionalDetail');
721 $this->waitForElementPresent('thankyou_date');
723 $this->type('note', 'This is a test note.');
724 $this->type('invoice_id', time());
725 $this->webtestFillDate('thankyou_date');
728 $this->click('_qf_Contribution_upload');
729 $this->waitForPageToLoad($this->getTimeoutMsec());
731 // Is status message correct?
732 $this->waitForElementPresent("xpath=//div[@id='Contributions']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
733 $this->assertTrue($this->isTextPresent('The contribution record has been saved.'), "Status message didn't show up after saving!");
735 //click through to the Contribution view screen
736 $this->click("xpath=//div[@id='Contributions']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
737 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
739 // View Contribution Record and test for expected values
741 'From' => "{$firstName} Contributor",
742 'Financial Type' => $financialType,
743 'Contribution Amount' => 'Contribution Total: $ 590.00',
744 'Paid By' => 'Check',
745 'Check Number' => '1041',
746 'Contribution Status' => 'Completed',
747 'Soft Credit To' => "$firstNameSoft $lastNameSoft",
749 $this->webtestVerifyTabularData($expected);
757 foreach ($exp as $lab => $val) {
758 $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[$lab]/td[3]",
763 // Check for Soft contact created
764 $this->click("css=input#sort_name_navigation");
765 $this->type("css=input#sort_name_navigation", "$lastNameSoft, $firstNameSoft");
766 $this->typeKeys("css=input#sort_name_navigation", "$lastNameSoft, $firstNameSoft");
767 // wait for result list
768 $this->waitForElementPresent("css=div.ac_results-inner li");
770 // visit contact summary page
771 $this->click("css=div.ac_results-inner li");
772 $this->waitForPageToLoad($this->getTimeoutMsec());
773 $this->click( 'css=li#tab_contribute a' );
774 $this->waitForElementPresent('link=Record Contribution (Check, Cash, EFT ...)');
776 $id = explode('id=', $this->getAttribute("xpath=id('rowid')/td[7]/a[text()='View']@href"));
777 $id = substr($id[1], 0, strpos($id[1], '&'));
778 $this->click("xpath=id('rowid')/td[7]/a");
779 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
781 $this->webtestVerifyTabularData($expected);
783 $params = array('contribution_id' => $id,
787 // Retrieve contribution from the DB via api and verify DB values against view contribution page
788 require_once 'api/api.php';
789 $fields = $this->webtest_civicrm_api('contribution','get',$params );
791 $params['id'] = $params['contact_id'] = $fields['values'][$fields['id']]['soft_credit_to'];
792 $softCreditContact = CRM_Contact_BAO_Contact
::retrieve($params, $defaults, TRUE);
794 // View Contribution Record and test for expected values
796 'From' => $fields['values'][$fields['id']]['display_name'],
797 'Financial Type' => $fields['values'][$fields['id']]['financial_type'],
798 'Contribution Amount' => $fields['values'][$fields['id']]['total_amount'],
799 'Contribution Status' => $fields['values'][$fields['id']]['contribution_status'],
800 'Paid By' => $fields['values'][$fields['id']]['contribution_payment_instrument'],
801 'Check Number' => $fields['values'][$fields['id']]['contribution_check_number'],
802 'Soft Credit To' => $softCreditContact->display_name
,
804 $this->webtestVerifyTabularData($expected);