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 // Use default payment processor
43 $processorName = 'Test Processor';
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 $this->waitForElementPresent("xpath=//div[@id='crm-main-content-wrapper']/div/a[1]");
121 $textFieldIdURL = $this->getAttribute("xpath=//div[@id='field_page']/table/tbody/tr[1]/td[9]/span[1]/a[2]@href");
122 $textFieldId = $this->urlArg('fid', $textFieldIdURL);
124 $this->open($pricesetLoc);
125 $this->waitForPageToLoad($this->getTimeoutMsec());
127 // get select field id
128 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/a");
129 $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[2]/span[2]");
130 $selectFieldLoc = $this->getLocation();
131 $selectFieldURL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[9]/span[1]/a[2]@href");
132 $selectFieldId = $this->urlArg('fid', $selectFieldURL);
134 // get select field ids
135 // get select field option1
136 $selectFieldOp1URL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]@href");
137 $selectFieldOp1 = $this->urlArg('oid', $selectFieldOp1URL);
139 // get select field option2
140 $selectFieldOp2URL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]@href");
141 $selectFieldOp2 = $this->urlArg('oid', $selectFieldOp2URL);
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 // Use default payment processor
234 $processorName = 'Test Processor';
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->waitForElementPresent("xpath=//div[@id='crm-main-content-wrapper']/div/a[1]");
319 $textFieldIdURL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]@href");
320 $textFieldId = $this->urlArg('fid', $textFieldIdURL);
322 $this->open($pricesetLoc);
323 $this->waitForPageToLoad($this->getTimeoutMsec());
325 // get select field id
326 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/a");
327 $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[2]/span[2]");
328 $selectFieldLoc = $this->getLocation();
329 $selectFieldURL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[9]/span[1]/a[2]@href");
330 $selectFieldId = $this->urlArg('fid', $selectFieldURL);
332 // get select field ids
333 // get select field option1
334 $selectFieldOp1URL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]@href");
335 $selectFieldOp1 = $this->urlArg('oid', $selectFieldOp1URL);
337 // get select field option2
338 $selectFieldOp2URL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]@href");
339 $selectFieldOp2 = $this->urlArg('oid', $selectFieldOp2URL);
342 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
343 $paramsEvent = array(
344 'title' => $eventTitle,
346 'event_type_id' => 4,
347 'payment_processor' => $processorName,
348 'price_set' => $priceset,
351 $infoEvent = $this->_testAddEvent($paramsEvent);
353 // logout to register for event.
354 $this->webtestLogout();
356 // Register Participant 1
357 // visit event info page
358 $this->open($infoEvent);
359 $this->waitForPageToLoad($this->getTimeoutMsec());
361 // register for event
362 $this->click('link=Register Now');
363 $this->waitForElementPresent('_qf_Register_upload-bottom');
365 // check for form rule
366 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
368 $this->type('first_name', 'Mary');
369 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
370 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
371 $this->type('email-Primary', $email);
373 // fill billing related info
374 $this->_fillRegisterWithBillingInfo();
376 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
378 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
380 // fill correct value and register
381 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
383 $this->click('_qf_Register_upload-bottom');
384 $this->waitForPageToLoad($this->getTimeoutMsec());
386 $this->_checkConfirmationAndRegister();
388 // Register Participant 2
389 // visit event info page
390 $this->open($infoEvent);
391 $this->waitForPageToLoad($this->getTimeoutMsec());
393 $this->click('link=Register Now');
394 $this->waitForElementPresent('_qf_Register_upload-bottom');
396 // check for form rule
397 $this->type("xpath=//input[@id='price_{$textFieldId}']", '2');
398 $this->type('first_name', 'Mary');
399 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
400 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
401 $this->type('email-Primary', $email);
403 // fill billing related info and register
404 $this->_fillRegisterWithBillingInfo();
406 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
408 // fill correct value and register
409 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
411 // check for sold option for select field
412 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
414 $this->click('_qf_Register_upload-bottom');
415 $this->waitForPageToLoad($this->getTimeoutMsec());
417 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
419 // check for sold option for select field
420 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
422 $this->click('_qf_Register_upload-bottom');
423 $this->waitForPageToLoad($this->getTimeoutMsec());
425 $this->_checkConfirmationAndRegister();
428 function testAdditionalParticipantWithoutFieldCount() {
429 // Log in using webtestLogin() method
430 $this->webtestLogin();
432 // Use default payment processor
433 $processorName = 'Test Processor';
434 $this->webtestAddPaymentProcessor($processorName);
437 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
438 $financialType = 'Donation';
439 $this->_testAddSet($priceset, $financialType);
441 // create price fields
443 'Full Conference' => array(
445 'amount' => '525.00',
447 'is_required' => TRUE,
448 'financial_type_id' => 1,
450 'Meal Choice' => array(
454 'label' => 'Chicken',
455 'amount' => '525.00',
457 'financial_type_id' => 1,
460 'label' => 'Vegetarian',
461 'amount' => '200.00',
463 'financial_type_id' => 1,
467 'Pre-conference Meetup?' => array(
474 'financial_type_id' => 1,
480 'financial_type_id' => 1,
484 'Evening Sessions' => array(
485 'type' => 'CheckBox',
488 'label' => 'First Five',
489 'amount' => '100.00',
491 'financial_type_id' => 1,
494 'label' => 'Second Four',
497 'financial_type_id' => 1,
504 $this->_testAddPriceFields($fields);
506 // get price set url.
507 $pricesetLoc = $this->getLocation();
509 // get text field Id.
510 $this->waitForElementPresent("xpath=//div[@id='crm-main-content-wrapper']/div/a[1]");
511 $textFieldURL = $this->getAttribute("xpath=//div[@id='field_page']/table/tbody/tr[1]/td[9]/span[1]/a[2]@href");
512 $textFieldId = $this->urlArg('fid', $textFieldURL);
514 $this->open($pricesetLoc);
515 $this->waitForPageToLoad($this->getTimeoutMsec());
517 // get select field id
518 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/a");
519 $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[2]/span[2]");
520 $selectFieldLoc = $this->getLocation();
521 $selectFieldURL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[9]/span[1]/a[2]@href");
522 $selectFieldId = $this->urlArg('fid', $selectFieldURL);
524 // get select field ids
525 // get select field option1
526 $selectFieldOp1URL = $this->getAttribute("xpath=//div[@id='field_page']/table/tbody/tr[1]/td[7]/span[1]/a[1]@href");
527 $selectFieldOp1 = $this->urlArg('oid', $selectFieldOp1URL);
529 // get select field option2
530 $selectFieldOp2URL = $this->getAttribute("xpath=//div[@id='field_page']/table/tbody/tr[2]/td[7]/span[1]/a[1]@href");
531 $selectFieldOp2 = $this->urlArg('oid', $selectFieldOp2URL);
534 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
535 $paramsEvent = array(
536 'title' => $eventTitle,
538 'event_type_id' => 4,
539 'payment_processor' => $processorName,
540 'price_set' => $priceset,
541 'is_multiple_registrations' => TRUE,
544 $infoEvent = $this->_testAddEvent($paramsEvent);
546 // logout to register for event.
547 $this->webtestLogout();
550 // Register Participant 1
551 // visit event info page
552 $this->open($infoEvent);
553 $this->waitForPageToLoad($this->getTimeoutMsec());
555 // register for event
556 $this->click('link=Register Now');
557 $this->waitForElementPresent('_qf_Register_upload-bottom');
559 // select 3 participants ( including current )
560 $this->select('additional_participants', 'value=2');
562 // Check for Participant1
563 // exceed maximun count for text field, check for form rule
564 $this->type("xpath=//input[@id='price_{$textFieldId}']", '7');
566 $this->type('first_name', 'Mary');
567 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
568 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
569 $this->type('email-Primary', $email);
571 // fill billing related info
572 $this->_fillRegisterWithBillingInfo();
574 $this->assertStringsPresent(array('Sorry, currently only 6 seats are available for this option.'));
576 // fill correct value for text field
577 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
578 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
580 $this->click('_qf_Register_upload-bottom');
581 $this->waitForPageToLoad($this->getTimeoutMsec());
583 // Check for Participant2
584 // exceed maximun count for text field, check for form rule
585 $this->type("xpath=//input[@id='price_{$textFieldId}']", '6');
587 $this->type('first_name', 'Mary Add 2');
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 $this->click('_qf_Participant_1_next-Array');
593 $this->waitForPageToLoad($this->getTimeoutMsec());
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}']", '3');
599 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
601 $this->click('_qf_Participant_1_next-Array');
602 $this->waitForPageToLoad($this->getTimeoutMsec());
604 // Check for Participant3, check and skip
605 // exceed maximun count for text field, check for form rule
606 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
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_2_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}']", '1');
622 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
624 $this->click('_qf_Participant_2_next-Array');
625 $this->waitForPageToLoad($this->getTimeoutMsec());
627 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
629 // Skip participant3 and register
630 $this->click('_qf_Participant_2_next_skip-Array');
631 $this->waitForPageToLoad($this->getTimeoutMsec());
633 $this->_checkConfirmationAndRegister();
636 // Register Participant 1
637 // visit event info page
638 $this->open($infoEvent);
639 $this->waitForPageToLoad($this->getTimeoutMsec());
641 // register for event
642 $this->click('link=Register Now');
643 $this->waitForElementPresent('_qf_Register_upload-bottom');
645 // select 2 participants ( including current )
646 $this->select('additional_participants', 'value=1');
648 // Check for Participant1
649 // exceed maximun count for text field, check for form rule
650 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
652 $this->type('first_name', 'Mary');
653 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
654 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
655 $this->type('email-Primary', $email);
657 // fill billing related info
658 $this->_fillRegisterWithBillingInfo();
660 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
662 // fill correct value for text field
663 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
665 // check for select field
666 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
668 $this->click('_qf_Register_upload-bottom');
669 $this->waitForPageToLoad($this->getTimeoutMsec());
671 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
673 // fill available value for select
674 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
676 $this->click('_qf_Register_upload-bottom');
677 $this->waitForPageToLoad($this->getTimeoutMsec());
679 // Check for Participant2
680 // exceed maximun count for text field, check for form rule
681 $this->type("xpath=//input[@id='price_{$textFieldId}']", '2');
683 $this->type('first_name', 'Mary Add 1');
684 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
685 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
686 $this->type('email-Primary', $email);
688 $this->click('_qf_Participant_1_next-Array');
689 $this->waitForPageToLoad($this->getTimeoutMsec());
691 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
693 // fill correct value for text field
694 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
696 // check for select field
697 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
699 $this->click('_qf_Participant_1_next-Array');
700 $this->waitForPageToLoad($this->getTimeoutMsec());
702 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
704 // fill available value for select
705 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
707 $this->click('_qf_Participant_1_next-Array');
708 $this->waitForPageToLoad($this->getTimeoutMsec());
710 $this->_checkConfirmationAndRegister();
713 function testAdditionalParticipantWithFieldCount() {
714 // Log in using webtestLogin() method
715 $this->webtestLogin();
717 // Use default payment processor
718 $processorName = 'Test Processor';
719 $this->webtestAddPaymentProcessor($processorName);
722 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
723 $financialType = 'Donation';
724 $this->_testAddSet($priceset, $financialType);
726 // create price fields
728 'Full Conference' => array(
730 'amount' => '525.00',
733 'is_required' => TRUE,
734 'financial_type_id' => 1,
736 'Meal Choice' => array(
740 'label' => 'Chicken',
741 'amount' => '525.00',
744 'financial_type_id' => 1,
747 'label' => 'Vegetarian',
748 'amount' => '200.00',
751 'financial_type_id' => 1,
755 'Pre-conference Meetup?' => array(
763 'financial_type_id' => 1,
770 'financial_type_id' => 1,
774 'Evening Sessions' => array(
775 'type' => 'CheckBox',
778 'label' => 'First Five',
779 'amount' => '100.00',
782 'financial_type_id' => 1,
785 'label' => 'Second Four',
789 'financial_type_id' => 1,
796 $this->_testAddPriceFields($fields);
798 // get price set url.
799 $pricesetLoc = $this->getLocation();
801 // get text field Id.
802 $this->waitForElementPresent("xpath=//div[@id='crm-main-content-wrapper']/div/a[1]");
803 $textFieldIdURL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]@href");
804 $textFieldId = $this->urlArg('fid', $textFieldIdURL);
806 $this->open($pricesetLoc);
807 $this->waitForPageToLoad($this->getTimeoutMsec());
809 // get select field id
810 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/a");
811 $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[2]/span[2]");
812 $selectFieldLoc = $this->getLocation();
813 $selectFieldURL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[9]/span[1]/a[2]@href");
814 $selectFieldId = $this->urlArg('fid', $selectFieldURL);
816 // get select field ids
817 // get select field option1
818 $selectFieldOp1URL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]@href");
819 $selectFieldOp1 = $this->urlArg('oid', $selectFieldOp1URL);
821 // get select field option2
822 $selectFieldOp2URL = $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]@href");
823 $selectFieldOp2 = $this->urlArg('oid', $selectFieldOp2URL);
826 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
827 $paramsEvent = array(
828 'title' => $eventTitle,
830 'event_type_id' => 4,
831 'payment_processor' => $processorName,
832 'price_set' => $priceset,
833 'is_multiple_registrations' => TRUE,
836 $infoEvent = $this->_testAddEvent($paramsEvent);
838 // logout to register for event.
839 $this->webtestLogout();
842 // Register Participant 1
843 // visit event info page
844 $this->open($infoEvent);
845 $this->waitForPageToLoad($this->getTimeoutMsec());
847 // register for event
848 $this->click('link=Register Now');
849 $this->waitForElementPresent('_qf_Register_upload-bottom');
851 // select 3 participants ( including current )
852 $this->select('additional_participants', 'value=2');
854 // Check for Participant1
855 // exceed maximun count for text field, check for form rule
856 $this->type("xpath=//input[@id='price_{$textFieldId}']", '7');
858 $this->type('first_name', 'Mary');
859 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
860 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
861 $this->type('email-Primary', $email);
863 // fill billing related info
864 $this->_fillRegisterWithBillingInfo();
866 $this->assertStringsPresent(array('Sorry, currently only 12 seats are available for this option.'));
868 // fill correct value for text field
869 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
870 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
872 $this->click('_qf_Register_upload-bottom');
873 $this->waitForPageToLoad($this->getTimeoutMsec());
875 // Check for Participant2
876 // exceed maximun count for text field, check for form rule
877 $this->type("xpath=//input[@id='price_{$textFieldId}']", '6');
879 $this->type('first_name', 'Mary Add 1');
880 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
881 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
882 $this->type('email-Primary', $email);
884 $this->click('_qf_Participant_1_next-Array');
885 $this->waitForPageToLoad($this->getTimeoutMsec());
887 $this->assertStringsPresent(array('Sorry, currently only 12 seats are available for this option.'));
889 // fill correct value for text field
890 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
891 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
893 $this->click('_qf_Participant_1_next-Array');
894 $this->waitForPageToLoad($this->getTimeoutMsec());
896 // Check for Participant3, check and skip
897 // exceed maximun count for text field, check for form rule
898 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
900 $this->type('first_name', 'Mary Add 2');
901 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
902 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
903 $this->type('email-Primary', $email);
905 $this->click('_qf_Participant_2_next-Array');
906 $this->waitForPageToLoad($this->getTimeoutMsec());
908 $this->assertStringsPresent(array('Sorry, currently only 12 seats are available for this option.'));
910 // fill correct value for text field
911 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
914 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
916 $this->click('_qf_Participant_2_next-Array');
917 $this->waitForPageToLoad($this->getTimeoutMsec());
919 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
921 // Skip participant3 and register
922 $this->click('_qf_Participant_2_next_skip-Array');
923 $this->waitForPageToLoad($this->getTimeoutMsec());
925 $this->_checkConfirmationAndRegister();
928 // Register Participant 1
929 // visit event info page
930 $this->open($infoEvent);
931 $this->waitForPageToLoad($this->getTimeoutMsec());
933 // register for event
934 $this->click('link=Register Now');
935 $this->waitForElementPresent('_qf_Register_upload-bottom');
937 // select 2 participants ( including current )
938 $this->select('additional_participants', 'value=1');
940 // Check for Participant1
941 // exceed maximun count for text field, check for form rule
942 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
944 $this->type('first_name', 'Mary');
945 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
946 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
947 $this->type('email-Primary', $email);
949 // fill billing related info
950 $this->_fillRegisterWithBillingInfo();
952 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
954 // fill correct value for text field
955 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
957 // check for select field
958 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
960 $this->click('_qf_Register_upload-bottom');
961 $this->waitForPageToLoad($this->getTimeoutMsec());
963 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
965 // fill available value for select
966 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
968 $this->click('_qf_Register_upload-bottom');
969 $this->waitForPageToLoad($this->getTimeoutMsec());
971 // Check for Participant2
972 // exceed maximun count for text field, check for form rule
973 $this->type("xpath=//input[@id='price_{$textFieldId}']", '2');
975 $this->type('first_name', 'Mary Add 1');
976 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
977 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
978 $this->type('email-Primary', $email);
980 $this->click('_qf_Participant_1_next-Array');
981 $this->waitForPageToLoad($this->getTimeoutMsec());
983 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
985 // fill correct value for text field
986 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
988 // check for select field
989 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
991 $this->click('_qf_Participant_1_next-Array');
992 $this->waitForPageToLoad($this->getTimeoutMsec());
994 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
996 // fill available value for select
997 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
999 $this->click('_qf_Participant_1_next-Array');
1000 $this->waitForPageToLoad($this->getTimeoutMsec());
1002 $this->_checkConfirmationAndRegister();
1007 * @param null $financialType
1009 function _testAddSet($setTitle, $financialType = NULL) {
1010 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
1012 // Enter Priceset fields (Title, Used For ...)
1013 $this->type('title', $setTitle);
1014 $this->check('extends_1');
1016 if ($financialType) {
1017 $this->select("css=select.crm-form-select", "label={$financialType}");
1020 $this->click("xpath=//form[@id='Set']/div[3]/table/tbody/tr[4]/td[2]/select");
1021 $this->type('help_pre', 'This is test priceset.');
1023 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
1024 $this->clickLink('_qf_Set_next-bottom');
1030 function _testAddPriceFields($fields) {
1031 $fieldCount = count($fields);
1033 $this->waitForElementPresent('label');
1034 foreach ($fields as $label => $field) {
1035 $this->waitForElementPresent('label');
1036 $this->type('label', $label);
1037 $this->select('html_type', "value={$field['type']}");
1039 if ($field['type'] == 'Text') {
1040 $this->type('price', $field['amount']);
1042 if (isset($field['count'])) {
1043 $this->waitForElementPresent('count');
1044 $this->type('count', $field['count']);
1047 if (isset($field['count'])) {
1048 $this->waitForElementPresent('count');
1049 $this->type('count', $field['count']);
1052 if (isset($field['max_count'])) {
1053 $this->waitForElementPresent('max_value');
1054 $this->type('max_value', $field['max_count']);
1057 if (isset($field['financial_type_id'])) {
1058 $this->waitForElementPresent('financial_type_id');
1059 $this->select('financial_type_id', "value={$field['financial_type_id']}");
1064 $this->_testAddMultipleChoiceOptions($field['options'], $field['type']);
1067 if (isset($field['is_required']) && $field['is_required']) {
1068 $this->check('is_required');
1071 if ($count < $fieldCount) {
1072 $this->click('_qf_Field_next_new-bottom');
1075 $this->click('_qf_Field_next-bottom');
1077 $this->waitForAjaxContent();
1078 $this->waitForText('crm-notification-container', "Price Field '$label' has been saved.");
1088 function _testAddMultipleChoiceOptions($options, $fieldType) {
1089 foreach ($options as $oIndex => $oValue) {
1090 $this->type("option_label_{$oIndex}", $oValue['label']);
1091 $this->type("option_amount_{$oIndex}", $oValue['amount']);
1093 if (isset($oValue['count'])) {
1094 $this->waitForElementPresent("option_count_{$oIndex}");
1095 $this->type("option_count_{$oIndex}", $oValue['count']);
1098 if (isset($oValue['max_count'])) {
1099 $this->waitForElementPresent("option_max_value_{$oIndex}");
1100 $this->type("option_max_value_{$oIndex}", $oValue['max_count']);
1103 if (!empty($oValue['financial_type_id'])) {
1104 $this->select("option_financial_type_id_{$oIndex}", "value={$oValue['financial_type_id']}");
1107 $this->click('link=another choice');
1110 // select first element as default
1111 if ($fieldType == 'CheckBox') {
1112 $this->click('default_checkbox_option[1]');
1115 $this->click('CIVICRM_QFID_1_2');
1124 function _testAddEvent($params) {
1125 $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom');
1127 $this->select('event_type_id', "value={$params['event_type_id']}");
1129 // Attendee role s/b selected now.
1130 $this->select('default_role_id', 'value=1');
1132 // Enter Event Title, Summary and Description
1133 $this->type('title', $params['title']);
1134 $this->type('summary', 'This is a great conference. Sign up now!');
1135 $this->fillRichTextField('description', 'Here is a description for this event.', 'CKEditor');
1137 // Choose Start and End dates.
1138 // Using helper webtestFillDate function.
1139 $this->webtestFillDateTime('start_date', '+1 week');
1140 $this->webtestFillDateTime('end_date', '+1 week 1 day 8 hours ');
1142 $this->type('max_participants', '50');
1143 $this->click('is_map');
1144 $this->click('_qf_EventInfo_upload-bottom');
1146 // Wait for Location tab form to load
1147 $this->waitForPageToLoad($this->getTimeoutMsec());
1150 $this->click('link=Fees');
1151 $this->waitForElementPresent('_qf_Fee_upload-bottom');
1152 $this->click('xpath=//form[@id="Fee"]/div[2]/table/tbody/tr[2]/td[2]/label[contains(text(), "Yes")]');
1153 $processorName = $params['payment_processor'];
1154 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='$processorName']");
1155 $this->select('financial_type_id', 'value=4');
1157 if (array_key_exists('price_set', $params)) {
1158 $this->select('price_set_id', 'label=' . $params['price_set']);
1160 if (array_key_exists('fee_level', $params)) {
1162 foreach ($params['fee_level'] as $label => $amount) {
1163 $this->type("label_{$counter}", $label);
1164 $this->type("value_{$counter}", $amount);
1169 $this->clickLink('_qf_Fee_upload-bottom', 'link=Online Registration', FALSE);
1171 // Go to Online Registration tab
1172 $this->click('link=Online Registration');
1173 $this->waitForElementPresent('_qf_Registration_upload-bottom');
1175 $this->check('is_online_registration');
1176 $this->assertChecked('is_online_registration');
1178 if (isset($params['is_multiple_registrations']) && $params['is_multiple_registrations']) {
1179 $this->click('is_multiple_registrations');
1182 $this->click('intro_text-plain');
1183 $this->fillRichTextField('intro_text', 'Fill in all the fields below and click Continue.');
1185 // enable confirmation email
1186 $this->click('CIVICRM_QFID_1_is_email_confirm');
1187 $this->type('confirm_from_name', 'Jane Doe');
1188 $this->type('confirm_from_email', 'jane.doe@example.org');
1190 $this->click('_qf_Registration_upload-bottom');
1191 $this->waitForTextPresent("'Fees' information has been saved.");
1193 // verify event input on info page
1194 // start at Manage Events listing
1195 $this->openCiviPage('event/manage', 'reset=1');
1196 $this->click('link=' . $params['title']);
1198 $this->waitForPageToLoad($this->getTimeoutMsec());
1199 return $this->getLocation();
1202 function _fillRegisterWithBillingInfo() {
1203 $this->waitForElementPresent('credit_card_type');
1204 $this->select('credit_card_type', 'value=Visa');
1205 $this->type('credit_card_number', '4111111111111111');
1206 $this->type('cvv2', '000');
1207 $this->select('credit_card_exp_date[M]', 'value=1');
1208 $this->select('credit_card_exp_date[Y]', 'value=2020');
1209 $this->type('billing_first_name', 'Jane_' . substr(sha1(rand()), 0, 5));
1210 $this->type('billing_last_name', 'San_' . substr(sha1(rand()), 0, 5));
1211 $this->type('billing_street_address-5', '15 Main St.');
1212 $this->type(' billing_city-5', 'San Jose');
1213 $this->select('billing_country_id-5', 'value=1228');
1214 $this->select('billing_state_province_id-5', 'value=1004');
1215 $this->type('billing_postal_code-5', '94129');
1217 $this->click('_qf_Register_upload-bottom');
1218 $this->waitForPageToLoad($this->getTimeoutMsec());
1221 function _checkConfirmationAndRegister() {
1222 $confirmStrings = array('Event Fee(s)', 'Billing Name and Address', 'Credit Card Information');
1223 $this->assertStringsPresent($confirmStrings);
1224 $this->click('_qf_Confirm_next-bottom');
1225 $this->waitForPageToLoad($this->getTimeoutMsec());
1226 $thankStrings = array('Thank You for Registering', 'Event Total', 'Transaction Date');
1227 $this->assertStringsPresent($thankStrings);