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';
30 * Class WebTest_Event_PricesetMaxCountTest
32 class WebTest_Event_PricesetMaxCountTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 function testWithoutFieldCount() {
39 // Log in using webtestLogin() method
40 $this->webtestLogin();
42 // We need a payment processor
43 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
44 $this->webtestAddPaymentProcessor($processorName);
47 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
48 $financialType = 'Donation';
49 $this->_testAddSet($priceset, $financialType);
51 // create price fields
53 'Full Conference' => array(
57 'is_required' => TRUE,
58 'financial_type_id' => 1,
60 'Meal Choice' => array(
67 'financial_type_id' => 1,
70 'label' => 'Vegetarian',
73 'financial_type_id' => 1,
77 'Pre-conference Meetup?' => array(
84 'financial_type_id' => 1,
90 'financial_type_id' => 1,
94 'Evening Sessions' => array(
98 'label' => 'First Five',
101 'financial_type_id' => 1,
104 'label' => 'Second Four',
107 'financial_type_id' => 1,
114 $this->_testAddPriceFields($fields);
116 // get price set url.
117 $pricesetLoc = $this->getLocation();
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];
125 $this->open($pricesetLoc);
126 $this->waitForPageToLoad($this->getTimeoutMsec());
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');
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];
141 $this->open($selectFieldLoc);
142 $this->waitForPageToLoad($this->getTimeoutMsec());
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];
151 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
152 $paramsEvent = array(
153 'title' => $eventTitle,
155 'event_type_id' => 4,
156 'payment_processor' => $processorName,
157 'price_set' => $priceset,
160 $infoEvent = $this->_testAddEvent($paramsEvent);
162 // logout to register for event.
163 $this->webtestLogout();
165 // Register Participant 1
166 // visit event info page
167 $this->open($infoEvent);
168 $this->waitForPageToLoad($this->getTimeoutMsec());
170 // register for event
171 $this->click('link=Register Now');
172 $this->waitForElementPresent('_qf_Register_upload-bottom');
174 // exceed maximun count for text field, check for form rule
175 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
177 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
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);
184 // fill billing related info
185 $this->_fillRegisterWithBillingInfo();
187 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
189 // fill correct value for text field
190 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
192 $this->click('_qf_Register_upload-bottom');
193 $this->waitForPageToLoad($this->getTimeoutMsec());
195 $this->_checkConfirmationAndRegister();
197 // Register Participant 2
198 // visit event info page
199 $this->open($infoEvent);
200 $this->waitForPageToLoad($this->getTimeoutMsec());
202 $this->click('link=Register Now');
203 $this->waitForElementPresent('_qf_Register_upload-bottom');
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);
212 // fill billing related info and register
213 $this->_fillRegisterWithBillingInfo();
215 $this->assertStringsPresent(array('Sorry, currently only a single seat is available for this option.'));
217 // fill correct value for test field
218 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
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());
225 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
227 // fill correct available option for select field
228 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
230 $this->click('_qf_Register_upload-bottom');
231 $this->waitForPageToLoad($this->getTimeoutMsec());
233 $this->_checkConfirmationAndRegister();
236 function testWithFieldCount() {
237 // Log in using webtestLogin() method
238 $this->webtestLogin();
240 // We need a payment processor
241 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
242 $this->webtestAddPaymentProcessor($processorName);
245 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
246 $financialType = 'Donation';
247 $this->_testAddSet($priceset, $financialType);
249 // create price fields
251 'Full Conference' => array(
253 'amount' => '525.00',
256 'is_required' => TRUE,
257 'financial_type_id' => 1,
259 'Meal Choice' => array(
263 'label' => 'Chicken',
264 'amount' => '525.00',
267 'financial_type_id' => 1,
270 'label' => 'Vegetarian',
271 'amount' => '200.00',
274 'financial_type_id' => 1,
278 'Pre-conference Meetup?' => array(
286 'financial_type_id' => 1,
293 'financial_type_id' => 1,
297 'Evening Sessions' => array(
298 'type' => 'CheckBox',
301 'label' => 'First Five',
302 'amount' => '100.00',
305 'financial_type_id' => 1,
308 'label' => 'Second Four',
312 'financial_type_id' => 1,
319 $this->_testAddPriceFields($fields);
321 // get price set url.
322 $pricesetLoc = $this->getLocation();
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];
330 $this->open($pricesetLoc);
331 $this->waitForPageToLoad($this->getTimeoutMsec());
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');
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];
346 $this->open($selectFieldLoc);
347 $this->waitForPageToLoad($this->getTimeoutMsec());
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];
356 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
357 $paramsEvent = array(
358 'title' => $eventTitle,
360 'event_type_id' => 4,
361 'payment_processor' => $processorName,
362 'price_set' => $priceset,
365 $infoEvent = $this->_testAddEvent($paramsEvent);
367 // logout to register for event.
368 $this->webtestLogout();
370 // Register Participant 1
371 // visit event info page
372 $this->open($infoEvent);
373 $this->waitForPageToLoad($this->getTimeoutMsec());
375 // register for event
376 $this->click('link=Register Now');
377 $this->waitForElementPresent('_qf_Register_upload-bottom');
379 // check for form rule
380 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
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);
387 // fill billing related info
388 $this->_fillRegisterWithBillingInfo();
390 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
392 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
394 // fill correct value and register
395 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
397 $this->click('_qf_Register_upload-bottom');
398 $this->waitForPageToLoad($this->getTimeoutMsec());
400 $this->_checkConfirmationAndRegister();
402 // Register Participant 2
403 // visit event info page
404 $this->open($infoEvent);
405 $this->waitForPageToLoad($this->getTimeoutMsec());
407 $this->click('link=Register Now');
408 $this->waitForElementPresent('_qf_Register_upload-bottom');
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);
417 // fill billing related info and register
418 $this->_fillRegisterWithBillingInfo();
420 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
422 // fill correct value and register
423 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
425 // check for sold option for select field
426 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
428 $this->click('_qf_Register_upload-bottom');
429 $this->waitForPageToLoad($this->getTimeoutMsec());
431 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
433 // check for sold option for select field
434 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
436 $this->click('_qf_Register_upload-bottom');
437 $this->waitForPageToLoad($this->getTimeoutMsec());
439 $this->_checkConfirmationAndRegister();
442 function testAdditionalParticipantWithoutFieldCount() {
443 // Log in using webtestLogin() method
444 $this->webtestLogin();
446 // We need a payment processor
447 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
448 $this->webtestAddPaymentProcessor($processorName);
451 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
452 $financialType = 'Donation';
453 $this->_testAddSet($priceset, $financialType);
455 // create price fields
457 'Full Conference' => array(
459 'amount' => '525.00',
461 'is_required' => TRUE,
462 'financial_type_id' => 1,
464 'Meal Choice' => array(
468 'label' => 'Chicken',
469 'amount' => '525.00',
471 'financial_type_id' => 1,
474 'label' => 'Vegetarian',
475 'amount' => '200.00',
477 'financial_type_id' => 1,
481 'Pre-conference Meetup?' => array(
488 'financial_type_id' => 1,
494 'financial_type_id' => 1,
498 'Evening Sessions' => array(
499 'type' => 'CheckBox',
502 'label' => 'First Five',
503 'amount' => '100.00',
505 'financial_type_id' => 1,
508 'label' => 'Second Four',
511 'financial_type_id' => 1,
518 $this->_testAddPriceFields($fields);
520 // get price set url.
521 $pricesetLoc = $this->getLocation();
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];
529 $this->open($pricesetLoc);
530 $this->waitForPageToLoad($this->getTimeoutMsec());
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');
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];
545 $this->open($selectFieldLoc);
546 $this->waitForPageToLoad($this->getTimeoutMsec());
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];
555 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
556 $paramsEvent = array(
557 'title' => $eventTitle,
559 'event_type_id' => 4,
560 'payment_processor' => $processorName,
561 'price_set' => $priceset,
562 'is_multiple_registrations' => TRUE,
565 $infoEvent = $this->_testAddEvent($paramsEvent);
567 // logout to register for event.
568 $this->webtestLogout();
571 // Register Participant 1
572 // visit event info page
573 $this->open($infoEvent);
574 $this->waitForPageToLoad($this->getTimeoutMsec());
576 // register for event
577 $this->click('link=Register Now');
578 $this->waitForElementPresent('_qf_Register_upload-bottom');
580 // select 3 participants ( including current )
581 $this->select('additional_participants', 'value=2');
583 // Check for Participant1
584 // exceed maximun count for text field, check for form rule
585 $this->type("xpath=//input[@id='price_{$textFieldId}']", '7');
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);
592 // fill billing related info
593 $this->_fillRegisterWithBillingInfo();
595 $this->assertStringsPresent(array('Sorry, currently only 6 seats are available for this option.'));
597 // fill correct value for text field
598 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
599 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
601 $this->click('_qf_Register_upload-bottom');
602 $this->waitForPageToLoad($this->getTimeoutMsec());
604 // Check for Participant2
605 // exceed maximun count for text field, check for form rule
606 $this->type("xpath=//input[@id='price_{$textFieldId}']", '6');
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);
613 $this->click('_qf_Participant_1_next-Array');
614 $this->waitForPageToLoad($this->getTimeoutMsec());
616 $this->assertStringsPresent(array('Sorry, currently only 6 seats are available for this option.'));
618 // fill correct value for text field
619 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
620 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
622 $this->click('_qf_Participant_1_next-Array');
623 $this->waitForPageToLoad($this->getTimeoutMsec());
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');
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);
634 $this->click('_qf_Participant_2_next-Array');
635 $this->waitForPageToLoad($this->getTimeoutMsec());
637 $this->assertStringsPresent(array('Sorry, currently only 6 seats are available for this option.'));
639 // fill correct value for text field
640 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
643 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
645 $this->click('_qf_Participant_2_next-Array');
646 $this->waitForPageToLoad($this->getTimeoutMsec());
648 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
650 // Skip participant3 and register
651 $this->click('_qf_Participant_2_next_skip-Array');
652 $this->waitForPageToLoad($this->getTimeoutMsec());
654 $this->_checkConfirmationAndRegister();
657 // Register Participant 1
658 // visit event info page
659 $this->open($infoEvent);
660 $this->waitForPageToLoad($this->getTimeoutMsec());
662 // register for event
663 $this->click('link=Register Now');
664 $this->waitForElementPresent('_qf_Register_upload-bottom');
666 // select 2 participants ( including current )
667 $this->select('additional_participants', 'value=1');
669 // Check for Participant1
670 // exceed maximun count for text field, check for form rule
671 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
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);
678 // fill billing related info
679 $this->_fillRegisterWithBillingInfo();
681 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
683 // fill correct value for text field
684 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
686 // check for select field
687 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
689 $this->click('_qf_Register_upload-bottom');
690 $this->waitForPageToLoad($this->getTimeoutMsec());
692 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
694 // fill available value for select
695 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
697 $this->click('_qf_Register_upload-bottom');
698 $this->waitForPageToLoad($this->getTimeoutMsec());
700 // Check for Participant2
701 // exceed maximun count for text field, check for form rule
702 $this->type("xpath=//input[@id='price_{$textFieldId}']", '2');
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);
709 $this->click('_qf_Participant_1_next-Array');
710 $this->waitForPageToLoad($this->getTimeoutMsec());
712 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
714 // fill correct value for text field
715 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
717 // check for select field
718 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
720 $this->click('_qf_Participant_1_next-Array');
721 $this->waitForPageToLoad($this->getTimeoutMsec());
723 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
725 // fill available value for select
726 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
728 $this->click('_qf_Participant_1_next-Array');
729 $this->waitForPageToLoad($this->getTimeoutMsec());
731 $this->_checkConfirmationAndRegister();
734 function testAdditionalParticipantWithFieldCount() {
735 // Log in using webtestLogin() method
736 $this->webtestLogin();
738 // We need a payment processor
739 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
740 $this->webtestAddPaymentProcessor($processorName);
743 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
744 $financialType = 'Donation';
745 $this->_testAddSet($priceset, $financialType);
747 // create price fields
749 'Full Conference' => array(
751 'amount' => '525.00',
754 'is_required' => TRUE,
755 'financial_type_id' => 1,
757 'Meal Choice' => array(
761 'label' => 'Chicken',
762 'amount' => '525.00',
765 'financial_type_id' => 1,
768 'label' => 'Vegetarian',
769 'amount' => '200.00',
772 'financial_type_id' => 1,
776 'Pre-conference Meetup?' => array(
784 'financial_type_id' => 1,
791 'financial_type_id' => 1,
795 'Evening Sessions' => array(
796 'type' => 'CheckBox',
799 'label' => 'First Five',
800 'amount' => '100.00',
803 'financial_type_id' => 1,
806 'label' => 'Second Four',
810 'financial_type_id' => 1,
817 $this->_testAddPriceFields($fields);
819 // get price set url.
820 $pricesetLoc = $this->getLocation();
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];
828 $this->open($pricesetLoc);
829 $this->waitForPageToLoad($this->getTimeoutMsec());
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');
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];
844 $this->open($selectFieldLoc);
845 $this->waitForPageToLoad($this->getTimeoutMsec());
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];
854 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
855 $paramsEvent = array(
856 'title' => $eventTitle,
858 'event_type_id' => 4,
859 'payment_processor' => $processorName,
860 'price_set' => $priceset,
861 'is_multiple_registrations' => TRUE,
864 $infoEvent = $this->_testAddEvent($paramsEvent);
866 // logout to register for event.
867 $this->webtestLogout();
870 // Register Participant 1
871 // visit event info page
872 $this->open($infoEvent);
873 $this->waitForPageToLoad($this->getTimeoutMsec());
875 // register for event
876 $this->click('link=Register Now');
877 $this->waitForElementPresent('_qf_Register_upload-bottom');
879 // select 3 participants ( including current )
880 $this->select('additional_participants', 'value=2');
882 // Check for Participant1
883 // exceed maximun count for text field, check for form rule
884 $this->type("xpath=//input[@id='price_{$textFieldId}']", '7');
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);
891 // fill billing related info
892 $this->_fillRegisterWithBillingInfo();
894 $this->assertStringsPresent(array('Sorry, currently only 12 seats are available for this option.'));
896 // fill correct value for text field
897 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
898 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
900 $this->click('_qf_Register_upload-bottom');
901 $this->waitForPageToLoad($this->getTimeoutMsec());
903 // Check for Participant2
904 // exceed maximun count for text field, check for form rule
905 $this->type("xpath=//input[@id='price_{$textFieldId}']", '6');
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);
912 $this->click('_qf_Participant_1_next-Array');
913 $this->waitForPageToLoad($this->getTimeoutMsec());
915 $this->assertStringsPresent(array('Sorry, currently only 12 seats are available for this option.'));
917 // fill correct value for text field
918 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
919 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
921 $this->click('_qf_Participant_1_next-Array');
922 $this->waitForPageToLoad($this->getTimeoutMsec());
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');
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);
933 $this->click('_qf_Participant_2_next-Array');
934 $this->waitForPageToLoad($this->getTimeoutMsec());
936 $this->assertStringsPresent(array('Sorry, currently only 12 seats are available for this option.'));
938 // fill correct value for text field
939 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
942 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
944 $this->click('_qf_Participant_2_next-Array');
945 $this->waitForPageToLoad($this->getTimeoutMsec());
947 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
949 // Skip participant3 and register
950 $this->click('_qf_Participant_2_next_skip-Array');
951 $this->waitForPageToLoad($this->getTimeoutMsec());
953 $this->_checkConfirmationAndRegister();
956 // Register Participant 1
957 // visit event info page
958 $this->open($infoEvent);
959 $this->waitForPageToLoad($this->getTimeoutMsec());
961 // register for event
962 $this->click('link=Register Now');
963 $this->waitForElementPresent('_qf_Register_upload-bottom');
965 // select 2 participants ( including current )
966 $this->select('additional_participants', 'value=1');
968 // Check for Participant1
969 // exceed maximun count for text field, check for form rule
970 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
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);
977 // fill billing related info
978 $this->_fillRegisterWithBillingInfo();
980 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
982 // fill correct value for text field
983 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
985 // check for select field
986 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
988 $this->click('_qf_Register_upload-bottom');
989 $this->waitForPageToLoad($this->getTimeoutMsec());
991 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
993 // fill available value for select
994 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
996 $this->click('_qf_Register_upload-bottom');
997 $this->waitForPageToLoad($this->getTimeoutMsec());
999 // Check for Participant2
1000 // exceed maximun count for text field, check for form rule
1001 $this->type("xpath=//input[@id='price_{$textFieldId}']", '2');
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);
1008 $this->click('_qf_Participant_1_next-Array');
1009 $this->waitForPageToLoad($this->getTimeoutMsec());
1011 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
1013 // fill correct value for text field
1014 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
1016 // check for select field
1017 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
1019 $this->click('_qf_Participant_1_next-Array');
1020 $this->waitForPageToLoad($this->getTimeoutMsec());
1022 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
1024 // fill available value for select
1025 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
1027 $this->click('_qf_Participant_1_next-Array');
1028 $this->waitForPageToLoad($this->getTimeoutMsec());
1030 $this->_checkConfirmationAndRegister();
1035 * @param null $financialType
1037 function _testAddSet($setTitle, $financialType = NULL) {
1038 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
1040 // Enter Priceset fields (Title, Used For ...)
1041 $this->type('title', $setTitle);
1042 $this->check('extends_1');
1044 if ($financialType) {
1045 $this->select("css=select.crm-form-select", "label={$financialType}");
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.');
1051 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
1052 $this->clickLink('_qf_Set_next-bottom');
1058 function _testAddPriceFields($fields) {
1059 $fieldCount = count($fields);
1061 $this->waitForElementPresent('label');
1062 foreach ($fields as $label => $field) {
1063 $this->type('label', $label);
1064 $this->select('html_type', "value={$field['type']}");
1066 if ($field['type'] == 'Text') {
1067 $this->type('price', $field['amount']);
1069 if (isset($field['count'])) {
1070 $this->waitForElementPresent('count');
1071 $this->type('count', $field['count']);
1074 if (isset($field['count'])) {
1075 $this->waitForElementPresent('count');
1076 $this->type('count', $field['count']);
1079 if (isset($field['max_count'])) {
1080 $this->waitForElementPresent('max_value');
1081 $this->type('max_value', $field['max_count']);
1084 if (isset($field['financial_type_id'])) {
1085 $this->waitForElementPresent('financial_type_id');
1086 $this->select('financial_type_id', "value={$field['financial_type_id']}");
1091 $this->_testAddMultipleChoiceOptions($field['options'], $field['type']);
1094 if (isset($field['is_required']) && $field['is_required']) {
1095 $this->check('is_required');
1098 if ($count < $fieldCount) {
1099 $this->click('_qf_Field_next_new-bottom');
1102 $this->click('_qf_Field_next-bottom');
1104 $this->waitForText('crm-notification-container', "Price Field '$label' has been saved.");
1114 function _testAddMultipleChoiceOptions($options, $fieldType) {
1115 foreach ($options as $oIndex => $oValue) {
1116 $this->type("option_label_{$oIndex}", $oValue['label']);
1117 $this->type("option_amount_{$oIndex}", $oValue['amount']);
1119 if (isset($oValue['count'])) {
1120 $this->waitForElementPresent("option_count_{$oIndex}");
1121 $this->type("option_count_{$oIndex}", $oValue['count']);
1124 if (isset($oValue['max_count'])) {
1125 $this->waitForElementPresent("option_max_value_{$oIndex}");
1126 $this->type("option_max_value_{$oIndex}", $oValue['max_count']);
1129 if (!empty($oValue['financial_type_id'])) {
1130 $this->select("option_financial_type_id_{$oIndex}", "value={$oValue['financial_type_id']}");
1133 $this->click('link=another choice');
1136 // select first element as default
1137 if ($fieldType == 'CheckBox') {
1138 $this->click('default_checkbox_option[1]');
1141 $this->click('CIVICRM_QFID_1_2');
1150 function _testAddEvent($params) {
1151 $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom');
1153 $this->select('event_type_id', "value={$params['event_type_id']}");
1155 // Attendee role s/b selected now.
1156 $this->select('default_role_id', 'value=1');
1158 // Enter Event Title, Summary and Description
1159 $this->type('title', $params['title']);
1160 $this->type('summary', 'This is a great conference. Sign up now!');
1161 $this->fillRichTextField('description', 'Here is a description for this event.', 'CKEditor');
1163 // Choose Start and End dates.
1164 // Using helper webtestFillDate function.
1165 $this->webtestFillDateTime('start_date', '+1 week');
1166 $this->webtestFillDateTime('end_date', '+1 week 1 day 8 hours ');
1168 $this->type('max_participants', '50');
1169 $this->click('is_map');
1170 $this->click('_qf_EventInfo_upload-bottom');
1172 // Wait for Location tab form to load
1173 $this->waitForPageToLoad($this->getTimeoutMsec());
1176 $this->click('link=Fees');
1177 $this->waitForElementPresent('_qf_Fee_upload-bottom');
1178 $this->click('xpath=//form[@id="Fee"]/div[2]/table/tbody/tr[2]/td[2]/label[contains(text(), "Yes")]');
1179 $processorName = $params['payment_processor'];
1180 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='$processorName']");
1181 $this->select('financial_type_id', 'value=4');
1183 if (array_key_exists('price_set', $params)) {
1184 $this->select('price_set_id', 'label=' . $params['price_set']);
1186 if (array_key_exists('fee_level', $params)) {
1188 foreach ($params['fee_level'] as $label => $amount) {
1189 $this->type("label_{$counter}", $label);
1190 $this->type("value_{$counter}", $amount);
1195 $this->clickLink('_qf_Fee_upload-bottom', 'link=Online Registration', FALSE);
1197 // Go to Online Registration tab
1198 $this->click('link=Online Registration');
1199 $this->waitForElementPresent('_qf_Registration_upload-bottom');
1201 $this->check('is_online_registration');
1202 $this->assertChecked('is_online_registration');
1204 if (isset($params['is_multiple_registrations']) && $params['is_multiple_registrations']) {
1205 $this->click('is_multiple_registrations');
1208 $this->click('intro_text-plain');
1209 $this->fillRichTextField('intro_text', 'Fill in all the fields below and click Continue.');
1211 // enable confirmation email
1212 $this->click('CIVICRM_QFID_1_is_email_confirm');
1213 $this->type('confirm_from_name', 'Jane Doe');
1214 $this->type('confirm_from_email', 'jane.doe@example.org');
1216 $this->click('_qf_Registration_upload-bottom');
1217 $this->waitForTextPresent("'Fees' information has been saved.");
1219 // verify event input on info page
1220 // start at Manage Events listing
1221 $this->openCiviPage('event/manage', 'reset=1');
1222 $this->click('link=' . $params['title']);
1224 $this->waitForPageToLoad($this->getTimeoutMsec());
1225 return $this->getLocation();
1228 function _fillRegisterWithBillingInfo() {
1229 $this->waitForElementPresent('credit_card_type');
1230 $this->select('credit_card_type', 'value=Visa');
1231 $this->type('credit_card_number', '4111111111111111');
1232 $this->type('cvv2', '000');
1233 $this->select('credit_card_exp_date[M]', 'value=1');
1234 $this->select('credit_card_exp_date[Y]', 'value=2020');
1235 $this->type('billing_first_name', 'Jane_' . substr(sha1(rand()), 0, 5));
1236 $this->type('billing_last_name', 'San_' . substr(sha1(rand()), 0, 5));
1237 $this->type('billing_street_address-5', '15 Main St.');
1238 $this->type(' billing_city-5', 'San Jose');
1239 $this->select('billing_country_id-5', 'value=1228');
1240 $this->select('billing_state_province_id-5', 'value=1004');
1241 $this->type('billing_postal_code-5', '94129');
1243 $this->click('_qf_Register_upload-bottom');
1244 $this->waitForPageToLoad($this->getTimeoutMsec());
1247 function _checkConfirmationAndRegister() {
1248 $confirmStrings = array('Event Fee(s)', 'Billing Name and Address', 'Credit Card Information');
1249 $this->assertStringsPresent($confirmStrings);
1250 $this->click('_qf_Confirm_next-bottom');
1251 $this->waitForPageToLoad($this->getTimeoutMsec());
1252 $thankStrings = array('Thank You for Registering', 'Event Total', 'Transaction Date');
1253 $this->assertStringsPresent($thankStrings);