1f453ac80d0162686a4729b94b5d4eed3aba7ea8
[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->open($this->sboxPath . 'civicrm/admin/price?reset=1&action=add');
71 $this->waitForPageToLoad($this->getTimeoutMsec());
72 $this->waitForElementPresent('_qf_Set_next-bottom');
73
74 // Enter Priceset fields (Title, Used For ...)
75 $this->type('title', $setTitle);
76 if ($usedFor == 'Event') {
77 $this->check('extends_1');
78 }
79 elseif ($usedFor == 'Contribution') {
80 $this->check('extends_2');
81 }
82
83 if ($financialType) {
84 $this->select("financial_type_id", "label={$financialType}");
85 }
86 $this->type('help_pre', $setHelp);
87
88 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
89 $this->click('_qf_Set_next-bottom');
90
91 $this->waitForPageToLoad($this->getTimeoutMsec());
92 $this->waitForElementPresent('_qf_Field_next-bottom');
93 }
94
95 function _testAddPriceFields(&$fields, &$validateString, $financialType, $dateSpecificFields = FALSE) {
96 $validateStrings[] = $financialType;
97 foreach ($fields as $label => $type) {
98 $validateStrings[] = $label;
99
100 $this->type('label', $label);
101 $this->select('html_type', "value={$type}");
102
103 switch ($type) {
104 case 'Text':
105 $validateStrings[] = '525.00';
106 $this->type('price', '525.00');
107 if ($dateSpecificFields == TRUE) {
108 $this->webtestFillDateTime('active_on', '+1 week');
109 }
110 else {
111 $this->check('is_required');
112 }
113 break;
114
115 case 'Select':
116 $options = array(
117 1 => array('label' => 'Chicken',
118 'amount' => '30.00',
119 ),
120 2 => array(
121 'label' => 'Vegetarian',
122 'amount' => '25.00',
123 ),
124 );
125 $this->addMultipleChoiceOptions($options, $validateStrings);
126 if ($dateSpecificFields == TRUE) {
127 $this->webtestFillDateTime('expire_on', '-1 week');
128 }
129 break;
130
131 case 'Radio':
132 $options = array(
133 1 => array('label' => 'Yes',
134 'amount' => '50.00',
135 ),
136 2 => array(
137 'label' => 'No',
138 'amount' => '0',
139 ),
140 );
141 $this->addMultipleChoiceOptions($options, $validateStrings);
142 $this->check('is_required');
143 if ($dateSpecificFields == TRUE) {
144 $this->webtestFillDateTime('active_on', '-1 week');
145 }
146 break;
147
148 case 'CheckBox':
149 $options = array(
150 1 => array('label' => 'First Night',
151 'amount' => '15.00',
152 ),
153 2 => array(
154 'label' => 'Second Night',
155 'amount' => '15.00',
156 ),
157 );
158 $this->addMultipleChoiceOptions($options, $validateStrings);
159 if ($dateSpecificFields == TRUE) {
160 $this->webtestFillDateTime('expire_on', '+1 week');
161 }
162 break;
163
164 default:
165 break;
166 }
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');
171 }
172 }
173
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;
182 $isActive = FALSE;
183 $isTax = TRUE;
184 $taxRate = 9;
185 $isDefault = FALSE;
186
187 //Add new organisation
188 if($orgName) {
189 $this->webtestAddOrganization($orgName);
190 }
191
192 $this->_testAddFinancialAccount($financialAccountTitle,
193 $financialAccountDescription,
194 $accountingCode,
195 $orgName,
196 $financialAccountType,
197 $taxDeductible,
198 $isActive,
199 $isTax,
200 $taxRate,
201 $isDefault
202 );
203 $this->waitForElementPresent("xpath=//table/tbody//tr/td[1][text()='{$financialAccountTitle}']/../td[9]/span/a[text()='Edit']");
204
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);
210
211 $accountRelationship = "Income Account is";
212 $expected[] = array('financial_account' => $financialAccountTitle,
213 'account_relationship' => $accountRelationship
214 );
215
216 $this->select('account_relationship', "label={$accountRelationship}");
217 sleep(2);
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'];
224 }
225
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());
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->open($this->sboxPath . 'civicrm/contribute/add?reset=1&action=add&context=standalone');
272
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');
276
277 // Let's start filling the form with values.
278
279 // create new contact using dialog
280 $firstName = substr(sha1(rand()), 0, 7);
281 $this->webtestNewDialogContact($firstName, 'Contributor', $firstName . '@example.com');
282
283 // select financial type
284 $this->select('financial_type_id', "label={$financialType}");
285
286 // fill in Received Date
287 $this->webtestFillDate('receive_date');
288
289 // source
290 $this->type('source', 'Mailer 1');
291
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');
301
302 $this->type('trxn_id', 'P20901X1' . rand(100, 10000));
303
304 //Additional Detail section
305 $this->click('AdditionalDetail');
306 $this->waitForElementPresent('thankyou_date');
307
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');
314
315 // Clicking save.
316 $this->click('_qf_Contribution_upload');
317 $this->waitForPageToLoad($this->getTimeoutMsec());
318
319 // Is status message correct?
320 $this->assertTrue($this->isTextPresent('The contribution record has been saved.'), "Status message didn't show up after saving!");
321
322 $this->waitForElementPresent("xpath=//div[@id='Contributions']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
323
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');
327 $expected = array(
328 2 => $financialType,
329 3 => '590.00',
330 9 => 'Completed',
331 10 => 'Check',
332 11 => 'check #1041',
333 );
334 foreach ($expected as $label => $value) {
335 $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[$label]/td[2]", preg_quote($value));
336 }
337
338 $exp = array(
339 2 => '$ 525.00',
340 3 => '$ 50.00',
341 4 => '$ 15.00',
342 );
343
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]",
346 preg_quote($val)
347 );
348 }
349 }
350
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]";
360 return $registerUrl;
361 }
362
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
366 // class attributes.
367 $this->open($this->sboxPath);
368
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();
375
376 //add financial type of account type expense
377 $financialType = $this->_testAddFinancialType();
378
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);
383
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);
389
390 $validStrings = array();
391 $fields = array(
392 'Full Conference' => 'Text',
393 'Meal Choice' => 'Select',
394 'Pre-conference Meetup?' => 'Radio',
395 'Evening Sessions' => 'CheckBox',
396 );
397
398 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
399
400 // load the Price Set Preview and check for expected values
401 $this->_testVerifyPriceSet($validateStrings, $sid);
402
403 // We need a payment processor
404 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
405 $this->webtestAddPaymentProcessor($processorName);
406
407 $this->open($this->sboxPath . 'civicrm/admin/contribute/add?reset=1&action=add');
408
409 $contributionTitle = substr(sha1(rand()), 0, 7);
410 $rand = 2 * rand(2, 50);
411
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');
417
418 $this->select('financial_type_id', "label={$financialType}");
419 // go to step 2
420 $this->click('_qf_Settings_next');
421 $this->waitForElementPresent('_qf_Amount_next-bottom');
422
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());
429
430 //get Url for Live Contribution Page
431 $registerUrl = $this->_testVerifyRegisterPage($contributionPageTitle);
432
433 //logout
434 $this->open($this->sboxPath . 'civicrm/logout?reset=1');
435 $this->waitForPageToLoad($this->getTimeoutMsec());
436
437 //Open Live Contribution Page
438 $this->open($this->sboxPath . $registerUrl);
439 $this->waitForElementPresent('_qf_Main_upload-bottom');
440
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']");
448
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');
455
456 //Credit Card Info
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');
462
463 //Billing Info
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');
472
473 $this->waitForPageToLoad($this->getTimeoutMsec());
474 $this->waitForElementPresent('_qf_Confirm_next-bottom');
475
476 $this->click('_qf_Confirm_next-bottom');
477 $this->waitForPageToLoad($this->getTimeoutMsec());
478
479 //login to check contribution
480 $this->open($this->sboxPath);
481
482 // Log in using webtestLogin() method
483 $this->webtestLogin();
484
485 //Find Contribution
486 $this->open($this->sboxPath . 'civicrm/contribute/search?reset=1');
487
488 $this->waitForElementPresent('contribution_date_low');
489
490 $this->type('sort_name', "$firstName $lastName");
491 $this->click('_qf_Search_refresh');
492
493 $this->waitForPageToLoad($this->getTimeoutMsec());
494
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");
499
500 // View Contribution Record and test for expected values
501 $expected = array(
502 'From' => "{$firstName} {$lastName}",
503 'Financial Type' => $financialType,
504 'Net Amount' => '$ 590.00',
505 'Contribution Status' => 'Completed',
506 );
507 $this->webtestVerifyTabularData($expected);
508
509 }
510
511 function testContributeWithDateSpecificPriceSet() {
512 $this->webtestLogin();
513
514 //add financial type of account type expense
515 $financialType= $this->_testAddFinancialType();
516
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);
521
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);
527
528 $validStrings = array();
529 $fields = array(
530 'Full Conference' => 'Text',
531 'Meal Choice' => 'Select',
532 'Pre-conference Meetup?' => 'Radio',
533 'Evening Sessions' => 'CheckBox',
534 );
535 $this->_testAddPriceFields($fields, $validateStrings, $financialType, TRUE);
536
537 // load the Price Set Preview and check for expected values
538 $this->_testVerifyPriceSet($validateStrings, $sid);
539
540 // We need a payment processor
541 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
542 $this->webtestAddPaymentProcessor($processorName);
543
544 $this->open($this->sboxPath . 'civicrm/admin/contribute/add?reset=1&action=add');
545
546 $contributionTitle = substr(sha1(rand()), 0, 7);
547 $rand = 2 * rand(2, 50);
548
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');
555
556 // go to step 2
557 $this->click('_qf_Settings_next');
558 $this->waitForElementPresent('_qf_Amount_next-bottom');
559
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());
566
567 //get Url for Live Contribution Page
568 $registerUrl = $this->_testVerifyRegisterPage($contributionPageTitle);
569
570 //logout
571 $this->open($this->sboxPath . 'civicrm/logout?reset=1');
572 $this->waitForPageToLoad($this->getTimeoutMsec());
573
574 //Open Live Contribution Page
575 $this->open($this->sboxPath . $registerUrl);
576 $this->waitForElementPresent('_qf_Main_upload-bottom');
577
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']");
584
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');
591
592 //Credit Card Info
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');
598
599 //Billing Info
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');
608
609 $this->waitForPageToLoad($this->getTimeoutMsec());
610 $this->waitForElementPresent('_qf_Confirm_next-bottom');
611
612 $this->click('_qf_Confirm_next-bottom');
613 $this->waitForPageToLoad($this->getTimeoutMsec());
614
615 //login to check contribution
616 $this->open($this->sboxPath);
617
618 // Log in using webtestLogin() method
619 $this->webtestLogin();
620
621 //Find Contribution
622 $this->open($this->sboxPath . 'civicrm/contribute/search?reset=1');
623
624 $this->waitForElementPresent('contribution_date_low');
625
626 $this->type('sort_name', "$firstName $lastName");
627 $this->click('_qf_Search_refresh');
628
629 $this->waitForPageToLoad($this->getTimeoutMsec());
630
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');
635
636 // View Contribution Record and test for expected values
637 $expected = array(
638 'From' => "{$firstName} {$lastName}",
639 'Financial Type' => $financialType,
640 'Net Amount' => '$ 65.00',
641 'Contribution Status' => 'Completed',
642 );
643 $this->webtestVerifyTabularData($expected);
644 }
645
646 function testContributeOfflineforSoftcreditwithApi() {
647 // Log in using webtestLogin() method
648 $this->webtestLogin();
649
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);
657
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);
663
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);
669
670 $validStrings = array();
671 $fields = array(
672 'Full Conference' => 'Text',
673 'Meal Choice' => 'Select',
674 'Pre-conference Meetup?' => 'Radio',
675 'Evening Sessions' => 'CheckBox',
676 );
677 $this->_testAddPriceFields($fields, $validateStrings, $financialType);
678
679 // load the Price Set Preview and check for expected values
680 $this->_testVerifyPriceSet($validateStrings, $sid);
681
682 $this->open($this->sboxPath . 'civicrm/contribute/add?reset=1&action=add&context=standalone');
683
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');
687
688 // Let's start filling the form with values.
689
690 // create new contact using dialog
691 $firstName = substr(sha1(rand()), 0, 7);
692 $this->webtestNewDialogContact($firstName, 'Contributor', $firstName . '@example.com');
693
694 // select contribution type
695 $this->select('financial_type_id', "label={$financialType}");
696
697 // fill in Received Date
698 $this->webtestFillDate('receive_date');
699
700 // source
701 $this->type('source', 'Mailer 1');
702
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');
712
713 $this->type('trxn_id', 'P20901X1' . rand(100, 10000));
714
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');
722
723 $this->type('note', 'This is a test note.');
724 $this->type('invoice_id', time());
725 $this->webtestFillDate('thankyou_date');
726
727 // Clicking save.
728 $this->click('_qf_Contribution_upload');
729 $this->waitForPageToLoad($this->getTimeoutMsec());
730
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!");
734
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');
738
739 // View Contribution Record and test for expected values
740 $expected = array(
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",
748 );
749 $this->webtestVerifyTabularData($expected);
750
751 $exp = array(
752 2 => '$ 525.00',
753 3 => '$ 50.00',
754 4 => '$ 15.00',
755 );
756
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]",
759 preg_quote($val)
760 );
761 }
762
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");
769
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 ...)');
775
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');
780
781 $this->webtestVerifyTabularData($expected);
782
783 $params = array('contribution_id' => $id,
784 'version' => 3,
785 );
786
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 );
790
791 $params['id'] = $params['contact_id'] = $fields['values'][$fields['id']]['soft_credit_to'];
792 $softCreditContact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, TRUE);
793
794 // View Contribution Record and test for expected values
795 $expected = array(
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,
803 );
804 $this->webtestVerifyTabularData($expected);
805 }
806 }
807