CRM-15031 Event Webtest Fix
[civicrm-core.git] / tests / phpunit / WebTest / Event / AddPricesetTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06a1bc01 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
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
6a488035 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Event_AddPricesetTest
31 */
6a488035
TO
32class WebTest_Event_AddPricesetTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testAddPriceSet() {
6a488035
TO
39
40 // Log in using webtestLogin() method
41 $this->webtestLogin();
42
43 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
42daf119
CW
44 $usedFor = 'Event';
45 $setHelp = 'Select your conference options.';
6a488035
TO
46 $this->_testAddSet($setTitle, $usedFor, $setHelp);
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.
a471a3b6 50 $sid = $this->urlArg('sid');
6a488035
TO
51 $this->assertType('numeric', $sid);
52
53 $validStrings = array();
54
55 $fields = array(
56 'Full Conference' => 'Text',
57 'Meal Choice' => 'Select',
58 'Pre-conference Meetup?' => 'Radio',
59 'Evening Sessions' => 'CheckBox',
60 );
61 $this->_testAddPriceFields($fields, $validateStrings);
62 // var_dump($validateStrings);
63
64 // load the Price Set Preview and check for expected values
65 $this->_testVerifyPriceSet($validateStrings, $sid);
66 }
67
4cbe18b8
EM
68 /**
69 * @param $setTitle
70 * @param $usedFor
71 * @param $setHelp
72 * @param string $financialType
73 */
6a488035 74 function _testAddSet($setTitle, $usedFor, $setHelp, $financialType = 'Event Fee') {
8b67c4d0 75 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
6a488035
TO
76
77 // Enter Priceset fields (Title, Used For ...)
78 $this->type('title', $setTitle);
79 if ($usedFor == 'Event') {
80 $this->check('extends[1]');
81 }
82 elseif ($usedFor == 'Contribution') {
83 $this->check('extends[2]');
84 }
85
9ffaaf79 86 $this->select("financial_type_id", "label={$financialType}");
76e86fd8 87
6a488035
TO
88 $this->type('help_pre', $setHelp);
89
90 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
225a8648 91 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom');
6a488035
TO
92 }
93
4cbe18b8
EM
94 /**
95 * @param $fields
96 * @param $validateStrings
97 * @param bool $dateSpecificFields
98 */
6a488035
TO
99 function _testAddPriceFields(&$fields, &$validateStrings, $dateSpecificFields = FALSE) {
100 foreach ($fields as $label => $type) {
101 $validateStrings[] = $label;
102
103 $this->type('label', $label);
104 $this->select('html_type', "value={$type}");
105
106 switch ($type) {
107 case 'Text':
108 $validateStrings[] = '525.00';
109 $this->type('price', '525.00');
110 $this->select('financial_type_id', 'Donation');
111 if ($dateSpecificFields == TRUE) {
112 $this->webtestFillDateTime('active_on', '+1 week');
113 }
114 else {
115 $this->check('is_required');
116 }
117 break;
118
119 case 'Select':
120 $options = array(
121 1 => array('label' => 'Chicken',
122 'amount' => '30.00',
123 'financial_type_id' => 'Donation'
124 ),
125 2 => array(
126 'label' => 'Vegetarian',
127 'amount' => '25.00',
128 'financial_type_id' => 'Donation'
129 ),
130 );
131 $this->addMultipleChoiceOptions($options, $validateStrings);
132 if ($dateSpecificFields == TRUE) {
133 $this->webtestFillDateTime('expire_on', '-1 week');
134 }
135 break;
136
137 case 'Radio':
138 $options = array(
139 1 => array('label' => 'Yes',
140 'amount' => '50.00',
76e86fd8
CW
141 'financial_type_id' => 'Donation'
142
6a488035
TO
143 ),
144 2 => array(
145 'label' => 'No',
146 'amount' => '0',
147 'financial_type_id' => 'Donation'
148 ),
149 );
150 $this->addMultipleChoiceOptions($options, $validateStrings);
151 $this->check('is_required');
152 if ($dateSpecificFields == TRUE) {
153 $this->webtestFillDateTime('active_on', '-1 week');
154 }
155 break;
156
157 case 'CheckBox':
158 $options = array(
159 1 => array('label' => 'First Night',
160 'amount' => '15.00',
161 'financial_type_id' => 'Donation'
162 ),
163 2 => array(
164 'label' => 'Second Night',
165 'amount' => '15.00',
166 'financial_type_id' => 'Donation'
167 ),
168 );
169 $this->addMultipleChoiceOptions($options, $validateStrings);
170 if ($dateSpecificFields == TRUE) {
171 $this->webtestFillDateTime('expire_on', '+1 week');
172 }
173 break;
174
175 default:
176 break;
177 }
225a8648 178 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom');
6a488035
TO
179 }
180 }
181
4cbe18b8
EM
182 /**
183 * @param $validateStrings
184 * @param $sid
185 */
6a488035
TO
186 function _testVerifyPriceSet($validateStrings, $sid) {
187 // verify Price Set at Preview page
188 // start at Manage Price Sets listing
a9f5275d 189 $this->openCiviPage('admin/price', 'reset=1');
6a488035
TO
190
191 // Use the price set id ($sid) to pick the correct row
9ffaaf79 192 $this->clickLink("//*[@id='price_set-{$sid}']/td[4]/span[1]/a[2]", '_qf_Preview_cancel-bottom');
6a488035
TO
193
194 // Check for expected price set field strings
195 $this->assertStringsPresent($validateStrings);
196 }
197
198 function testRegisterWithPriceSet() {
6a488035
TO
199 // Log in using webtestLogin() method
200 $this->webtestLogin();
201
202 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
42daf119
CW
203 $usedFor = 'Event';
204 $setHelp = 'Select your conference options.';
6a488035
TO
205 $this->_testAddSet($setTitle, $usedFor, $setHelp);
206
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.
a471a3b6 209 $sid = $this->urlArg('sid');
6a488035
TO
210 $this->assertType('numeric', $sid);
211
212 $validStrings = array();
213 $fields = array(
214 'Full Conference' => 'Text',
215 'Meal Choice' => 'Select',
216 'Pre-conference Meetup?' => 'Radio',
217 'Evening Sessions' => 'CheckBox',
218 );
219 $this->_testAddPriceFields($fields, $validateStrings);
220
221 // load the Price Set Preview and check for expected values
222 $this->_testVerifyPriceSet($validateStrings, $sid);
223
224 // We need a payment processor
225 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
226 $this->webtestAddPaymentProcessor($processorName);
227
8b67c4d0 228 $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom');
6a488035 229
42daf119
CW
230 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
231 $email = 'Smith' . substr(sha1(rand()), 0, 7) . '@example.com';
6a488035
TO
232 $eventDescription = 'Here is a description for this conference.';
233
6a488035
TO
234 $this->select('event_type_id', 'value=1');
235
236 // Attendee role s/b selected now.
237 $this->select('default_role_id', 'value=1');
238
239 // Enter Event Title, Summary and Description
240 $this->type('title', $eventTitle);
241 $this->type('summary', 'This is a great conference. Sign up now!');
242
243 // Type description in ckEditor (fieldname, text to type, editor)
244 $this->fillRichTextField('description', $eventDescription);
245
246 // Choose Start and End dates.
247 // Using helper webtestFillDate function.
248 $this->webtestFillDateTime("start_date", "+1 week");
249 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
250
251 $this->type('max_participants', '50');
252 $this->click('is_map');
253 $this->click('_qf_EventInfo_upload-bottom');
254
255 // Wait for Location tab form to load
3379d026 256 $this->waitForElementPresent('_qf_Location_upload_done-bottom');
6a488035
TO
257
258 // Go to Fees tab
259 $this->click('link=Fees');
3379d026 260 $this->waitForElementPresent('_qf_Fee_upload_done-bottom');
6a488035
TO
261 $this->click('CIVICRM_QFID_1_is_monetary');
262 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='$processorName']");
263 $this->select('financial_type_id','label=Event Fee');
264 $this->select('price_set_id', 'label=' . $setTitle);
265
6a488035
TO
266
267 // intro text for registration page
268 $registerIntro = 'Fill in all the fields below and click Continue.';
3379d026 269 $this->clickLink('_qf_Fee_upload-bottom', 'link=Online Registration', FALSE);
6a488035
TO
270
271 // Go to Online Registration tab
272 $this->click('link=Online Registration');
273 $this->waitForElementPresent('_qf_Registration_upload-bottom');
274
275 $this->check('is_online_registration');
276 $this->assertChecked('is_online_registration');
277
60709d21 278 $this->click('intro_text-plain');
6a488035
TO
279 $this->fillRichTextField('intro_text', $registerIntro);
280
281 // enable confirmation email
282 $this->click('CIVICRM_QFID_1_is_email_confirm');
283 $this->type('confirm_from_name', 'Jane Doe');
284 $this->type('confirm_from_email', 'jane.doe@example.org');
285
286 $this->click('_qf_Registration_upload-bottom');
3379d026 287 $this->waitForTextPresent("'Online Registration' information has been saved.");
6a488035
TO
288
289 // verify event input on info page
290 // start at Manage Events listing
a9f5275d 291 $this->openCiviPage('event/manage', 'reset=1');
6a488035
TO
292 $this->click("link=$eventTitle");
293
294 $this->waitForPageToLoad($this->getTimeoutMsec());
295 $eventInfoUrl = $this->getLocation();
296
3379d026 297 $permissions = array("edit-1-register-for-events");
298 $this->changePermissions($permissions);
42daf119 299 $this->webtestLogout();
6a488035
TO
300 $this->open($eventInfoUrl);
301 $this->click('link=Register Now');
302 $this->waitForElementPresent('_qf_Register_upload-bottom');
303
3379d026 304 $this->type("xpath=//input[@class='four crm-form-text required']", "1");
305 $this->click("xpath=//input[@class='crm-form-radio']");
306 $this->click("xpath=//input[@class='crm-form-checkbox']");
70452444 307 $this->type("first_name", "Jane");
308 $lastName = "Smith" . substr(sha1(rand()), 0, 7);
309 $this->type("last_name", $lastName);
6a488035
TO
310 $this->type('email-Primary', $email);
311
312 $this->waitForElementPresent('credit_card_type');
313 $this->select('credit_card_type', 'value=Visa');
314 $this->type('credit_card_number', '4111111111111111');
315 $this->type('cvv2', '000');
316 $this->select('credit_card_exp_date[M]', 'value=1');
317 $this->select('credit_card_exp_date[Y]', 'value=2020');
318 $this->type('billing_first_name', 'Jane');
70452444 319 $this->type('billing_last_name', $lastName);
6a488035
TO
320 $this->type('billing_street_address-5', '15 Main St.');
321 $this->type(' billing_city-5', 'San Jose');
322 $this->select('billing_country_id-5', 'value=1228');
323 $this->select('billing_state_province_id-5', 'value=1004');
324 $this->type('billing_postal_code-5', '94129');
325
225a8648 326 $this->clickLink('_qf_Register_upload-bottom', '_qf_Confirm_next-bottom');
6a488035
TO
327 $confirmStrings = array('Event Fee(s)', 'Billing Name and Address', 'Credit Card Information');
328 $this->assertStringsPresent($confirmStrings);
329 $this->click('_qf_Confirm_next-bottom');
330 $this->waitForPageToLoad($this->getTimeoutMsec());
331 $thankStrings = array('Thank You for Registering', 'Event Total', 'Transaction Date');
332 $this->assertStringsPresent($thankStrings);
333
6a488035
TO
334 // Log in using webtestLogin() method
335 $this->webtestLogin();
336
337 //Find Participant
8b67c4d0 338 $this->openCiviPage('event/search', 'reset=1', '_qf_Search_refresh');
6a488035
TO
339
340 $this->type('sort_name', "$email");
225a8648 341 $this->clickLink('_qf_Search_refresh', "xpath=id('participantSearch')/table/tbody/tr/td[11]/span/a[text()='View']");
6a488035
TO
342 $this->click("xpath=id('participantSearch')/table/tbody/tr/td[11]/span/a[text()='View']");
343 $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom');
344
345 $expected = array(
346 2 => 'Full Conference',
347 3 => 'Pre-conference Meetup? - Yes',
348 4 => 'Evening Sessions - First Night',
349 );
350 foreach ($expected as $value => $label) {
3379d026 351 $this->verifyText("xpath=id('ParticipantView')/div[2]/table[1]/tbody/tr[8]/td[2]/table/tbody/tr[$value]/td", $label);
6a488035
TO
352 }
353 // Fixme: We can't asset full string like - "Event Total: $ 590.00" as it has special char
354 $this->assertStringsPresent(' 590.00');
355 $this->click('_qf_ParticipantView_cancel-bottom');
356 }
357
358 function testParticipantWithDateSpecificPriceSet() {
6a488035
TO
359
360 // Log in using webtestLogin() method
361 $this->webtestLogin();
362
363 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
42daf119
CW
364 $usedFor = 'Event';
365 $setHelp = 'Select your conference options.';
6a488035
TO
366 $this->_testAddSet($setTitle, $usedFor, $setHelp);
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.
a471a3b6 370 $sid = $this->urlArg('sid');
6a488035
TO
371 $this->assertType('numeric', $sid);
372
373 $validStrings = array();
374 $fields = array(
375 'Full Conference' => 'Text',
376 'Meal Choice' => 'Select',
377 'Pre-conference Meetup?' => 'Radio',
378 'Evening Sessions' => 'CheckBox',
379 );
380 $this->_testAddPriceFields($fields, $validateStrings, TRUE);
381
382 // load the Price Set Preview and check for expected values
383 $this->_testVerifyPriceSet($validateStrings, $sid);
384
385 // We need a payment processor
386 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
387 $this->webtestAddPaymentProcessor($processorName);
388
8b67c4d0 389 $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom');
6a488035 390
42daf119
CW
391 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
392 $email = 'Smith' . substr(sha1(rand()), 0, 7) . '@example.com';
6a488035
TO
393 $eventDescription = 'Here is a description for this conference.';
394
6a488035
TO
395 $this->select('event_type_id', 'value=1');
396
397 // Attendee role s/b selected now.
398 $this->select('default_role_id', 'value=1');
399
400 // Enter Event Title, Summary and Description
401 $this->type('title', $eventTitle);
402 $this->type('summary', 'This is a great conference. Sign up now!');
403
404 // Type description in ckEditor (fieldname, text to type, editor)
405 $this->fillRichTextField('description', $eventDescription );
406
407 // Choose Start and End dates.
408 // Using helper webtestFillDate function.
409 $this->webtestFillDateTime("start_date", "+1 week");
410 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
411
412 $this->type('max_participants', '50');
413 $this->click('is_map');
414 $this->click('_qf_EventInfo_upload-bottom');
415
416 // Wait for Location tab form to load
417 $this->waitForPageToLoad($this->getTimeoutMsec());
418
419 // Go to Fees tab
420 $this->click('link=Fees');
421 $this->waitForElementPresent('_qf_Fee_upload-bottom');
422 $this->click('CIVICRM_QFID_1_is_monetary');
423 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='$processorName']");
424 $this->select('financial_type_id','label=Event Fee');
425 $this->select('price_set_id', 'label=' . $setTitle);
426
3379d026 427 $this->clickLink('_qf_Fee_upload-bottom', 'link=Online Registration', FALSE);
6a488035
TO
428
429 // intro text for registration page
430 $registerIntro = 'Fill in all the fields below and click Continue.';
431
432 // Go to Online Registration tab
433 $this->click('link=Online Registration');
434 $this->waitForElementPresent('_qf_Registration_upload-bottom');
435
436 $this->check('is_online_registration');
437 $this->assertChecked('is_online_registration');
438
60709d21 439 $this->click('intro_text-plain');
6a488035
TO
440 $this->fillRichTextField('intro_text', $registerIntro);
441
442 // enable confirmation email
443 $this->click('CIVICRM_QFID_1_is_email_confirm');
444 $this->type('confirm_from_name', 'Jane Doe');
445 $this->type('confirm_from_email', 'jane.doe@example.org');
446
447 $this->click('_qf_Registration_upload-bottom');
3379d026 448 $this->waitForTextPresent("'Online Registration' information has been saved.");
6a488035
TO
449
450 // verify event input on info page
451 // start at Manage Events listing
a9f5275d 452 $this->openCiviPage('event/manage', 'reset=1');
6a488035
TO
453 $this->click("link=$eventTitle");
454
455 $this->waitForPageToLoad($this->getTimeoutMsec());
456 // Adding contact with randomized first name (so we can then select that contact when creating event registration)
457 // We're using Quick Add block on the main page for this.
458 $firstName = substr(sha1(rand()), 0, 7);
459 $this->webtestAddContact($firstName, 'Anderson', TRUE);
460 $contactName = "Anderson, $firstName";
461 $displayName = "$firstName Anderson";
462
8b67c4d0 463 $this->openCiviPage('participant/add', 'reset=1&action=add&context=standalone', '_qf_Participant_upload-bottom');
6a488035 464
6a488035
TO
465 // Type contact last name in contact auto-complete, wait for dropdown and click first result
466 $this->webtestFillAutocomplete($firstName);
467
468 // Select event. Based on label for now.
e6c6db94 469 $this->select2('event_id', "$eventTitle");
6a488035 470 // Select role
e6c6db94 471 $this->multiselect2('role_id', array('Volunteer'));
6a488035 472
3379d026 473 $this->click("xpath=//input[@class='crm-form-radio']");
474 $this->click("xpath=//input[@class='crm-form-checkbox']");
6a488035
TO
475
476 // Choose Registration Date.
477 // Using helper webtestFillDate function.
478 $this->webtestFillDate('register_date', 'now');
479 $today = date('F jS, Y', strtotime('now'));
480
481 // Select participant status
482 $this->select('status_id', 'value=1');
483
484 // Clicking save.
485 $this->click('_qf_Participant_upload-bottom');
486 $this->waitForPageToLoad($this->getTimeoutMsec());
487 // Is status message correct?
e6c6db94 488 $this->waitForText("crm-notification-container", "Event registration for $displayName has been added", "Status message didn't show up after saving!");
6a488035 489
3379d026 490 $this->waitForElementPresent("xpath=//*[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
6a488035
TO
491
492 //click through to the participant view screen
3379d026 493 $this->click("xpath=//*[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
6a488035
TO
494 $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom');
495 }
7f587af0
PN
496
497 /**
76e86fd8
CW
498 * Function to test to regiter participant for event with
499
7f587af0 500 * multiple price fields in price-set
76e86fd8
CW
501 * CRM-11986
502
7f587af0
PN
503 *
504 */
505 function testEventWithPriceSet() {
76e86fd8 506
7f587af0
PN
507 // Log in using webtestLogin() method
508 $this->webtestLogin();
76e86fd8 509
7f587af0
PN
510 // Adding contact with randomized first name (so we can then select that contact when creating event registration)
511 // We're using Quick Add block on the main page for this.
512 $firstName = substr(sha1(rand()), 0, 7);
513 $this->webtestAddContact($firstName, 'Anderson', TRUE);
514 $contactName = "Anderson, $firstName";
515 $displayName = "$firstName Anderson";
76e86fd8 516
7f587af0 517 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
42daf119
CW
518 $usedFor = 'Event';
519 $setHelp = 'Select your conference options.';
7f587af0
PN
520 $this->_testAddSet($setTitle, $usedFor, $setHelp);
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.
a471a3b6 524 $sid = $this->urlArg('sid');
7f587af0
PN
525 $this->assertType('numeric', $sid);
526
527 $validStrings = array();
528 $fields = array(
529 'Full Conference' => 'Text',
530 'Pre-conference Meetup?' => 'Radio',
531 'Evening Sessions' => 'CheckBox',
532 );
533 $this->_testAddPriceFields($fields, $validateStrings);
76e86fd8 534
7f587af0
PN
535 // load the Price Set Preview and check for expected values
536 $this->_testVerifyPriceSet($validateStrings, $sid);
42daf119 537
8b67c4d0 538 $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom');
7f587af0 539
42daf119
CW
540 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
541 $email = 'Smith' . substr(sha1(rand()), 0, 7) . '@example.com';
7f587af0 542 $eventDescription = 'Here is a description for this conference.';
7f587af0 543
7f587af0 544 $this->select('event_type_id', 'value=1');
76e86fd8 545
7f587af0
PN
546 // Attendee role s/b selected now.
547 $this->select('default_role_id', 'value=1');
76e86fd8 548
7f587af0
PN
549 // Enter Event Title, Summary and Description
550 $this->type('title', $eventTitle);
551 $this->type('summary', 'This is a great conference. Sign up now!');
76e86fd8 552
7f587af0
PN
553 // Type description in ckEditor (fieldname, text to type, editor)
554 $this->fillRichTextField('description', $eventDescription);
76e86fd8 555
7f587af0
PN
556 // Choose Start and End dates.
557 // Using helper webtestFillDate function.
558 $this->webtestFillDateTime("start_date", "+1 week");
559 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
560
561 $this->type('max_participants', '50');
562 $this->click('is_map');
563 $this->click('_qf_EventInfo_upload-bottom');
564
565 // Wait for Location tab form to load
566 $this->waitForPageToLoad($this->getTimeoutMsec());
567
568 // Go to Fees tab
569 $this->click('link=Fees');
570 $this->waitForElementPresent('_qf_Fee_upload-bottom');
571 $this->click('CIVICRM_QFID_1_is_monetary');
572 $this->select('financial_type_id','label=Event Fee');
573 $this->select('price_set_id', 'label=' . $setTitle);
76e86fd8 574
7f587af0 575 $this->click('_qf_Fee_upload-bottom');
9ffaaf79 576 $this->waitForText("crm-notification-container","'Fees' information has been saved.");
7f587af0 577
42daf119 578 $this->openCiviPage('participant/add', 'reset=1&action=add&context=standalone', '_qf_Participant_upload-bottom');
7f587af0 579
7f587af0
PN
580 // Type contact last name in contact auto-complete, wait for dropdown and click first result
581 $this->webtestFillAutocomplete($firstName);
9ffaaf79 582 $this->select2('event_id', $eventTitle);
7f587af0 583 // Select role
e6c6db94 584 $this->multiselect2('role_id', array('Volunteer'));
76e86fd8 585
7f587af0
PN
586 // Choose Registration Date.
587 // Using helper webtestFillDate function.
588 $this->webtestFillDate('register_date', 'now');
589 $today = date('F jS, Y', strtotime('now'));
590 // May 5th, 2010
76e86fd8 591
7f587af0
PN
592 // Select participant status
593 $this->select('status_id', 'value=1');
594
595 // Setting registration source
596 $this->type('source', 'Event StandaloneAddTest Webtest');
76e86fd8 597
7f587af0
PN
598 // Select an event fee
599 $this->waitForElementPresent('priceset');
3bbf7318 600 $this->type("//div[@id='priceset']/div[2]/div[2]/input", '5');
601 $this->fireEvent("//div[@id='priceset']/div[2]/div[2]/input", 'blur');
602 $this->click("xpath=//div[@id='priceset']/div[3]/div[2]/div[1]/span/input");
603 $this->click("xpath=//div[@id='priceset']/div[4]/div[2]/div[1]/span/input");
604 $this->click("xpath=//div[@id='priceset']/div[4]/div[2]/div[2]/span/input");
76e86fd8 605
7f587af0
PN
606 // Select payment method = Check and enter chk number
607 $this->select('payment_instrument_id', 'value=4');
608 $this->waitForElementPresent('check_number');
76e86fd8
CW
609 $this->type('check_number', '1044');
610
7f587af0
PN
611 // Clicking save.
612 $this->click('_qf_Participant_upload-bottom');
613 $this->waitForPageToLoad($this->getTimeoutMsec());
76e86fd8 614
7f587af0 615 // Is status message correct?
c038a4f0 616 $this->assertElementContainsText("css=#crm-notification-container", "Event registration for $displayName has been added", "Status message didn't show up after saving!");
76e86fd8 617
9ffaaf79 618 $this->waitForElementPresent("xpath=//form[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
7f587af0 619 //click through to the participant view screen
9ffaaf79 620 $this->click("xpath=//form[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
7f587af0 621 $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom');
76e86fd8 622
7f587af0
PN
623 $this->webtestVerifyTabularData(
624 array(
625 'Event' => $eventTitle,
626 'Participant Role' => 'Attendee',
627 'Status' => 'Registered',
628 'Event Source' => 'Event StandaloneAddTest Webtest',
7f587af0
PN
629 )
630 );
e6c6db94 631 $this->waitForElementPresent("xpath=//table/tbody/tr/td[text()='Fees']/following-sibling::td");
632 $this->verifyText("xpath=//table/tbody/tr/td[text()='Fees']/following-sibling::td/table/tbody/tr[2]/td", preg_quote('$ 2,705.00'), 'In line ' . __LINE__);
7f587af0
PN
633 $expectedLineItems = array(
634 2 => array(
635 1 => 'Full Conference',
636 2 => '5',
637 3 => '$ 525.00',
638 4 => '$ 2,625.00',
639 ),
640 3 => array(
641 2 => '1',
642 3 => '$ 50.00',
643 4 => '$ 50.00',
644 ),
645 4 => array(
646 1 => 'Evening Sessions - First Night',
647 2 => '1',
648 3 => '$ 15.00',
649 4 => '$ 15.00',
650 ),
651 5 => array(
652 1 => 'Evening Sessions - Second Night',
653 2 => '1',
654 3 => '$ 15.00',
655 4 => '$ 15.00',
656 ),
657 );
658 $this->_checkLineItems($expectedLineItems);
659 // check contribution record as well
660 // click through to the contribution view screen
9ffaaf79 661 $this->click("xpath=//*[@id='ParticipantView']/div[2]/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']");
7f587af0
PN
662 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
663
664 $this->webtestVerifyTabularData(
665 array(
666 'From' => $displayName,
667 'Financial Type' => 'Event Fee',
668 'Contribution Status' => 'Completed',
669 'Paid By' => 'Check',
670 'Check Number' => '1044',
7f587af0
PN
671 'Received Into' => 'Deposit Bank Account',
672 )
673 );
60709d21 674 $this->verifyText("xpath=//td[text()='Contribution Amount']/following-sibling::td//div/div", preg_quote('Contribution Total: $ 2,705.00'));
7f587af0 675 }
76e86fd8 676
9669d0f3
RN
677
678 function testDeletePriceSetforEventTemplate() {
679 // Log in using webtestLogin() method
680 $this->webtestLogin();
4cbe18b8 681
9669d0f3
RN
682 $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7);
683 $usedFor = 'Event';
684 $setHelp = 'Select your conference options.';
685 $this->_testAddSet($setTitle, $usedFor, $setHelp);
4cbe18b8 686
9669d0f3
RN
687 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
688 // which is where we are after adding Price Set.
689 $sid = $this->urlArg('sid');
690 $this->assertType('numeric', $sid);
4cbe18b8 691
9669d0f3
RN
692 $validStrings = array();
693 $fields = array(
694 'Test Field' => 'Text',
695 );
696 $this->_testAddPriceFields($fields, $validateStrings);
697
698 // load the Price Set Preview and check for expected values
699 $this->_testVerifyPriceSet($validateStrings, $sid);
700 $this->openCiviPage('admin/eventTemplate', 'reset=1');
701 $this->clickLink('newEventTemplate');
702 $this->select("template_id", "value=6");
703 // Wait for event type to be filled in (since page reloads)
3379d026 704 $this->waitForElementPresent("template_id");
9669d0f3 705 // Enter Event Title, Summary and Description
3379d026 706 $this->select("event_type_id", "value=4");
707 $this->select("default_role_id", "value=1");
9669d0f3
RN
708 $this->type("title", "Test Event");
709 $this->type("summary", "This is a great conference. Sign up now!");
4cbe18b8 710
3379d026 711 $this->click("_qf_EventInfo_upload-bottom");
712 $this->waitForElementPresent('link=Fees');
9669d0f3
RN
713 // Go to Fees tab
714 $this->click('link=Fees');
715 $this->waitForElementPresent('_qf_Fee_upload-bottom');
716 $this->click('CIVICRM_QFID_1_is_monetary');
717 $this->select('financial_type_id','label=Event Fee');
718 $this->select('price_set_id', 'label=' . $setTitle);
719 $templateId = $this->urlArg('id');
3379d026 720 $this->click('_qf_Fee_upload-bottom');
4cbe18b8 721
9669d0f3
RN
722 //check the delete for price field
723 $this->openCiviPage("admin/price/field", "reset=1&action=browse&sid={$sid}");
724 $this->click("xpath=//table[@id='option11']/tbody/tr/td[9]/span[2]/ul/li[2]/a");
725 // Check confirmation alert.
726 $this->assertTrue((bool)preg_match("/^Are you sure you want to delete this price field?/",
727 $this->getConfirmation()
728 ));
729 $this->chooseOkOnNextConfirmation();
730 $this->waitForPageToLoad($this->getTimeoutMsec());
731 //assert the message
5be3afb2 732 $this->waitForText('price_set_used_by',
733 "it is currently in use by one or more active events or contribution pages or contributions or event templates.");
4cbe18b8 734
9669d0f3
RN
735 //check the delete for priceset
736 $this->openCiviPage("admin/price", "reset=1");
737 $this->click("xpath=//table[@id='option11']/tbody/tr/td[4]/span[2]/ul/li[3]/a");
738 // Check confirmation alert.
739 $this->assertTrue((bool)preg_match("/^Are you sure you want to delete this price set?/",
740 $this->getConfirmation()
741 ));
742 $this->chooseOkOnNextConfirmation();
743 $this->waitForPageToLoad($this->getTimeoutMsec());
744 //assert the message
5be3afb2 745 $this->waitForText('price_set_used_by',
746 "it is currently in use by one or more active events or contribution pages or contributions or event templates.");
9669d0f3 747 }
4cbe18b8
EM
748
749 /**
750 * @param $expectedLineItems
751 */
7f587af0 752 function _checkLineItems($expectedLineItems) {
76e86fd8 753 foreach ($expectedLineItems as $lineKey => $lineValue) {
76e86fd8 754 foreach ($lineValue as $key => $value) {
9ffaaf79 755 $this->verifyText("xpath=//table/tbody//tr/td[text()='Selections']/following-sibling::td/table/tbody//tr[$lineKey]/td[$key]", preg_quote($value));
7f587af0
PN
756 }
757 }
758 }
6a488035
TO
759}
760