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 $textFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]@href"));
117 $textFieldId = explode('&', $textFieldId[0]);
118 $textFieldId = explode('=', $textFieldId[3]);
119 $textFieldId = $textFieldId[1];
121 $this->open($pricesetLoc);
122 $this->waitForPageToLoad($this->getTimeoutMsec());
124 // get select field id
125 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/a");
126 $this->waitForPageToLoad($this->getTimeoutMsec());
127 $selectFieldLoc = $this->getLocation();
128 $selectFieldId = $this->urlArg('fid');
130 // get select field ids
131 // get select field option1
132 $selectFieldOp1 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]@href"));
133 $selectFieldOp1 = explode('&', $selectFieldOp1[0]);
134 $selectFieldOp1 = explode('=', $selectFieldOp1[2]);
135 $selectFieldOp1 = $selectFieldOp1[1];
137 $this->open($selectFieldLoc);
138 $this->waitForPageToLoad($this->getTimeoutMsec());
140 // get select field option2
141 $selectFieldOp2 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]@href"));
142 $selectFieldOp2 = explode('&', $selectFieldOp2[0]);
143 $selectFieldOp2 = explode('=', $selectFieldOp2[2]);
144 $selectFieldOp2 = $selectFieldOp2[1];
147 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
148 $paramsEvent = array(
149 'title' => $eventTitle,
151 'event_type_id' => 4,
152 'payment_processor' => $processorName,
153 'price_set' => $priceset,
156 $infoEvent = $this->_testAddEvent($paramsEvent);
158 // logout to register for event.
159 $this->webtestLogout();
161 // Register Participant 1
162 // visit event info page
163 $this->open($infoEvent);
164 $this->waitForPageToLoad($this->getTimeoutMsec());
166 // register for event
167 $this->click('link=Register Now');
168 $this->waitForElementPresent('_qf_Register_upload-bottom');
170 // exceed maximun count for text field, check for form rule
171 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
173 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
175 $this->type('first_name', 'Mary');
176 $this->type('last_name', 'Jones'. substr(sha1(rand()), 0, 5));
177 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
178 $this->type('email-Primary', $email);
180 // fill billing related info
181 $this->_fillRegisterWithBillingInfo();
183 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
185 // fill correct value for text field
186 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
188 $this->click('_qf_Register_upload-bottom');
189 $this->waitForPageToLoad($this->getTimeoutMsec());
191 $this->_checkConfirmationAndRegister();
193 // Register Participant 2
194 // visit event info page
195 $this->open($infoEvent);
196 $this->waitForPageToLoad($this->getTimeoutMsec());
198 $this->click('link=Register Now');
199 $this->waitForElementPresent('_qf_Register_upload-bottom');
201 // exceed maximun count for text field, check for form rule
202 $this->type("xpath=//input[@id='price_{$textFieldId}']", '2');
203 $this->type('first_name', 'Mary');
204 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
205 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
206 $this->type('email-Primary', $email);
208 // fill billing related info and register
209 $this->_fillRegisterWithBillingInfo();
211 $this->assertStringsPresent(array('Sorry, currently only a single seat is available for this option.'));
213 // fill correct value for test field
214 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
216 // select sold option for select field, check for form rule
217 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
218 $this->click('_qf_Register_upload-bottom');
219 $this->waitForPageToLoad($this->getTimeoutMsec());
221 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
223 // fill correct available option for select field
224 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
226 $this->click('_qf_Register_upload-bottom');
227 $this->waitForPageToLoad($this->getTimeoutMsec());
229 $this->_checkConfirmationAndRegister();
232 function testWithFieldCount() {
233 // Log in using webtestLogin() method
234 $this->webtestLogin();
236 // We need a payment processor
237 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
238 $this->webtestAddPaymentProcessor($processorName);
241 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
242 $financialType = 'Donation';
243 $this->_testAddSet($priceset, $financialType);
245 // create price fields
247 'Full Conference' => array(
249 'amount' => '525.00',
252 'is_required' => TRUE,
253 'financial_type_id' => 1,
255 'Meal Choice' => array(
259 'label' => 'Chicken',
260 'amount' => '525.00',
263 'financial_type_id' => 1,
266 'label' => 'Vegetarian',
267 'amount' => '200.00',
270 'financial_type_id' => 1,
274 'Pre-conference Meetup?' => array(
282 'financial_type_id' => 1,
289 'financial_type_id' => 1,
293 'Evening Sessions' => array(
294 'type' => 'CheckBox',
297 'label' => 'First Five',
298 'amount' => '100.00',
301 'financial_type_id' => 1,
304 'label' => 'Second Four',
308 'financial_type_id' => 1,
315 $this->_testAddPriceFields($fields);
317 // get price set url.
318 $pricesetLoc = $this->getLocation();
320 // get text field Id.
321 $textFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]@href"));
322 $textFieldId = explode('&', $textFieldId[0]);
323 $textFieldId = explode('=', $textFieldId[3]);
324 $textFieldId = $textFieldId[1];
326 $this->open($pricesetLoc);
327 $this->waitForPageToLoad($this->getTimeoutMsec());
329 // get select field id
330 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/a");
331 $this->waitForPageToLoad($this->getTimeoutMsec());
332 $selectFieldLoc = $this->getLocation();
333 $selectFieldId = $this->urlArg('fid');
335 // get select field ids
336 // get select field option1
337 $selectFieldOp1 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]@href"));
338 $selectFieldOp1 = explode('&', $selectFieldOp1[0]);
339 $selectFieldOp1 = explode('=', $selectFieldOp1[2]);
340 $selectFieldOp1 = $selectFieldOp1[1];
342 $this->open($selectFieldLoc);
343 $this->waitForPageToLoad($this->getTimeoutMsec());
345 // get select field option2
346 $selectFieldOp2 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]@href"));
347 $selectFieldOp2 = explode('&', $selectFieldOp2[0]);
348 $selectFieldOp2 = explode('=', $selectFieldOp2[2]);
349 $selectFieldOp2 = $selectFieldOp2[1];
352 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
353 $paramsEvent = array(
354 'title' => $eventTitle,
356 'event_type_id' => 4,
357 'payment_processor' => $processorName,
358 'price_set' => $priceset,
361 $infoEvent = $this->_testAddEvent($paramsEvent);
363 // logout to register for event.
364 $this->webtestLogout();
366 // Register Participant 1
367 // visit event info page
368 $this->open($infoEvent);
369 $this->waitForPageToLoad($this->getTimeoutMsec());
371 // register for event
372 $this->click('link=Register Now');
373 $this->waitForElementPresent('_qf_Register_upload-bottom');
375 // check for form rule
376 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
378 $this->type('first_name', 'Mary');
379 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
380 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
381 $this->type('email-Primary', $email);
383 // fill billing related info
384 $this->_fillRegisterWithBillingInfo();
386 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
388 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
390 // fill correct value and register
391 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
393 $this->click('_qf_Register_upload-bottom');
394 $this->waitForPageToLoad($this->getTimeoutMsec());
396 $this->_checkConfirmationAndRegister();
398 // Register Participant 2
399 // visit event info page
400 $this->open($infoEvent);
401 $this->waitForPageToLoad($this->getTimeoutMsec());
403 $this->click('link=Register Now');
404 $this->waitForElementPresent('_qf_Register_upload-bottom');
406 // check for form rule
407 $this->type("xpath=//input[@id='price_{$textFieldId}']", '2');
408 $this->type('first_name', 'Mary');
409 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
410 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
411 $this->type('email-Primary', $email);
413 // fill billing related info and register
414 $this->_fillRegisterWithBillingInfo();
416 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
418 // fill correct value and register
419 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
421 // check for sold option for select field
422 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
424 $this->click('_qf_Register_upload-bottom');
425 $this->waitForPageToLoad($this->getTimeoutMsec());
427 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
429 // check for sold option for select field
430 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
432 $this->click('_qf_Register_upload-bottom');
433 $this->waitForPageToLoad($this->getTimeoutMsec());
435 $this->_checkConfirmationAndRegister();
438 function testAdditionalParticipantWithoutFieldCount() {
439 // Log in using webtestLogin() method
440 $this->webtestLogin();
442 // We need a payment processor
443 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
444 $this->webtestAddPaymentProcessor($processorName);
447 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
448 $financialType = 'Donation';
449 $this->_testAddSet($priceset, $financialType);
451 // create price fields
453 'Full Conference' => array(
455 'amount' => '525.00',
457 'is_required' => TRUE,
458 'financial_type_id' => 1,
460 'Meal Choice' => array(
464 'label' => 'Chicken',
465 'amount' => '525.00',
467 'financial_type_id' => 1,
470 'label' => 'Vegetarian',
471 'amount' => '200.00',
473 'financial_type_id' => 1,
477 'Pre-conference Meetup?' => array(
484 'financial_type_id' => 1,
490 'financial_type_id' => 1,
494 'Evening Sessions' => array(
495 'type' => 'CheckBox',
498 'label' => 'First Five',
499 'amount' => '100.00',
501 'financial_type_id' => 1,
504 'label' => 'Second Four',
507 'financial_type_id' => 1,
514 $this->_testAddPriceFields($fields);
516 // get price set url.
517 $pricesetLoc = $this->getLocation();
519 // get text field Id.
520 $textFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]@href"));
521 $textFieldId = explode('&', $textFieldId[0]);
522 $textFieldId = explode('=', $textFieldId[3]);
523 $textFieldId = $textFieldId[1];
525 $this->open($pricesetLoc);
526 $this->waitForPageToLoad($this->getTimeoutMsec());
528 // get select field id
529 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/a");
530 $this->waitForPageToLoad($this->getTimeoutMsec());
531 $selectFieldLoc = $this->getLocation();
532 $selectFieldId = $this->urlArg('fid');
534 // get select field ids
535 // get select field option1
536 $selectFieldOp1 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]@href"));
537 $selectFieldOp1 = explode('&', $selectFieldOp1[0]);
538 $selectFieldOp1 = explode('=', $selectFieldOp1[2]);
539 $selectFieldOp1 = $selectFieldOp1[1];
541 $this->open($selectFieldLoc);
542 $this->waitForPageToLoad($this->getTimeoutMsec());
544 // get select field option2
545 $selectFieldOp2 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]@href"));
546 $selectFieldOp2 = explode('&', $selectFieldOp2[0]);
547 $selectFieldOp2 = explode('=', $selectFieldOp2[2]);
548 $selectFieldOp2 = $selectFieldOp2[1];
551 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
552 $paramsEvent = array(
553 'title' => $eventTitle,
555 'event_type_id' => 4,
556 'payment_processor' => $processorName,
557 'price_set' => $priceset,
558 'is_multiple_registrations' => TRUE,
561 $infoEvent = $this->_testAddEvent($paramsEvent);
563 // logout to register for event.
564 $this->webtestLogout();
567 // Register Participant 1
568 // visit event info page
569 $this->open($infoEvent);
570 $this->waitForPageToLoad($this->getTimeoutMsec());
572 // register for event
573 $this->click('link=Register Now');
574 $this->waitForElementPresent('_qf_Register_upload-bottom');
576 // select 3 participants ( including current )
577 $this->select('additional_participants', 'value=2');
579 // Check for Participant1
580 // exceed maximun count for text field, check for form rule
581 $this->type("xpath=//input[@id='price_{$textFieldId}']", '7');
583 $this->type('first_name', 'Mary');
584 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
585 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
586 $this->type('email-Primary', $email);
588 // fill billing related info
589 $this->_fillRegisterWithBillingInfo();
591 $this->assertStringsPresent(array('Sorry, currently only 6 seats are available for this option.'));
593 // fill correct value for text field
594 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
595 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
597 $this->click('_qf_Register_upload-bottom');
598 $this->waitForPageToLoad($this->getTimeoutMsec());
600 // Check for Participant2
601 // exceed maximun count for text field, check for form rule
602 $this->type("xpath=//input[@id='price_{$textFieldId}']", '6');
604 $this->type('first_name', 'Mary Add 2');
605 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
606 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
607 $this->type('email-Primary', $email);
609 $this->click('_qf_Participant_1_next-Array');
610 $this->waitForPageToLoad($this->getTimeoutMsec());
612 $this->assertStringsPresent(array('Sorry, currently only 6 seats are available for this option.'));
614 // fill correct value for text field
615 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
616 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
618 $this->click('_qf_Participant_1_next-Array');
619 $this->waitForPageToLoad($this->getTimeoutMsec());
621 // Check for Participant3, check and skip
622 // exceed maximun count for text field, check for form rule
623 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
625 $this->type('first_name', 'Mary Add 2');
626 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
627 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
628 $this->type('email-Primary', $email);
630 $this->click('_qf_Participant_2_next-Array');
631 $this->waitForPageToLoad($this->getTimeoutMsec());
633 $this->assertStringsPresent(array('Sorry, currently only 6 seats are available for this option.'));
635 // fill correct value for text field
636 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
639 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
641 $this->click('_qf_Participant_2_next-Array');
642 $this->waitForPageToLoad($this->getTimeoutMsec());
644 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
646 // Skip participant3 and register
647 $this->click('_qf_Participant_2_next_skip-Array');
648 $this->waitForPageToLoad($this->getTimeoutMsec());
650 $this->_checkConfirmationAndRegister();
653 // Register Participant 1
654 // visit event info page
655 $this->open($infoEvent);
656 $this->waitForPageToLoad($this->getTimeoutMsec());
658 // register for event
659 $this->click('link=Register Now');
660 $this->waitForElementPresent('_qf_Register_upload-bottom');
662 // select 2 participants ( including current )
663 $this->select('additional_participants', 'value=1');
665 // Check for Participant1
666 // exceed maximun count for text field, check for form rule
667 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
669 $this->type('first_name', 'Mary');
670 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
671 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
672 $this->type('email-Primary', $email);
674 // fill billing related info
675 $this->_fillRegisterWithBillingInfo();
677 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
679 // fill correct value for text field
680 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
682 // check for select field
683 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
685 $this->click('_qf_Register_upload-bottom');
686 $this->waitForPageToLoad($this->getTimeoutMsec());
688 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
690 // fill available value for select
691 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
693 $this->click('_qf_Register_upload-bottom');
694 $this->waitForPageToLoad($this->getTimeoutMsec());
696 // Check for Participant2
697 // exceed maximun count for text field, check for form rule
698 $this->type("xpath=//input[@id='price_{$textFieldId}']", '2');
700 $this->type('first_name', 'Mary Add 1');
701 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
702 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
703 $this->type('email-Primary', $email);
705 $this->click('_qf_Participant_1_next-Array');
706 $this->waitForPageToLoad($this->getTimeoutMsec());
708 $this->assertStringsPresent(array('Sorry, currently only 2 seats are available for this option.'));
710 // fill correct value for text field
711 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
713 // check for select field
714 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
716 $this->click('_qf_Participant_1_next-Array');
717 $this->waitForPageToLoad($this->getTimeoutMsec());
719 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
721 // fill available value for select
722 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
724 $this->click('_qf_Participant_1_next-Array');
725 $this->waitForPageToLoad($this->getTimeoutMsec());
727 $this->_checkConfirmationAndRegister();
730 function testAdditionalParticipantWithFieldCount() {
731 // Log in using webtestLogin() method
732 $this->webtestLogin();
734 // We need a payment processor
735 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
736 $this->webtestAddPaymentProcessor($processorName);
739 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
740 $financialType = 'Donation';
741 $this->_testAddSet($priceset, $financialType);
743 // create price fields
745 'Full Conference' => array(
747 'amount' => '525.00',
750 'is_required' => TRUE,
751 'financial_type_id' => 1,
753 'Meal Choice' => array(
757 'label' => 'Chicken',
758 'amount' => '525.00',
761 'financial_type_id' => 1,
764 'label' => 'Vegetarian',
765 'amount' => '200.00',
768 'financial_type_id' => 1,
772 'Pre-conference Meetup?' => array(
780 'financial_type_id' => 1,
787 'financial_type_id' => 1,
791 'Evening Sessions' => array(
792 'type' => 'CheckBox',
795 'label' => 'First Five',
796 'amount' => '100.00',
799 'financial_type_id' => 1,
802 'label' => 'Second Four',
806 'financial_type_id' => 1,
813 $this->_testAddPriceFields($fields);
815 // get price set url.
816 $pricesetLoc = $this->getLocation();
818 // get text field Id.
819 $textFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[9]/span[1]/a[2]@href"));
820 $textFieldId = explode('&', $textFieldId[0]);
821 $textFieldId = explode('=', $textFieldId[3]);
822 $textFieldId = $textFieldId[1];
824 $this->open($pricesetLoc);
825 $this->waitForPageToLoad($this->getTimeoutMsec());
827 // get select field id
828 $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/a");
829 $this->waitForPageToLoad($this->getTimeoutMsec());
830 $selectFieldLoc = $this->getLocation();
831 $selectFieldId = $this->urlArg('fid');
833 // get select field ids
834 // get select field option1
835 $selectFieldOp1 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[7]/span[1]/a[1]@href"));
836 $selectFieldOp1 = explode('&', $selectFieldOp1[0]);
837 $selectFieldOp1 = explode('=', $selectFieldOp1[2]);
838 $selectFieldOp1 = $selectFieldOp1[1];
840 $this->open($selectFieldLoc);
841 $this->waitForPageToLoad($this->getTimeoutMsec());
843 // get select field option2
844 $selectFieldOp2 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[7]/span[1]/a[1]@href"));
845 $selectFieldOp2 = explode('&', $selectFieldOp2[0]);
846 $selectFieldOp2 = explode('=', $selectFieldOp2[2]);
847 $selectFieldOp2 = $selectFieldOp2[1];
850 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
851 $paramsEvent = array(
852 'title' => $eventTitle,
854 'event_type_id' => 4,
855 'payment_processor' => $processorName,
856 'price_set' => $priceset,
857 'is_multiple_registrations' => TRUE,
860 $infoEvent = $this->_testAddEvent($paramsEvent);
862 // logout to register for event.
863 $this->webtestLogout();
866 // Register Participant 1
867 // visit event info page
868 $this->open($infoEvent);
869 $this->waitForPageToLoad($this->getTimeoutMsec());
871 // register for event
872 $this->click('link=Register Now');
873 $this->waitForElementPresent('_qf_Register_upload-bottom');
875 // select 3 participants ( including current )
876 $this->select('additional_participants', 'value=2');
878 // Check for Participant1
879 // exceed maximun count for text field, check for form rule
880 $this->type("xpath=//input[@id='price_{$textFieldId}']", '7');
882 $this->type('first_name', 'Mary');
883 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
884 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
885 $this->type('email-Primary', $email);
887 // fill billing related info
888 $this->_fillRegisterWithBillingInfo();
890 $this->assertStringsPresent(array('Sorry, currently only 12 seats are available for this option.'));
892 // fill correct value for text field
893 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
894 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
896 $this->click('_qf_Register_upload-bottom');
897 $this->waitForPageToLoad($this->getTimeoutMsec());
899 // Check for Participant2
900 // exceed maximun count for text field, check for form rule
901 $this->type("xpath=//input[@id='price_{$textFieldId}']", '6');
903 $this->type('first_name', 'Mary Add 1');
904 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
905 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
906 $this->type('email-Primary', $email);
908 $this->click('_qf_Participant_1_next-Array');
909 $this->waitForPageToLoad($this->getTimeoutMsec());
911 $this->assertStringsPresent(array('Sorry, currently only 12 seats are available for this option.'));
913 // fill correct value for text field
914 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
915 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
917 $this->click('_qf_Participant_1_next-Array');
918 $this->waitForPageToLoad($this->getTimeoutMsec());
920 // Check for Participant3, check and skip
921 // exceed maximun count for text field, check for form rule
922 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
924 $this->type('first_name', 'Mary Add 2');
925 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
926 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
927 $this->type('email-Primary', $email);
929 $this->click('_qf_Participant_2_next-Array');
930 $this->waitForPageToLoad($this->getTimeoutMsec());
932 $this->assertStringsPresent(array('Sorry, currently only 12 seats are available for this option.'));
934 // fill correct value for text field
935 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
938 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
940 $this->click('_qf_Participant_2_next-Array');
941 $this->waitForPageToLoad($this->getTimeoutMsec());
943 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
945 // Skip participant3 and register
946 $this->click('_qf_Participant_2_next_skip-Array');
947 $this->waitForPageToLoad($this->getTimeoutMsec());
949 $this->_checkConfirmationAndRegister();
952 // Register Participant 1
953 // visit event info page
954 $this->open($infoEvent);
955 $this->waitForPageToLoad($this->getTimeoutMsec());
957 // register for event
958 $this->click('link=Register Now');
959 $this->waitForElementPresent('_qf_Register_upload-bottom');
961 // select 2 participants ( including current )
962 $this->select('additional_participants', 'value=1');
964 // Check for Participant1
965 // exceed maximun count for text field, check for form rule
966 $this->type("xpath=//input[@id='price_{$textFieldId}']", '3');
968 $this->type('first_name', 'Mary');
969 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
970 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
971 $this->type('email-Primary', $email);
973 // fill billing related info
974 $this->_fillRegisterWithBillingInfo();
976 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
978 // fill correct value for text field
979 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
981 // check for select field
982 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
984 $this->click('_qf_Register_upload-bottom');
985 $this->waitForPageToLoad($this->getTimeoutMsec());
987 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
989 // fill available value for select
990 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
992 $this->click('_qf_Register_upload-bottom');
993 $this->waitForPageToLoad($this->getTimeoutMsec());
995 // Check for Participant2
996 // exceed maximun count for text field, check for form rule
997 $this->type("xpath=//input[@id='price_{$textFieldId}']", '2');
999 $this->type('first_name', 'Mary Add 1');
1000 $this->type('last_name', 'Jane'. substr(sha1(rand()), 0, 5));
1001 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
1002 $this->type('email-Primary', $email);
1004 $this->click('_qf_Participant_1_next-Array');
1005 $this->waitForPageToLoad($this->getTimeoutMsec());
1007 $this->assertStringsPresent(array('Sorry, currently only 4 seats are available for this option.'));
1009 // fill correct value for text field
1010 $this->type("xpath=//input[@id='price_{$textFieldId}']", '1');
1012 // check for select field
1013 $this->select("price_{$selectFieldId}", "value={$selectFieldOp2}");
1015 $this->click('_qf_Participant_1_next-Array');
1016 $this->waitForPageToLoad($this->getTimeoutMsec());
1018 $this->assertStringsPresent(array('Sorry, this option is currently sold out.'));
1020 // fill available value for select
1021 $this->select("price_{$selectFieldId}", "value={$selectFieldOp1}");
1023 $this->click('_qf_Participant_1_next-Array');
1024 $this->waitForPageToLoad($this->getTimeoutMsec());
1026 $this->_checkConfirmationAndRegister();
1029 function _testAddSet($setTitle, $financialType = NULL) {
1030 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
1032 // Enter Priceset fields (Title, Used For ...)
1033 $this->type('title', $setTitle);
1034 $this->check('extends_1');
1036 if ($financialType) {
1037 $this->select("css=select.crm-form-select", "label={$financialType}");
1040 $this->click("xpath=//form[@id='Set']/div[3]/table/tbody/tr[4]/td[2]/select");
1041 $this->type('help_pre', 'This is test priceset.');
1043 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
1044 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom');
1047 function _testAddPriceFields($fields) {
1048 $fieldCount = count($fields);
1050 foreach ($fields as $label => $field) {
1051 $this->type('label', $label);
1052 $this->select('html_type', "value={$field['type']}");
1054 if ($field['type'] == 'Text') {
1055 $this->type('price', $field['amount']);
1057 if (isset($field['count'])) {
1058 $this->waitForElementPresent('count');
1059 $this->type('count', $field['count']);
1062 if (isset($field['count'])) {
1063 $this->waitForElementPresent('count');
1064 $this->type('count', $field['count']);
1067 if (isset($field['max_count'])) {
1068 $this->waitForElementPresent('max_value');
1069 $this->type('max_value', $field['max_count']);
1072 if (isset($field['financial_type_id'])) {
1073 $this->waitForElementPresent('financial_type_id');
1074 $this->select('financial_type_id', "value={$field['financial_type_id']}");
1079 $this->_testAddMultipleChoiceOptions($field['options'], $field['type']);
1082 if (isset($field['is_required']) && $field['is_required']) {
1083 $this->check('is_required');
1086 if ($count < $fieldCount) {
1087 $this->click('_qf_Field_next_new-bottom');
1090 $this->click('_qf_Field_next-bottom');
1092 $this->waitForPageToLoad($this->getTimeoutMsec());
1098 function _testAddMultipleChoiceOptions($options, $fieldType) {
1099 foreach ($options as $oIndex => $oValue) {
1100 $this->type("option_label_{$oIndex}", $oValue['label']);
1101 $this->type("option_amount_{$oIndex}", $oValue['amount']);
1103 if (isset($oValue['count'])) {
1104 $this->waitForElementPresent("option_count_{$oIndex}");
1105 $this->type("option_count_{$oIndex}", $oValue['count']);
1108 if (isset($oValue['max_count'])) {
1109 $this->waitForElementPresent("option_max_value_{$oIndex}");
1110 $this->type("option_max_value_{$oIndex}", $oValue['max_count']);
1113 if (!empty($oValue['financial_type_id'])) {
1114 $this->select("option_financial_type_id_{$oIndex}", "value={$oValue['financial_type_id']}");
1117 $this->click('link=another choice');
1120 // select first element as default
1121 if ($fieldType == 'CheckBox') {
1122 $this->click('default_checkbox_option[1]');
1125 $this->click('CIVICRM_QFID_1_2');
1129 function _testAddEvent($params) {
1130 $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom');
1132 $this->select('event_type_id', "value={$params['event_type_id']}");
1134 // Attendee role s/b selected now.
1135 $this->select('default_role_id', 'value=1');
1137 // Enter Event Title, Summary and Description
1138 $this->type('title', $params['title']);
1139 $this->type('summary', 'This is a great conference. Sign up now!');
1140 $this->fillRichTextField('description', 'Here is a description for this event.', 'CKEditor');
1142 // Choose Start and End dates.
1143 // Using helper webtestFillDate function.
1144 $this->webtestFillDateTime('start_date', '+1 week');
1145 $this->webtestFillDateTime('end_date', '+1 week 1 day 8 hours ');
1147 $this->type('max_participants', '50');
1148 $this->click('is_map');
1149 $this->click('_qf_EventInfo_upload-bottom');
1151 // Wait for Location tab form to load
1152 $this->waitForPageToLoad($this->getTimeoutMsec());
1155 $this->click('link=Fees');
1156 $this->waitForElementPresent('_qf_Fee_upload-bottom');
1157 $this->click('xpath=//form[@id="Fee"]/div[2]/table/tbody/tr[2]/td[2]/label[contains(text(), "Yes")]');
1158 $processorName = $params['payment_processor'];
1159 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='$processorName']");
1160 $this->select('financial_type_id', 'value=4');
1162 if (array_key_exists('price_set', $params)) {
1163 $this->select('price_set_id', 'label=' . $params['price_set']);
1165 if (array_key_exists('fee_level', $params)) {
1167 foreach ($params['fee_level'] as $label => $amount) {
1168 $this->type("label_{$counter}", $label);
1169 $this->type("value_{$counter}", $amount);
1174 $this->clickLink('_qf_Fee_upload-bottom', 'link=Online Registration', FALSE);
1176 // Go to Online Registration tab
1177 $this->click('link=Online Registration');
1178 $this->waitForElementPresent('_qf_Registration_upload-bottom');
1180 $this->check('is_online_registration');
1181 $this->assertChecked('is_online_registration');
1183 if (isset($params['is_multiple_registrations']) && $params['is_multiple_registrations']) {
1184 $this->click('is_multiple_registrations');
1187 $this->fillRichTextField('intro_text', 'Fill in all the fields below and click Continue.');
1189 // enable confirmation email
1190 $this->click('CIVICRM_QFID_1_is_email_confirm');
1191 $this->type('confirm_from_name', 'Jane Doe');
1192 $this->type('confirm_from_email', 'jane.doe@example.org');
1194 $this->click('_qf_Registration_upload-bottom');
1195 $this->waitForTextPresent("'Fees' information has been saved.");
1197 // verify event input on info page
1198 // start at Manage Events listing
1199 $this->openCiviPage('event/manage', 'reset=1');
1200 $this->click('link=' . $params['title']);
1202 $this->waitForPageToLoad($this->getTimeoutMsec());
1203 return $this->getLocation();
1206 function _fillRegisterWithBillingInfo() {
1207 $this->waitForElementPresent('credit_card_type');
1208 $this->select('credit_card_type', 'value=Visa');
1209 $this->type('credit_card_number', '4111111111111111');
1210 $this->type('cvv2', '000');
1211 $this->select('credit_card_exp_date[M]', 'value=1');
1212 $this->select('credit_card_exp_date[Y]', 'value=2020');
1213 $this->type('billing_first_name', 'Jane_' . substr(sha1(rand()), 0, 5));
1214 $this->type('billing_last_name', 'San_' . substr(sha1(rand()), 0, 5));
1215 $this->type('billing_street_address-5', '15 Main St.');
1216 $this->type(' billing_city-5', 'San Jose');
1217 $this->select('billing_country_id-5', 'value=1228');
1218 $this->select('billing_state_province_id-5', 'value=1004');
1219 $this->type('billing_postal_code-5', '94129');
1221 $this->click('_qf_Register_upload-bottom');
1222 $this->waitForPageToLoad($this->getTimeoutMsec());
1225 function _checkConfirmationAndRegister() {
1226 $confirmStrings = array('Event Fee(s)', 'Billing Name and Address', 'Credit Card Information');
1227 $this->assertStringsPresent($confirmStrings);
1228 $this->click('_qf_Confirm_next-bottom');
1229 $this->waitForPageToLoad($this->getTimeoutMsec());
1230 $thankStrings = array('Thank You for Registering', 'Event Total', 'Transaction Date');
1231 $this->assertStringsPresent($thankStrings);