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