Import from SVN (r45945, r596)
[civicrm-core.git] / tests / phpunit / WebTest / Event / PricesetMaxCountTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25 */
26
27
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Event_PricesetMaxCountTest extends CiviSeleniumTestCase {
30
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testWithoutFieldCount() {
36 $this->open($this->sboxPath);
37
38 // Log in using webtestLogin() method
39 $this->webtestLogin();
40
41 // We need a payment processor
42 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
43 $this->webtestAddPaymentProcessor($processorName);
44
45 // create priceset
46 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
47 $financialType = 'Donation';
48 $this->_testAddSet($priceset, $financialType);
49
50 // create price fields
51 $fields = array(
52 'Full Conference' => array('type' => 'Text',
53 'amount' => '525.00',
54 'max_count' => 2,
55 'is_required' => TRUE,
56 'financial_type_id' => 1,
57 ),
58 'Meal Choice' => array(
59 'type' => 'Select',
60 'options' => array(
61 1 => array('label' => 'Chicken',
62 'amount' => '525.00',
63 'max_count' => 1,
64 'financial_type_id' => 1,
65 ),
66 2 => array(
67 'label' => 'Vegetarian',
68 'amount' => '200.00',
69 'max_count' => 5,
70 'financial_type_id' => 1,
71 ),
72 ),
73 ),
74 'Pre-conference Meetup?' => array(
75 'type' => 'Radio',
76 'options' => array(
77 1 => array('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('label' => 'First Five',
94 'amount' => '100.00',
95 'max_count' => 2,
96 'financial_type_id' => 1,
97 ),
98 2 => array(
99 'label' => 'Second Four',
100 'amount' => '50.00',
101 'max_count' => 4,
102 'financial_type_id' => 1,
103 ),
104 ),
105 ),
106 );
107
108 // add price fields
109 $this->_testAddPriceFields($fields);
110
111 // get price set url.
112 $pricesetLoc = $this->getLocation();
113
114 // get text field Id.
115 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]");
116 $this->waitForPageToLoad($this->getTimeoutMsec());
117 $matches = array();
118 preg_match('/fid=([0-9]+)/', $this->getLocation(), $matches);
119 $textFieldId = $matches[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 $matches = array();
129 preg_match('/fid=([0-9]+)/', $this->getLocation(), $matches);
130 $selectFieldId = $matches[1];
131
132 // get select field ids
133 // get select field option1
134 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]");
135 $this->waitForPageToLoad($this->getTimeoutMsec());
136 $matches = array();
137 preg_match('/oid=([0-9]+)/', $this->getLocation(), $matches);
138 $selectFieldOp1 = $matches[1];
139
140 $this->open($selectFieldLoc);
141 $this->waitForPageToLoad($this->getTimeoutMsec());
142
143 // get select field option2
144 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]");
145 $this->waitForPageToLoad($this->getTimeoutMsec());
146 $matches = array();
147 preg_match('/oid=([0-9]+)/', $this->getLocation(), $matches);
148 $selectFieldOp2 = $matches[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->open($this->sboxPath . 'civicrm/logout?reset=1');
164 $this->waitForPageToLoad($this->getTimeoutMsec());
165
166 // Register Participant 1
167 // visit event info page
168 $this->open($infoEvent);
169 $this->waitForPageToLoad($this->getTimeoutMsec());
170
171 // register for event
172 $this->click('link=Register Now');
173 $this->waitForElementPresent('_qf_Register_upload-bottom');
174
175 // exceed maximun count for text field, check for form rule
176 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
177
178 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
179
180 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
181 $this->type('email-Primary', $email);
182
183 // fill billing related info
184 $this->_fillRegisterWithBillingInfo();
185
186 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
187
188 // fill correct value for text field
189 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
190
191 $this->click('_qf_Register_upload-bottom');
192 $this->waitForPageToLoad($this->getTimeoutMsec());
193
194 $this->_checkConfirmationAndRegister();
195
196 // Register Participant 2
197 // visit event info page
198 $this->open($infoEvent);
199 $this->waitForPageToLoad($this->getTimeoutMsec());
200
201 $this->click('link=Register Now');
202 $this->waitForElementPresent('_qf_Register_upload-bottom');
203
204 // exceed maximun count for text field, check for form rule
205 $this->type("xpath=//input[@id='price_{$textFieldId}']", '2');
206 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
207 $this->type('email-Primary', $email);
208
209 // fill billing related info and register
210 $this->_fillRegisterWithBillingInfo();
211
212 $this->assertStringsPresent(array('Sorry, currently only a single seat is available for this option.'));
213
214 // fill correct value for test field
215 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
216
217 // select sold option for select field, check for form rule
218 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
219 $this->click('_qf_Register_upload-bottom');
220 $this->waitForPageToLoad($this->getTimeoutMsec());
221
222 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
223
224 // fill correct available option for select field
225 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
226
227 $this->click('_qf_Register_upload-bottom');
228 $this->waitForPageToLoad($this->getTimeoutMsec());
229
230 $this->_checkConfirmationAndRegister();
231 }
232
233 function testWithFieldCount() {
234 $this->open($this->sboxPath);
235
236 // Log in using webtestLogin() method
237 $this->webtestLogin();
238
239 // We need a payment processor
240 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
241 $this->webtestAddPaymentProcessor($processorName);
242
243 // create priceset
244 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
245 $financialType = 'Donation';
246 $this->_testAddSet($priceset, $financialType);
247
248 // create price fields
249 $fields = array(
250 'Full Conference' => array('type' => 'Text',
251 'amount' => '525.00',
252 'max_count' => 4,
253 'count' => 2,
254 'is_required' => TRUE,
255 'financial_type_id' => 1,
256 ),
257 'Meal Choice' => array(
258 'type' => 'Select',
259 'options' => array(
260 1 => array('label' => 'Chicken',
261 'amount' => '525.00',
262 'max_count' => 2,
263 'count' => 2,
264 'financial_type_id' => 1,
265 ),
266 2 => array(
267 'label' => 'Vegetarian',
268 'amount' => '200.00',
269 'max_count' => 10,
270 'count' => 5,
271 'financial_type_id' => 1,
272 ),
273 ),
274 ),
275 'Pre-conference Meetup?' => array(
276 'type' => 'Radio',
277 'options' => array(
278 1 => array('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('label' => 'First Five',
297 'amount' => '100.00',
298 'max_count' => 4,
299 'count' => 2,
300 'financial_type_id' => 1,
301 ),
302 2 => array(
303 'label' => 'Second Four',
304 'amount' => '50.00',
305 'max_count' => 8,
306 'count' => 4,
307 'financial_type_id' => 1,
308 ),
309 ),
310 ),
311 );
312
313 // add price fields
314 $this->_testAddPriceFields($fields);
315
316 // get price set url.
317 $pricesetLoc = $this->getLocation();
318
319 // get text field Id.
320 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]");
321 $this->waitForPageToLoad($this->getTimeoutMsec());
322 $matches = array();
323 preg_match('/fid=([0-9]+)/', $this->getLocation(), $matches);
324 $textFieldId = $matches[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 $matches = array();
334 preg_match('/fid=([0-9]+)/', $this->getLocation(), $matches);
335 $selectFieldId = $matches[1];
336
337 // get select field ids
338 // get select field option1
339 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]");
340 $this->waitForPageToLoad($this->getTimeoutMsec());
341 $matches = array();
342 preg_match('/oid=([0-9]+)/', $this->getLocation(), $matches);
343 $selectFieldOp1 = $matches[1];
344
345 $this->open($selectFieldLoc);
346 $this->waitForPageToLoad($this->getTimeoutMsec());
347
348 // get select field option2
349 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]");
350 $this->waitForPageToLoad($this->getTimeoutMsec());
351 $matches = array();
352 preg_match('/oid=([0-9]+)/', $this->getLocation(), $matches);
353 $selectFieldOp2 = $matches[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->open($this->sboxPath . 'civicrm/logout?reset=1');
369 $this->waitForPageToLoad($this->getTimeoutMsec());
370
371 // Register Participant 1
372 // visit event info page
373 $this->open($infoEvent);
374 $this->waitForPageToLoad($this->getTimeoutMsec());
375
376 // register for event
377 $this->click('link=Register Now');
378 $this->waitForElementPresent('_qf_Register_upload-bottom');
379
380 // check for form rule
381 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
382
383 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
384 $this->type('email-Primary', $email);
385
386 // fill billing related info
387 $this->_fillRegisterWithBillingInfo();
388
389 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
390
391 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
392
393 // fill correct value and register
394 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
395
396 $this->click('_qf_Register_upload-bottom');
397 $this->waitForPageToLoad($this->getTimeoutMsec());
398
399 $this->_checkConfirmationAndRegister();
400
401 // Register Participant 2
402 // visit event info page
403 $this->open($infoEvent);
404 $this->waitForPageToLoad($this->getTimeoutMsec());
405
406 $this->click('link=Register Now');
407 $this->waitForElementPresent('_qf_Register_upload-bottom');
408
409 // check for form rule
410 $this->type("xpath=//input[@id='price_{$textFieldId}']", '2');
411 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
412 $this->type('email-Primary', $email);
413
414 // fill billing related info and register
415 $this->_fillRegisterWithBillingInfo();
416
417 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
418
419 // fill correct value and register
420 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
421
422 // check for sold option for select field
423 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
424
425 $this->click('_qf_Register_upload-bottom');
426 $this->waitForPageToLoad($this->getTimeoutMsec());
427
428 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
429
430 // check for sold option for select field
431 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
432
433 $this->click('_qf_Register_upload-bottom');
434 $this->waitForPageToLoad($this->getTimeoutMsec());
435
436 $this->_checkConfirmationAndRegister();
437 }
438
439 function testAdditionalParticipantWithoutFieldCount() {
440 $this->open($this->sboxPath);
441
442 // Log in using webtestLogin() method
443 $this->webtestLogin();
444
445 // We need a payment processor
446 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
447 $this->webtestAddPaymentProcessor($processorName);
448
449 // create priceset
450 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
451 $financialType = 'Donation';
452 $this->_testAddSet($priceset, $financialType);
453
454 // create price fields
455 $fields = array(
456 'Full Conference' => array('type' => 'Text',
457 'amount' => '525.00',
458 'max_count' => 6,
459 'is_required' => TRUE,
460 'financial_type_id' => 1,
461 ),
462 'Meal Choice' => array(
463 'type' => 'Select',
464 'options' => array(
465 1 => array('label' => 'Chicken',
466 'amount' => '525.00',
467 'max_count' => 3,
468 'financial_type_id' => 1,
469 ),
470 2 => array(
471 'label' => 'Vegetarian',
472 'amount' => '200.00',
473 'max_count' => 2,
474 'financial_type_id' => 1,
475 ),
476 ),
477 ),
478 'Pre-conference Meetup?' => array(
479 'type' => 'Radio',
480 'options' => array(
481 1 => array('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('label' => 'First Five',
498 'amount' => '100.00',
499 'max_count' => 6,
500 'financial_type_id' => 1,
501 ),
502 2 => array(
503 'label' => 'Second Four',
504 'amount' => '50.00',
505 'max_count' => 4,
506 'financial_type_id' => 1,
507 ),
508 ),
509 ),
510 );
511
512 // add price fields
513 $this->_testAddPriceFields($fields);
514
515 // get price set url.
516 $pricesetLoc = $this->getLocation();
517
518 // get text field Id.
519 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]");
520 $this->waitForPageToLoad($this->getTimeoutMsec());
521 $matches = array();
522 preg_match('/fid=([0-9]+)/', $this->getLocation(), $matches);
523 $textFieldId = $matches[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 $matches = array();
533 preg_match('/fid=([0-9]+)/', $this->getLocation(), $matches);
534 $selectFieldId = $matches[1];
535
536 // get select field ids
537 // get select field option1
538 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]");
539 $this->waitForPageToLoad($this->getTimeoutMsec());
540 $matches = array();
541 preg_match('/oid=([0-9]+)/', $this->getLocation(), $matches);
542 $selectFieldOp1 = $matches[1];
543
544 $this->open($selectFieldLoc);
545 $this->waitForPageToLoad($this->getTimeoutMsec());
546
547 // get select field option2
548 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]");
549 $this->waitForPageToLoad($this->getTimeoutMsec());
550 $matches = array();
551 preg_match('/oid=([0-9]+)/', $this->getLocation(), $matches);
552 $selectFieldOp2 = $matches[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->open($this->sboxPath . 'civicrm/logout?reset=1');
569 $this->waitForPageToLoad($this->getTimeoutMsec());
570
571
572 // 1'st registration
573 // Register Participant 1
574 // visit event info page
575 $this->open($infoEvent);
576 $this->waitForPageToLoad($this->getTimeoutMsec());
577
578 // register for event
579 $this->click('link=Register Now');
580 $this->waitForElementPresent('_qf_Register_upload-bottom');
581
582 // select 3 participants ( including current )
583 $this->select('additional_participants', 'value=2');
584
585 // Check for Participant1
586 // exceed maximun count for text field, check for form rule
587 $this->type("xpath=//input[@id='price_{$textFieldId}']", '7');
588
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 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
609 $this->type('email-Primary', $email);
610
611 $this->click('_qf_Participant_1_next-Array');
612 $this->waitForPageToLoad($this->getTimeoutMsec());
613
614 $this->assertStringsPresent(array('Sorry, currently only 6 seats are available for this option.'));
615
616 // fill correct value for text field
617 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
618 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
619
620 $this->click('_qf_Participant_1_next-Array');
621 $this->waitForPageToLoad($this->getTimeoutMsec());
622
623 // Check for Participant3, check and skip
624 // exceed maximun count for text field, check for form rule
625 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
626
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
653 // 2'st registration
654 // Register Participant 1
655 // visit event info page
656 $this->open($infoEvent);
657 $this->waitForPageToLoad($this->getTimeoutMsec());
658
659 // register for event
660 $this->click('link=Register Now');
661 $this->waitForElementPresent('_qf_Register_upload-bottom');
662
663 // select 2 participants ( including current )
664 $this->select('additional_participants', 'value=1');
665
666 // Check for Participant1
667 // exceed maximun count for text field, check for form rule
668 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
669
670 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
671 $this->type('email-Primary', $email);
672
673 // fill billing related info
674 $this->_fillRegisterWithBillingInfo();
675
676 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
677
678 // fill correct value for text field
679 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
680
681 // check for select field
682 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
683
684 $this->click('_qf_Register_upload-bottom');
685 $this->waitForPageToLoad($this->getTimeoutMsec());
686
687 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
688
689 // fill available value for select
690 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
691
692 $this->click('_qf_Register_upload-bottom');
693 $this->waitForPageToLoad($this->getTimeoutMsec());
694
695 // Check for Participant2
696 // exceed maximun count for text field, check for form rule
697 $this->type("xpath=//input[@id='price_{$textFieldId}']", '2');
698
699 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
700 $this->type('email-Primary', $email);
701
702 $this->click('_qf_Participant_1_next-Array');
703 $this->waitForPageToLoad($this->getTimeoutMsec());
704
705 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
706
707 // fill correct value for text field
708 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
709
710 // check for select field
711 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
712
713 $this->click('_qf_Participant_1_next-Array');
714 $this->waitForPageToLoad($this->getTimeoutMsec());
715
716 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
717
718 // fill available value for select
719 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
720
721 $this->click('_qf_Participant_1_next-Array');
722 $this->waitForPageToLoad($this->getTimeoutMsec());
723
724 $this->_checkConfirmationAndRegister();
725 }
726
727 function testAdditionalParticipantWithFieldCount() {
728 $this->open($this->sboxPath);
729
730 // Log in using webtestLogin() method
731 $this->webtestLogin();
732
733 // We need a payment processor
734 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
735 $this->webtestAddPaymentProcessor($processorName);
736
737 // create priceset
738 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
739 $financialType = 'Donation';
740 $this->_testAddSet($priceset, $financialType);
741
742 // create price fields
743 $fields = array(
744 'Full Conference' => array('type' => 'Text',
745 'amount' => '525.00',
746 'count' => 2,
747 'max_count' => 12,
748 'is_required' => TRUE,
749 'financial_type_id' => 1,
750 ),
751 'Meal Choice' => array(
752 'type' => 'Select',
753 'options' => array(
754 1 => array('label' => 'Chicken',
755 'amount' => '525.00',
756 'count' => 1,
757 'max_count' => 3,
758 'financial_type_id' => 1,
759 ),
760 2 => array(
761 'label' => 'Vegetarian',
762 'amount' => '200.00',
763 'count' => 2,
764 'max_count' => 4,
765 'financial_type_id' => 1,
766 ),
767 ),
768 ),
769 'Pre-conference Meetup?' => array(
770 'type' => 'Radio',
771 'options' => array(
772 1 => array('label' => 'Yes',
773 'amount' => '50.00',
774 'count' => 2,
775 'max_count' => 8,
776 'financial_type_id' => 1,
777 ),
778 2 => array(
779 'label' => 'No',
780 'amount' => '10',
781 'count' => 5,
782 'max_count' => 25,
783 'financial_type_id' => 1,
784 ),
785 ),
786 ),
787 'Evening Sessions' => array(
788 'type' => 'CheckBox',
789 'options' => array(
790 1 => array('label' => 'First Five',
791 'amount' => '100.00',
792 'count' => 2,
793 'max_count' => 16,
794 'financial_type_id' => 1,
795 ),
796 2 => array(
797 'label' => 'Second Four',
798 'amount' => '50.00',
799 'count' => 1,
800 'max_count' => 4,
801 'financial_type_id' => 1,
802 ),
803 ),
804 ),
805 );
806
807 // add price fields
808 $this->_testAddPriceFields($fields);
809
810 // get price set url.
811 $pricesetLoc = $this->getLocation();
812
813 // get text field Id.
814 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]");
815 $this->waitForPageToLoad($this->getTimeoutMsec());
816 $matches = array();
817 preg_match('/fid=([0-9]+)/', $this->getLocation(), $matches);
818 $textFieldId = $matches[1];
819
820 $this->open($pricesetLoc);
821 $this->waitForPageToLoad($this->getTimeoutMsec());
822
823 // get select field id
824 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/a");
825 $this->waitForPageToLoad($this->getTimeoutMsec());
826 $selectFieldLoc = $this->getLocation();
827 $matches = array();
828 preg_match('/fid=([0-9]+)/', $this->getLocation(), $matches);
829 $selectFieldId = $matches[1];
830
831 // get select field ids
832 // get select field option1
833 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]");
834 $this->waitForPageToLoad($this->getTimeoutMsec());
835 $matches = array();
836 preg_match('/oid=([0-9]+)/', $this->getLocation(), $matches);
837 $selectFieldOp1 = $matches[1];
838
839 $this->open($selectFieldLoc);
840 $this->waitForPageToLoad($this->getTimeoutMsec());
841
842 // get select field option2
843 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]");
844 $this->waitForPageToLoad($this->getTimeoutMsec());
845 $matches = array();
846 preg_match('/oid=([0-9]+)/', $this->getLocation(), $matches);
847 $selectFieldOp2 = $matches[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->open($this->sboxPath . 'civicrm/logout?reset=1');
864 $this->waitForPageToLoad($this->getTimeoutMsec());
865
866
867 // 1'st registration
868 // Register Participant 1
869 // visit event info page
870 $this->open($infoEvent);
871 $this->waitForPageToLoad($this->getTimeoutMsec());
872
873 // register for event
874 $this->click('link=Register Now');
875 $this->waitForElementPresent('_qf_Register_upload-bottom');
876
877 // select 3 participants ( including current )
878 $this->select('additional_participants', 'value=2');
879
880 // Check for Participant1
881 // exceed maximun count for text field, check for form rule
882 $this->type("xpath=//input[@id='price_{$textFieldId}']", '7');
883
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 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
904 $this->type('email-Primary', $email);
905
906 $this->click('_qf_Participant_1_next-Array');
907 $this->waitForPageToLoad($this->getTimeoutMsec());
908
909 $this->assertStringsPresent(array('Sorry, currently only 12 seats are available for this option.'));
910
911 // fill correct value for text field
912 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
913 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
914
915 $this->click('_qf_Participant_1_next-Array');
916 $this->waitForPageToLoad($this->getTimeoutMsec());
917
918 // Check for Participant3, check and skip
919 // exceed maximun count for text field, check for form rule
920 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
921
922 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
923 $this->type('email-Primary', $email);
924
925 $this->click('_qf_Participant_2_next-Array');
926 $this->waitForPageToLoad($this->getTimeoutMsec());
927
928 $this->assertStringsPresent(array('Sorry, currently only 12 seats are available for this option.'));
929
930 // fill correct value for text field
931 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
932
933 // check for select
934 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
935
936 $this->click('_qf_Participant_2_next-Array');
937 $this->waitForPageToLoad($this->getTimeoutMsec());
938
939 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
940
941 // Skip participant3 and register
942 $this->click('_qf_Participant_2_next_skip-Array');
943 $this->waitForPageToLoad($this->getTimeoutMsec());
944
945 $this->_checkConfirmationAndRegister();
946
947
948 // 2'st registration
949 // Register Participant 1
950 // visit event info page
951 $this->open($infoEvent);
952 $this->waitForPageToLoad($this->getTimeoutMsec());
953
954 // register for event
955 $this->click('link=Register Now');
956 $this->waitForElementPresent('_qf_Register_upload-bottom');
957
958 // select 2 participants ( including current )
959 $this->select('additional_participants', 'value=1');
960
961 // Check for Participant1
962 // exceed maximun count for text field, check for form rule
963 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
964
965 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
966 $this->type('email-Primary', $email);
967
968 // fill billing related info
969 $this->_fillRegisterWithBillingInfo();
970
971 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
972
973 // fill correct value for text field
974 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
975
976 // check for select field
977 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
978
979 $this->click('_qf_Register_upload-bottom');
980 $this->waitForPageToLoad($this->getTimeoutMsec());
981
982 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
983
984 // fill available value for select
985 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
986
987 $this->click('_qf_Register_upload-bottom');
988 $this->waitForPageToLoad($this->getTimeoutMsec());
989
990 // Check for Participant2
991 // exceed maximun count for text field, check for form rule
992 $this->type("xpath=//input[@id='price_{$textFieldId}']", '2');
993
994 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
995 $this->type('email-Primary', $email);
996
997 $this->click('_qf_Participant_1_next-Array');
998 $this->waitForPageToLoad($this->getTimeoutMsec());
999
1000 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
1001
1002 // fill correct value for text field
1003 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
1004
1005 // check for select field
1006 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
1007
1008 $this->click('_qf_Participant_1_next-Array');
1009 $this->waitForPageToLoad($this->getTimeoutMsec());
1010
1011 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
1012
1013 // fill available value for select
1014 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
1015
1016 $this->click('_qf_Participant_1_next-Array');
1017 $this->waitForPageToLoad($this->getTimeoutMsec());
1018
1019 $this->_checkConfirmationAndRegister();
1020 }
1021
1022 function _testAddSet($setTitle, $financialType = NULL) {
1023 $this->open($this->sboxPath . 'civicrm/admin/price?reset=1&action=add');
1024 $this->waitForPageToLoad($this->getTimeoutMsec());
1025 $this->waitForElementPresent('_qf_Set_next-bottom');
1026
1027 // Enter Priceset fields (Title, Used For ...)
1028 $this->type('title', $setTitle);
1029 $this->check('extends_1');
1030
1031 if ($financialType) {
1032 $this->select("css=select.form-select", "label={$financialType}");
1033 }
1034
1035 $this->click("xpath=//form[@id='Set']/div[3]/table/tbody/tr[4]/td[2]/select");
1036 $this->type('help_pre', 'This is test priceset.');
1037
1038 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
1039 $this->click('_qf_Set_next-bottom');
1040
1041 $this->waitForPageToLoad($this->getTimeoutMsec());
1042 $this->waitForElementPresent('_qf_Field_next-bottom');
1043 }
1044
1045 function _testAddPriceFields($fields) {
1046 $fieldCount = count($fields);
1047 $count = 1;
1048 foreach ($fields as $label => $field) {
1049 $this->type('label', $label);
1050 $this->select('html_type', "value={$field['type']}");
1051
1052 if ($field['type'] == 'Text') {
1053 $this->type('price', $field['amount']);
1054
1055 if (isset($field['count'])) {
1056 $this->waitForElementPresent('count');
1057 $this->type('count', $field['count']);
1058 }
1059
1060 if (isset($field['count'])) {
1061 $this->waitForElementPresent('count');
1062 $this->type('count', $field['count']);
1063 }
1064
1065 if (isset($field['max_count'])) {
1066 $this->waitForElementPresent('max_value');
1067 $this->type('max_value', $field['max_count']);
1068 }
1069
1070 if (isset($field['financial_type_id'])) {
1071 $this->waitForElementPresent('financial_type_id');
1072 $this->select('financial_type_id', "value={$field['financial_type_id']}");
1073 }
1074 }
1075 else {
1076 $this->_testAddMultipleChoiceOptions($field['options'], $field['type']);
1077 }
1078
1079 if (isset($field['is_required']) && $field['is_required']) {
1080 $this->check('is_required');
1081 }
1082
1083 if ($count < $fieldCount) {
1084 $this->click('_qf_Field_next_new-bottom');
1085 }
1086 else {
1087 $this->click('_qf_Field_next-bottom');
1088 }
1089 $this->waitForPageToLoad($this->getTimeoutMsec());
1090
1091 $count++;
1092 }
1093 }
1094
1095 function _testAddMultipleChoiceOptions($options, $fieldType) {
1096 foreach ($options as $oIndex => $oValue) {
1097 $this->type("option_label_{$oIndex}", $oValue['label']);
1098 $this->type("option_amount_{$oIndex}", $oValue['amount']);
1099
1100 if (isset($oValue['count'])) {
1101 $this->waitForElementPresent("option_count_{$oIndex}");
1102 $this->type("option_count_{$oIndex}", $oValue['count']);
1103 }
1104
1105 if (isset($oValue['max_count'])) {
1106 $this->waitForElementPresent("option_max_value_{$oIndex}");
1107 $this->type("option_max_value_{$oIndex}", $oValue['max_count']);
1108 }
1109
1110 if (!empty($oValue['financial_type_id'])) {
1111 $this->select( "option_financial_type_id_{$oIndex}", "value={$oValue['financial_type_id']}" );
1112 }
1113
1114 $this->click('link=another choice');
1115 }
1116
1117 // select first element as default
1118 if ($fieldType == 'CheckBox') {
1119 $this->click('default_checkbox_option[1]');
1120 }
1121 else {
1122 $this->click('CIVICRM_QFID_1_2');
1123 }
1124 }
1125
1126 function _testAddEvent($params) {
1127 $this->open($this->sboxPath . 'civicrm/event/add?reset=1&action=add');
1128
1129 $this->waitForElementPresent('_qf_EventInfo_upload-bottom');
1130
1131 // Let's start filling the form with values.
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->click('_qf_Fee_upload-bottom');
1175 $this->waitForPageToLoad($this->getTimeoutMsec());
1176
1177 // Go to Online Registration tab
1178 $this->click('link=Online Registration');
1179 $this->waitForElementPresent('_qf_Registration_upload-bottom');
1180
1181 $this->check('is_online_registration');
1182 $this->assertChecked('is_online_registration');
1183
1184 if (isset($params['is_multiple_registrations']) && $params['is_multiple_registrations']) {
1185 $this->click('is_multiple_registrations');
1186 }
1187
1188 $this->fillRichTextField('intro_text', 'Fill in all the fields below and click Continue.');
1189
1190 // enable confirmation email
1191 $this->click('CIVICRM_QFID_1_is_email_confirm');
1192 $this->type('confirm_from_name', 'Jane Doe');
1193 $this->type('confirm_from_email', 'jane.doe@example.org');
1194
1195 $this->click('_qf_Registration_upload-bottom');
1196 $this->waitForPageToLoad($this->getTimeoutMsec());
1197 $this->waitForTextPresent("'Registration' information has been saved.");
1198
1199 // verify event input on info page
1200 // start at Manage Events listing
1201 $this->open($this->sboxPath . 'civicrm/event/manage?reset=1');
1202 $this->click('link=' . $params['title']);
1203
1204 $this->waitForPageToLoad($this->getTimeoutMsec());
1205 return $this->getLocation();
1206 }
1207
1208 function _fillRegisterWithBillingInfo() {
1209 $this->waitForElementPresent('credit_card_type');
1210 $this->select('credit_card_type', 'value=Visa');
1211 $this->type('credit_card_number', '4111111111111111');
1212 $this->type('cvv2', '000');
1213 $this->select('credit_card_exp_date[M]', 'value=1');
1214 $this->select('credit_card_exp_date[Y]', 'value=2020');
1215 $this->type('billing_first_name', 'Jane_' . substr(sha1(rand()), 0, 5));
1216 $this->type('billing_last_name', 'San_' . substr(sha1(rand()), 0, 5));
1217 $this->type('billing_street_address-5', '15 Main St.');
1218 $this->type(' billing_city-5', 'San Jose');
1219 $this->select('billing_country_id-5', 'value=1228');
1220 $this->select('billing_state_province_id-5', 'value=1004');
1221 $this->type('billing_postal_code-5', '94129');
1222
1223 $this->click('_qf_Register_upload-bottom');
1224 $this->waitForPageToLoad($this->getTimeoutMsec());
1225 }
1226
1227 function _checkConfirmationAndRegister() {
1228 $confirmStrings = array('Event Fee(s)', 'Billing Name and Address', 'Credit Card Information');
1229 $this->assertStringsPresent($confirmStrings);
1230 $this->click('_qf_Confirm_next-bottom');
1231 $this->waitForPageToLoad($this->getTimeoutMsec());
1232 $thankStrings = array('Thank You for Registering', 'Event Total', 'Transaction Date');
1233 $this->assertStringsPresent($thankStrings);
1234 }
1235 }
1236