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_ParticipantCountTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testParticipantCountWithFeelevel() {
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 $eventTitle = 'A Conference - ' . substr(sha1(rand()), 0, 7);
45 'title' => $eventTitle,
48 'payment_processor' => $processorName,
51 'Non-Member' => '325.00',
55 $infoEvent = $this->_testAddEvent($paramsEvent);
57 // logout to register for event.
58 $this->webtestLogout();
60 // Register Participant 1
61 // visit event info page
62 $this->open($infoEvent);
63 $this->waitForPageToLoad($this->getTimeoutMsec());
66 $this->click('link=Register Now');
67 $this->waitForElementPresent('_qf_Register_upload-bottom');
68 $this->click("xpath=//input[@class='crm-form-radio']");
70 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
71 $this->type('first_name', 'Mary');
72 $this->type('last_name', 'Jones'. substr(sha1(rand()), 0, 5));
73 $this->type('email-Primary', $email);
75 // fill billing details and register
76 $this->_testRegisterWithBillingInfo();
78 // Register Participant 2
79 // visit event info page
80 $this->open($infoEvent);
83 $this->click('link=Register Now');
84 $this->waitForElementPresent('_qf_Register_upload-bottom');
86 $this->click("xpath=//input[@class='crm-form-radio']");
87 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
88 $this->type('first_name', 'Mary');
89 $this->type('last_name', 'Jones'. substr(sha1(rand()), 0, 5));
90 $this->type('email-Primary', $email);
92 // fill billing details and register
93 $this->_testRegisterWithBillingInfo();
95 // login to check participant count
96 $this->webtestLogin();
99 $this->openCiviPage("event/search", "reset=1", 'participant_fee_amount_low');
100 $this->select2("event_id", $eventTitle);
101 $this->click('_qf_Search_refresh');
102 $this->waitForPageToLoad($this->getTimeoutMsec());
104 // verify number of registered participants
105 $this->assertStringsPresent(array('2 Result'));
108 function testParticipantCountWithPriceset() {
109 // Log in using webtestLogin() method
110 $this->webtestLogin();
112 // We need a payment processor
113 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
114 $this->webtestAddPaymentProcessor($processorName);
117 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
118 $this->_testAddSet($priceset);
120 // create price fields
122 'Full Conference' => array(
124 'amount' => '525.00',
127 'Meal Choice' => array(
131 'label' => 'Chicken',
132 'amount' => '525.00',
136 'label' => 'Vegetarian',
137 'amount' => '200.00',
142 'Pre-conference Meetup?' => array(
156 'Evening Sessions' => array(
157 'type' => 'CheckBox',
160 'label' => 'First Five',
161 'amount' => '100.00',
165 'label' => 'Second Four',
173 foreach ($fields as $label => $field) {
174 $this->type('label', $label);
175 $this->select('html_type', "value={$field['type']}");
177 if ($field['type'] == 'Text') {
178 $this->type('price', $field['amount']);
180 $this->waitForElementPresent('count');
181 $this->type('count', $field['count']);
182 $this->check('is_required');
185 $this->_testAddMultipleChoiceOptions($field['options']);
187 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom');
191 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
192 $paramsEvent = array(
193 'title' => $eventTitle,
195 'event_type_id' => 4,
196 'payment_processor' => $processorName,
197 'price_set' => $priceset,
200 $infoEvent = $this->_testAddEvent($paramsEvent);
202 // logout to register for event.
203 $this->webtestLogout();
205 $priceFieldOptionCounts = $participants = array();
207 // Register Participant 1
208 // visit event info page
209 $this->open($infoEvent);
210 $this->waitForPageToLoad($this->getTimeoutMsec());
212 // register for event
213 $this->click('link=Register Now');
214 $this->waitForElementPresent('_qf_Register_upload-bottom');
216 $this->type("xpath=//input[@class='four crm-form-text required']", '1');
218 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
219 $participants[1] = array(
221 'first_name' => 'Jane_' . substr(sha1(rand()), 0, 5),
222 'last_name' => 'San_' . substr(sha1(rand()), 0, 5),
225 $this->type('first_name', $participants[1]['first_name']);
226 $this->type('last_name', $participants[1]['last_name']);
227 $this->type('email-Primary', $email);
229 // fill billing related info and register
230 $this->_testRegisterWithBillingInfo($participants[1]);
232 // Options filled by 1st participants.
233 $priceFieldOptionCounts[1] = array(
234 'Full Conference' => 1,
235 'Meal Choice - Chicken' => 1,
236 'Meal Choice - Vegetarian' => 0,
237 'Pre-conference Meetup? - Yes' => 1,
238 'Pre-conference Meetup? - No' => 0,
239 'Evening Sessions - First Five' => 1,
240 'Evening Sessions - Second Four' => 0,
243 // Register Participant 1
244 // visit event info page
245 $this->open($infoEvent);
247 // register for event
248 $this->click('link=Register Now');
249 $this->waitForElementPresent('_qf_Register_upload-bottom');
251 $this->type("xpath=//input[@class='four crm-form-text required']", '2');
252 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
254 $participants[2] = array(
256 'first_name' => 'Jane_' . substr(sha1(rand()), 0, 5),
257 'last_name' => 'San_' . substr(sha1(rand()), 0, 5),
260 $this->type('first_name', $participants[2]['first_name']);
261 $this->type('last_name', $participants[2]['last_name']);
262 $this->type('email-Primary', $email);
264 // fill billing related info and register
265 $this->_testRegisterWithBillingInfo($participants[2]);
267 // Options filled by 2nd participants.
268 $priceFieldOptionCounts[2] = array(
269 'Full Conference' => 2,
270 'Meal Choice - Chicken' => 1,
271 'Meal Choice - Vegetarian' => 0,
272 'Pre-conference Meetup? - Yes' => 1,
273 'Pre-conference Meetup? - No' => 0,
274 'Evening Sessions - First Five' => 1,
275 'Evening Sessions - Second Four' => 0,
278 // login to check participant count
279 $this->webtestLogin();
282 $this->openCiviPage('event/search', 'reset=1', 'participant_fee_amount_low');
283 $this->select2("event_id", $eventTitle);
284 $this->click('_qf_Search_refresh');
285 $this->waitForPageToLoad($this->getTimeoutMsec());
287 // verify number of participants records and total participant count
288 $this->assertStringsPresent(array('2 Result', 'Actual participant count : 24'));
290 // CRM-7953, check custom search Price Set Details for Event
292 $this->_testPricesetDetailsCustomSearch($paramsEvent, $participants, $priceFieldOptionCounts);
295 function _testAddSet($setTitle, $financialType = 'Event Fee') {
296 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
298 // Enter Priceset fields (Title, Used For ...)
299 $this->type('title', $setTitle);
300 $this->check('extends[1]');
301 $this->select("css=select.crm-form-select", "label={$financialType}");
302 $this->type('help_pre', 'This is test priceset.');
304 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
305 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom');
308 function _testAddMultipleChoiceOptions($options) {
309 foreach ($options as $oIndex => $oValue) {
310 $this->type("option_label_{$oIndex}", $oValue['label']);
311 $this->type("option_amount_{$oIndex}", $oValue['amount']);
312 if (array_key_exists('count', $oValue)) {
313 $this->waitForElementPresent("option_count_{$oIndex}");
314 $this->type("option_count_{$oIndex}", $oValue['count']);
316 $this->click('link=another choice');
318 $this->click('CIVICRM_QFID_1_2');
321 function _testAddEvent($params) {
322 $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom');
324 $this->select('event_type_id', "value={$params['event_type_id']}");
326 // Attendee role s/b selected now.
327 $this->select('default_role_id', 'value=1');
329 // Enter Event Title, Summary and Description
330 $this->type('title', $params['title']);
331 $this->type('summary', 'This is a great conference. Sign up now!');
332 $this->fillRichTextField('description', 'Here is a description for this event.', 'CKEditor');
334 // Choose Start and End dates.
335 // Using helper webtestFillDate function.
336 $this->webtestFillDateTime('start_date', '+1 week');
337 $this->webtestFillDateTime('end_date', '+1 week 1 day 8 hours ');
339 $this->type('max_participants', '50');
340 $this->click('is_map');
341 $this->click('_qf_EventInfo_upload-bottom');
343 // Wait for Location tab form to load
344 $this->waitForPageToLoad($this->getTimeoutMsec());
347 $this->click('link=Fees');
348 $this->waitForElementPresent('_qf_Fee_upload-bottom');
349 $this->click('CIVICRM_QFID_1_is_monetary');
350 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='" . $params['payment_processor'] . "']");
351 $this->select('financial_type_id', 'Event Fee');
352 if (array_key_exists('price_set', $params)) {
353 $this->select('price_set_id', 'label=' . $params['price_set']);
355 if (array_key_exists('fee_level', $params)) {
357 foreach ($params['fee_level'] as $label => $amount) {
358 $this->type("label_{$counter}", $label);
359 $this->type("value_{$counter}", $amount);
364 $this->click('_qf_Fee_upload-bottom');
365 $this->waitForElementPresent('_qf_Fee_cancel-top');
367 // Go to Online Registration tab
368 $this->click('link=Online Registration');
369 $this->waitForElementPresent('_qf_Registration_upload-bottom');
371 $this->check('is_online_registration');
372 $this->assertChecked('is_online_registration');
374 $this->fillRichTextField('intro_text', 'Fill in all the fields below and click Continue.');
376 // enable confirmation email
377 $this->click('CIVICRM_QFID_1_is_email_confirm');
378 $this->type('confirm_from_name', 'Jane Doe');
379 $this->type('confirm_from_email', 'jane.doe@example.org');
381 $this->click('_qf_Registration_upload-bottom');
382 $this->waitForElementPresent('_qf_Registration_upload-bottom');
383 $this->waitForTextPresent("'Online Registration' information has been saved.");
385 // verify event input on info page
386 // start at Manage Events listing
387 $this->openCiviPage('event/manage', 'reset=1');
388 $this->click('link=' . $params['title']);
390 $this->waitForPageToLoad($this->getTimeoutMsec());
391 return $this->getLocation();
394 function _testRegisterWithBillingInfo($participant = array()) {
395 $this->waitForElementPresent("credit_card_type");
396 $this->select('credit_card_type', 'value=Visa');
397 $this->type('credit_card_number', '4111111111111111');
398 $this->type('cvv2', '000');
399 $this->select('credit_card_exp_date[M]', 'value=1');
400 $this->select('credit_card_exp_date[Y]', 'value=2020');
401 $this->type('billing_first_name', isset($participant['first_name']) ?
$participant['first_name'] : 'Jane_' . substr(sha1(rand()), 0, 5));
402 $this->type('billing_last_name', isset($participant['last_name']) ?
$participant['last_name'] : 'San_' . substr(sha1(rand()), 0, 5));
403 $this->type('billing_street_address-5', '15 Main St.');
404 $this->type(' billing_city-5', 'San Jose');
405 $this->select('billing_country_id-5', 'value=1228');
406 $this->select('billing_state_province_id-5', 'value=1004');
407 $this->type('billing_postal_code-5', '94129');
409 $this->clickLink('_qf_Register_upload-bottom', '_qf_Confirm_next-bottom');
410 $confirmStrings = array('Event Fee(s)', 'Billing Name and Address', 'Credit Card Information');
411 $this->assertStringsPresent($confirmStrings);
412 $this->click('_qf_Confirm_next-bottom');
413 $this->waitForPageToLoad($this->getTimeoutMsec());
414 $thankStrings = array('Thank You for Registering', 'Event Total', 'Transaction Date');
415 $this->assertStringsPresent($thankStrings);
418 function _testPricesetDetailsCustomSearch($eventParams, $participants, $priceFieldOptionCounts) {
419 $this->openCiviPage('contact/search/custom', 'csid=9&reset=1');
421 $this->select('event_id', 'label=' . $eventParams['title']);
422 $this->click('_qf_Custom_refresh-bottom');
423 $this->waitForPageToLoad($this->getTimeoutMsec());
425 $tableHeaders = array('Contact Id', 'Participant Id', 'Name');
426 $tableHeaders = array_merge($tableHeaders, array_keys(current($priceFieldOptionCounts)));
429 foreach ($tableHeaders as $header) {
430 $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector row-highlight']/thead/tr[1]/th[$tdnum]", $header);
434 foreach ($participants as $participantNum => $participant) {
436 $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']}"));
437 foreach ($priceFieldOptionCounts[$participantNum] as $priceFieldOptionCount) {
439 $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector row-highlight']/tbody/tr[{$participantNum}]/td[{$tdnum}]", preg_quote($priceFieldOptionCount));