3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Event_PricesetMaxCountTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testWithoutFieldCount() {
35 // Log in using webtestLogin() method
36 $this->webtestLogin();
38 // We need a payment processor
39 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
40 $this->webtestAddPaymentProcessor($processorName);
43 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
44 $financialType = 'Donation';
45 $this->_testAddSet($priceset, $financialType);
47 // create price fields
49 'Full Conference' => array(
53 'is_required' => TRUE,
54 'financial_type_id' => 1,
56 'Meal Choice' => array(
63 'financial_type_id' => 1,
66 'label' => 'Vegetarian',
69 'financial_type_id' => 1,
73 'Pre-conference Meetup?' => array(
80 'financial_type_id' => 1,
86 'financial_type_id' => 1,
90 'Evening Sessions' => array(
94 'label' => 'First Five',
97 'financial_type_id' => 1,
100 'label' => 'Second Four',
103 'financial_type_id' => 1,
110 $this->_testAddPriceFields($fields);
112 // get price set url.
113 $pricesetLoc = $this->getLocation();
115 // get text field Id.
116 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]");
117 $this->waitForPageToLoad($this->getTimeoutMsec());
118 $textFieldId = $this->urlArg('fid');
120 $this->open($pricesetLoc);
121 $this->waitForPageToLoad($this->getTimeoutMsec());
123 // get select field id
124 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/a");
125 $this->waitForPageToLoad($this->getTimeoutMsec());
126 $selectFieldLoc = $this->getLocation();
127 $selectFieldId = $this->urlArg('fid');
129 // get select field ids
130 // get select field option1
131 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]");
132 $this->waitForPageToLoad($this->getTimeoutMsec());
133 $selectFieldOp1 = $this->urlArg('oid');
135 $this->open($selectFieldLoc);
136 $this->waitForPageToLoad($this->getTimeoutMsec());
138 // get select field option2
139 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]");
140 $this->waitForPageToLoad($this->getTimeoutMsec());
141 $selectFieldOp2 = $this->urlArg('oid');
144 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
145 $paramsEvent = array(
146 'title' => $eventTitle,
148 'event_type_id' => 4,
149 'payment_processor' => $processorName,
150 'price_set' => $priceset,
153 $infoEvent = $this->_testAddEvent($paramsEvent);
155 // logout to register for event.
156 $this->webtestLogout();
158 // Register Participant 1
159 // visit event info page
160 $this->open($infoEvent);
161 $this->waitForPageToLoad($this->getTimeoutMsec());
163 // register for event
164 $this->click('link=Register Now');
165 $this->waitForElementPresent('_qf_Register_upload-bottom');
167 // exceed maximun count for text field, check for form rule
168 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
170 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
172 $this->type('first_name', 'Mary');
173 $this->type('last_name', 'Jones'. substr(sha1(rand()), 0, 5));
174 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
175 $this->type('email-Primary', $email);
177 // fill billing related info
178 $this->_fillRegisterWithBillingInfo();
180 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
182 // fill correct value for text field
183 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
185 $this->click('_qf_Register_upload-bottom');
186 $this->waitForPageToLoad($this->getTimeoutMsec());
188 $this->_checkConfirmationAndRegister();
190 // Register Participant 2
191 // visit event info page
192 $this->open($infoEvent);
193 $this->waitForPageToLoad($this->getTimeoutMsec());
195 $this->click('link=Register Now');
196 $this->waitForElementPresent('_qf_Register_upload-bottom');
198 // exceed maximun count for text field, check for form rule
199 $this->type("xpath=//input[@id='price_{$textFieldId}']", '2');
200 $this->type('first_name', 'Mary');
201 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
202 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
203 $this->type('email-Primary', $email);
205 // fill billing related info and register
206 $this->_fillRegisterWithBillingInfo();
208 $this->assertStringsPresent(array('Sorry, currently only a single seat is available for this option.'));
210 // fill correct value for test field
211 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
213 // select sold option for select field, check for form rule
214 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
215 $this->click('_qf_Register_upload-bottom');
216 $this->waitForPageToLoad($this->getTimeoutMsec());
218 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
220 // fill correct available option for select field
221 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
223 $this->click('_qf_Register_upload-bottom');
224 $this->waitForPageToLoad($this->getTimeoutMsec());
226 $this->_checkConfirmationAndRegister();
229 function testWithFieldCount() {
230 // Log in using webtestLogin() method
231 $this->webtestLogin();
233 // We need a payment processor
234 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
235 $this->webtestAddPaymentProcessor($processorName);
238 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
239 $financialType = 'Donation';
240 $this->_testAddSet($priceset, $financialType);
242 // create price fields
244 'Full Conference' => array(
246 'amount' => '525.00',
249 'is_required' => TRUE,
250 'financial_type_id' => 1,
252 'Meal Choice' => array(
256 'label' => 'Chicken',
257 'amount' => '525.00',
260 'financial_type_id' => 1,
263 'label' => 'Vegetarian',
264 'amount' => '200.00',
267 'financial_type_id' => 1,
271 'Pre-conference Meetup?' => array(
279 'financial_type_id' => 1,
286 'financial_type_id' => 1,
290 'Evening Sessions' => array(
291 'type' => 'CheckBox',
294 'label' => 'First Five',
295 'amount' => '100.00',
298 'financial_type_id' => 1,
301 'label' => 'Second Four',
305 'financial_type_id' => 1,
312 $this->_testAddPriceFields($fields);
314 // get price set url.
315 $pricesetLoc = $this->getLocation();
317 // get text field Id.
318 $this->clickLink("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]");
319 $textFieldId = $this->urlArg('fid');
321 $this->open($pricesetLoc);
322 $this->waitForPageToLoad($this->getTimeoutMsec());
324 // get select field id
325 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/a");
326 $this->waitForPageToLoad($this->getTimeoutMsec());
327 $selectFieldLoc = $this->getLocation();
328 $selectFieldId = $this->urlArg('fid');
330 // get select field ids
331 // get select field option1
332 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]");
333 $this->waitForPageToLoad($this->getTimeoutMsec());
334 $selectFieldOp1 = $this->urlArg('oid');
336 $this->open($selectFieldLoc);
337 $this->waitForPageToLoad($this->getTimeoutMsec());
339 // get select field option2
340 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]");
341 $this->waitForPageToLoad($this->getTimeoutMsec());
342 $selectFieldOp2 = $this->urlArg('oid');
345 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
346 $paramsEvent = array(
347 'title' => $eventTitle,
349 'event_type_id' => 4,
350 'payment_processor' => $processorName,
351 'price_set' => $priceset,
354 $infoEvent = $this->_testAddEvent($paramsEvent);
356 // logout to register for event.
357 $this->webtestLogout();
359 // Register Participant 1
360 // visit event info page
361 $this->open($infoEvent);
362 $this->waitForPageToLoad($this->getTimeoutMsec());
364 // register for event
365 $this->click('link=Register Now');
366 $this->waitForElementPresent('_qf_Register_upload-bottom');
368 // check for form rule
369 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
371 $this->type('first_name', 'Mary');
372 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
373 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
374 $this->type('email-Primary', $email);
376 // fill billing related info
377 $this->_fillRegisterWithBillingInfo();
379 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
381 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
383 // fill correct value and register
384 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
386 $this->click('_qf_Register_upload-bottom');
387 $this->waitForPageToLoad($this->getTimeoutMsec());
389 $this->_checkConfirmationAndRegister();
391 // Register Participant 2
392 // visit event info page
393 $this->open($infoEvent);
394 $this->waitForPageToLoad($this->getTimeoutMsec());
396 $this->click('link=Register Now');
397 $this->waitForElementPresent('_qf_Register_upload-bottom');
399 // check for form rule
400 $this->type("xpath=//input[@id='price_{$textFieldId}']", '2');
401 $this->type('first_name', 'Mary');
402 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
403 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
404 $this->type('email-Primary', $email);
406 // fill billing related info and register
407 $this->_fillRegisterWithBillingInfo();
409 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
411 // fill correct value and register
412 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
414 // check for sold option for select field
415 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
417 $this->click('_qf_Register_upload-bottom');
418 $this->waitForPageToLoad($this->getTimeoutMsec());
420 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
422 // check for sold option for select field
423 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
425 $this->click('_qf_Register_upload-bottom');
426 $this->waitForPageToLoad($this->getTimeoutMsec());
428 $this->_checkConfirmationAndRegister();
431 function testAdditionalParticipantWithoutFieldCount() {
432 // Log in using webtestLogin() method
433 $this->webtestLogin();
435 // We need a payment processor
436 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
437 $this->webtestAddPaymentProcessor($processorName);
440 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
441 $financialType = 'Donation';
442 $this->_testAddSet($priceset, $financialType);
444 // create price fields
446 'Full Conference' => array(
448 'amount' => '525.00',
450 'is_required' => TRUE,
451 'financial_type_id' => 1,
453 'Meal Choice' => array(
457 'label' => 'Chicken',
458 'amount' => '525.00',
460 'financial_type_id' => 1,
463 'label' => 'Vegetarian',
464 'amount' => '200.00',
466 'financial_type_id' => 1,
470 'Pre-conference Meetup?' => array(
477 'financial_type_id' => 1,
483 'financial_type_id' => 1,
487 'Evening Sessions' => array(
488 'type' => 'CheckBox',
491 'label' => 'First Five',
492 'amount' => '100.00',
494 'financial_type_id' => 1,
497 'label' => 'Second Four',
500 'financial_type_id' => 1,
507 $this->_testAddPriceFields($fields);
509 // get price set url.
510 $pricesetLoc = $this->getLocation();
512 // get text field Id.
513 $this->clickLink("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]");
514 $textFieldId = $this->urlArg('fid');
516 $this->open($pricesetLoc);
517 $this->waitForPageToLoad($this->getTimeoutMsec());
519 // get select field id
520 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/a");
521 $this->waitForPageToLoad($this->getTimeoutMsec());
522 $selectFieldLoc = $this->getLocation();
523 $selectFieldId = $this->urlArg('fid');
525 // get select field ids
526 // get select field option1
527 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]");
528 $this->waitForPageToLoad($this->getTimeoutMsec());
529 $selectFieldOp1 = $this->urlArg('oid');
531 $this->open($selectFieldLoc);
532 $this->waitForPageToLoad($this->getTimeoutMsec());
534 // get select field option2
535 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]");
536 $this->waitForPageToLoad($this->getTimeoutMsec());
537 $selectFieldOp2 = $this->urlArg('oid');
540 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
541 $paramsEvent = array(
542 'title' => $eventTitle,
544 'event_type_id' => 4,
545 'payment_processor' => $processorName,
546 'price_set' => $priceset,
547 'is_multiple_registrations' => TRUE,
550 $infoEvent = $this->_testAddEvent($paramsEvent);
552 // logout to register for event.
553 $this->webtestLogout();
556 // Register Participant 1
557 // visit event info page
558 $this->open($infoEvent);
559 $this->waitForPageToLoad($this->getTimeoutMsec());
561 // register for event
562 $this->click('link=Register Now');
563 $this->waitForElementPresent('_qf_Register_upload-bottom');
565 // select 3 participants ( including current )
566 $this->select('additional_participants', 'value=2');
568 // Check for Participant1
569 // exceed maximun count for text field, check for form rule
570 $this->type("xpath=//input[@id='price_{$textFieldId}']", '7');
572 $this->type('first_name', 'Mary');
573 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
574 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
575 $this->type('email-Primary', $email);
577 // fill billing related info
578 $this->_fillRegisterWithBillingInfo();
580 $this->assertStringsPresent(array('Sorry, currently only 6 seats are available for this option.'));
582 // fill correct value for text field
583 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
584 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
586 $this->click('_qf_Register_upload-bottom');
587 $this->waitForPageToLoad($this->getTimeoutMsec());
589 // Check for Participant2
590 // exceed maximun count for text field, check for form rule
591 $this->type("xpath=//input[@id='price_{$textFieldId}']", '6');
593 $this->type('first_name', 'Mary Add 2');
594 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
595 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
596 $this->type('email-Primary', $email);
598 $this->click('_qf_Participant_1_next-Array');
599 $this->waitForPageToLoad($this->getTimeoutMsec());
601 $this->assertStringsPresent(array('Sorry, currently only 6 seats are available for this option.'));
603 // fill correct value for text field
604 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
605 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
607 $this->click('_qf_Participant_1_next-Array');
608 $this->waitForPageToLoad($this->getTimeoutMsec());
610 // Check for Participant3, check and skip
611 // exceed maximun count for text field, check for form rule
612 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
614 $this->type('first_name', 'Mary Add 2');
615 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
616 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
617 $this->type('email-Primary', $email);
619 $this->click('_qf_Participant_2_next-Array');
620 $this->waitForPageToLoad($this->getTimeoutMsec());
622 $this->assertStringsPresent(array('Sorry, currently only 6 seats are available for this option.'));
624 // fill correct value for text field
625 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
628 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
630 $this->click('_qf_Participant_2_next-Array');
631 $this->waitForPageToLoad($this->getTimeoutMsec());
633 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
635 // Skip participant3 and register
636 $this->click('_qf_Participant_2_next_skip-Array');
637 $this->waitForPageToLoad($this->getTimeoutMsec());
639 $this->_checkConfirmationAndRegister();
642 // Register Participant 1
643 // visit event info page
644 $this->open($infoEvent);
645 $this->waitForPageToLoad($this->getTimeoutMsec());
647 // register for event
648 $this->click('link=Register Now');
649 $this->waitForElementPresent('_qf_Register_upload-bottom');
651 // select 2 participants ( including current )
652 $this->select('additional_participants', 'value=1');
654 // Check for Participant1
655 // exceed maximun count for text field, check for form rule
656 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
658 $this->type('first_name', 'Mary');
659 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
660 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
661 $this->type('email-Primary', $email);
663 // fill billing related info
664 $this->_fillRegisterWithBillingInfo();
666 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
668 // fill correct value for text field
669 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
671 // check for select field
672 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
674 $this->click('_qf_Register_upload-bottom');
675 $this->waitForPageToLoad($this->getTimeoutMsec());
677 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
679 // fill available value for select
680 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
682 $this->click('_qf_Register_upload-bottom');
683 $this->waitForPageToLoad($this->getTimeoutMsec());
685 // Check for Participant2
686 // exceed maximun count for text field, check for form rule
687 $this->type("xpath=//input[@id='price_{$textFieldId}']", '2');
689 $this->type('first_name', 'Mary Add 1');
690 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
691 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
692 $this->type('email-Primary', $email);
694 $this->click('_qf_Participant_1_next-Array');
695 $this->waitForPageToLoad($this->getTimeoutMsec());
697 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
699 // fill correct value for text field
700 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
702 // check for select field
703 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
705 $this->click('_qf_Participant_1_next-Array');
706 $this->waitForPageToLoad($this->getTimeoutMsec());
708 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
710 // fill available value for select
711 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
713 $this->click('_qf_Participant_1_next-Array');
714 $this->waitForPageToLoad($this->getTimeoutMsec());
716 $this->_checkConfirmationAndRegister();
719 function testAdditionalParticipantWithFieldCount() {
720 // Log in using webtestLogin() method
721 $this->webtestLogin();
723 // We need a payment processor
724 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
725 $this->webtestAddPaymentProcessor($processorName);
728 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
729 $financialType = 'Donation';
730 $this->_testAddSet($priceset, $financialType);
732 // create price fields
734 'Full Conference' => array(
736 'amount' => '525.00',
739 'is_required' => TRUE,
740 'financial_type_id' => 1,
742 'Meal Choice' => array(
746 'label' => 'Chicken',
747 'amount' => '525.00',
750 'financial_type_id' => 1,
753 'label' => 'Vegetarian',
754 'amount' => '200.00',
757 'financial_type_id' => 1,
761 'Pre-conference Meetup?' => array(
769 'financial_type_id' => 1,
776 'financial_type_id' => 1,
780 'Evening Sessions' => array(
781 'type' => 'CheckBox',
784 'label' => 'First Five',
785 'amount' => '100.00',
788 'financial_type_id' => 1,
791 'label' => 'Second Four',
795 'financial_type_id' => 1,
802 $this->_testAddPriceFields($fields);
804 // get price set url.
805 $pricesetLoc = $this->getLocation();
807 // get text field Id.
808 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]");
809 $this->waitForPageToLoad($this->getTimeoutMsec());
810 $textFieldId = $this->urlArg('fid');
812 $this->open($pricesetLoc);
813 $this->waitForPageToLoad($this->getTimeoutMsec());
815 // get select field id
816 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/a");
817 $this->waitForPageToLoad($this->getTimeoutMsec());
818 $selectFieldLoc = $this->getLocation();
819 $selectFieldId = $this->urlArg('fid');
821 // get select field ids
822 // get select field option1
823 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]");
824 $this->waitForPageToLoad($this->getTimeoutMsec());
825 $selectFieldOp1 = $this->urlArg('oid');
827 $this->open($selectFieldLoc);
828 $this->waitForPageToLoad($this->getTimeoutMsec());
830 // get select field option2
831 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]");
832 $this->waitForPageToLoad($this->getTimeoutMsec());
833 $selectFieldOp2 = $this->urlArg('oid');
836 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
837 $paramsEvent = array(
838 'title' => $eventTitle,
840 'event_type_id' => 4,
841 'payment_processor' => $processorName,
842 'price_set' => $priceset,
843 'is_multiple_registrations' => TRUE,
846 $infoEvent = $this->_testAddEvent($paramsEvent);
848 // logout to register for event.
849 $this->webtestLogout();
852 // Register Participant 1
853 // visit event info page
854 $this->open($infoEvent);
855 $this->waitForPageToLoad($this->getTimeoutMsec());
857 // register for event
858 $this->click('link=Register Now');
859 $this->waitForElementPresent('_qf_Register_upload-bottom');
861 // select 3 participants ( including current )
862 $this->select('additional_participants', 'value=2');
864 // Check for Participant1
865 // exceed maximun count for text field, check for form rule
866 $this->type("xpath=//input[@id='price_{$textFieldId}']", '7');
868 $this->type('first_name', 'Mary');
869 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
870 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
871 $this->type('email-Primary', $email);
873 // fill billing related info
874 $this->_fillRegisterWithBillingInfo();
876 $this->assertStringsPresent(array('Sorry, currently only 12 seats are available for this option.'));
878 // fill correct value for text field
879 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
880 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
882 $this->click('_qf_Register_upload-bottom');
883 $this->waitForPageToLoad($this->getTimeoutMsec());
885 // Check for Participant2
886 // exceed maximun count for text field, check for form rule
887 $this->type("xpath=//input[@id='price_{$textFieldId}']", '6');
889 $this->type('first_name', 'Mary Add 1');
890 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
891 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
892 $this->type('email-Primary', $email);
894 $this->click('_qf_Participant_1_next-Array');
895 $this->waitForPageToLoad($this->getTimeoutMsec());
897 $this->assertStringsPresent(array('Sorry, currently only 12 seats are available for this option.'));
899 // fill correct value for text field
900 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
901 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
903 $this->click('_qf_Participant_1_next-Array');
904 $this->waitForPageToLoad($this->getTimeoutMsec());
906 // Check for Participant3, check and skip
907 // exceed maximun count for text field, check for form rule
908 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
910 $this->type('first_name', 'Mary Add 2');
911 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
912 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
913 $this->type('email-Primary', $email);
915 $this->click('_qf_Participant_2_next-Array');
916 $this->waitForPageToLoad($this->getTimeoutMsec());
918 $this->assertStringsPresent(array('Sorry, currently only 12 seats are available for this option.'));
920 // fill correct value for text field
921 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
924 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
926 $this->click('_qf_Participant_2_next-Array');
927 $this->waitForPageToLoad($this->getTimeoutMsec());
929 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
931 // Skip participant3 and register
932 $this->click('_qf_Participant_2_next_skip-Array');
933 $this->waitForPageToLoad($this->getTimeoutMsec());
935 $this->_checkConfirmationAndRegister();
938 // Register Participant 1
939 // visit event info page
940 $this->open($infoEvent);
941 $this->waitForPageToLoad($this->getTimeoutMsec());
943 // register for event
944 $this->click('link=Register Now');
945 $this->waitForElementPresent('_qf_Register_upload-bottom');
947 // select 2 participants ( including current )
948 $this->select('additional_participants', 'value=1');
950 // Check for Participant1
951 // exceed maximun count for text field, check for form rule
952 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
954 $this->type('first_name', 'Mary');
955 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
956 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
957 $this->type('email-Primary', $email);
959 // fill billing related info
960 $this->_fillRegisterWithBillingInfo();
962 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
964 // fill correct value for text field
965 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
967 // check for select field
968 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
970 $this->click('_qf_Register_upload-bottom');
971 $this->waitForPageToLoad($this->getTimeoutMsec());
973 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
975 // fill available value for select
976 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
978 $this->click('_qf_Register_upload-bottom');
979 $this->waitForPageToLoad($this->getTimeoutMsec());
981 // Check for Participant2
982 // exceed maximun count for text field, check for form rule
983 $this->type("xpath=//input[@id='price_{$textFieldId}']", '2');
985 $this->type('first_name', 'Mary Add 1');
986 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
987 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
988 $this->type('email-Primary', $email);
990 $this->click('_qf_Participant_1_next-Array');
991 $this->waitForPageToLoad($this->getTimeoutMsec());
993 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
995 // fill correct value for text field
996 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
998 // check for select field
999 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
1001 $this->click('_qf_Participant_1_next-Array');
1002 $this->waitForPageToLoad($this->getTimeoutMsec());
1004 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
1006 // fill available value for select
1007 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
1009 $this->click('_qf_Participant_1_next-Array');
1010 $this->waitForPageToLoad($this->getTimeoutMsec());
1012 $this->_checkConfirmationAndRegister();
1015 function _testAddSet($setTitle, $financialType = NULL) {
1016 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
1018 // Enter Priceset fields (Title, Used For ...)
1019 $this->type('title', $setTitle);
1020 $this->check('extends_1');
1022 if ($financialType) {
1023 $this->select("css=select.form-select", "label={$financialType}");
1026 $this->click("xpath=//form[@id='Set']/div[3]/table/tbody/tr[4]/td[2]/select");
1027 $this->type('help_pre', 'This is test priceset.');
1029 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
1030 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom');
1033 function _testAddPriceFields($fields) {
1034 $fieldCount = count($fields);
1036 foreach ($fields as $label => $field) {
1037 $this->type('label', $label);
1038 $this->select('html_type', "value={$field['type']}");
1040 if ($field['type'] == 'Text') {
1041 $this->type('price', $field['amount']);
1043 if (isset($field['count'])) {
1044 $this->waitForElementPresent('count');
1045 $this->type('count', $field['count']);
1048 if (isset($field['count'])) {
1049 $this->waitForElementPresent('count');
1050 $this->type('count', $field['count']);
1053 if (isset($field['max_count'])) {
1054 $this->waitForElementPresent('max_value');
1055 $this->type('max_value', $field['max_count']);
1058 if (isset($field['financial_type_id'])) {
1059 $this->waitForElementPresent('financial_type_id');
1060 $this->select('financial_type_id', "value={$field['financial_type_id']}");
1065 $this->_testAddMultipleChoiceOptions($field['options'], $field['type']);
1068 if (isset($field['is_required']) && $field['is_required']) {
1069 $this->check('is_required');
1072 if ($count < $fieldCount) {
1073 $this->click('_qf_Field_next_new-bottom');
1076 $this->click('_qf_Field_next-bottom');
1078 $this->waitForPageToLoad($this->getTimeoutMsec());
1084 function _testAddMultipleChoiceOptions($options, $fieldType) {
1085 foreach ($options as $oIndex => $oValue) {
1086 $this->type("option_label_{$oIndex}", $oValue['label']);
1087 $this->type("option_amount_{$oIndex}", $oValue['amount']);
1089 if (isset($oValue['count'])) {
1090 $this->waitForElementPresent("option_count_{$oIndex}");
1091 $this->type("option_count_{$oIndex}", $oValue['count']);
1094 if (isset($oValue['max_count'])) {
1095 $this->waitForElementPresent("option_max_value_{$oIndex}");
1096 $this->type("option_max_value_{$oIndex}", $oValue['max_count']);
1099 if (!empty($oValue['financial_type_id'])) {
1100 $this->select("option_financial_type_id_{$oIndex}", "value={$oValue['financial_type_id']}");
1103 $this->click('link=another choice');
1106 // select first element as default
1107 if ($fieldType == 'CheckBox') {
1108 $this->click('default_checkbox_option[1]');
1111 $this->click('CIVICRM_QFID_1_2');
1115 function _testAddEvent($params) {
1116 $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom');
1118 $this->select('event_type_id', "value={$params['event_type_id']}");
1120 // Attendee role s/b selected now.
1121 $this->select('default_role_id', 'value=1');
1123 // Enter Event Title, Summary and Description
1124 $this->type('title', $params['title']);
1125 $this->type('summary', 'This is a great conference. Sign up now!');
1126 $this->fillRichTextField('description', 'Here is a description for this event.', 'CKEditor');
1128 // Choose Start and End dates.
1129 // Using helper webtestFillDate function.
1130 $this->webtestFillDateTime('start_date', '+1 week');
1131 $this->webtestFillDateTime('end_date', '+1 week 1 day 8 hours ');
1133 $this->type('max_participants', '50');
1134 $this->click('is_map');
1135 $this->click('_qf_EventInfo_upload-bottom');
1137 // Wait for Location tab form to load
1138 $this->waitForPageToLoad($this->getTimeoutMsec());
1141 $this->click('link=Fees');
1142 $this->waitForElementPresent('_qf_Fee_upload-bottom');
1143 $this->click('xpath=//form[@id="Fee"]/div[2]/table/tbody/tr[2]/td[2]/label[contains(text(), "Yes")]');
1144 $processorName = $params['payment_processor'];
1145 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='$processorName']");
1146 $this->select('financial_type_id', 'value=4');
1148 if (array_key_exists('price_set', $params)) {
1149 $this->select('price_set_id', 'label=' . $params['price_set']);
1151 if (array_key_exists('fee_level', $params)) {
1153 foreach ($params['fee_level'] as $label => $amount) {
1154 $this->type("label_{$counter}", $label);
1155 $this->type("value_{$counter}", $amount);
1160 $this->click('_qf_Fee_upload-bottom');
1161 $this->waitForPageToLoad($this->getTimeoutMsec());
1163 // Go to Online Registration tab
1164 $this->click('link=Online Registration');
1165 $this->waitForElementPresent('_qf_Registration_upload-bottom');
1167 $this->check('is_online_registration');
1168 $this->assertChecked('is_online_registration');
1170 if (isset($params['is_multiple_registrations']) && $params['is_multiple_registrations']) {
1171 $this->click('is_multiple_registrations');
1174 $this->fillRichTextField('intro_text', 'Fill in all the fields below and click Continue.');
1176 // enable confirmation email
1177 $this->click('CIVICRM_QFID_1_is_email_confirm');
1178 $this->type('confirm_from_name', 'Jane Doe');
1179 $this->type('confirm_from_email', 'jane.doe@example.org');
1181 $this->click('_qf_Registration_upload-bottom');
1182 $this->waitForPageToLoad($this->getTimeoutMsec());
1183 $this->waitForTextPresent("'Registration' information has been saved.");
1185 // verify event input on info page
1186 // start at Manage Events listing
1187 $this->openCiviPage('event/manage', 'reset=1');
1188 $this->click('link=' . $params['title']);
1190 $this->waitForPageToLoad($this->getTimeoutMsec());
1191 return $this->getLocation();
1194 function _fillRegisterWithBillingInfo() {
1195 $this->waitForElementPresent('credit_card_type');
1196 $this->select('credit_card_type', 'value=Visa');
1197 $this->type('credit_card_number', '4111111111111111');
1198 $this->type('cvv2', '000');
1199 $this->select('credit_card_exp_date[M]', 'value=1');
1200 $this->select('credit_card_exp_date[Y]', 'value=2020');
1201 $this->type('billing_first_name', 'Jane_' . substr(sha1(rand()), 0, 5));
1202 $this->type('billing_last_name', 'San_' . substr(sha1(rand()), 0, 5));
1203 $this->type('billing_street_address-5', '15 Main St.');
1204 $this->type(' billing_city-5', 'San Jose');
1205 $this->select('billing_country_id-5', 'value=1228');
1206 $this->select('billing_state_province_id-5', 'value=1004');
1207 $this->type('billing_postal_code-5', '94129');
1209 $this->click('_qf_Register_upload-bottom');
1210 $this->waitForPageToLoad($this->getTimeoutMsec());
1213 function _checkConfirmationAndRegister() {
1214 $confirmStrings = array('Event Fee(s)', 'Billing Name and Address', 'Credit Card Information');
1215 $this->assertStringsPresent($confirmStrings);
1216 $this->click('_qf_Confirm_next-bottom');
1217 $this->waitForPageToLoad($this->getTimeoutMsec());
1218 $thankStrings = array('Thank You for Registering', 'Event Total', 'Transaction Date');
1219 $this->assertStringsPresent($thankStrings);