Merge branch '4.4' into master
[civicrm-core.git] / tests / phpunit / WebTest / Event / PricesetMaxCountTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Event_PricesetMaxCountTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testWithoutFieldCount() {
35 // Log in using webtestLogin() method
36 $this->webtestLogin();
37
38 // We need a payment processor
39 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
40 $this->webtestAddPaymentProcessor($processorName);
41
42 // create priceset
43 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
44 $financialType = 'Donation';
45 $this->_testAddSet($priceset, $financialType);
46
47 // create price fields
48 $fields = array(
49 'Full Conference' => array(
50 'type' => 'Text',
51 'amount' => '525.00',
52 'max_count' => 2,
53 'is_required' => TRUE,
54 'financial_type_id' => 1,
55 ),
56 'Meal Choice' => array(
57 'type' => 'Select',
58 'options' => array(
59 1 => array(
60 'label' => 'Chicken',
61 'amount' => '525.00',
62 'max_count' => 1,
63 'financial_type_id' => 1,
64 ),
65 2 => array(
66 'label' => 'Vegetarian',
67 'amount' => '200.00',
68 'max_count' => 5,
69 'financial_type_id' => 1,
70 ),
71 ),
72 ),
73 'Pre-conference Meetup?' => array(
74 'type' => 'Radio',
75 'options' => array(
76 1 => array(
77 'label' => 'Yes',
78 'amount' => '50.00',
79 'max_count' => 1,
80 'financial_type_id' => 1,
81 ),
82 2 => array(
83 'label' => 'No',
84 'amount' => '10',
85 'max_count' => 5,
86 'financial_type_id' => 1,
87 ),
88 ),
89 ),
90 'Evening Sessions' => array(
91 'type' => 'CheckBox',
92 'options' => array(
93 1 => array(
94 'label' => 'First Five',
95 'amount' => '100.00',
96 'max_count' => 2,
97 'financial_type_id' => 1,
98 ),
99 2 => array(
100 'label' => 'Second Four',
101 'amount' => '50.00',
102 'max_count' => 4,
103 'financial_type_id' => 1,
104 ),
105 ),
106 ),
107 );
108
109 // add price fields
110 $this->_testAddPriceFields($fields);
111
112 // get price set url.
113 $pricesetLoc = $this->getLocation();
114
115 // get text field Id.
116 $textFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]@href"));
117 $textFieldId = explode('&', $textFieldId[0]);
118 $textFieldId = explode('=', $textFieldId[3]);
119 $textFieldId = $textFieldId[1];
120
121 $this->open($pricesetLoc);
122 $this->waitForPageToLoad($this->getTimeoutMsec());
123
124 // get select field id
125 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/a");
126 $this->waitForPageToLoad($this->getTimeoutMsec());
127 $selectFieldLoc = $this->getLocation();
128 $selectFieldId = $this->urlArg('fid');
129
130 // get select field ids
131 // get select field option1
132 $selectFieldOp1 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]@href"));
133 $selectFieldOp1 = explode('&', $selectFieldOp1[0]);
134 $selectFieldOp1 = explode('=', $selectFieldOp1[2]);
135 $selectFieldOp1 = $selectFieldOp1[1];
136
137 $this->open($selectFieldLoc);
138 $this->waitForPageToLoad($this->getTimeoutMsec());
139
140 // get select field option2
141 $selectFieldOp2 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]@href"));
142 $selectFieldOp2 = explode('&', $selectFieldOp2[0]);
143 $selectFieldOp2 = explode('=', $selectFieldOp2[2]);
144 $selectFieldOp2 = $selectFieldOp2[1];
145
146 // create event.
147 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
148 $paramsEvent = array(
149 'title' => $eventTitle,
150 'template_id' => 6,
151 'event_type_id' => 4,
152 'payment_processor' => $processorName,
153 'price_set' => $priceset,
154 );
155
156 $infoEvent = $this->_testAddEvent($paramsEvent);
157
158 // logout to register for event.
159 $this->webtestLogout();
160
161 // Register Participant 1
162 // visit event info page
163 $this->open($infoEvent);
164 $this->waitForPageToLoad($this->getTimeoutMsec());
165
166 // register for event
167 $this->click('link=Register Now');
168 $this->waitForElementPresent('_qf_Register_upload-bottom');
169
170 // exceed maximun count for text field, check for form rule
171 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
172
173 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
174
175 $this->type('first_name', 'Mary');
176 $this->type('last_name', 'Jones'. substr(sha1(rand()), 0, 5));
177 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
178 $this->type('email-Primary', $email);
179
180 // fill billing related info
181 $this->_fillRegisterWithBillingInfo();
182
183 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
184
185 // fill correct value for text field
186 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
187
188 $this->click('_qf_Register_upload-bottom');
189 $this->waitForPageToLoad($this->getTimeoutMsec());
190
191 $this->_checkConfirmationAndRegister();
192
193 // Register Participant 2
194 // visit event info page
195 $this->open($infoEvent);
196 $this->waitForPageToLoad($this->getTimeoutMsec());
197
198 $this->click('link=Register Now');
199 $this->waitForElementPresent('_qf_Register_upload-bottom');
200
201 // exceed maximun count for text field, check for form rule
202 $this->type("xpath=//input[@id='price_{$textFieldId}']", '2');
203 $this->type('first_name', 'Mary');
204 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
205 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
206 $this->type('email-Primary', $email);
207
208 // fill billing related info and register
209 $this->_fillRegisterWithBillingInfo();
210
211 $this->assertStringsPresent(array('Sorry, currently only a single seat is available for this option.'));
212
213 // fill correct value for test field
214 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
215
216 // select sold option for select field, check for form rule
217 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
218 $this->click('_qf_Register_upload-bottom');
219 $this->waitForPageToLoad($this->getTimeoutMsec());
220
221 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
222
223 // fill correct available option for select field
224 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
225
226 $this->click('_qf_Register_upload-bottom');
227 $this->waitForPageToLoad($this->getTimeoutMsec());
228
229 $this->_checkConfirmationAndRegister();
230 }
231
232 function testWithFieldCount() {
233 // Log in using webtestLogin() method
234 $this->webtestLogin();
235
236 // We need a payment processor
237 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
238 $this->webtestAddPaymentProcessor($processorName);
239
240 // create priceset
241 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
242 $financialType = 'Donation';
243 $this->_testAddSet($priceset, $financialType);
244
245 // create price fields
246 $fields = array(
247 'Full Conference' => array(
248 'type' => 'Text',
249 'amount' => '525.00',
250 'max_count' => 4,
251 'count' => 2,
252 'is_required' => TRUE,
253 'financial_type_id' => 1,
254 ),
255 'Meal Choice' => array(
256 'type' => 'Select',
257 'options' => array(
258 1 => array(
259 'label' => 'Chicken',
260 'amount' => '525.00',
261 'max_count' => 2,
262 'count' => 2,
263 'financial_type_id' => 1,
264 ),
265 2 => array(
266 'label' => 'Vegetarian',
267 'amount' => '200.00',
268 'max_count' => 10,
269 'count' => 5,
270 'financial_type_id' => 1,
271 ),
272 ),
273 ),
274 'Pre-conference Meetup?' => array(
275 'type' => 'Radio',
276 'options' => array(
277 1 => array(
278 'label' => 'Yes',
279 'amount' => '50.00',
280 'max_count' => 2,
281 'count' => 1,
282 'financial_type_id' => 1,
283 ),
284 2 => array(
285 'label' => 'No',
286 'amount' => '10',
287 'max_count' => 10,
288 'count' => 5,
289 'financial_type_id' => 1,
290 ),
291 ),
292 ),
293 'Evening Sessions' => array(
294 'type' => 'CheckBox',
295 'options' => array(
296 1 => array(
297 'label' => 'First Five',
298 'amount' => '100.00',
299 'max_count' => 4,
300 'count' => 2,
301 'financial_type_id' => 1,
302 ),
303 2 => array(
304 'label' => 'Second Four',
305 'amount' => '50.00',
306 'max_count' => 8,
307 'count' => 4,
308 'financial_type_id' => 1,
309 ),
310 ),
311 ),
312 );
313
314 // add price fields
315 $this->_testAddPriceFields($fields);
316
317 // get price set url.
318 $pricesetLoc = $this->getLocation();
319
320 // get text field Id.
321 $textFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]@href"));
322 $textFieldId = explode('&', $textFieldId[0]);
323 $textFieldId = explode('=', $textFieldId[3]);
324 $textFieldId = $textFieldId[1];
325
326 $this->open($pricesetLoc);
327 $this->waitForPageToLoad($this->getTimeoutMsec());
328
329 // get select field id
330 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/a");
331 $this->waitForPageToLoad($this->getTimeoutMsec());
332 $selectFieldLoc = $this->getLocation();
333 $selectFieldId = $this->urlArg('fid');
334
335 // get select field ids
336 // get select field option1
337 $selectFieldOp1 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]@href"));
338 $selectFieldOp1 = explode('&', $selectFieldOp1[0]);
339 $selectFieldOp1 = explode('=', $selectFieldOp1[2]);
340 $selectFieldOp1 = $selectFieldOp1[1];
341
342 $this->open($selectFieldLoc);
343 $this->waitForPageToLoad($this->getTimeoutMsec());
344
345 // get select field option2
346 $selectFieldOp2 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]@href"));
347 $selectFieldOp2 = explode('&', $selectFieldOp2[0]);
348 $selectFieldOp2 = explode('=', $selectFieldOp2[2]);
349 $selectFieldOp2 = $selectFieldOp2[1];
350
351 // create event.
352 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
353 $paramsEvent = array(
354 'title' => $eventTitle,
355 'template_id' => 6,
356 'event_type_id' => 4,
357 'payment_processor' => $processorName,
358 'price_set' => $priceset,
359 );
360
361 $infoEvent = $this->_testAddEvent($paramsEvent);
362
363 // logout to register for event.
364 $this->webtestLogout();
365
366 // Register Participant 1
367 // visit event info page
368 $this->open($infoEvent);
369 $this->waitForPageToLoad($this->getTimeoutMsec());
370
371 // register for event
372 $this->click('link=Register Now');
373 $this->waitForElementPresent('_qf_Register_upload-bottom');
374
375 // check for form rule
376 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
377
378 $this->type('first_name', 'Mary');
379 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
380 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
381 $this->type('email-Primary', $email);
382
383 // fill billing related info
384 $this->_fillRegisterWithBillingInfo();
385
386 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
387
388 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
389
390 // fill correct value and register
391 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
392
393 $this->click('_qf_Register_upload-bottom');
394 $this->waitForPageToLoad($this->getTimeoutMsec());
395
396 $this->_checkConfirmationAndRegister();
397
398 // Register Participant 2
399 // visit event info page
400 $this->open($infoEvent);
401 $this->waitForPageToLoad($this->getTimeoutMsec());
402
403 $this->click('link=Register Now');
404 $this->waitForElementPresent('_qf_Register_upload-bottom');
405
406 // check for form rule
407 $this->type("xpath=//input[@id='price_{$textFieldId}']", '2');
408 $this->type('first_name', 'Mary');
409 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
410 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
411 $this->type('email-Primary', $email);
412
413 // fill billing related info and register
414 $this->_fillRegisterWithBillingInfo();
415
416 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
417
418 // fill correct value and register
419 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
420
421 // check for sold option for select field
422 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
423
424 $this->click('_qf_Register_upload-bottom');
425 $this->waitForPageToLoad($this->getTimeoutMsec());
426
427 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
428
429 // check for sold option for select field
430 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
431
432 $this->click('_qf_Register_upload-bottom');
433 $this->waitForPageToLoad($this->getTimeoutMsec());
434
435 $this->_checkConfirmationAndRegister();
436 }
437
438 function testAdditionalParticipantWithoutFieldCount() {
439 // Log in using webtestLogin() method
440 $this->webtestLogin();
441
442 // We need a payment processor
443 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
444 $this->webtestAddPaymentProcessor($processorName);
445
446 // create priceset
447 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
448 $financialType = 'Donation';
449 $this->_testAddSet($priceset, $financialType);
450
451 // create price fields
452 $fields = array(
453 'Full Conference' => array(
454 'type' => 'Text',
455 'amount' => '525.00',
456 'max_count' => 6,
457 'is_required' => TRUE,
458 'financial_type_id' => 1,
459 ),
460 'Meal Choice' => array(
461 'type' => 'Select',
462 'options' => array(
463 1 => array(
464 'label' => 'Chicken',
465 'amount' => '525.00',
466 'max_count' => 3,
467 'financial_type_id' => 1,
468 ),
469 2 => array(
470 'label' => 'Vegetarian',
471 'amount' => '200.00',
472 'max_count' => 2,
473 'financial_type_id' => 1,
474 ),
475 ),
476 ),
477 'Pre-conference Meetup?' => array(
478 'type' => 'Radio',
479 'options' => array(
480 1 => array(
481 'label' => 'Yes',
482 'amount' => '50.00',
483 'max_count' => 4,
484 'financial_type_id' => 1,
485 ),
486 2 => array(
487 'label' => 'No',
488 'amount' => '10',
489 'max_count' => 5,
490 'financial_type_id' => 1,
491 ),
492 ),
493 ),
494 'Evening Sessions' => array(
495 'type' => 'CheckBox',
496 'options' => array(
497 1 => array(
498 'label' => 'First Five',
499 'amount' => '100.00',
500 'max_count' => 6,
501 'financial_type_id' => 1,
502 ),
503 2 => array(
504 'label' => 'Second Four',
505 'amount' => '50.00',
506 'max_count' => 4,
507 'financial_type_id' => 1,
508 ),
509 ),
510 ),
511 );
512
513 // add price fields
514 $this->_testAddPriceFields($fields);
515
516 // get price set url.
517 $pricesetLoc = $this->getLocation();
518
519 // get text field Id.
520 $textFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]@href"));
521 $textFieldId = explode('&', $textFieldId[0]);
522 $textFieldId = explode('=', $textFieldId[3]);
523 $textFieldId = $textFieldId[1];
524
525 $this->open($pricesetLoc);
526 $this->waitForPageToLoad($this->getTimeoutMsec());
527
528 // get select field id
529 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/a");
530 $this->waitForPageToLoad($this->getTimeoutMsec());
531 $selectFieldLoc = $this->getLocation();
532 $selectFieldId = $this->urlArg('fid');
533
534 // get select field ids
535 // get select field option1
536 $selectFieldOp1 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]@href"));
537 $selectFieldOp1 = explode('&', $selectFieldOp1[0]);
538 $selectFieldOp1 = explode('=', $selectFieldOp1[2]);
539 $selectFieldOp1 = $selectFieldOp1[1];
540
541 $this->open($selectFieldLoc);
542 $this->waitForPageToLoad($this->getTimeoutMsec());
543
544 // get select field option2
545 $selectFieldOp2 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]@href"));
546 $selectFieldOp2 = explode('&', $selectFieldOp2[0]);
547 $selectFieldOp2 = explode('=', $selectFieldOp2[2]);
548 $selectFieldOp2 = $selectFieldOp2[1];
549
550 // create event.
551 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
552 $paramsEvent = array(
553 'title' => $eventTitle,
554 'template_id' => 6,
555 'event_type_id' => 4,
556 'payment_processor' => $processorName,
557 'price_set' => $priceset,
558 'is_multiple_registrations' => TRUE,
559 );
560
561 $infoEvent = $this->_testAddEvent($paramsEvent);
562
563 // logout to register for event.
564 $this->webtestLogout();
565
566 // 1'st registration
567 // Register Participant 1
568 // visit event info page
569 $this->open($infoEvent);
570 $this->waitForPageToLoad($this->getTimeoutMsec());
571
572 // register for event
573 $this->click('link=Register Now');
574 $this->waitForElementPresent('_qf_Register_upload-bottom');
575
576 // select 3 participants ( including current )
577 $this->select('additional_participants', 'value=2');
578
579 // Check for Participant1
580 // exceed maximun count for text field, check for form rule
581 $this->type("xpath=//input[@id='price_{$textFieldId}']", '7');
582
583 $this->type('first_name', 'Mary');
584 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
585 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
586 $this->type('email-Primary', $email);
587
588 // fill billing related info
589 $this->_fillRegisterWithBillingInfo();
590
591 $this->assertStringsPresent(array('Sorry, currently only 6 seats are available for this option.'));
592
593 // fill correct value for text field
594 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
595 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
596
597 $this->click('_qf_Register_upload-bottom');
598 $this->waitForPageToLoad($this->getTimeoutMsec());
599
600 // Check for Participant2
601 // exceed maximun count for text field, check for form rule
602 $this->type("xpath=//input[@id='price_{$textFieldId}']", '6');
603
604 $this->type('first_name', 'Mary Add 2');
605 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
606 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
607 $this->type('email-Primary', $email);
608
609 $this->click('_qf_Participant_1_next-Array');
610 $this->waitForPageToLoad($this->getTimeoutMsec());
611
612 $this->assertStringsPresent(array('Sorry, currently only 6 seats are available for this option.'));
613
614 // fill correct value for text field
615 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
616 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
617
618 $this->click('_qf_Participant_1_next-Array');
619 $this->waitForPageToLoad($this->getTimeoutMsec());
620
621 // Check for Participant3, check and skip
622 // exceed maximun count for text field, check for form rule
623 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
624
625 $this->type('first_name', 'Mary Add 2');
626 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
627 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
628 $this->type('email-Primary', $email);
629
630 $this->click('_qf_Participant_2_next-Array');
631 $this->waitForPageToLoad($this->getTimeoutMsec());
632
633 $this->assertStringsPresent(array('Sorry, currently only 6 seats are available for this option.'));
634
635 // fill correct value for text field
636 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
637
638 // check for select
639 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
640
641 $this->click('_qf_Participant_2_next-Array');
642 $this->waitForPageToLoad($this->getTimeoutMsec());
643
644 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
645
646 // Skip participant3 and register
647 $this->click('_qf_Participant_2_next_skip-Array');
648 $this->waitForPageToLoad($this->getTimeoutMsec());
649
650 $this->_checkConfirmationAndRegister();
651
652 // 2'st registration
653 // Register Participant 1
654 // visit event info page
655 $this->open($infoEvent);
656 $this->waitForPageToLoad($this->getTimeoutMsec());
657
658 // register for event
659 $this->click('link=Register Now');
660 $this->waitForElementPresent('_qf_Register_upload-bottom');
661
662 // select 2 participants ( including current )
663 $this->select('additional_participants', 'value=1');
664
665 // Check for Participant1
666 // exceed maximun count for text field, check for form rule
667 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
668
669 $this->type('first_name', 'Mary');
670 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
671 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
672 $this->type('email-Primary', $email);
673
674 // fill billing related info
675 $this->_fillRegisterWithBillingInfo();
676
677 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
678
679 // fill correct value for text field
680 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
681
682 // check for select field
683 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
684
685 $this->click('_qf_Register_upload-bottom');
686 $this->waitForPageToLoad($this->getTimeoutMsec());
687
688 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
689
690 // fill available value for select
691 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
692
693 $this->click('_qf_Register_upload-bottom');
694 $this->waitForPageToLoad($this->getTimeoutMsec());
695
696 // Check for Participant2
697 // exceed maximun count for text field, check for form rule
698 $this->type("xpath=//input[@id='price_{$textFieldId}']", '2');
699
700 $this->type('first_name', 'Mary Add 1');
701 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
702 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
703 $this->type('email-Primary', $email);
704
705 $this->click('_qf_Participant_1_next-Array');
706 $this->waitForPageToLoad($this->getTimeoutMsec());
707
708 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
709
710 // fill correct value for text field
711 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
712
713 // check for select field
714 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
715
716 $this->click('_qf_Participant_1_next-Array');
717 $this->waitForPageToLoad($this->getTimeoutMsec());
718
719 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
720
721 // fill available value for select
722 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
723
724 $this->click('_qf_Participant_1_next-Array');
725 $this->waitForPageToLoad($this->getTimeoutMsec());
726
727 $this->_checkConfirmationAndRegister();
728 }
729
730 function testAdditionalParticipantWithFieldCount() {
731 // Log in using webtestLogin() method
732 $this->webtestLogin();
733
734 // We need a payment processor
735 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
736 $this->webtestAddPaymentProcessor($processorName);
737
738 // create priceset
739 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
740 $financialType = 'Donation';
741 $this->_testAddSet($priceset, $financialType);
742
743 // create price fields
744 $fields = array(
745 'Full Conference' => array(
746 'type' => 'Text',
747 'amount' => '525.00',
748 'count' => 2,
749 'max_count' => 12,
750 'is_required' => TRUE,
751 'financial_type_id' => 1,
752 ),
753 'Meal Choice' => array(
754 'type' => 'Select',
755 'options' => array(
756 1 => array(
757 'label' => 'Chicken',
758 'amount' => '525.00',
759 'count' => 1,
760 'max_count' => 3,
761 'financial_type_id' => 1,
762 ),
763 2 => array(
764 'label' => 'Vegetarian',
765 'amount' => '200.00',
766 'count' => 2,
767 'max_count' => 4,
768 'financial_type_id' => 1,
769 ),
770 ),
771 ),
772 'Pre-conference Meetup?' => array(
773 'type' => 'Radio',
774 'options' => array(
775 1 => array(
776 'label' => 'Yes',
777 'amount' => '50.00',
778 'count' => 2,
779 'max_count' => 8,
780 'financial_type_id' => 1,
781 ),
782 2 => array(
783 'label' => 'No',
784 'amount' => '10',
785 'count' => 5,
786 'max_count' => 25,
787 'financial_type_id' => 1,
788 ),
789 ),
790 ),
791 'Evening Sessions' => array(
792 'type' => 'CheckBox',
793 'options' => array(
794 1 => array(
795 'label' => 'First Five',
796 'amount' => '100.00',
797 'count' => 2,
798 'max_count' => 16,
799 'financial_type_id' => 1,
800 ),
801 2 => array(
802 'label' => 'Second Four',
803 'amount' => '50.00',
804 'count' => 1,
805 'max_count' => 4,
806 'financial_type_id' => 1,
807 ),
808 ),
809 ),
810 );
811
812 // add price fields
813 $this->_testAddPriceFields($fields);
814
815 // get price set url.
816 $pricesetLoc = $this->getLocation();
817
818 // get text field Id.
819 $textFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]@href"));
820 $textFieldId = explode('&', $textFieldId[0]);
821 $textFieldId = explode('=', $textFieldId[3]);
822 $textFieldId = $textFieldId[1];
823
824 $this->open($pricesetLoc);
825 $this->waitForPageToLoad($this->getTimeoutMsec());
826
827 // get select field id
828 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/a");
829 $this->waitForPageToLoad($this->getTimeoutMsec());
830 $selectFieldLoc = $this->getLocation();
831 $selectFieldId = $this->urlArg('fid');
832
833 // get select field ids
834 // get select field option1
835 $selectFieldOp1 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]@href"));
836 $selectFieldOp1 = explode('&', $selectFieldOp1[0]);
837 $selectFieldOp1 = explode('=', $selectFieldOp1[2]);
838 $selectFieldOp1 = $selectFieldOp1[1];
839
840 $this->open($selectFieldLoc);
841 $this->waitForPageToLoad($this->getTimeoutMsec());
842
843 // get select field option2
844 $selectFieldOp2 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]@href"));
845 $selectFieldOp2 = explode('&', $selectFieldOp2[0]);
846 $selectFieldOp2 = explode('=', $selectFieldOp2[2]);
847 $selectFieldOp2 = $selectFieldOp2[1];
848
849 // create event.
850 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
851 $paramsEvent = array(
852 'title' => $eventTitle,
853 'template_id' => 6,
854 'event_type_id' => 4,
855 'payment_processor' => $processorName,
856 'price_set' => $priceset,
857 'is_multiple_registrations' => TRUE,
858 );
859
860 $infoEvent = $this->_testAddEvent($paramsEvent);
861
862 // logout to register for event.
863 $this->webtestLogout();
864
865 // 1'st registration
866 // Register Participant 1
867 // visit event info page
868 $this->open($infoEvent);
869 $this->waitForPageToLoad($this->getTimeoutMsec());
870
871 // register for event
872 $this->click('link=Register Now');
873 $this->waitForElementPresent('_qf_Register_upload-bottom');
874
875 // select 3 participants ( including current )
876 $this->select('additional_participants', 'value=2');
877
878 // Check for Participant1
879 // exceed maximun count for text field, check for form rule
880 $this->type("xpath=//input[@id='price_{$textFieldId}']", '7');
881
882 $this->type('first_name', 'Mary');
883 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
884 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
885 $this->type('email-Primary', $email);
886
887 // fill billing related info
888 $this->_fillRegisterWithBillingInfo();
889
890 $this->assertStringsPresent(array('Sorry, currently only 12 seats are available for this option.'));
891
892 // fill correct value for text field
893 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
894 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
895
896 $this->click('_qf_Register_upload-bottom');
897 $this->waitForPageToLoad($this->getTimeoutMsec());
898
899 // Check for Participant2
900 // exceed maximun count for text field, check for form rule
901 $this->type("xpath=//input[@id='price_{$textFieldId}']", '6');
902
903 $this->type('first_name', 'Mary Add 1');
904 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
905 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
906 $this->type('email-Primary', $email);
907
908 $this->click('_qf_Participant_1_next-Array');
909 $this->waitForPageToLoad($this->getTimeoutMsec());
910
911 $this->assertStringsPresent(array('Sorry, currently only 12 seats are available for this option.'));
912
913 // fill correct value for text field
914 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
915 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
916
917 $this->click('_qf_Participant_1_next-Array');
918 $this->waitForPageToLoad($this->getTimeoutMsec());
919
920 // Check for Participant3, check and skip
921 // exceed maximun count for text field, check for form rule
922 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
923
924 $this->type('first_name', 'Mary Add 2');
925 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
926 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
927 $this->type('email-Primary', $email);
928
929 $this->click('_qf_Participant_2_next-Array');
930 $this->waitForPageToLoad($this->getTimeoutMsec());
931
932 $this->assertStringsPresent(array('Sorry, currently only 12 seats are available for this option.'));
933
934 // fill correct value for text field
935 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
936
937 // check for select
938 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
939
940 $this->click('_qf_Participant_2_next-Array');
941 $this->waitForPageToLoad($this->getTimeoutMsec());
942
943 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
944
945 // Skip participant3 and register
946 $this->click('_qf_Participant_2_next_skip-Array');
947 $this->waitForPageToLoad($this->getTimeoutMsec());
948
949 $this->_checkConfirmationAndRegister();
950
951 // 2'st registration
952 // Register Participant 1
953 // visit event info page
954 $this->open($infoEvent);
955 $this->waitForPageToLoad($this->getTimeoutMsec());
956
957 // register for event
958 $this->click('link=Register Now');
959 $this->waitForElementPresent('_qf_Register_upload-bottom');
960
961 // select 2 participants ( including current )
962 $this->select('additional_participants', 'value=1');
963
964 // Check for Participant1
965 // exceed maximun count for text field, check for form rule
966 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
967
968 $this->type('first_name', 'Mary');
969 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
970 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
971 $this->type('email-Primary', $email);
972
973 // fill billing related info
974 $this->_fillRegisterWithBillingInfo();
975
976 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
977
978 // fill correct value for text field
979 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
980
981 // check for select field
982 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
983
984 $this->click('_qf_Register_upload-bottom');
985 $this->waitForPageToLoad($this->getTimeoutMsec());
986
987 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
988
989 // fill available value for select
990 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
991
992 $this->click('_qf_Register_upload-bottom');
993 $this->waitForPageToLoad($this->getTimeoutMsec());
994
995 // Check for Participant2
996 // exceed maximun count for text field, check for form rule
997 $this->type("xpath=//input[@id='price_{$textFieldId}']", '2');
998
999 $this->type('first_name', 'Mary Add 1');
1000 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
1001 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
1002 $this->type('email-Primary', $email);
1003
1004 $this->click('_qf_Participant_1_next-Array');
1005 $this->waitForPageToLoad($this->getTimeoutMsec());
1006
1007 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
1008
1009 // fill correct value for text field
1010 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
1011
1012 // check for select field
1013 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
1014
1015 $this->click('_qf_Participant_1_next-Array');
1016 $this->waitForPageToLoad($this->getTimeoutMsec());
1017
1018 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
1019
1020 // fill available value for select
1021 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
1022
1023 $this->click('_qf_Participant_1_next-Array');
1024 $this->waitForPageToLoad($this->getTimeoutMsec());
1025
1026 $this->_checkConfirmationAndRegister();
1027 }
1028
1029 function _testAddSet($setTitle, $financialType = NULL) {
1030 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
1031
1032 // Enter Priceset fields (Title, Used For ...)
1033 $this->type('title', $setTitle);
1034 $this->check('extends_1');
1035
1036 if ($financialType) {
1037 $this->select("css=select.crm-form-select", "label={$financialType}");
1038 }
1039
1040 $this->click("xpath=//form[@id='Set']/div[3]/table/tbody/tr[4]/td[2]/select");
1041 $this->type('help_pre', 'This is test priceset.');
1042
1043 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
1044 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom');
1045 }
1046
1047 function _testAddPriceFields($fields) {
1048 $fieldCount = count($fields);
1049 $count = 1;
1050 foreach ($fields as $label => $field) {
1051 $this->type('label', $label);
1052 $this->select('html_type', "value={$field['type']}");
1053
1054 if ($field['type'] == 'Text') {
1055 $this->type('price', $field['amount']);
1056
1057 if (isset($field['count'])) {
1058 $this->waitForElementPresent('count');
1059 $this->type('count', $field['count']);
1060 }
1061
1062 if (isset($field['count'])) {
1063 $this->waitForElementPresent('count');
1064 $this->type('count', $field['count']);
1065 }
1066
1067 if (isset($field['max_count'])) {
1068 $this->waitForElementPresent('max_value');
1069 $this->type('max_value', $field['max_count']);
1070 }
1071
1072 if (isset($field['financial_type_id'])) {
1073 $this->waitForElementPresent('financial_type_id');
1074 $this->select('financial_type_id', "value={$field['financial_type_id']}");
1075 }
1076
1077 }
1078 else {
1079 $this->_testAddMultipleChoiceOptions($field['options'], $field['type']);
1080 }
1081
1082 if (isset($field['is_required']) && $field['is_required']) {
1083 $this->check('is_required');
1084 }
1085
1086 if ($count < $fieldCount) {
1087 $this->click('_qf_Field_next_new-bottom');
1088 }
1089 else {
1090 $this->click('_qf_Field_next-bottom');
1091 }
1092 $this->waitForPageToLoad($this->getTimeoutMsec());
1093
1094 $count++;
1095 }
1096 }
1097
1098 function _testAddMultipleChoiceOptions($options, $fieldType) {
1099 foreach ($options as $oIndex => $oValue) {
1100 $this->type("option_label_{$oIndex}", $oValue['label']);
1101 $this->type("option_amount_{$oIndex}", $oValue['amount']);
1102
1103 if (isset($oValue['count'])) {
1104 $this->waitForElementPresent("option_count_{$oIndex}");
1105 $this->type("option_count_{$oIndex}", $oValue['count']);
1106 }
1107
1108 if (isset($oValue['max_count'])) {
1109 $this->waitForElementPresent("option_max_value_{$oIndex}");
1110 $this->type("option_max_value_{$oIndex}", $oValue['max_count']);
1111 }
1112
1113 if (!empty($oValue['financial_type_id'])) {
1114 $this->select("option_financial_type_id_{$oIndex}", "value={$oValue['financial_type_id']}");
1115 }
1116
1117 $this->click('link=another choice');
1118 }
1119
1120 // select first element as default
1121 if ($fieldType == 'CheckBox') {
1122 $this->click('default_checkbox_option[1]');
1123 }
1124 else {
1125 $this->click('CIVICRM_QFID_1_2');
1126 }
1127 }
1128
1129 function _testAddEvent($params) {
1130 $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom');
1131
1132 $this->select('event_type_id', "value={$params['event_type_id']}");
1133
1134 // Attendee role s/b selected now.
1135 $this->select('default_role_id', 'value=1');
1136
1137 // Enter Event Title, Summary and Description
1138 $this->type('title', $params['title']);
1139 $this->type('summary', 'This is a great conference. Sign up now!');
1140 $this->fillRichTextField('description', 'Here is a description for this event.', 'CKEditor');
1141
1142 // Choose Start and End dates.
1143 // Using helper webtestFillDate function.
1144 $this->webtestFillDateTime('start_date', '+1 week');
1145 $this->webtestFillDateTime('end_date', '+1 week 1 day 8 hours ');
1146
1147 $this->type('max_participants', '50');
1148 $this->click('is_map');
1149 $this->click('_qf_EventInfo_upload-bottom');
1150
1151 // Wait for Location tab form to load
1152 $this->waitForPageToLoad($this->getTimeoutMsec());
1153
1154 // Go to Fees tab
1155 $this->click('link=Fees');
1156 $this->waitForElementPresent('_qf_Fee_upload-bottom');
1157 $this->click('xpath=//form[@id="Fee"]/div[2]/table/tbody/tr[2]/td[2]/label[contains(text(), "Yes")]');
1158 $processorName = $params['payment_processor'];
1159 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='$processorName']");
1160 $this->select('financial_type_id', 'value=4');
1161
1162 if (array_key_exists('price_set', $params)) {
1163 $this->select('price_set_id', 'label=' . $params['price_set']);
1164 }
1165 if (array_key_exists('fee_level', $params)) {
1166 $counter = 1;
1167 foreach ($params['fee_level'] as $label => $amount) {
1168 $this->type("label_{$counter}", $label);
1169 $this->type("value_{$counter}", $amount);
1170 $counter++;
1171 }
1172 }
1173
1174 $this->clickLink('_qf_Fee_upload-bottom', 'link=Online Registration', FALSE);
1175
1176 // Go to Online Registration tab
1177 $this->click('link=Online Registration');
1178 $this->waitForElementPresent('_qf_Registration_upload-bottom');
1179
1180 $this->check('is_online_registration');
1181 $this->assertChecked('is_online_registration');
1182
1183 if (isset($params['is_multiple_registrations']) && $params['is_multiple_registrations']) {
1184 $this->click('is_multiple_registrations');
1185 }
1186
1187 $this->fillRichTextField('intro_text', 'Fill in all the fields below and click Continue.');
1188
1189 // enable confirmation email
1190 $this->click('CIVICRM_QFID_1_is_email_confirm');
1191 $this->type('confirm_from_name', 'Jane Doe');
1192 $this->type('confirm_from_email', 'jane.doe@example.org');
1193
1194 $this->click('_qf_Registration_upload-bottom');
1195 $this->waitForTextPresent("'Fees' information has been saved.");
1196
1197 // verify event input on info page
1198 // start at Manage Events listing
1199 $this->openCiviPage('event/manage', 'reset=1');
1200 $this->click('link=' . $params['title']);
1201
1202 $this->waitForPageToLoad($this->getTimeoutMsec());
1203 return $this->getLocation();
1204 }
1205
1206 function _fillRegisterWithBillingInfo() {
1207 $this->waitForElementPresent('credit_card_type');
1208 $this->select('credit_card_type', 'value=Visa');
1209 $this->type('credit_card_number', '4111111111111111');
1210 $this->type('cvv2', '000');
1211 $this->select('credit_card_exp_date[M]', 'value=1');
1212 $this->select('credit_card_exp_date[Y]', 'value=2020');
1213 $this->type('billing_first_name', 'Jane_' . substr(sha1(rand()), 0, 5));
1214 $this->type('billing_last_name', 'San_' . substr(sha1(rand()), 0, 5));
1215 $this->type('billing_street_address-5', '15 Main St.');
1216 $this->type(' billing_city-5', 'San Jose');
1217 $this->select('billing_country_id-5', 'value=1228');
1218 $this->select('billing_state_province_id-5', 'value=1004');
1219 $this->type('billing_postal_code-5', '94129');
1220
1221 $this->click('_qf_Register_upload-bottom');
1222 $this->waitForPageToLoad($this->getTimeoutMsec());
1223 }
1224
1225 function _checkConfirmationAndRegister() {
1226 $confirmStrings = array('Event Fee(s)', 'Billing Name and Address', 'Credit Card Information');
1227 $this->assertStringsPresent($confirmStrings);
1228 $this->click('_qf_Confirm_next-bottom');
1229 $this->waitForPageToLoad($this->getTimeoutMsec());
1230 $thankStrings = array('Thank You for Registering', 'Event Total', 'Transaction Date');
1231 $this->assertStringsPresent($thankStrings);
1232 }
1233 }