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