3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
30 * Class WebTest_Contribute_AddPricesetTest
32 class WebTest_Contribute_AddPricesetTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testAddPriceSet() {
39 // Log in using webtestLogin() method
40 $this->webtestLogin();
42 //add financial type of account type expense
44 $financialType = $this->_testAddFinancialType();
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);
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);
56 $validStrings = array();
59 'Full Conference' => 'Text',
60 'Meal Choice' => 'Select',
61 'Pre-conference Meetup?' => 'Radio',
62 'Evening Sessions' => 'CheckBox',
64 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
65 // var_dump($validateStrings);
67 // load the Price Set Preview and check for expected values
68 $this->_testVerifyPriceSet($validateStrings, $sid);
74 public function _testAddFinancialType() {
75 //Add new Financial Type
76 $financialType['name'] = 'FinancialType ' . substr(sha1(rand()), 0, 4);
77 $financialType['is_deductible'] = TRUE;
78 $financialType['is_reserved'] = FALSE;
79 $this->addeditFinancialType($financialType);
80 return $financialType['name'];
84 * @param $validateStrings
87 public function _testVerifyPriceSet($validateStrings, $sid) {
88 // verify Price Set at Preview page
89 // start at Manage Price Sets listing
90 $this->openCiviPage("admin/price", "reset=1");
92 // Use the price set id ($sid) to pick the correct row
93 $this->clickLink("//*[@id='price_set-{$sid}']/td[4]/span[1]/a[1]", 'Link=Add Price Field');
94 // Check for expected price set field strings
95 $this->assertStringsPresent($validateStrings);
98 public function testContributeOfflineWithPriceSet() {
99 // Log in using webtestLogin() method
100 $this->webtestLogin();
102 //add financial type of account type expense
103 $financialType = $this->_testAddFinancialType();
105 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
106 $usedFor = 'Contribution';
107 $setHelp = 'Select your conference options.';
108 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
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.
112 $sid = $this->urlArg('sid');
113 $this->assertType('numeric', $sid);
115 $validStrings = array();
117 'Full Conference' => 'Text',
118 'Meal Choice' => 'Select',
119 'Pre-conference Meetup?' => 'Radio',
120 'Evening Sessions' => 'CheckBox',
122 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
124 // load the Price Set Preview and check for expected values
125 $this->_testVerifyPriceSet($validateStrings, $sid);
126 $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", '_qf_Contribution_upload');
128 // create new contact using dialog
129 $this->createDialogContact();
131 // select financial type
132 $this->select('financial_type_id', "label={$financialType}");
134 // fill in Received Date
135 $this->webtestFillDate('receive_date');
138 $this->type('source', 'Mailer 1');
140 // select price set items
141 $this->select('price_set_id', "label=$setTitle");
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']");
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');
150 $this->type('trxn_id', 'P20901X1' . rand(100, 10000));
152 //Additional Detail section
153 $this->click('AdditionalDetail');
154 $this->waitForElementPresent('thankyou_date');
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');
164 $this->click('_qf_Contribution_upload');
165 $this->waitForPageToLoad($this->getTimeoutMsec());
167 // Is status message correct?
168 $this->assertTrue($this->isTextPresent('The contribution record has been saved.'), "Status message didn't show up after saving!");
169 $this->waitForElementPresent("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span//a[text()='View']");
171 //click through to the Membership view screen
172 $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span//a[text()='View']");
173 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
181 foreach ($expected as $label => $value) {
182 $this->assertElementContainsText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[$label]/td[2]", $value);
191 foreach ($exp as $lab => $val) {
192 $this->assertElementContainsText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[$lab]/td[3]", $val);
196 public function testContributeOnlineWithPriceSet() {
197 $this->webtestLogin();
199 //add financial type of account type expense
200 $financialType = $this->_testAddFinancialType();
202 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
203 $usedFor = 'Contribution';
204 $setHelp = 'Select your conference options.';
205 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
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.
209 $sid = $this->urlArg('sid');
210 $this->assertType('numeric', $sid);
212 $validStrings = array();
214 'Full Conference' => 'Text',
215 'Meal Choice' => 'Select',
216 'Pre-conference Meetup?' => 'Radio',
217 'Evening Sessions' => 'CheckBox',
220 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
222 // load the Price Set Preview and check for expected values
223 $this->_testVerifyPriceSet($validateStrings, $sid);
225 // Use default payment processor
226 $processorName = 'Test Processor';
227 $this->webtestAddPaymentProcessor($processorName);
229 $this->openCiviPage("admin/contribute/add", "reset=1&action=add");
231 $contributionTitle = substr(sha1(rand()), 0, 7);
232 $rand = 2 * rand(2, 50);
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');
240 $this->select('financial_type_id', "label={$financialType}");
243 $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom");
245 // Get contribution page id
246 $pageId = $this->urlArg('id');
248 //this contribution page for online contribution
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());
255 $this->webtestLogout();
257 //Open Live Contribution Page
258 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId&action=preview", '_qf_Main_upload-bottom');
260 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
261 $lastName = 'An' . substr(sha1(rand()), 0, 7);
262 $email = $firstName . "@example.com";
263 $this->waitForElementPresent('_qf_Main_upload-bottom');
264 $this->type("email-5", $email);
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']");
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');
273 $this->waitForAjaxContent();
274 $this->select('billing_country_id-5', 'value=1228');
275 $this->select('billing_state_province_id-5', 'value=1001');
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');
285 $this->type('billing_first_name', $firstName);
286 $this->type('billing_last_name', $lastName);
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');
292 $this->clickLink('_qf_Main_upload-bottom', '_qf_Confirm_next-bottom');
294 $this->click('_qf_Confirm_next-bottom');
295 $this->waitForPageToLoad($this->getTimeoutMsec());
297 //login to check contribution
299 // Log in using webtestLogin() method
300 $this->webtestLogin();
303 $this->openCiviPage("contribute/search", "reset=1", 'contribution_date_low');
305 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
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]");
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);
312 // View Contribution Record and test for expected values
314 'From' => "{$firstName} {$lastName}",
315 'Financial Type' => $financialType,
316 // as per changes made in CRM-15407
317 'Fee Amount' => '$ 1.50',
318 'Net Amount' => '$ 588.50',
319 'Contribution Status' => 'Completed',
321 $this->webtestVerifyTabularData($expected);
325 public function testContributeWithDateSpecificPriceSet() {
326 $this->webtestLogin();
328 //add financial type of account type expense
329 $financialType = $this->_testAddFinancialType();
331 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
332 $usedFor = 'Contribution';
333 $setHelp = 'Select your conference options.';
334 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
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.
338 $sid = $this->urlArg('sid');
339 $this->assertType('numeric', $sid);
341 $validStrings = array();
343 'Full Conference' => 'Text',
344 'Meal Choice' => 'Select',
345 'Pre-conference Meetup?' => 'Radio',
346 'Evening Sessions' => 'CheckBox',
348 $this->_testAddPriceFields($fields, $validateStrings, $financialType, TRUE);
350 // load the Price Set Preview and check for expected values
351 $this->_testVerifyPriceSet($validateStrings, $sid);
353 // Use default payment processor
354 $processorName = 'Test Processor';
355 $this->webtestAddPaymentProcessor($processorName);
357 $this->openCiviPage("admin/contribute/add", "reset=1&action=add");
359 $contributionTitle = substr(sha1(rand()), 0, 7);
360 $rand = 2 * rand(2, 50);
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');
370 $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom");
372 // Get contribution page id
373 $pageId = $this->urlArg('id');
375 //this contribution page for online contribution
376 $this->waitForElementPresent("xpath=//tr[@class='crm-contribution-contributionpage-amount-form-block-payment_processor']/td");
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);
379 $this->clickLink('_qf_Amount_next-bottom');
382 $this->webtestLogout();
384 //Open Live Contribution Page
385 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId&action=preview", '_qf_Main_upload-bottom');
387 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
388 $lastName = 'An' . substr(sha1(rand()), 0, 7);
389 $email = $firstName . "@example.com";
390 $this->waitForElementPresent('_qf_Main_upload-bottom');
391 $this->type('email-5', $email);
392 $this->click("xpath=//input[@class='crm-form-radio']");
393 $this->click("xpath=//input[@class='crm-form-checkbox']");
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');
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');
410 $this->type('billing_first_name', $firstName);
411 $this->type('billing_last_name', $lastName);
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');
417 $this->clickLink('_qf_Main_upload-bottom', '_qf_Confirm_next-bottom');
419 $this->click('_qf_Confirm_next-bottom');
420 $this->waitForPageToLoad($this->getTimeoutMsec());
422 //login to check contribution
423 $this->webtestLogin();
426 $this->openCiviPage("contribute/search", "reset=1", 'contribution_date_low');
427 $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
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]");
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);
434 // View Contribution Record and test for expected values
436 'From' => "{$firstName} {$lastName}",
437 'Financial Type' => $financialType,
438 // as per changes made in CRM-15407
439 'Fee Amount' => '$ 1.50',
440 'Net Amount' => '$ 63.50',
441 'Contribution Status' => 'Completed',
443 $this->webtestVerifyTabularData($expected);
446 public function testContributeOfflineforSoftcreditwithApi() {
447 // Log in using webtestLogin() method
448 $this->webtestLogin();
450 //create a contact and return the contact id
451 $firstNameSoft = "John_" . substr(sha1(rand()), 0, 5);
452 $lastNameSoft = "Doe_" . substr(sha1(rand()), 0, 5);
453 $this->webtestAddContact($firstNameSoft, $lastNameSoft);
454 $url = $this->parseURL();
455 $cid = $url['queryString']['cid'];
456 $this->assertType('numeric', $cid);
458 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
459 $usedFor = 'Contribution';
460 $setHelp = 'Select your conference options.';
461 $financialType = $this->_testAddFinancialType();
462 $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType);
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.
466 $sid = $this->urlArg('sid');
467 $this->assertType('numeric', $sid);
469 $validStrings = array();
471 'Full Conference' => 'Text',
472 'Meal Choice' => 'Select',
473 'Pre-conference Meetup?' => 'Radio',
474 'Evening Sessions' => 'CheckBox',
476 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
478 // load the Price Set Preview and check for expected values
479 $this->_testVerifyPriceSet($validateStrings, $sid);
481 $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", '_qf_Contribution_upload');
483 // create new contact using dialog
484 $contact = $this->createDialogContact();
486 // select contribution type
487 $this->select('financial_type_id', "label={$financialType}");
489 // fill in Received Date
490 $this->webtestFillDate('receive_date');
493 $this->type('source', 'Mailer 1');
495 // select price set items
496 $this->select('price_set_id', "label=$setTitle");
497 $this->type("xpath=//input[@class='four crm-form-text required']", "1");
498 $this->click("xpath=//input[@class='crm-form-radio']");
499 $this->click("xpath=//input[@class='crm-form-checkbox']");
500 // select payment instrument type = Check and enter chk number
501 $this->select('payment_instrument_id', 'value=4');
502 $this->waitForElementPresent('check_number');
503 $this->type('check_number', '1041');
505 $this->type('trxn_id', 'P20901X1' . rand(100, 10000));
507 $this->webtestFillAutocomplete("{$lastNameSoft}, {$firstNameSoft}", 'soft_credit_contact_id_1');
509 $this->type('soft_credit_amount_1', "65");
510 //Additional Detail section
511 $this->click('AdditionalDetail');
512 $this->waitForElementPresent('thankyou_date');
514 $this->type('note', 'This is a test note.');
515 $this->type('invoice_id', time());
516 $this->webtestFillDate('thankyou_date');
519 $this->clickLink('_qf_Contribution_upload', "xpath=//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span//a[text()='View']", FALSE);
520 $this->assertTrue($this->isTextPresent('The contribution record has been saved.'), "Status message didn't show up after saving!");
522 //click through to the Contribution view screen
523 $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']");
524 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
526 // View Contribution Record and test for expected values
528 'From' => $contact['display_name'],
529 'Financial Type' => $financialType,
530 'Contribution Amount' => 'Contribution Total: $ 590.00',
531 'Payment Method' => 'Check',
532 'Check Number' => '1041',
533 'Contribution Status' => 'Completed',
535 $this->webtestVerifyTabularData($expected);
543 foreach ($exp as $lab => $val) {
544 $this->assertElementContainsText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[$lab]/td[3]", $val);
547 // verify if soft credit was created successfully
548 $softCreditValues = array(
549 'Soft Credit To' => "{$firstNameSoft} {$lastNameSoft}",
553 foreach ($softCreditValues as $value) {
554 $this->assertElementContainsText("css=table.crm-soft-credit-listing", $value);
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
562 $this->waitForElementPresent("css=ul.ui-autocomplete li");
564 // visit contact summary page
565 $this->click("css=ul.ui-autocomplete li");
566 $this->waitForPageToLoad($this->getTimeoutMsec());
567 $this->click('css=li#tab_contribute a');
568 $this->waitForElementPresent('link=Record Contribution (Check, Cash, EFT ...)');
570 $id = explode('id=', $this->getAttribute("xpath=//table[@class='selector row-highlight']/tbody//tr[@id='rowid']/td[8]/a[text()='View']@href"));
571 $id = substr($id[1], 0, strpos($id[1], '&'));
572 $this->click("xpath=//table[@class='selector row-highlight']/tbody//tr[@id='rowid']/td[8]/a");
573 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
575 $this->webtestVerifyTabularData($expected);
578 'contribution_id' => $id,
582 // Retrieve contribution from the DB via api and verify DB values against view contribution page
583 $fields = $this->webtest_civicrm_api('contribution', 'get', $params);
585 $params['id'] = $params['contact_id'] = $fields['values'][$fields['id']]['soft_credit_to'];
586 $softCreditContact = CRM_Contact_BAO_Contact
::retrieve($params, $defaults, TRUE);
588 // View Contribution Record and test for expected values
590 'From' => $fields['values'][$fields['id']]['display_name'],
591 'Financial Type' => $fields['values'][$fields['id']]['financial_type'],
592 'Contribution Amount' => $fields['values'][$fields['id']]['total_amount'],
593 'Contribution Status' => $fields['values'][$fields['id']]['contribution_status'],
594 'Payment Method' => $fields['values'][$fields['id']]['payment_instrument'],
595 'Check Number' => $fields['values'][$fields['id']]['contribution_check_number'],
598 $this->webtestVerifyTabularData($expected);
600 // verify if soft credit
601 $softCreditValues = array(
602 'Soft Credit To' => $softCreditContact->display_name
,
606 foreach ($softCreditValues as $value) {
607 $this->assertElementContainsText("css=table.crm-soft-credit-listing", $value);