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