3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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_ParticipantCountTest
32 class WebTest_Event_ParticipantCountTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testParticipantCountWithFeelevel() {
39 $this->markTestSkipped('Skipping for now as it works fine locally.');
40 // Log in using webtestLogin() method
41 $this->webtestLogin();
43 // Use default payment processor
44 $processorName = 'Test Processor';
45 $this->webtestAddPaymentProcessor($processorName);
48 $eventTitle = 'A Conference - ' . substr(sha1(rand()), 0, 7);
50 'title' => $eventTitle,
53 'payment_processor' => $processorName,
56 'Non-Member' => '325.00',
60 $infoEvent = $this->_testAddEvent($paramsEvent);
62 // logout to register for event.
63 $this->webtestLogout();
65 // Register Participant 1
66 // visit event info page
67 $this->open($infoEvent);
68 $this->waitForPageToLoad($this->getTimeoutMsec());
71 $this->click('link=Register Now');
72 $this->waitForElementPresent('_qf_Register_upload-bottom');
73 $this->click("xpath=//input[@class='crm-form-radio']");
75 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
76 $this->type('first_name', 'Mary');
77 $this->type('last_name', 'Jones' . substr(sha1(rand()), 0, 5));
78 $this->type('email-Primary', $email);
80 // fill billing details and register
81 $this->_testRegisterWithBillingInfo();
83 // Register Participant 2
84 // visit event info page
85 $this->open($infoEvent);
88 $this->click('link=Register Now');
89 $this->waitForElementPresent('_qf_Register_upload-bottom');
91 $this->click("xpath=//input[@class='crm-form-radio']");
92 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
93 $this->type('first_name', 'Mary');
94 $this->type('last_name', 'Jones' . substr(sha1(rand()), 0, 5));
95 $this->type('email-Primary', $email);
97 // fill billing details and register
98 $this->_testRegisterWithBillingInfo();
100 // login to check participant count
101 $this->webtestLogin();
104 $this->openCiviPage("event/search", "reset=1", 'participant_fee_amount_low');
105 $this->select2("event_id", $eventTitle);
106 $this->click('_qf_Search_refresh');
107 $this->waitForPageToLoad($this->getTimeoutMsec());
109 // verify number of registered participants
110 $this->assertElementContainsText("xpath=//div[@class='crm-results-block']//div/table/tbody/tr/td", '2 Results');
113 public function testParticipantCountWithPriceset() {
114 // Log in using webtestLogin() method
115 $this->webtestLogin();
117 // Use default payment processor
118 $processorName = 'Test Processor';
119 $this->webtestAddPaymentProcessor($processorName);
122 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
123 $this->_testAddSet($priceset);
125 // create price fields
127 'Full Conference' => array(
129 'amount' => '525.00',
132 'Meal Choice' => array(
136 'label' => 'Chicken',
137 'amount' => '525.00',
141 'label' => 'Vegetarian',
142 'amount' => '200.00',
147 'Pre-conference Meetup?' => array(
161 'Evening Sessions' => array(
162 'type' => 'CheckBox',
165 'label' => 'First Five',
166 'amount' => '100.00',
170 'label' => 'Second Four',
178 foreach ($fields as $label => $field) {
179 $this->waitForAjaxContent();
180 $this->select('html_type', "value={$field['type']}");
181 if ($field['type'] == 'Text') {
182 $this->type('price', $field['amount']);
184 $this->waitForElementPresent('count');
185 $this->type('count', $field['count']);
186 $this->check('is_required');
189 $this->_testAddMultipleChoiceOptions($field['options']);
191 $this->type('label', $label);
192 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom', FALSE);
193 $this->waitForText("crm-notification-container", "Price Field '$label' has been saved.");
197 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
198 $paramsEvent = array(
199 'title' => $eventTitle,
201 'event_type_id' => 4,
202 'payment_processor' => $processorName,
203 'price_set' => $priceset,
206 $infoEvent = $this->_testAddEvent($paramsEvent);
208 // logout to register for event.
209 $this->webtestLogout();
211 $priceFieldOptionCounts = $participants = array();
213 // Register Participant 1
214 // visit event info page
215 $this->open($infoEvent);
216 $this->waitForPageToLoad($this->getTimeoutMsec());
218 // register for event
219 $this->click('link=Register Now');
220 $this->waitForElementPresent('_qf_Register_upload-bottom');
222 $this->type("xpath=//input[@class='four crm-form-text required']", '1');
224 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
225 $participants[1] = array(
227 'first_name' => 'Jane_' . substr(sha1(rand()), 0, 5),
228 'last_name' => 'San_' . substr(sha1(rand()), 0, 5),
231 $this->type('first_name', $participants[1]['first_name']);
232 $this->type('last_name', $participants[1]['last_name']);
233 $this->type('email-Primary', $email);
235 // fill billing related info and register
236 $this->_testRegisterWithBillingInfo($participants[1]);
238 // Options filled by 1st participants.
239 $priceFieldOptionCounts[1] = array(
240 'Full Conference' => 1,
241 'Meal Choice - Chicken' => 1,
242 'Meal Choice - Vegetarian' => 0,
243 'Pre-conference Meetup? - Yes' => 1,
244 'Pre-conference Meetup? - No' => 0,
245 'Evening Sessions - First Five' => 1,
246 'Evening Sessions - Second Four' => 0,
249 // Register Participant 1
250 // visit event info page
251 $this->open($infoEvent);
253 // register for event
254 $this->click('link=Register Now');
255 $this->waitForElementPresent('_qf_Register_upload-bottom');
257 $this->type("xpath=//input[@class='four crm-form-text required']", '2');
258 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
260 $participants[2] = array(
262 'first_name' => 'Jane_' . substr(sha1(rand()), 0, 5),
263 'last_name' => 'San_' . substr(sha1(rand()), 0, 5),
266 $this->type('first_name', $participants[2]['first_name']);
267 $this->type('last_name', $participants[2]['last_name']);
268 $this->type('email-Primary', $email);
270 // fill billing related info and register
271 $this->_testRegisterWithBillingInfo($participants[2]);
273 // Options filled by 2nd participants.
274 $priceFieldOptionCounts[2] = array(
275 'Full Conference' => 2,
276 'Meal Choice - Chicken' => 1,
277 'Meal Choice - Vegetarian' => 0,
278 'Pre-conference Meetup? - Yes' => 1,
279 'Pre-conference Meetup? - No' => 0,
280 'Evening Sessions - First Five' => 1,
281 'Evening Sessions - Second Four' => 0,
284 // login to check participant count
285 $this->webtestLogin();
288 $this->openCiviPage('event/search', 'reset=1', 'participant_fee_amount_low');
289 $this->waitForElementPresent('event_id');
290 $this->select2("event_id", $eventTitle);
291 $this->click('_qf_Search_refresh');
292 $this->waitForPageToLoad($this->getTimeoutMsec());
294 // verify number of participants records and total participant count
295 $this->waitForAjaxContent();
296 $this->assertStringsPresent(array('2 Results', 'Actual participant count : 24'));
298 // CRM-7953, check custom search Price Set Details for Event
300 $this->_testPricesetDetailsCustomSearch($paramsEvent, $participants, $priceFieldOptionCounts);
305 * @param string $financialType
307 public function _testAddSet($setTitle, $financialType = 'Event Fee') {
308 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
310 // Enter Priceset fields (Title, Used For ...)
311 $this->waitForElementPresent("title");
312 $this->type('title', $setTitle);
313 $this->check('extends[1]');
314 $this->select("css=select.crm-form-select", "label={$financialType}");
315 $this->waitForElementPresent("help_pre");
316 $this->type('help_pre', 'This is test priceset.');
318 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
319 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom');
325 public function _testAddMultipleChoiceOptions($options) {
326 foreach ($options as $oIndex => $oValue) {
327 $this->type("option_label_{$oIndex}", $oValue['label']);
328 $this->type("option_amount_{$oIndex}", $oValue['amount']);
329 if (array_key_exists('count', $oValue)) {
330 $this->waitForElementPresent("option_count_{$oIndex}");
331 $this->type("option_count_{$oIndex}", $oValue['count']);
333 $this->click('link=another choice');
335 $this->click('CIVICRM_QFID_1_2');
339 * @param array $params
343 public function _testAddEvent($params) {
344 $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom');
346 $this->select('event_type_id', "value={$params['event_type_id']}");
348 // Attendee role s/b selected now.
349 $this->select('default_role_id', 'value=1');
351 // Enter Event Title, Summary and Description
352 $this->type('title', $params['title']);
353 $this->type('summary', 'This is a great conference. Sign up now!');
354 $this->fillRichTextField('description', 'Here is a description for this event.', 'CKEditor');
356 // Choose Start and End dates.
357 // Using helper webtestFillDate function.
358 $this->webtestFillDateTime('start_date', '+1 week');
359 $this->webtestFillDateTime('end_date', '+1 week 1 day 8 hours ');
361 $this->type('max_participants', '50');
362 $this->click('is_map');
363 $this->click('_qf_EventInfo_upload-bottom');
365 // Wait for Location tab form to load
366 $this->waitForPageToLoad($this->getTimeoutMsec());
369 $this->click('link=Fees');
370 $this->waitForElementPresent('_qf_Fee_upload-bottom');
371 $this->click('CIVICRM_QFID_1_is_monetary');
372 $this->select2('payment_processor', $params['payment_processor'], TRUE);
374 $this->select('financial_type_id', 'Event Fee');
375 if (array_key_exists('price_set', $params)) {
376 $this->select('price_set_id', 'label=' . $params['price_set']);
378 if (array_key_exists('fee_level', $params)) {
380 foreach ($params['fee_level'] as $label => $amount) {
381 $this->type("label_{$counter}", $label);
382 $this->type("value_{$counter}", $amount);
387 $this->click('_qf_Fee_upload-bottom');
388 $this->waitForElementPresent('_qf_Fee_cancel-top');
390 // Go to Online Registration tab
391 $this->click('link=Online Registration');
392 $this->waitForElementPresent('_qf_Registration_upload-bottom');
394 $this->check('is_online_registration');
395 $this->assertChecked('is_online_registration');
397 $this->click('intro_text');
398 $this->fillRichTextField('intro_text', 'Fill in all the fields below and click Continue.', 'CKEditor', TRUE);
400 // enable confirmation email
401 $this->click('CIVICRM_QFID_1_is_email_confirm');
402 $this->type('confirm_from_name', 'Jane Doe');
403 $this->type('confirm_from_email', 'jane.doe@example.org');
405 $this->click('_qf_Registration_upload-bottom');
406 $this->waitForElementPresent('_qf_Registration_upload-bottom');
407 $this->waitForTextPresent("'Online Registration' information has been saved.");
409 // verify event input on info page
410 // start at Manage Events listing
411 $this->openCiviPage('event/manage', 'reset=1');
412 $this->click('link=' . $params['title']);
414 $this->waitForPageToLoad($this->getTimeoutMsec());
415 return $this->getLocation();
419 * @param array $participant
421 public function _testRegisterWithBillingInfo($participant = array()) {
422 $this->waitForElementPresent("credit_card_type");
423 $this->select('credit_card_type', 'value=Visa');
424 $this->type('credit_card_number', '4111111111111111');
425 $this->type('cvv2', '000');
426 $this->select('credit_card_exp_date[M]', 'value=1');
427 $this->select('credit_card_exp_date[Y]', 'value=2020');
428 $this->type('billing_first_name', isset($participant['first_name']) ?
$participant['first_name'] : 'Jane_' . substr(sha1(rand()), 0, 5));
429 $this->type('billing_last_name', isset($participant['last_name']) ?
$participant['last_name'] : 'San_' . substr(sha1(rand()), 0, 5));
430 $this->type('billing_street_address-5', '15 Main St.');
431 $this->type(' billing_city-5', 'San Jose');
432 $this->select('billing_country_id-5', 'value=1228');
433 $this->select('billing_state_province_id-5', 'value=1004');
434 $this->type('billing_postal_code-5', '94129');
436 $this->clickLink('_qf_Register_upload-bottom', '_qf_Confirm_next-bottom');
437 $confirmStrings = array('Event Fee(s)', 'Billing Name and Address', 'Credit Card Information');
438 $this->assertStringsPresent($confirmStrings);
439 $this->click('_qf_Confirm_next-bottom');
440 $this->waitForPageToLoad($this->getTimeoutMsec());
441 $thankStrings = array('Thank You for Registering', 'Event Total', 'Transaction Date');
442 $this->assertStringsPresent($thankStrings);
446 * @param array $eventParams
447 * @param $participants
448 * @param $priceFieldOptionCounts
450 public function _testPricesetDetailsCustomSearch($eventParams, $participants, $priceFieldOptionCounts) {
451 $this->openCiviPage('contact/search/custom', 'csid=9&reset=1');
453 $this->select('event_id', 'label=' . $eventParams['title']);
454 $this->click('_qf_Custom_refresh-bottom');
455 $this->waitForPageToLoad($this->getTimeoutMsec());
457 $tableHeaders = array('Contact ID', 'Participant ID', 'Name');
458 $tableHeaders = array_merge($tableHeaders, array_keys(current($priceFieldOptionCounts)));
461 foreach ($tableHeaders as $header) {
462 $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector row-highlight']/thead/tr[1]/th[$tdnum]", $header);
466 foreach ($participants as $participantNum => $participant) {
468 $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector row-highlight']/tbody/tr[{$participantNum}]/td[{$tdnum}]", preg_quote("{$participant['first_name']} {$participant['last_name']}"));
469 foreach ($priceFieldOptionCounts[$participantNum] as $priceFieldOptionCount) {
471 $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector row-highlight']/tbody/tr[{$participantNum}]/td[{$tdnum}]", preg_quote($priceFieldOptionCount));